diff --git a/app/client/src/ce/utils/workflowHelpers.ts b/app/client/src/ce/utils/workflowHelpers.ts index b7f05145a5..63cdcdf4d1 100644 --- a/app/client/src/ce/utils/workflowHelpers.ts +++ b/app/client/src/ce/utils/workflowHelpers.ts @@ -1,3 +1,10 @@ export const useWorkflowOptions = () => { return []; }; + +// We don't want to show the create new JS object option if the user is in the workflow editor +// this is done since worflows runner doesn't support multiple JS objects +// TODO: Remove this once workflows can support multiple JS objects +export const checkIfJSObjectCreationAllowed = () => { + return false; +}; diff --git a/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.test.ts b/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.test.ts index a5f28a5458..c3f7760d30 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.test.ts +++ b/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.test.ts @@ -295,4 +295,58 @@ describe("getFilteredAndSortedFileOperations", () => { }), ); }); + + it("should not show new js object option if disableJSObjectCreation is true", () => { + const fileOptions = useFilteredAndSortedFileOperations({ + query: "new js", + allDatasources: [], + recentlyUsedDSMap: {}, + canCreateActions: true, + canCreateDatasource: true, + disableJSObjectCreation: true, + }); + + expect(fileOptions.length).toEqual(1); + expect(fileOptions[0]).toEqual( + expect.objectContaining({ + title: "New datasource", + }), + ); + }); + + it("should show new js object option if disableJSObjectCreation is false", () => { + const fileOptions = useFilteredAndSortedFileOperations({ + query: "new js", + allDatasources: [], + recentlyUsedDSMap: {}, + canCreateActions: true, + canCreateDatasource: true, + disableJSObjectCreation: false, + }); + + expect(fileOptions.length).toEqual(2); + expect(fileOptions[0]).toEqual( + expect.objectContaining({ + title: "New JS Object", + }), + ); + }); + + it("should show new js object option if disableJSObjectCreation is not set", () => { + const fileOptions = useFilteredAndSortedFileOperations({ + query: "new js", + allDatasources: [], + recentlyUsedDSMap: {}, + canCreateActions: true, + canCreateDatasource: true, + disableJSObjectCreation: false, + }); + + expect(fileOptions.length).toEqual(2); + expect(fileOptions[0]).toEqual( + expect.objectContaining({ + title: "New JS Object", + }), + ); + }); }); diff --git a/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.tsx b/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.tsx index 883bc58b86..6a97013bca 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.tsx +++ b/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.tsx @@ -38,7 +38,10 @@ import type { Plugin } from "api/PluginApi"; import { useModuleOptions } from "ee/utils/moduleInstanceHelpers"; import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers"; import { createNewQueryBasedOnParentEntity } from "ee/actions/helpers"; -import { useWorkflowOptions } from "ee/utils/workflowHelpers"; +import { + checkIfJSObjectCreationAllowed, + useWorkflowOptions, +} from "ee/utils/workflowHelpers"; export interface FilterFileOperationsProps { canCreateActions: boolean; @@ -58,6 +61,11 @@ export const useFilteredFileOperations = ({ const moduleOptions = useModuleOptions(); const workflowOptions = useWorkflowOptions(); + // We don't want to show the create new JS object option if the user is in the workflow editor + // this is done since worflows runner doesn't support multiple JS objects + // TODO: Remove this once workflows can support multiple JS objects + const disableJSObjectCreation = checkIfJSObjectCreationAllowed(); + // helper map for sorting based on recent usage const recentlyUsedDSMap = useRecentlyUsedDSMap(); @@ -90,6 +98,8 @@ export const useFilteredFileOperations = ({ plugins, recentlyUsedDSMap, query, + // TODO: Remove this once workflows can support multiple JS objects + disableJSObjectCreation, }); }; @@ -97,6 +107,7 @@ export const useFilteredAndSortedFileOperations = ({ allDatasources = [], canCreateActions = true, canCreateDatasource = true, + disableJSObjectCreation = false, moduleOptions = [], plugins = [], query, @@ -111,6 +122,7 @@ export const useFilteredAndSortedFileOperations = ({ query: string; recentlyUsedDSMap?: Record; workflowOptions?: ActionOperation[]; + disableJSObjectCreation?: boolean; }) => { const fileOperations: ActionOperation[] = []; @@ -127,8 +139,11 @@ export const useFilteredAndSortedFileOperations = ({ */ const actionOps = updateActionOperations(plugins, actionOperations); - // Add JS Object operation - fileOperations.push(actionOps[2]); + // TODO: Remove this check once workflows can support multiple JS objects + if (!disableJSObjectCreation) { + // Add JS Object operation + fileOperations.push(actionOps[2]); + } // Add Module operations if (moduleOptions.length > 0) { diff --git a/app/client/src/pages/Editor/Explorer/Files/index.tsx b/app/client/src/pages/Editor/Explorer/Files/index.tsx index 60c8d524b1..0cf1d60055 100644 --- a/app/client/src/pages/Editor/Explorer/Files/index.tsx +++ b/app/client/src/pages/Editor/Explorer/Files/index.tsx @@ -67,7 +67,7 @@ function Files() { const onCreate = useCallback(() => { openMenu(true); - }, [dispatch, openMenu]); + }, [openMenu]); const activeActionBaseId = useActiveActionBaseId(); @@ -141,7 +141,7 @@ function Files() { ); } }), - [files, activeActionBaseId, parentEntityId], + [files, activeActionBaseId, parentEntityId, parentEntityType], ); const handleClick = useCallback( @@ -161,7 +161,7 @@ function Files() { item.redirect(parentEntityId, DatasourceCreateEntryPoints.SUBMENU); } }, - [parentEntityId, dispatch], + [dispatch, parentEntityId, parentEntityType], ); return (