2022-10-17 15:16:38 +00:00
|
|
|
import { matchPath } from "react-router";
|
|
|
|
|
import {
|
|
|
|
|
API_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH,
|
|
|
|
|
BUILDER_PATH,
|
|
|
|
|
BUILDER_PATH_DEPRECATED,
|
2022-12-02 03:06:22 +00:00
|
|
|
DATA_SOURCES_EDITOR_ID_PATH,
|
2023-02-21 13:38:16 +00:00
|
|
|
INTEGRATION_EDITOR_PATH,
|
2022-10-17 15:16:38 +00:00
|
|
|
JS_COLLECTION_ID_PATH,
|
|
|
|
|
QUERIES_EDITOR_ID_PATH,
|
2023-02-21 13:38:16 +00:00
|
|
|
WIDGETS_EDITOR_ID_PATH,
|
2022-10-17 15:16:38 +00:00
|
|
|
} from "constants/routes";
|
2023-11-20 07:58:08 +00:00
|
|
|
import {
|
|
|
|
|
SAAS_EDITOR_API_ID_PATH,
|
|
|
|
|
SAAS_EDITOR_DATASOURCE_ID_PATH,
|
|
|
|
|
} from "pages/Editor/SaaSEditor/constants";
|
2023-04-26 16:03:35 +00:00
|
|
|
import { TEMP_DATASOURCE_ID } from "constants/Datasource";
|
2023-11-30 09:26:24 +00:00
|
|
|
import { EditorState } from "../entities/IDE/constants";
|
2022-10-17 15:16:38 +00:00
|
|
|
|
|
|
|
|
export enum FocusEntity {
|
2022-12-08 07:21:58 +00:00
|
|
|
PAGE = "PAGE",
|
2022-10-17 15:16:38 +00:00
|
|
|
API = "API",
|
|
|
|
|
CANVAS = "CANVAS",
|
2023-10-18 07:14:10 +00:00
|
|
|
DATASOURCE_LIST = "DATASOURCE_LIST",
|
2022-12-02 03:06:22 +00:00
|
|
|
DATASOURCE = "DATASOURCE",
|
2023-04-10 12:59:14 +00:00
|
|
|
DEBUGGER = "DEBUGGER",
|
2022-10-17 15:16:38 +00:00
|
|
|
QUERY = "QUERY",
|
2023-11-28 12:46:43 +00:00
|
|
|
QUERY_LIST = "QUERY_LIST",
|
2022-10-17 15:16:38 +00:00
|
|
|
JS_OBJECT = "JS_OBJECT",
|
2023-11-28 12:46:43 +00:00
|
|
|
JS_OBJECT_LIST = "JS_OBJECT_LIST",
|
2022-10-17 15:16:38 +00:00
|
|
|
PROPERTY_PANE = "PROPERTY_PANE",
|
|
|
|
|
NONE = "NONE",
|
2023-11-20 07:58:08 +00:00
|
|
|
APP_STATE = "APP_STATE",
|
|
|
|
|
LIBRARY = "LIBRARY",
|
|
|
|
|
SETTINGS = "SETTINGS",
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-21 13:38:16 +00:00
|
|
|
export const FocusStoreHierarchy: Partial<Record<FocusEntity, FocusEntity>> = {
|
|
|
|
|
[FocusEntity.PROPERTY_PANE]: FocusEntity.CANVAS,
|
2023-10-18 07:14:10 +00:00
|
|
|
[FocusEntity.DATASOURCE]: FocusEntity.DATASOURCE_LIST,
|
2023-11-28 12:46:43 +00:00
|
|
|
[FocusEntity.JS_OBJECT]: FocusEntity.JS_OBJECT_LIST,
|
|
|
|
|
[FocusEntity.QUERY]: FocusEntity.QUERY_LIST,
|
2023-02-21 13:38:16 +00:00
|
|
|
};
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
export interface FocusEntityInfo {
|
2022-10-17 15:16:38 +00:00
|
|
|
entity: FocusEntity;
|
|
|
|
|
id: string;
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState;
|
2022-12-08 07:21:58 +00:00
|
|
|
pageId?: string;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2022-10-17 15:16:38 +00:00
|
|
|
|
2023-02-21 13:38:16 +00:00
|
|
|
export function identifyEntityFromPath(path: string): FocusEntityInfo {
|
2022-10-17 15:16:38 +00:00
|
|
|
const match = matchPath<{
|
|
|
|
|
apiId?: string;
|
2022-12-02 03:06:22 +00:00
|
|
|
datasourceId?: string;
|
2022-11-15 06:20:18 +00:00
|
|
|
pluginPackageName?: string;
|
2022-10-17 15:16:38 +00:00
|
|
|
queryId?: string;
|
|
|
|
|
appId?: string;
|
|
|
|
|
pageId?: string;
|
|
|
|
|
collectionId?: string;
|
2023-02-21 13:38:16 +00:00
|
|
|
widgetIds?: string;
|
|
|
|
|
selectedTab?: string; // Datasource creation/list screen
|
2023-10-18 07:14:10 +00:00
|
|
|
entity?: string;
|
2023-02-21 13:38:16 +00:00
|
|
|
}>(path, {
|
2022-10-17 15:16:38 +00:00
|
|
|
path: [
|
|
|
|
|
BUILDER_PATH_DEPRECATED + API_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_PATH + API_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + API_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_PATH_DEPRECATED + QUERIES_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_PATH + QUERIES_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + QUERIES_EDITOR_ID_PATH,
|
2022-12-02 03:06:22 +00:00
|
|
|
BUILDER_PATH_DEPRECATED + DATA_SOURCES_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_PATH + DATA_SOURCES_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + DATA_SOURCES_EDITOR_ID_PATH,
|
2023-02-21 13:38:16 +00:00
|
|
|
BUILDER_PATH_DEPRECATED + INTEGRATION_EDITOR_PATH,
|
|
|
|
|
BUILDER_PATH + INTEGRATION_EDITOR_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + INTEGRATION_EDITOR_PATH,
|
2022-12-02 03:06:22 +00:00
|
|
|
BUILDER_PATH + SAAS_EDITOR_DATASOURCE_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + SAAS_EDITOR_DATASOURCE_ID_PATH,
|
2022-11-15 06:20:18 +00:00
|
|
|
BUILDER_PATH_DEPRECATED + SAAS_EDITOR_API_ID_PATH,
|
|
|
|
|
BUILDER_PATH + SAAS_EDITOR_API_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + SAAS_EDITOR_API_ID_PATH,
|
2022-10-17 15:16:38 +00:00
|
|
|
BUILDER_PATH_DEPRECATED + JS_COLLECTION_ID_PATH,
|
|
|
|
|
BUILDER_PATH + JS_COLLECTION_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + JS_COLLECTION_ID_PATH,
|
2023-02-21 13:38:16 +00:00
|
|
|
BUILDER_PATH + WIDGETS_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH + WIDGETS_EDITOR_ID_PATH,
|
|
|
|
|
BUILDER_PATH_DEPRECATED + WIDGETS_EDITOR_ID_PATH,
|
2023-10-18 07:14:10 +00:00
|
|
|
BUILDER_PATH + "/:entity",
|
|
|
|
|
BUILDER_CUSTOM_PATH + "/:entity",
|
|
|
|
|
BUILDER_PATH_DEPRECATED + "/:entity",
|
2022-10-17 15:16:38 +00:00
|
|
|
BUILDER_PATH_DEPRECATED,
|
|
|
|
|
BUILDER_PATH,
|
|
|
|
|
BUILDER_CUSTOM_PATH,
|
|
|
|
|
],
|
2022-12-08 07:21:58 +00:00
|
|
|
exact: true,
|
2022-10-17 15:16:38 +00:00
|
|
|
});
|
|
|
|
|
if (!match) {
|
2023-11-20 07:58:08 +00:00
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.NONE,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
};
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
|
|
|
|
if (match.params.apiId) {
|
2022-11-15 06:20:18 +00:00
|
|
|
if (match.params.pluginPackageName) {
|
2022-12-08 07:21:58 +00:00
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: match.params.apiId,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
};
|
2022-11-15 06:20:18 +00:00
|
|
|
}
|
2022-12-08 07:21:58 +00:00
|
|
|
return {
|
2023-11-28 12:46:43 +00:00
|
|
|
entity: FocusEntity.QUERY,
|
2022-12-08 07:21:58 +00:00
|
|
|
id: match.params.apiId,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
};
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
2023-11-20 07:58:08 +00:00
|
|
|
if (match.params.datasourceId) {
|
|
|
|
|
if (match.params.datasourceId == TEMP_DATASOURCE_ID) {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.NONE,
|
|
|
|
|
id: match.params.datasourceId,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-20 07:58:08 +00:00
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: match.params.datasourceId,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-20 07:58:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
2022-12-02 03:06:22 +00:00
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
if (match.params.selectedTab) {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: match.params.selectedTab,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-02-21 13:38:16 +00:00
|
|
|
};
|
|
|
|
|
}
|
2023-10-18 07:14:10 +00:00
|
|
|
if (match.params.entity === "datasource") {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-10-18 07:14:10 +00:00
|
|
|
};
|
|
|
|
|
}
|
2022-10-17 15:16:38 +00:00
|
|
|
if (match.params.queryId) {
|
2022-12-08 07:21:58 +00:00
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: match.params.queryId,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
};
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
|
|
|
|
if (match.params.collectionId) {
|
2022-12-08 07:21:58 +00:00
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: match.params.collectionId,
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
};
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
if (match.params.widgetIds) {
|
2022-12-08 07:21:58 +00:00
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
2023-02-21 13:38:16 +00:00
|
|
|
id: match.params.widgetIds,
|
2022-12-08 07:21:58 +00:00
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
};
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|
2023-11-28 12:46:43 +00:00
|
|
|
if (match.params.entity === "queries") {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.QUERY_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (match.params.entity === "jsObjects") {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
};
|
|
|
|
|
}
|
2023-11-20 07:58:08 +00:00
|
|
|
if (match.params.entity) {
|
|
|
|
|
if (match.params.entity === "libraries") {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.LIBRARY,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.LIBRARIES,
|
2023-11-20 07:58:08 +00:00
|
|
|
pageId: match.params.pageId,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (match.params.entity === "settings") {
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.SETTINGS,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.SETTINGS,
|
2023-11-20 07:58:08 +00:00
|
|
|
pageId: match.params.pageId,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: match.params.pageId,
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
};
|
2022-10-17 15:16:38 +00:00
|
|
|
}
|