2022-10-17 15:16:38 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
|
|
|
|
import { EvaluatedPopupState } from "reducers/uiReducers/editorContextReducer";
|
|
|
|
|
import { all, put, select, takeLatest } from "redux-saga/effects";
|
|
|
|
|
import { getCurrentPageId } from "selectors/editorSelectors";
|
|
|
|
|
import { generatePropertyKey } from "utils/editorContextUtils";
|
2022-11-15 06:20:18 +00:00
|
|
|
import {
|
|
|
|
|
CodeEditorFocusState,
|
|
|
|
|
setCodeEditorCursorHistory,
|
|
|
|
|
setFocusableCodeEditorField,
|
|
|
|
|
} from "actions/editorContextActions";
|
|
|
|
|
import { setFocusablePropertyPaneField } from "actions/propertyPaneActions";
|
|
|
|
|
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
|
2022-10-17 15:16:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method appends the PageId along with the focusable propertyPath
|
|
|
|
|
* @param action
|
|
|
|
|
*/
|
2022-11-15 06:20:18 +00:00
|
|
|
function* generateKeyAndSetFocusableEditor(
|
|
|
|
|
action: ReduxAction<CodeEditorFocusState>,
|
2022-10-17 15:16:38 +00:00
|
|
|
) {
|
|
|
|
|
const currentPageId: string = yield select(getCurrentPageId);
|
|
|
|
|
|
2022-11-15 06:20:18 +00:00
|
|
|
const { cursorPosition, key } = action.payload;
|
|
|
|
|
|
|
|
|
|
const propertyFieldKey = generatePropertyKey(key, currentPageId);
|
|
|
|
|
const entityInfo = identifyEntityFromPath(
|
|
|
|
|
window.location.pathname,
|
|
|
|
|
window.location.hash,
|
2022-10-17 15:16:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (propertyFieldKey) {
|
2022-11-15 06:20:18 +00:00
|
|
|
if (entityInfo.entity !== FocusEntity.PROPERTY_PANE) {
|
|
|
|
|
yield put(setFocusableCodeEditorField(propertyFieldKey));
|
|
|
|
|
}
|
|
|
|
|
yield put(setCodeEditorCursorHistory(propertyFieldKey, cursorPosition));
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method appends the PageId along with the focusable propertyPath
|
|
|
|
|
* @param action
|
|
|
|
|
*/
|
2022-11-15 06:20:18 +00:00
|
|
|
function* generateKeyAndSetEvalPopupState(
|
2022-10-17 15:16:38 +00:00
|
|
|
action: ReduxAction<{
|
|
|
|
|
key: string | undefined;
|
2022-11-15 06:20:18 +00:00
|
|
|
evalPopupState: EvaluatedPopupState;
|
2022-10-17 15:16:38 +00:00
|
|
|
}>,
|
|
|
|
|
) {
|
|
|
|
|
const currentPageId: string = yield select(getCurrentPageId);
|
|
|
|
|
|
2022-11-15 06:20:18 +00:00
|
|
|
const { evalPopupState, key } = action.payload;
|
2022-10-17 15:16:38 +00:00
|
|
|
|
|
|
|
|
const propertyFieldKey = generatePropertyKey(key, currentPageId);
|
|
|
|
|
|
|
|
|
|
if (propertyFieldKey) {
|
|
|
|
|
yield put({
|
2022-11-15 06:20:18 +00:00
|
|
|
type: ReduxActionTypes.SET_EVAL_POPUP_STATE,
|
|
|
|
|
payload: { key: propertyFieldKey, evalPopupState },
|
2022-10-17 15:16:38 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-15 06:20:18 +00:00
|
|
|
function* generateKeyAndSetFocusablePropertyPaneField(
|
|
|
|
|
action: ReduxAction<{ path?: string }>,
|
2022-10-17 15:16:38 +00:00
|
|
|
) {
|
|
|
|
|
const currentPageId: string = yield select(getCurrentPageId);
|
|
|
|
|
|
2022-11-15 06:20:18 +00:00
|
|
|
const propertyFieldKey = generatePropertyKey(
|
|
|
|
|
action.payload.path,
|
|
|
|
|
currentPageId,
|
|
|
|
|
);
|
2022-10-17 15:16:38 +00:00
|
|
|
|
|
|
|
|
if (propertyFieldKey) {
|
2022-11-15 06:20:18 +00:00
|
|
|
yield put(setFocusablePropertyPaneField(propertyFieldKey));
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function* editorContextSagas() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.GENERATE_KEY_AND_SET_CODE_EDITOR_LAST_FOCUS,
|
|
|
|
|
generateKeyAndSetFocusableEditor,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.GENERATE_KEY_AND_SET_EVAL_POPUP_STATE,
|
|
|
|
|
generateKeyAndSetEvalPopupState,
|
|
|
|
|
),
|
2022-11-15 06:20:18 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.GENERATE_KEY_AND_SET_FOCUSABLE_PROPERTY_FIELD,
|
|
|
|
|
generateKeyAndSetFocusablePropertyPaneField,
|
|
|
|
|
),
|
2022-10-17 15:16:38 +00:00
|
|
|
]);
|
|
|
|
|
}
|