2021-08-27 09:25:28 +00:00
|
|
|
import { put, select } from "redux-saga/effects";
|
|
|
|
|
import { getWidgetByName } from "sagas/selectors";
|
|
|
|
|
import {
|
|
|
|
|
resetChildrenMetaProperty,
|
|
|
|
|
resetWidgetMetaProperty,
|
|
|
|
|
} from "actions/metaActions";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
|
|
|
import { ResetWidgetDescription } from "entities/DataTree/actionTriggers";
|
2021-09-23 07:21:57 +00:00
|
|
|
import { TriggerMeta } from "sagas/ActionExecution/ActionExecutionSagas";
|
|
|
|
|
import { TriggerFailureError } from "sagas/ActionExecution/errorUtils";
|
2021-08-27 09:25:28 +00:00
|
|
|
|
|
|
|
|
export default function* resetWidgetActionSaga(
|
|
|
|
|
payload: ResetWidgetDescription["payload"],
|
2021-09-23 07:21:57 +00:00
|
|
|
triggerMeta: TriggerMeta,
|
2021-08-27 09:25:28 +00:00
|
|
|
) {
|
|
|
|
|
if (typeof payload.widgetName !== "string") {
|
2021-09-23 07:21:57 +00:00
|
|
|
throw new TriggerFailureError(
|
|
|
|
|
"widgetName needs to be a string",
|
|
|
|
|
triggerMeta,
|
|
|
|
|
);
|
2021-08-27 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const widget = yield select(getWidgetByName, payload.widgetName);
|
|
|
|
|
if (!widget) {
|
2021-09-23 07:21:57 +00:00
|
|
|
throw new TriggerFailureError(
|
|
|
|
|
`widget ${payload.widgetName} not found`,
|
|
|
|
|
triggerMeta,
|
|
|
|
|
);
|
2021-08-27 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield put(resetWidgetMetaProperty(widget.widgetId));
|
|
|
|
|
if (payload.resetChildren) {
|
|
|
|
|
yield put(resetChildrenMetaProperty(widget.widgetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppsmithConsole.info({
|
|
|
|
|
text: `resetWidget('${payload.widgetName}', ${payload.resetChildren}) was triggered`,
|
|
|
|
|
});
|
|
|
|
|
}
|