Skip to content

Commit

Permalink
Sync changes from EE excluding enterprise directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushpahwa committed Sep 3, 2024
1 parent fb21570 commit 5cb101f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/client/src/ce/utils/workflowHelpers.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -91,13 +98,16 @@ export const useFilteredFileOperations = ({
plugins,
recentlyUsedDSMap,
query,
// TODO: Remove this once workflows can support multiple JS objects
disableJSObjectCreation,
});
};

export const useFilteredAndSortedFileOperations = ({
allDatasources = [],
canCreateActions = true,
canCreateDatasource = true,
disableJSObjectCreation = false,
moduleOptions = [],
plugins = [],
query,
Expand All @@ -112,6 +122,7 @@ export const useFilteredAndSortedFileOperations = ({
query: string;
recentlyUsedDSMap?: Record<string, number>;
workflowOptions?: ActionOperation[];
disableJSObjectCreation?: boolean;
}) => {
const fileOperations: ActionOperation[] = [];

Expand All @@ -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]);
}
Expand Down

0 comments on commit 5cb101f

Please sign in to comment.