From 72d18157d2a47011738366079cfe0b2e2548add7 Mon Sep 17 00:00:00 2001 From: Ayush Pahwa Date: Wed, 4 Sep 2024 11:37:09 +0800 Subject: [PATCH] feat: disable create js object option in workflows editor (#36094) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Workflows is not currently supporting multiple js objects. Hence, we need to disable the option for the workflows editor. EE branch: https://github.com/appsmithorg/appsmith-ee/pull/5027 Fixes #32239 ## Automation /test js ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 5cb101fca88fad7d8ddba64ccec99b76fd49674b > Cypress dashboard. > Tags: `@tag.JS` > Spec: >
Tue, 03 Sep 2024 16:45:16 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit - **New Features** - Enhanced logic for creating new JavaScript objects, preventing unnecessary additions in the workflow editor. - Introduced a function to determine if creating a new JavaScript object is allowed, improving user experience in the workflow editor. - Improved responsiveness of the Files component based on the parent entity type, allowing for context-sensitive behavior. - **Bug Fixes** - Addressed limitations in workflow runner support for multiple JavaScript objects. - **Refactor** - Simplified the `onCreate` function's dependencies for improved clarity and functionality. - **Tests** - Added new test cases to validate the behavior of JavaScript object creation options based on user settings. --- app/client/src/ce/utils/workflowHelpers.ts | 7 +++ .../GlobalSearch/GlobalSearchHooks.test.ts | 54 +++++++++++++++++++ .../GlobalSearch/GlobalSearchHooks.tsx | 21 ++++++-- .../src/pages/Editor/Explorer/Files/index.tsx | 6 +-- 4 files changed, 82 insertions(+), 6 deletions(-) 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 (