feat: disable create js object option in workflows editor (#36094)

## 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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10686636668>
> Commit: 5cb101fca88fad7d8ddba64ccec99b76fd49674b
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10686636668&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS`
> Spec:
> <hr>Tue, 03 Sep 2024 16:45:16 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Ayush Pahwa 2024-09-04 11:37:09 +08:00 committed by GitHub
parent 6ad6a114c3
commit 72d18157d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 82 additions and 6 deletions

View File

@ -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;
};

View File

@ -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",
}),
);
});
});

View File

@ -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<string, number>;
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) {

View File

@ -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 (