From d67aedbdebcfc459c635ed137b185925c5687efb Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Wed, 31 Jan 2024 17:18:42 +0530 Subject: [PATCH] fix: improve query add url split (#30790) improve upon the query add url fix by splitting it for extensibility with EE We will now extend a utility function `getQueryAddUrl` on EE to add EE cases instead of rewriting the implementation as it does today fixes: #30764 ## Summary by CodeRabbit - **Refactor** - Enhanced URL construction method for adding queries in the Editor Pane to improve navigation and consistency. --- .../Editor/IDE/EditorPane/Query/hooks.ts | 33 ++----------------- .../Editor/IDE/EditorPane/Query/utils.ts | 31 +++++++++++------ 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.ts index a82e55fbca..f4fca1ad30 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.ts +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.ts @@ -3,14 +3,6 @@ import history from "utils/history"; import { LIST_PATH } from "@appsmith/constants/routes/appRoutes"; import { useLocation } from "react-router"; import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity"; -import { useCurrentEditorState } from "pages/Editor/IDE/hooks"; -import { EditorEntityTabState } from "@appsmith/entities/IDE/constants"; -import { - apiEditorIdURL, - queryAddURL, - queryEditorIdURL, - saasEditorApiIdURL, -} from "@appsmith/RouteBuilder"; import { useSelector } from "react-redux"; import { useFilteredFileOperations } from "components/editorComponents/GlobalSearch/GlobalSearchHooks"; import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; @@ -20,35 +12,16 @@ import { getHasCreateActionPermission } from "@appsmith/utils/BusinessFeatures/p import type { ActionOperation } from "components/editorComponents/GlobalSearch/utils"; import { SEARCH_ITEM_TYPES } from "components/editorComponents/GlobalSearch/utils"; import { createMessage, EDITOR_PANE_TEXTS } from "@appsmith/constants/messages"; -import { getQueryType, QueryType } from "./utils"; +import { getQueryAddUrl } from "./utils"; export const useQueryAdd = () => { const location = useLocation(); const currentEntityInfo = identifyEntityFromPath(location.pathname); - const { segmentMode } = useCurrentEditorState(); const addButtonClickHandler = useCallback(() => { - let url = queryAddURL({}); - if (segmentMode === EditorEntityTabState.Edit) { - switch (getQueryType(currentEntityInfo)) { - case QueryType.QUERY: - url = queryEditorIdURL({ queryId: currentEntityInfo.id, add: true }); - break; - case QueryType.API: - url = apiEditorIdURL({ apiId: currentEntityInfo.id, add: true }); - break; - case QueryType.SAAS: - if (currentEntityInfo.params.pluginPackageName) { - url = saasEditorApiIdURL({ - apiId: currentEntityInfo.id, - pluginPackageName: currentEntityInfo.params.pluginPackageName, - add: true, - }); - } - } - } + const url = getQueryAddUrl(currentEntityInfo); history.push(url); - }, [currentEntityInfo.id, location, segmentMode]); + }, [currentEntityInfo.id]); return addButtonClickHandler; }; diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.ts index 85abb10344..6551758fce 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.ts +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.ts @@ -1,6 +1,12 @@ import type { EntityItem } from "@appsmith/entities/IDE/constants"; import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers"; import type { FocusEntityInfo } from "navigation/FocusEntity"; +import { + apiEditorIdURL, + queryAddURL, + queryEditorIdURL, + saasEditorApiIdURL, +} from "@appsmith/RouteBuilder"; export const getQueryEntityItemUrl = ( item: EntityItem, @@ -13,20 +19,25 @@ export const getQueryEntityItemUrl = ( return config.getURL(pageId, item.key, item.type); }; -export enum QueryType { - API = "API", - SAAS = "SAAS", - QUERY = "QUERY", -} - -export const getQueryType = (item: FocusEntityInfo): QueryType | undefined => { +export const getQueryAddUrl = (item: FocusEntityInfo): string => { if (item.params.apiId) { if (item.params.pluginPackageName) { - return QueryType.SAAS; + return saasEditorApiIdURL({ + pluginPackageName: item.params.pluginPackageName, + apiId: item.params.apiId, + add: true, + }); } else { - return QueryType.API; + return apiEditorIdURL({ + apiId: item.params.apiId, + add: true, + }); } } else if (item.params.queryId) { - return QueryType.QUERY; + return queryEditorIdURL({ + queryId: item.params.queryId, + add: true, + }); } + return queryAddURL({}); };