2024-01-23 04:52:50 +00:00
|
|
|
import type { FocusEntityInfo } from "navigation/FocusEntity";
|
2025-03-06 07:52:24 +00:00
|
|
|
import { FocusEntity } from "navigation/FocusEntity";
|
2024-02-27 05:12:27 +00:00
|
|
|
import { all, call, put, select, takeEvery } from "redux-saga/effects";
|
2024-04-26 11:36:57 +00:00
|
|
|
import { getJSTabs, getQueryTabs } from "selectors/ideSelectors";
|
2024-02-27 05:12:27 +00:00
|
|
|
import {
|
|
|
|
|
setIdeEditorViewMode,
|
|
|
|
|
setJSTabs,
|
|
|
|
|
setQueryTabs,
|
|
|
|
|
} from "actions/ideActions";
|
2024-02-02 05:06:02 +00:00
|
|
|
import history from "../utils/history";
|
2024-04-05 12:26:17 +00:00
|
|
|
import {
|
|
|
|
|
jsCollectionAddURL,
|
|
|
|
|
jsCollectionListURL,
|
|
|
|
|
queryAddURL,
|
|
|
|
|
queryListURL,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/RouteBuilder";
|
2025-02-07 11:15:55 +00:00
|
|
|
import type { EntityItem } from "ee/IDE/Interfaces/EntityItem";
|
2025-02-17 07:34:23 +00:00
|
|
|
import { getQueryEntityItemUrl } from "ee/pages/AppIDE/layouts/routers/utils/getQueryEntityItemUrl";
|
|
|
|
|
import { getJSEntityItemUrl } from "ee/pages/AppIDE/layouts/routers/utils/getJSEntityItemUrl";
|
2024-02-02 05:06:02 +00:00
|
|
|
import log from "loglevel";
|
2025-01-10 04:51:54 +00:00
|
|
|
import type { ReduxAction } from "actions/ReduxActionTypes";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
|
2025-02-07 11:15:55 +00:00
|
|
|
import type { EditorViewMode } from "IDE/Interfaces/EditorTypes";
|
2024-02-27 05:12:27 +00:00
|
|
|
import { retrieveIDEViewMode, storeIDEViewMode } from "utils/storage";
|
2024-04-19 06:49:24 +00:00
|
|
|
import {
|
|
|
|
|
selectJSSegmentEditorTabs,
|
|
|
|
|
selectQuerySegmentEditorTabs,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/selectors/appIDESelectors";
|
2024-07-31 02:54:51 +00:00
|
|
|
import { getCurrentBasePageId } from "selectors/editorSelectors";
|
2025-03-06 07:52:24 +00:00
|
|
|
import {
|
|
|
|
|
getNextEntityAfterRemove,
|
|
|
|
|
RedirectAction,
|
|
|
|
|
} from "IDE/utils/getNextEntityAfterRemove";
|
|
|
|
|
import { getUpdatedTabs } from "IDE/utils/getUpdatedTabs";
|
2024-01-23 04:52:50 +00:00
|
|
|
|
|
|
|
|
export function* updateIDETabsOnRouteChangeSaga(entityInfo: FocusEntityInfo) {
|
2024-05-08 17:27:27 +00:00
|
|
|
const { entity, id, params } = entityInfo;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-31 02:54:51 +00:00
|
|
|
if (!params.basePageId) return;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-20 05:01:57 +00:00
|
|
|
if (
|
|
|
|
|
entity === FocusEntity.JS_OBJECT ||
|
|
|
|
|
entity === FocusEntity.JS_MODULE_INSTANCE
|
|
|
|
|
) {
|
2024-01-23 04:52:50 +00:00
|
|
|
const jsTabs: string[] = yield select(getJSTabs);
|
|
|
|
|
const newTabs: string[] = yield call(getUpdatedTabs, id, jsTabs);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-31 02:54:51 +00:00
|
|
|
yield put(setJSTabs(newTabs, params.basePageId));
|
2024-01-23 04:52:50 +00:00
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-20 05:01:57 +00:00
|
|
|
if (
|
|
|
|
|
entity === FocusEntity.QUERY ||
|
|
|
|
|
entity === FocusEntity.QUERY_MODULE_INSTANCE
|
|
|
|
|
) {
|
2024-01-23 04:52:50 +00:00
|
|
|
const queryTabs: string[] = yield select(getQueryTabs);
|
|
|
|
|
const newTabs: string[] = yield call(getUpdatedTabs, id, queryTabs);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-31 02:54:51 +00:00
|
|
|
yield put(setQueryTabs(newTabs, params.basePageId));
|
2024-01-23 04:52:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-02 05:06:02 +00:00
|
|
|
export function* handleJSEntityRedirect(deletedId: string) {
|
2024-07-31 02:54:51 +00:00
|
|
|
const basePageId: string = yield select(getCurrentBasePageId);
|
2024-04-19 06:49:24 +00:00
|
|
|
const jsTabs: EntityItem[] = yield select(selectJSSegmentEditorTabs);
|
|
|
|
|
const redirectAction = getNextEntityAfterRemove(deletedId, jsTabs);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-02 05:06:02 +00:00
|
|
|
switch (redirectAction.action) {
|
2024-04-05 12:26:17 +00:00
|
|
|
case RedirectAction.LIST:
|
2024-07-31 02:54:51 +00:00
|
|
|
history.push(jsCollectionListURL({ basePageId }));
|
2024-02-02 05:06:02 +00:00
|
|
|
break;
|
|
|
|
|
case RedirectAction.ITEM:
|
|
|
|
|
if (!redirectAction.payload) {
|
|
|
|
|
log.error("Redirect item does not have a payload");
|
2024-07-31 02:54:51 +00:00
|
|
|
history.push(jsCollectionAddURL({ basePageId }));
|
2024-02-02 05:06:02 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-02 05:06:02 +00:00
|
|
|
const { payload } = redirectAction;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-31 02:54:51 +00:00
|
|
|
history.push(getJSEntityItemUrl(payload, basePageId));
|
2024-02-02 05:06:02 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* handleQueryEntityRedirect(deletedId: string) {
|
2024-07-31 02:54:51 +00:00
|
|
|
const basePageId: string = yield select(getCurrentBasePageId);
|
2024-04-19 06:49:24 +00:00
|
|
|
const queryTabs: EntityItem[] = yield select(selectQuerySegmentEditorTabs);
|
|
|
|
|
const redirectAction = getNextEntityAfterRemove(deletedId, queryTabs);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-02 05:06:02 +00:00
|
|
|
switch (redirectAction.action) {
|
2024-04-05 12:26:17 +00:00
|
|
|
case RedirectAction.LIST:
|
2024-07-31 02:54:51 +00:00
|
|
|
history.push(queryListURL({ basePageId }));
|
2024-02-02 05:06:02 +00:00
|
|
|
break;
|
|
|
|
|
case RedirectAction.ITEM:
|
|
|
|
|
if (!redirectAction.payload) {
|
2024-07-31 02:54:51 +00:00
|
|
|
history.push(queryAddURL({ basePageId }));
|
2024-02-02 05:06:02 +00:00
|
|
|
log.error("Redirect item does not have a payload");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-02 05:06:02 +00:00
|
|
|
const { payload } = redirectAction;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-31 02:54:51 +00:00
|
|
|
history.push(getQueryEntityItemUrl(payload, basePageId));
|
2024-02-02 05:06:02 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 05:12:27 +00:00
|
|
|
function* storeIDEViewChangeSaga(
|
|
|
|
|
action: ReduxAction<{ view: EditorViewMode }>,
|
|
|
|
|
) {
|
|
|
|
|
yield call(storeIDEViewMode, action.payload.view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* restoreIDEViewModeSaga() {
|
|
|
|
|
const storedState: EditorViewMode = yield call(retrieveIDEViewMode);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-27 05:12:27 +00:00
|
|
|
if (storedState) {
|
|
|
|
|
yield put(setIdeEditorViewMode(storedState));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function* root() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.SET_IDE_EDITOR_VIEW_MODE,
|
|
|
|
|
storeIDEViewChangeSaga,
|
|
|
|
|
),
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.RESTORE_IDE_EDITOR_VIEW_MODE,
|
|
|
|
|
restoreIDEViewModeSaga,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
}
|