* fix: [WIP] reset meta to default value * refactor * fix reset child widget and type in metaReducer * Fix type and refactor test * fix multiselect click * Add jest test for reset widget action * Add cypress test * Add comments * Add more cases as per comment * remove `only` from test case * Add default value case of array with values * MultiSelect spec fix * fix currencyInput reset * refactor test code suggested in comments * fix type * fix more type * fix cypress test Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { put, select, take } from "redux-saga/effects";
|
|
import { getWidgetByName } from "sagas/selectors";
|
|
import {
|
|
resetChildrenMetaProperty,
|
|
resetWidgetMetaProperty,
|
|
} from "actions/metaActions";
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
import {
|
|
ActionTriggerType,
|
|
ResetWidgetDescription,
|
|
} from "entities/DataTree/actionTriggers";
|
|
import {
|
|
ActionValidationError,
|
|
TriggerFailureError,
|
|
} from "sagas/ActionExecution/errorUtils";
|
|
import { getType, Types } from "utils/TypeHelpers";
|
|
import { FlattenedWidgetProps } from "widgets/constants";
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
|
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
|
import { isWidget } from "workers/evaluationUtils";
|
|
|
|
export default function* resetWidgetActionSaga(
|
|
payload: ResetWidgetDescription["payload"],
|
|
) {
|
|
const { widgetName } = payload;
|
|
if (getType(widgetName) !== Types.STRING) {
|
|
throw new ActionValidationError(
|
|
ActionTriggerType.RESET_WIDGET_META_RECURSIVE_BY_NAME,
|
|
"widgetName",
|
|
Types.STRING,
|
|
getType(widgetName),
|
|
);
|
|
}
|
|
const dataTree: DataTree = yield select(getDataTree);
|
|
|
|
const widget: FlattenedWidgetProps | undefined = yield select(
|
|
getWidgetByName,
|
|
widgetName,
|
|
);
|
|
if (!widget) {
|
|
throw new TriggerFailureError(`Widget ${payload.widgetName} not found`);
|
|
}
|
|
const evaluatedEntity = dataTree[widget.widgetName];
|
|
if (isWidget(evaluatedEntity)) {
|
|
yield put(resetWidgetMetaProperty(widget.widgetId, evaluatedEntity));
|
|
if (payload.resetChildren) {
|
|
yield put(resetChildrenMetaProperty(widget.widgetId));
|
|
}
|
|
}
|
|
|
|
yield take(ReduxActionTypes.RESET_WIDGET_META_EVALUATED);
|
|
|
|
AppsmithConsole.info({
|
|
text: `resetWidget('${payload.widgetName}', ${payload.resetChildren}) was triggered`,
|
|
});
|
|
}
|