diff --git a/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceInfo.tsx b/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceInfo.tsx index 4c00cc7c3143..7b639a11a7e7 100644 --- a/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceInfo.tsx +++ b/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceInfo.tsx @@ -8,8 +8,8 @@ import { datasourcesEditorIdURL } from "ee/RouteBuilder"; import { omit } from "lodash"; import { getQueryParams } from "utils/URLUtils"; import history from "utils/history"; -import { useEditorType } from "ee/hooks"; -import { useParentEntityInfo } from "ee/hooks/datasourceEditorHooks"; +import { useParentEntityInfo } from "ee/IDE/hooks/useParentEntityInfo"; +import { getIDETypeByUrl } from "ee/entities/IDE/utils"; import type { Plugin } from "entities/Plugin"; interface Props { @@ -25,8 +25,8 @@ const DatasourceInfo = ({ plugin, showEditButton, }: Props) => { - const editorType = useEditorType(location.pathname); - const { parentEntityId } = useParentEntityInfo(editorType); + const ideType = getIDETypeByUrl(location.pathname); + const { parentEntityId } = useParentEntityInfo(ideType); // eslint-disable-next-line react-perf/jsx-no-new-function-as-prop const editDatasource = () => { diff --git a/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceTab.tsx b/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceTab.tsx index 78964d811697..c31b4668ee70 100644 --- a/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceTab.tsx +++ b/app/client/src/PluginActionEditor/components/PluginActionResponse/components/DatasourceTab/DatasourceTab.tsx @@ -23,8 +23,7 @@ import { isEmpty, omit } from "lodash"; import { getQueryParams } from "utils/URLUtils"; import { TableColumns } from "./TableColumns"; import { BOTTOMBAR_HEIGHT } from "./constants"; -import { useEditorType } from "ee/hooks"; -import { useParentEntityInfo } from "ee/hooks/datasourceEditorHooks"; +import { useParentEntityInfo } from "ee/IDE/hooks/useParentEntityInfo"; import DatasourceInfo from "./DatasourceInfo"; import { getPlugin } from "ee/selectors/entitiesSelector"; import { @@ -34,6 +33,7 @@ import { } from "ee/utils/BusinessFeatures/permissionPageHelpers"; import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; +import { getIDETypeByUrl } from "ee/entities/IDE/utils"; interface Props { datasourceId: string; @@ -58,8 +58,8 @@ const DatasourceTab = (props: Props) => { const plugin = useSelector((state) => getPlugin(state, pluginId || "")); - const editorType = useEditorType(location.pathname); - const { parentEntityId } = useParentEntityInfo(editorType); + const ideType = getIDETypeByUrl(location.pathname); + const { parentEntityId } = useParentEntityInfo(ideType); const [selectedTable, setSelectedTable] = useState(); diff --git a/app/client/src/ce/IDE/hooks/useParentEntityInfo.ts b/app/client/src/ce/IDE/hooks/useParentEntityInfo.ts new file mode 100644 index 000000000000..47a277a4cca8 --- /dev/null +++ b/app/client/src/ce/IDE/hooks/useParentEntityInfo.ts @@ -0,0 +1,19 @@ +import { ActionParentEntityType } from "ee/entities/Engine/actionHelpers"; +import type { IDEType } from "ee/entities/IDE/constants"; +import { useSelector } from "react-redux"; +import { + getCurrentApplicationId, + getCurrentBasePageId, +} from "selectors/editorSelectors"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export const useParentEntityInfo = (ideType: IDEType) => { + const appId = useSelector(getCurrentApplicationId); + const basePageId = useSelector(getCurrentBasePageId); + + return { + editorId: appId || "", + parentEntityId: basePageId || "", + parentEntityType: ActionParentEntityType.PAGE, + }; +}; diff --git a/app/client/src/ce/actions/helpers.ts b/app/client/src/ce/actions/helpers.ts index 5c976888d3e9..f244ff7483d2 100644 --- a/app/client/src/ce/actions/helpers.ts +++ b/app/client/src/ce/actions/helpers.ts @@ -10,6 +10,7 @@ import { saveActionName, } from "actions/pluginActionActions"; import { saveJSObjectName } from "actions/jsActionActions"; +import { IDE_TYPE, type IDEType } from "ee/entities/IDE/constants"; export const createNewQueryBasedOnParentEntity = ( entityId: string, @@ -43,29 +44,29 @@ export const createNewJSCollectionBasedOnParentEntity = ( return createNewJSCollection(entityId, from); }; -export const saveActionNameBasedOnParentEntity = ( +export const saveActionNameBasedOnIdeType = ( id: string, name: string, // Used in EE // eslint-disable-next-line @typescript-eslint/no-unused-vars - parentEntityType: ActionParentEntityTypeInterface = ActionParentEntityType.PAGE, + ideType: IDEType = IDE_TYPE.App, ) => { return saveActionName({ id, name }); }; -export const saveJSObjectNameBasedOnParentEntity = ( +export const saveJSObjectNameBasedOnIdeType = ( id: string, name: string, // Used in EE // eslint-disable-next-line @typescript-eslint/no-unused-vars - parentEntityType: ActionParentEntityTypeInterface = ActionParentEntityType.PAGE, + ideType: IDEType = IDE_TYPE.App, ) => { return saveJSObjectName({ id, name }); }; -export const createNewApiActionBasedOnEditorType = ( +export const createNewApiActionBasedOnIdeType = ( // eslint-disable-next-line @typescript-eslint/no-unused-vars - editorType: string, + ideType: IDEType, // eslint-disable-next-line @typescript-eslint/no-unused-vars editorId: string, parentEntityId: string, diff --git a/app/client/src/ce/entities/IDE/hooks/useCreateActionsPermissions.ts b/app/client/src/ce/entities/IDE/hooks/useCreateActionsPermissions.ts new file mode 100644 index 000000000000..c984e29bc061 --- /dev/null +++ b/app/client/src/ce/entities/IDE/hooks/useCreateActionsPermissions.ts @@ -0,0 +1,20 @@ +import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; +import { IDE_TYPE, type IDEType } from "ee/entities/IDE/constants"; +import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; +import { useSelector } from "react-redux"; +import { getPagePermissions } from "selectors/editorSelectors"; +import { getHasCreateActionPermission } from "ee/utils/BusinessFeatures/permissionPageHelpers"; + +export const useCreateActionsPermissions = (ideType: IDEType) => { + const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); + const pagePermissions = useSelector(getPagePermissions); + + switch (ideType) { + case IDE_TYPE.App: { + return getHasCreateActionPermission(isFeatureEnabled, pagePermissions); + } + default: { + return true; + } + } +}; diff --git a/app/client/src/ce/hooks/datasourceEditorHooks.tsx b/app/client/src/ce/hooks/datasourceEditorHooks.tsx index 5dde79d1f35d..db6730c1961d 100644 --- a/app/client/src/ce/hooks/datasourceEditorHooks.tsx +++ b/app/client/src/ce/hooks/datasourceEditorHooks.tsx @@ -2,7 +2,6 @@ import { GENERATE_NEW_PAGE_BUTTON_TEXT, createMessage, } from "ee/constants/messages"; -import { ActionParentEntityType } from "ee/entities/Engine/actionHelpers"; import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; import type { AppState } from "ee/reducers"; import { getPlugin } from "ee/selectors/entitiesSelector"; @@ -18,17 +17,13 @@ import NewActionButton from "pages/Editor/DataSourceEditor/NewActionButton"; import { useShowPageGenerationOnHeader } from "pages/Editor/DataSourceEditor/hooks"; import React from "react"; import { useDispatch, useSelector } from "react-redux"; -import { - getCurrentApplicationId, - getCurrentBasePageId, - getPagePermissions, -} from "selectors/editorSelectors"; +import { getPagePermissions } from "selectors/editorSelectors"; import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors"; import { isEnabledForPreviewData } from "utils/editorContextUtils"; import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; -import { EditorNames } from "./"; import { getCurrentApplication } from "ee/selectors/applicationSelectors"; import { openGeneratePageModal } from "pages/Editor/GeneratePage/store/generatePageActions"; +import { IDE_TYPE, type IDEType } from "ee/entities/IDE/constants"; export interface HeaderActionProps { datasource: Datasource | ApiDatasourceForm | undefined; @@ -38,7 +33,7 @@ export interface HeaderActionProps { } export const useHeaderActions = ( - editorType: string, + ideType: IDEType, { datasource, isPluginAuthorized, @@ -77,7 +72,7 @@ export const useHeaderActions = ( ? false : !!isPluginAllowedToPreviewData; - if (editorType === EditorNames.APPLICATION) { + if (ideType === IDE_TYPE.App) { const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({ isEnabled: isFeatureEnabled, dsPermissions: datasource?.userPermissions ?? [], @@ -141,15 +136,3 @@ export const useHeaderActions = ( return {}; }; - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const useParentEntityInfo = (editorType: string) => { - const appId = useSelector(getCurrentApplicationId); - const basePageId = useSelector(getCurrentBasePageId); - - return { - editorId: appId || "", - parentEntityId: basePageId || "", - parentEntityType: ActionParentEntityType.PAGE, - }; -}; diff --git a/app/client/src/ce/hooks/hooks.test.ts b/app/client/src/ce/hooks/hooks.test.ts deleted file mode 100644 index 8259537e9dd3..000000000000 --- a/app/client/src/ce/hooks/hooks.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { useEditorType, EditorNames } from "./index"; -import { - BUILDER_VIEWER_PATH_PREFIX, - BUILDER_BASE_PATH_DEPRECATED, -} from "constants/routes"; - -describe("useEditorType", () => { - it('should return "app" for BUILDER_VIEWER_PATH_PREFIX', () => { - const result = useEditorType(BUILDER_VIEWER_PATH_PREFIX); - - expect(result).toBe(EditorNames.APPLICATION); - }); - - it('should return "app" for BUILDER_BASE_PATH_DEPRECATED', () => { - const result = useEditorType(BUILDER_BASE_PATH_DEPRECATED); - - expect(result).toBe(EditorNames.APPLICATION); - }); - - it('should default to "app" for unmatched paths', () => { - const result = useEditorType("/some-random-path"); - - expect(result).toBe(EditorNames.APPLICATION); - }); -}); diff --git a/app/client/src/ce/hooks/index.ts b/app/client/src/ce/hooks/index.ts index 07f4b12bcd7c..44bb64e4445e 100644 --- a/app/client/src/ce/hooks/index.ts +++ b/app/client/src/ce/hooks/index.ts @@ -1,39 +1,4 @@ -import { - BUILDER_BASE_PATH_DEPRECATED, - BUILDER_VIEWER_PATH_PREFIX, -} from "constants/routes"; import { useEffect, type RefObject } from "react"; -import { matchPath } from "react-router"; - -export const EditorNames = { - APPLICATION: "app", -}; - -export interface EditorType { - [key: string]: string; -} - -export const editorType: EditorType = { - [BUILDER_VIEWER_PATH_PREFIX]: EditorNames.APPLICATION, - [BUILDER_BASE_PATH_DEPRECATED]: EditorNames.APPLICATION, -}; - -// Utility function to get editor type based on path -// to be used in non react functions -export const getEditorType = (path: string) => { - const basePath = matchPath(path, { - path: [BUILDER_VIEWER_PATH_PREFIX, BUILDER_BASE_PATH_DEPRECATED], - }); - - return basePath - ? editorType[basePath.path] - : editorType[BUILDER_VIEWER_PATH_PREFIX]; -}; - -// custom hook to get editor type based on path -export const useEditorType = (path: string) => { - return getEditorType(path); -}; export function useOutsideClick( ref: RefObject, diff --git a/app/client/src/ce/navigation/FocusSetters.ts b/app/client/src/ce/navigation/FocusSetters.ts index 85a26812644e..4d5aa3197b08 100644 --- a/app/client/src/ce/navigation/FocusSetters.ts +++ b/app/client/src/ce/navigation/FocusSetters.ts @@ -7,7 +7,7 @@ import { import { PluginType } from "entities/Plugin"; import type { FocusEntityInfo } from "navigation/FocusEntity"; import { FocusEntity } from "navigation/FocusEntity"; -import { getQueryEntityItemUrl } from "../pages/Editor/IDE/EditorPane/Query/utils"; +import { getQueryEntityItemUrl } from "ee/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl"; export function setSelectedDatasource(id?: string) { if (id) { diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/ListItem.tsx b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/ListItem.tsx index cf79cc6e9748..65db9a369bd6 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/ListItem.tsx +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/ListItem.tsx @@ -1,6 +1,5 @@ import React from "react"; import ExplorerJSCollectionEntity from "pages/Editor/Explorer/JSActions/JSActionEntity"; -import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers"; import { Flex } from "@appsmith/ads"; import type { EntityItem } from "ee/entities/IDE/constants"; @@ -8,11 +7,10 @@ export interface JSListItemProps { item: EntityItem; isActive: boolean; parentEntityId: string; - parentEntityType: ActionParentEntityTypeInterface; } export const JSListItem = (props: JSListItemProps) => { - const { isActive, item, parentEntityId, parentEntityType } = props; + const { isActive, item, parentEntityId } = props; return ( @@ -21,7 +19,6 @@ export const JSListItem = (props: JSListItemProps) => { isActive={isActive} key={item.key} parentEntityId={parentEntityId} - parentEntityType={parentEntityType} searchKeyword={""} step={1} /> diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/hooks.tsx b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/hooks.tsx index 34ce88dd556a..9f71fb80b129 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/hooks.tsx +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/hooks.tsx @@ -12,7 +12,7 @@ import { ADD_PATH } from "ee/constants/routes/appRoutes"; import history from "utils/history"; import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity"; import { useModuleOptions } from "ee/utils/moduleInstanceHelpers"; -import { getJSUrl } from "ee/pages/Editor/IDE/EditorPane/JS/utils"; +import { getJSUrl } from "ee/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl"; import { getIDEViewMode } from "selectors/ideSelectors"; import { EditorViewMode } from "ee/entities/IDE/constants"; import { setListViewActiveState } from "actions/ideActions"; diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSEntityItemUrl.test.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSEntityItemUrl.test.ts new file mode 100644 index 000000000000..d05e384edd34 --- /dev/null +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSEntityItemUrl.test.ts @@ -0,0 +1,21 @@ +import { getJSEntityItemUrl } from "./getJSEntityItemUrl"; +import urlBuilder from "ee/entities/URLRedirect/URLAssembly"; +import { PluginType } from "entities/Plugin"; + +describe("getJSEntityItemUrl", () => { + urlBuilder.setCurrentBasePageId("0123456789abcdef00000000"); + it("returns a JS url", () => { + const url = getJSEntityItemUrl( + { + title: "TestTitle", + key: "abc", + type: PluginType.JS, + }, + "0123456789abcdef00000000", + ); + + expect(url).toEqual( + "/app/application/page-0123456789abcdef00000000/edit/jsObjects/abc", + ); + }); +}); diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSEntityItemUrl.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSEntityItemUrl.ts new file mode 100644 index 000000000000..e394f9db47fd --- /dev/null +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSEntityItemUrl.ts @@ -0,0 +1,12 @@ +import type { EntityItem } from "ee/entities/IDE/constants"; +import { jsCollectionIdURL } from "ee/RouteBuilder"; + +export const getJSEntityItemUrl = ( + item: EntityItem, + basePageId: string, +): string => { + return jsCollectionIdURL({ + baseCollectionId: item.key, + basePageId, + }); +}; diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils.test.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl.test.ts similarity index 77% rename from app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils.test.ts rename to app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl.test.ts index d12cadbbf429..d71b88d4f4bd 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils.test.ts +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl.test.ts @@ -1,28 +1,9 @@ -import { getJSEntityItemUrl, getJSUrl } from "./utils"; +import { getJSUrl } from "./getJSUrl"; import urlBuilder from "ee/entities/URLRedirect/URLAssembly"; -import { PluginType } from "entities/Plugin"; import type { FocusEntityInfo } from "navigation/FocusEntity"; import { FocusEntity } from "navigation/FocusEntity"; import { EditorState } from "ee/entities/IDE/constants"; -describe("getJSEntityItemUrl", () => { - urlBuilder.setCurrentBasePageId("0123456789abcdef00000000"); - it("returns a JS url", () => { - const url = getJSEntityItemUrl( - { - title: "TestTitle", - key: "abc", - type: PluginType.JS, - }, - "0123456789abcdef00000000", - ); - - expect(url).toEqual( - "/app/application/page-0123456789abcdef00000000/edit/jsObjects/abc", - ); - }); -}); - describe("getJSUrl", () => { urlBuilder.setCurrentBasePageId("0123456789abcdef00000000"); it("returns a JS collection url", () => { diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl.ts similarity index 74% rename from app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils.ts rename to app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl.ts index efc02a20c386..af7f33f6a406 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils.ts +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/JS/utils/getJSUrl.ts @@ -1,4 +1,3 @@ -import type { EntityItem } from "ee/entities/IDE/constants"; import { jsCollectionAddURL, jsCollectionIdURL, @@ -6,16 +5,6 @@ import { } from "ee/RouteBuilder"; import { FocusEntity, type FocusEntityInfo } from "navigation/FocusEntity"; -export const getJSEntityItemUrl = ( - item: EntityItem, - basePageId: string, -): string => { - return jsCollectionIdURL({ - baseCollectionId: item.key, - basePageId, - }); -}; - export const getJSUrl = ( item: FocusEntityInfo, add: boolean = true, diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/ListItem.tsx b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/ListItem.tsx index 9cbf4f993aa8..90db39393a2a 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/ListItem.tsx +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/ListItem.tsx @@ -1,5 +1,4 @@ import React from "react"; -import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers"; import ExplorerActionEntity from "pages/Editor/Explorer/Actions/ActionEntity"; import type { EntityItem } from "ee/entities/IDE/constants"; @@ -7,11 +6,10 @@ export interface QueryListItemProps { item: EntityItem; isActive: boolean; parentEntityId: string; - parentEntityType: ActionParentEntityTypeInterface; } export const QueryListItem = (props: QueryListItemProps) => { - const { isActive, item, parentEntityId, parentEntityType } = props; + const { isActive, item, parentEntityId } = props; return ( { isActive={isActive} key={item.key} parentEntityId={parentEntityId} - parentEntityType={parentEntityType} searchKeyword={""} step={1} type={item.type} diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.tsx b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.tsx index 1c850a191c4f..d7aacb7d649a 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.tsx +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.tsx @@ -15,7 +15,7 @@ import { getHasCreateActionPermission } from "ee/utils/BusinessFeatures/permissi import type { ActionOperation } from "components/editorComponents/GlobalSearch/utils"; import { SEARCH_ITEM_TYPES } from "components/editorComponents/GlobalSearch/utils"; import { createMessage, EDITOR_PANE_TEXTS } from "ee/constants/messages"; -import { getQueryUrl } from "ee/pages/Editor/IDE/EditorPane/Query/utils"; +import { getQueryUrl } from "ee/pages/Editor/IDE/EditorPane/Query/utils/getQueryUrl"; import { ADD_PATH, API_EDITOR_ID_PATH, diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl.test.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl.test.ts new file mode 100644 index 000000000000..211808cffca0 --- /dev/null +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl.test.ts @@ -0,0 +1,26 @@ +import { getQueryEntityItemUrl } from "./getQueryEntityItemUrl"; +import { PluginType } from "entities/Plugin"; + +describe("getQueryEntityItemUrl", () => { + it("throws error if plugin type is not a query", () => { + const item = { + title: "testTitle", + type: PluginType.JS, + key: "abc", + }; + + expect(() => getQueryEntityItemUrl(item, "")).toThrow(); + }); + + it("returns url for a query type plugin", () => { + const item = { + title: "testTitle", + type: PluginType.INTERNAL, + key: "abc", + }; + + expect(getQueryEntityItemUrl(item, "0123456789abcdef00000000")).toEqual( + "/app/application/page-0123456789abcdef00000000/edit/queries/abc", + ); + }); +}); diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl.ts new file mode 100644 index 000000000000..b8b7ae4112de --- /dev/null +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl.ts @@ -0,0 +1,15 @@ +import type { EntityItem } from "ee/entities/IDE/constants"; +import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers"; + +export const getQueryEntityItemUrl = ( + item: EntityItem, + basePageId: string, +): string => { + const config = getActionConfig(item.type); + + if (!config) { + throw Error(`Cannot find url of plugin type ${item.type}`); + } + + return config.getURL(basePageId, item.key, item.type); +}; diff --git a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.test.ts b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryUrl.test.ts similarity index 81% rename from app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.test.ts rename to app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryUrl.test.ts index f6e557398c62..aa5fee5925da 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.test.ts +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryUrl.test.ts @@ -1,34 +1,10 @@ -import { getQueryEntityItemUrl, getQueryUrl } from "./utils"; +import { getQueryUrl } from "./getQueryUrl"; import type { FocusEntityInfo } from "navigation/FocusEntity"; import { FocusEntity } from "navigation/FocusEntity"; import { EditorState } from "ee/entities/IDE/constants"; -import { PluginPackageName, PluginType } from "entities/Plugin"; +import { PluginPackageName } from "entities/Plugin"; import urlBuilder from "ee/entities/URLRedirect/URLAssembly"; -describe("getQueryEntityItemUrl", () => { - it("throws error if plugin type is not a query", () => { - const item = { - title: "testTitle", - type: PluginType.JS, - key: "abc", - }; - - expect(() => getQueryEntityItemUrl(item, "")).toThrow(); - }); - - it("returns url for a query type plugin", () => { - const item = { - title: "testTitle", - type: PluginType.INTERNAL, - key: "abc", - }; - - expect(getQueryEntityItemUrl(item, "0123456789abcdef00000000")).toEqual( - "/app/application/page-0123456789abcdef00000000/edit/queries/abc", - ); - }); -}); - describe("getQueryUrl", () => { urlBuilder.setCurrentBasePageId("0123456789abcdef00000000"); it("gets the correct SAAS plugin url", () => { 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/getQueryUrl.ts similarity index 70% rename from app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.ts rename to app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryUrl.ts index 6a732cee324b..f56cc625940b 100644 --- a/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils.ts +++ b/app/client/src/ce/pages/Editor/IDE/EditorPane/Query/utils/getQueryUrl.ts @@ -1,6 +1,3 @@ -import type { EntityItem } from "ee/entities/IDE/constants"; -import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers"; -import type { FocusEntityInfo } from "navigation/FocusEntity"; import { apiEditorIdURL, queryAddURL, @@ -8,19 +5,7 @@ import { queryListURL, saasEditorApiIdURL, } from "ee/RouteBuilder"; - -export const getQueryEntityItemUrl = ( - item: EntityItem, - basePageId: string, -): string => { - const config = getActionConfig(item.type); - - if (!config) { - throw Error(`Cannot find url of plugin type ${item.type}`); - } - - return config.getURL(basePageId, item.key, item.type); -}; +import type { FocusEntityInfo } from "navigation/FocusEntity"; export const getQueryUrl = ( item: FocusEntityInfo, diff --git a/app/client/src/ce/pages/Editor/gitSync/useReconnectModalData.ts b/app/client/src/ce/pages/Editor/gitSync/useReconnectModalData.ts index 42e4c97d492b..b8c012ee97d1 100644 --- a/app/client/src/ce/pages/Editor/gitSync/useReconnectModalData.ts +++ b/app/client/src/ce/pages/Editor/gitSync/useReconnectModalData.ts @@ -1,10 +1,10 @@ +import { IDE_TYPE } from "ee/entities/IDE/constants"; import { builderURL } from "ee/RouteBuilder"; import { RECONNECT_MISSING_DATASOURCE_CREDENTIALS_DESCRIPTION, SKIP_TO_APPLICATION, createMessage, } from "ee/constants/messages"; -import { EditorNames } from "ee/hooks"; import { getApplicationByIdFromWorkspaces } from "ee/selectors/applicationSelectors"; import { useSelector } from "react-redux"; @@ -36,7 +36,7 @@ function useReconnectModalData({ appId, pageId }: UseReconnectModalDataProps) { editorURL, editorId: appId, parentEntityId: pageId, - editorType: EditorNames.APPLICATION, + ideType: IDE_TYPE.App, }; } diff --git a/app/client/src/ce/selectors/appIDESelectors.ts b/app/client/src/ce/selectors/appIDESelectors.ts index 79d4fd62558b..16fcca2e5e5f 100644 --- a/app/client/src/ce/selectors/appIDESelectors.ts +++ b/app/client/src/ce/selectors/appIDESelectors.ts @@ -9,7 +9,7 @@ import { getJSTabs, getQueryTabs } from "selectors/ideSelectors"; import type { AppState } from "ee/reducers"; import { identifyEntityFromPath } from "navigation/FocusEntity"; import { getCurrentBasePageId } from "selectors/editorSelectors"; -import { getQueryEntityItemUrl } from "ee/pages/Editor/IDE/EditorPane/Query/utils"; +import { getQueryEntityItemUrl } from "ee/pages/Editor/IDE/EditorPane/Query/utils/getQueryEntityItemUrl"; export type EditorSegmentList = Array<{ group: string | "NA"; diff --git a/app/client/src/ce/selectors/entitiesSelector.ts b/app/client/src/ce/selectors/entitiesSelector.ts index d81657d5d4a0..10b30bc32b90 100644 --- a/app/client/src/ce/selectors/entitiesSelector.ts +++ b/app/client/src/ce/selectors/entitiesSelector.ts @@ -64,6 +64,7 @@ import { EditorEntityTab, type EntityItem, type GenericEntityItem, + type IDEType, } from "ee/entities/IDE/constants"; import { ActionUrlIcon, @@ -1701,16 +1702,17 @@ export const getSelectedTableName = (state: AppState) => export const getDatasourceUsageCountForApp = createSelector( getActions, getDatasources, - (state: AppState, editorType: string) => editorType, - (actions, datasources, editorType) => { + (state: AppState, ideType: IDEType) => ideType, + (actions, datasources, ideType) => { const actionCount = countBy(actions, "config.datasource.id"); const actionDsMap: Record = {}; datasources.forEach((ds) => { - actionDsMap[ds.id] = `No queries in this ${editorType}`; + actionDsMap[ds.id] = `No queries in this ${ideType.toLowerCase()}`; }); Object.keys(actionCount).forEach((dsId) => { - actionDsMap[dsId] = `${actionCount[dsId]} queries in this ${editorType}`; + actionDsMap[dsId] = + `${actionCount[dsId]} queries in this ${ideType.toLowerCase()}`; }); return actionDsMap; diff --git a/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx b/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx index 8cd3dcb06c47..e882d308b893 100644 --- a/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx +++ b/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx @@ -43,7 +43,7 @@ import { hasExecuteActionPermission as hasExecuteActionPermission_EE } from "ee/ import { hasAuditLogsReadPermission as hasAuditLogsReadPermission_CE } from "ce/utils/permissionHelpers"; import { hasAuditLogsReadPermission as hasAuditLogsReadPermission_EE } from "ee/utils/permissionHelpers"; -import { EditorNames } from "ee/hooks"; +import { IDE_TYPE, type IDEType } from "ee/entities/IDE/constants"; export const getHasCreateWorkspacePermission = ( isEnabled: boolean, @@ -167,16 +167,16 @@ export const getHasAuditLogsReadPermission = ( export const hasCreateDSActionPermissionInApp = ({ dsPermissions, - editorType, + ideType, isEnabled, pagePermissions, }: { dsPermissions?: string[]; - editorType?: string; + ideType?: IDEType; isEnabled: boolean; pagePermissions?: string[]; }) => { - return !editorType || editorType === EditorNames.APPLICATION + return !ideType || ideType === IDE_TYPE.App ? getHasCreateDatasourceActionPermission(isEnabled, dsPermissions) && getHasCreateActionPermission(isEnabled, pagePermissions) : getHasCreateDatasourceActionPermission(isEnabled, dsPermissions); diff --git a/app/client/src/ce/utils/lintRulesHelpers.ts b/app/client/src/ce/utils/lintRulesHelpers.ts index fc857cad6b1e..fe0c07471d15 100644 --- a/app/client/src/ce/utils/lintRulesHelpers.ts +++ b/app/client/src/ce/utils/lintRulesHelpers.ts @@ -1,5 +1,7 @@ +import type { IDEType } from "ee/entities/IDE/constants"; + interface ContextType { - editorType: string; + ideType: IDEType; } /** diff --git a/app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx b/app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx index b728ad86e495..c42dd6c333a3 100644 --- a/app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx +++ b/app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx @@ -80,7 +80,7 @@ function DropdownWrapper(props: DropdownWrapperProps) { return (