From 5cb101fca88fad7d8ddba64ccec99b76fd49674b Mon Sep 17 00:00:00 2001 From: Ayush Pahwa Date: Tue, 3 Sep 2024 21:38:44 +0530 Subject: [PATCH] Sync changes from EE excluding enterprise directory --- app/client/src/ce/utils/workflowHelpers.ts | 7 +++ .../GlobalSearch/GlobalSearchHooks.test.ts | 54 +++++++++++++++++++ .../GlobalSearch/GlobalSearchHooks.tsx | 19 +++++-- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/app/client/src/ce/utils/workflowHelpers.ts b/app/client/src/ce/utils/workflowHelpers.ts index b7f05145a5e..63cdcdf4d14 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 a5f28a5458c..c3f7760d308 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 812c4cd6fe3..6a97013bca2 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.tsx +++ b/app/client/src/components/editorComponents/GlobalSearch/GlobalSearchHooks.tsx @@ -38,8 +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 urlBuilder, { EDITOR_TYPE } from "ee/entities/URLRedirect/URLAssembly"; +import { + checkIfJSObjectCreationAllowed, + useWorkflowOptions, +} from "ee/utils/workflowHelpers"; export interface FilterFileOperationsProps { canCreateActions: boolean; @@ -59,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(); @@ -91,6 +98,8 @@ export const useFilteredFileOperations = ({ plugins, recentlyUsedDSMap, query, + // TODO: Remove this once workflows can support multiple JS objects + disableJSObjectCreation, }); }; @@ -98,6 +107,7 @@ export const useFilteredAndSortedFileOperations = ({ allDatasources = [], canCreateActions = true, canCreateDatasource = true, + disableJSObjectCreation = false, moduleOptions = [], plugins = [], query, @@ -112,6 +122,7 @@ export const useFilteredAndSortedFileOperations = ({ query: string; recentlyUsedDSMap?: Record; workflowOptions?: ActionOperation[]; + disableJSObjectCreation?: boolean; }) => { const fileOperations: ActionOperation[] = []; @@ -128,10 +139,8 @@ export const useFilteredAndSortedFileOperations = ({ */ const actionOps = updateActionOperations(plugins, actionOperations); - // 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 check once workflows can support multiple JS objects - if (urlBuilder.getDefaultEditorType() !== EDITOR_TYPE.WORKFLOW) { + if (!disableJSObjectCreation) { // Add JS Object operation fileOperations.push(actionOps[2]); }