2022-02-17 04:31:59 +00:00
|
|
|
import { put, select, take } from "redux-saga/effects";
|
2021-08-27 09:25:28 +00:00
|
|
|
import { getWidgetByName } from "sagas/selectors";
|
|
|
|
|
import {
|
|
|
|
|
resetChildrenMetaProperty,
|
|
|
|
|
resetWidgetMetaProperty,
|
|
|
|
|
} from "actions/metaActions";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
2021-12-23 14:17:20 +00:00
|
|
|
import {
|
|
|
|
|
ActionTriggerType,
|
|
|
|
|
ResetWidgetDescription,
|
|
|
|
|
} from "entities/DataTree/actionTriggers";
|
|
|
|
|
import {
|
|
|
|
|
ActionValidationError,
|
|
|
|
|
TriggerFailureError,
|
|
|
|
|
} from "sagas/ActionExecution/errorUtils";
|
|
|
|
|
import { getType, Types } from "utils/TypeHelpers";
|
2022-06-21 13:57:34 +00:00
|
|
|
import { FlattenedWidgetProps } from "widgets/constants";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
2022-06-25 05:30:54 +00:00
|
|
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
|
|
|
|
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
|
|
|
|
import { isWidget } from "workers/evaluationUtils";
|
2021-08-27 09:25:28 +00:00
|
|
|
|
|
|
|
|
export default function* resetWidgetActionSaga(
|
|
|
|
|
payload: ResetWidgetDescription["payload"],
|
|
|
|
|
) {
|
2021-12-23 14:17:20 +00:00
|
|
|
const { widgetName } = payload;
|
|
|
|
|
if (getType(widgetName) !== Types.STRING) {
|
|
|
|
|
throw new ActionValidationError(
|
|
|
|
|
ActionTriggerType.RESET_WIDGET_META_RECURSIVE_BY_NAME,
|
|
|
|
|
"widgetName",
|
|
|
|
|
Types.STRING,
|
|
|
|
|
getType(widgetName),
|
2021-09-23 07:21:57 +00:00
|
|
|
);
|
2021-08-27 09:25:28 +00:00
|
|
|
}
|
2022-06-25 05:30:54 +00:00
|
|
|
const dataTree: DataTree = yield select(getDataTree);
|
2021-08-27 09:25:28 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
const widget: FlattenedWidgetProps | undefined = yield select(
|
|
|
|
|
getWidgetByName,
|
|
|
|
|
widgetName,
|
|
|
|
|
);
|
2021-08-27 09:25:28 +00:00
|
|
|
if (!widget) {
|
2021-12-23 14:17:20 +00:00
|
|
|
throw new TriggerFailureError(`Widget ${payload.widgetName} not found`);
|
2021-08-27 09:25:28 +00:00
|
|
|
}
|
2022-06-25 05:30:54 +00:00
|
|
|
const evaluatedEntity = dataTree[widget.widgetName];
|
|
|
|
|
if (isWidget(evaluatedEntity)) {
|
|
|
|
|
yield put(resetWidgetMetaProperty(widget.widgetId, evaluatedEntity));
|
|
|
|
|
if (payload.resetChildren) {
|
|
|
|
|
yield put(resetChildrenMetaProperty(widget.widgetId));
|
|
|
|
|
}
|
2021-08-27 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-17 04:31:59 +00:00
|
|
|
yield take(ReduxActionTypes.RESET_WIDGET_META_EVALUATED);
|
|
|
|
|
|
2021-08-27 09:25:28 +00:00
|
|
|
AppsmithConsole.info({
|
|
|
|
|
text: `resetWidget('${payload.widgetName}', ${payload.resetChildren}) was triggered`,
|
|
|
|
|
});
|
|
|
|
|
}
|