PromucFlow_constructor/app/client/src/sagas/ReplaySaga.ts

378 lines
11 KiB
TypeScript
Raw Normal View History

2021-12-07 09:45:18 +00:00
import {
takeEvery,
put,
select,
call,
takeLatest,
all,
delay,
} from "redux-saga/effects";
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
import * as Sentry from "@sentry/react";
import log from "loglevel";
import {
getIsPropertyPaneVisible,
getCurrentWidgetId,
} from "../selectors/propertyPaneSelectors";
feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
import { closePropertyPane } from "actions/widgetActions";
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
import {
selectMultipleWidgetsInitAction,
selectWidgetAction,
} from "actions/widgetSelectionActions";
import {
2021-12-07 09:45:18 +00:00
ReduxAction,
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
ReduxActionTypes,
ReplayReduxActionTypes,
} from "constants/ReduxActionConstants";
import { flashElementsById } from "utils/helpers";
import {
scrollWidgetIntoView,
processUndoRedoToasts,
2021-12-07 09:45:18 +00:00
highlightReplayElement,
switchTab,
expandAccordion,
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
} from "utils/replayHelpers";
2021-12-07 09:45:18 +00:00
import { updateAndSaveLayout } from "actions/pageActions";
import AnalyticsUtil from "../utils/AnalyticsUtil";
import { commentModeSelector } from "selectors/commentsSelectors";
import { snipingModeSelector } from "selectors/editorSelectors";
import { findFieldInfo, REPLAY_FOCUS_DELAY } from "entities/Replay/replayUtils";
import { setActionProperty, updateAction } from "actions/pluginActionActions";
import { getEntityInCurrentPath } from "./RecentEntitiesSagas";
import { updateJSCollectionBody } from "actions/jsPaneActions";
import {
updateReplayEntitySaga,
workerComputeUndoRedo,
} from "./EvaluationsSaga";
import { createBrowserHistory } from "history";
import {
getEditorConfig,
getPluginForm,
getSettingConfig,
} from "selectors/entitiesSelector";
import {
Action,
isAPIAction,
isQueryAction,
isSaaSAction,
} from "entities/Action";
import { API_EDITOR_TABS } from "constants/ApiEditorConstants";
import { EDITOR_TABS } from "constants/QueryEditorConstants";
import _, { isEmpty } from "lodash";
import { ReplayEditorUpdate } from "entities/Replay/ReplayEntity/ReplayEditor";
import { ENTITY_TYPE } from "entities/AppsmithConsole";
import { Datasource } from "entities/Datasource";
import { initialize } from "redux-form";
import {
API_EDITOR_FORM_NAME,
DATASOURCE_DB_FORM,
DATASOURCE_REST_API_FORM,
QUERY_EDITOR_FORM_NAME,
} from "constants/forms";
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
export type UndoRedoPayload = {
operation: ReplayReduxActionTypes;
};
export default function* undoRedoListenerSaga() {
2021-12-07 09:45:18 +00:00
yield all([
takeEvery(ReduxActionTypes.UNDO_REDO_OPERATION, undoRedoSaga),
takeLatest(ReduxActionTypes.UPDATE_REPLAY_ENTITY, updateReplayEntitySaga),
]);
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
}
/**
* This Saga is called if the type of update is a property change
* @param replay
* @returns
*/
export function* openPropertyPaneSaga(replay: any) {
try {
if (Object.keys(replay.widgets).length > 1) {
yield put(selectWidgetAction(replay.widgets[0], false));
}
const replayWidgetId = Object.keys(replay.widgets)[0];
if (!replayWidgetId || !replay.widgets[replayWidgetId].propertyUpdates)
return;
scrollWidgetIntoView(replayWidgetId);
const isPropertyPaneVisible: boolean = yield select(
getIsPropertyPaneVisible,
);
const selectedWidgetId: string = yield select(getCurrentWidgetId);
//if property pane is not visible, select the widget and force open property pane
if (selectedWidgetId !== replayWidgetId || !isPropertyPaneVisible) {
yield put(selectWidgetAction(replayWidgetId, false));
}
flashElementsById(
btoa(
replay.widgets[replayWidgetId].propertyUpdates.slice(0, 2).join("."),
),
0,
1000,
);
} catch (e) {
log.error(e);
Sentry.captureException(e);
}
}
/**
* This saga is called when type of chenge is not a property Change
* @param replay
* @returns
*/
export function* postUndoRedoSaga(replay: any) {
try {
const isPropertyPaneVisible: boolean = yield select(
getIsPropertyPaneVisible,
);
if (isPropertyPaneVisible) yield put(closePropertyPane());
// display toasts if it is a destructive operation
if (replay.toasts && replay.toasts.length > 0) {
processUndoRedoToasts(replay.toasts);
}
if (!replay.widgets || Object.keys(replay.widgets).length <= 0) return;
const widgetIds = Object.keys(replay.widgets);
if (widgetIds.length > 1) {
yield put(selectMultipleWidgetsInitAction(widgetIds));
} else {
yield put(selectWidgetAction(widgetIds[0], false));
}
scrollWidgetIntoView(widgetIds[0]);
} catch (e) {
log.error(e);
Sentry.captureException(e);
}
}
2021-12-07 09:45:18 +00:00
/**
* saga that listen for UNDO_REDO_OPERATION
* it won't do anything in case of sniping/comment mode
*
* @param action
* @returns
*/
export function* undoRedoSaga(action: ReduxAction<UndoRedoPayload>) {
const isCommentMode: boolean = yield select(commentModeSelector);
const isSnipingMode: boolean = yield select(snipingModeSelector);
// if the app is in snipping or comments mode, don't do anything
if (isCommentMode || isSnipingMode) return;
try {
const history = createBrowserHistory();
const pathname = history.location.pathname;
const { id, type } = getEntityInCurrentPath(pathname);
const entityId = type === "page" ? "canvas" : id;
const workerResponse = yield call(
workerComputeUndoRedo,
action.payload.operation,
entityId,
);
// if there is no change, then don't do anythingÎ
if (!workerResponse) return;
const {
event,
logs,
paths,
replay,
replayEntity,
replayEntityType,
timeTaken,
} = workerResponse;
logs && logs.forEach((evalLog: any) => log.debug(evalLog));
switch (replayEntityType) {
case ENTITY_TYPE.WIDGET: {
const isPropertyUpdate = replay.widgets && replay.propertyUpdates;
AnalyticsUtil.logEvent(event, { paths, timeTaken });
if (isPropertyUpdate) yield call(openPropertyPaneSaga, replay);
yield put(updateAndSaveLayout(replayEntity, false, false));
if (!isPropertyUpdate) yield call(postUndoRedoSaga, replay);
break;
}
case ENTITY_TYPE.ACTION:
yield call(replayActionSaga, replayEntity, replay);
break;
case ENTITY_TYPE.DATASOURCE: {
yield call(replayDatasourceSaga, replayEntity, replay);
break;
}
case ENTITY_TYPE.JSACTION:
yield put(
updateJSCollectionBody(replayEntity.body, replayEntity.id, true),
);
break;
}
} catch (e) {
log.error(e);
Sentry.captureException(e);
}
}
function* replayActionSaga(
replayEntity: Action,
replay: { updates: ReplayEditorUpdate[] },
) {
const { updates = [] } = replay;
/**
* Pick one diff to determine tab switching.
* Diffs across multiple tabs are unlikely
*/
const { modifiedProperty } = updates[updates.length - 1] || {};
const { currentTab } = yield call(
getEditorFieldConfig,
replayEntity,
modifiedProperty,
);
/**
* Check if tab needs to be switched and switch is necessary
* Delay change if tab needs to be switched
*/
const didSwitch: boolean = yield call(switchTab, currentTab);
if (didSwitch) yield delay(REPLAY_FOCUS_DELAY);
//Reinitialize form
const currentFormName =
isQueryAction(replayEntity) || isSaaSAction(replayEntity)
? QUERY_EDITOR_FORM_NAME
: API_EDITOR_FORM_NAME;
2021-12-07 09:45:18 +00:00
yield put(initialize(currentFormName, replayEntity));
//Begin modified field highlighting
highlightReplayElement(
updates.map((u: ReplayEditorUpdate) => u.modifiedProperty),
);
/**
* Update all the diffs in the action object.
* We need this for debugger logs, dynamicBindingPathList and to call relevant APIs */
yield all(
updates.map((u) =>
put(
setActionProperty({
actionId: replayEntity.id,
propertyName: u.modifiedProperty,
value:
u.kind === "A" ? _.get(replayEntity, u.modifiedProperty) : u.update,
skipSave: true,
}),
),
),
);
//Save the updated action object
yield put(updateAction({ id: replayEntity.id }));
}
function* replayDatasourceSaga(
replayEntity: Datasource,
replay: { updates: ReplayEditorUpdate[] },
) {
const { updates = [] } = replay;
const { modifiedProperty } = updates[updates.length - 1] || {};
const { fieldInfo: { parentSection = "" } = {} } = yield call(
getDatasourceFieldConfig,
replayEntity,
modifiedProperty,
);
/**
* Check if the modified field is under a collapsed section and expand if necessary
* Delay change if accordion needs to be expanded
*/
const didExpand: boolean = yield call(expandAccordion, parentSection);
if (didExpand) yield delay(REPLAY_FOCUS_DELAY);
/**
* Reinitialize redux form
* Attribute "datasourceId" is used as a differentiator between rest-api datasources and the others */
if (replayEntity.hasOwnProperty("datasourceId")) {
yield put(initialize(DATASOURCE_REST_API_FORM, replayEntity));
} else {
yield put(initialize(DATASOURCE_DB_FORM, _.omit(replayEntity, ["name"])));
}
// Highlight modified fields
highlightReplayElement(
updates.map((u: ReplayEditorUpdate) => u.modifiedProperty),
);
}
/*
Figure out the field config of the last modified field in datasource forms
*/
function* getDatasourceFieldConfig(
replayEntity: Datasource,
modifiedProperty: string,
) {
const formConfig: [Record<any, any>] = yield select(
getPluginForm,
replayEntity.pluginId,
);
const fieldInfo = findFieldInfo(formConfig, modifiedProperty);
return { fieldInfo };
}
/*
Figure out the tab in which the last modified field is present and the
field config of the last modified field.
*/
function* getEditorFieldConfig(replayEntity: Action, modifiedProperty: string) {
let currentTab = "";
let fieldInfo = {};
if (!modifiedProperty) return { currentTab, fieldInfo };
if (isAPIAction(replayEntity)) {
if (modifiedProperty.includes("headers"))
currentTab = API_EDITOR_TABS.HEADERS;
else if (modifiedProperty.includes("queryParameters"))
currentTab = API_EDITOR_TABS.PARAMS;
else if (modifiedProperty.includes("body"))
currentTab = API_EDITOR_TABS.BODY;
else if (
modifiedProperty.includes("pagination") ||
modifiedProperty.includes("next") ||
modifiedProperty.includes("previous")
)
currentTab = API_EDITOR_TABS.PAGINATION;
if (!currentTab) {
const settingsConfig: [Record<any, any>] = yield select(
getSettingConfig,
replayEntity.pluginId,
);
fieldInfo = findFieldInfo(settingsConfig, modifiedProperty);
if (!isEmpty(fieldInfo)) currentTab = API_EDITOR_TABS.SETTINGS;
}
} else {
const editorConfig: [Record<any, any>] = yield select(
getEditorConfig,
replayEntity.pluginId,
);
fieldInfo = findFieldInfo(editorConfig, modifiedProperty);
if (!isEmpty(fieldInfo)) {
currentTab = EDITOR_TABS.QUERY;
} else {
const settingsConfig: [Record<any, any>] = yield select(
getSettingConfig,
replayEntity.pluginId,
);
fieldInfo = findFieldInfo(settingsConfig, modifiedProperty);
if (!isEmpty(fieldInfo)) currentTab = EDITOR_TABS.SETTINGS;
}
}
return { currentTab, fieldInfo };
}