Skip to content
12 changes: 11 additions & 1 deletion app/client/src/assets/icons/menu/js-function.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { IDEToolbar } from "IDE";
import React, { useState } from "react";
import { IDEToolbar, ToolbarSettingsPopover } from "IDE";
import { JSFunctionRun } from "./components/JSFunctionRun";
import type { JSActionDropdownOption } from "./types";
import type { SaveActionNameParams } from "PluginActionEditor";
Expand All @@ -8,6 +8,7 @@ import type { JSAction, JSCollection } from "entities/JSCollection";
import type { DropdownOnSelect } from "@appsmith/ads-old";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import { createMessage, JS_EDITOR_SETTINGS } from "ee/constants/messages";
import { JSHeader } from "./JSHeader";
import { JSFunctionSettings } from "./components/JSFunctionSettings";
import type { JSFunctionSettingsProps } from "./components/old/JSFunctionSettings";
Expand Down Expand Up @@ -48,6 +49,8 @@ export const JSEditorToolbar = (props: Props) => {
FEATURE_FLAG.release_actions_redesign_enabled,
);

const [isOpen, setIsOpen] = useState(false);

// If the action redesign is not enabled, render the JSHeader component
if (!isActionRedesignEnabled) {
return <JSHeader {...props} />;
Expand All @@ -71,11 +74,18 @@ export const JSEditorToolbar = (props: Props) => {
/>
</div>
{props.showSettings ? (
<JSFunctionSettings
actions={props.jsActions}
disabled={!props.changePermitted}
onUpdateSettings={props.onUpdateSettings}
/>
<ToolbarSettingsPopover
dataTestId={"t--js-editor-SETTINGS"}
handleOpenChange={setIsOpen}
isOpen={isOpen}
title={createMessage(JS_EDITOR_SETTINGS.TITLE)}
>
<JSFunctionSettings
actions={props.jsActions}
disabled={!props.changePermitted}
onUpdateSettings={props.onUpdateSettings}
/>
</ToolbarSettingsPopover>
) : null}

{props.hideContextMenuOnEditor ? null : props.contextMenu}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { JSActionDropdownOption } from "../types";
import React, { useCallback } from "react";
import { MenuItem } from "@appsmith/ads";
import { MenuTitle } from "./styled";

export const JSFunctionItem = ({
onSelect,
option,
}: {
option: JSActionDropdownOption;
onSelect: (option: JSActionDropdownOption) => void;
}) => {
const onFunctionSelect = useCallback(() => {
onSelect(option);
}, [onSelect, option]);

return (
<MenuItem onSelect={onFunctionSelect} size="sm">
<MenuTitle>{option.label}</MenuTitle>
</MenuItem>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
Flex,
Menu,
MenuContent,
MenuItem,
MenuTrigger,
Tooltip,
} from "@appsmith/ads";
import type { JSActionDropdownOption } from "../types";
import { RUN_BUTTON_DEFAULTS, testLocators } from "../constants";
import { createMessage, NO_JS_FUNCTION_TO_RUN } from "ee/constants/messages";
import { JSFunctionItem } from "./JSFunctionItem";

interface Props {
disabled: boolean;
Expand All @@ -33,16 +33,21 @@ interface Props {
*
*/
export const JSFunctionRun = (props: Props) => {
const { onSelect } = props;

const isActionRedesignEnabled = useFeatureFlag(
FEATURE_FLAG.release_actions_redesign_enabled,
);

// Callback function to handle function selection from the dropdown menu
const onFunctionSelect = useCallback((option: JSActionDropdownOption) => {
if (props.onSelect) {
props.onSelect(option.value);
}
}, []);
const onFunctionSelect = useCallback(
(option: JSActionDropdownOption) => {
if (onSelect) {
onSelect(option.value);
}
},
[onSelect],
);

if (!isActionRedesignEnabled) {
return <OldJSFunctionRun {...props} />;
Expand All @@ -58,20 +63,18 @@ export const JSFunctionRun = (props: Props) => {
isDisabled={props.disabled}
kind="tertiary"
size="sm"
startIcon=""
startIcon="js-function"
>
{props.selected.label}
</Button>
</MenuTrigger>
<MenuContent align="end">
{props.options.map((option) => (
<MenuItem
<JSFunctionItem
key={option.label}
onSelect={() => onFunctionSelect(option)}
size="sm"
>
{option.label}
</MenuItem>
onSelect={onFunctionSelect}
option={option}
/>
))}
</MenuContent>
</Menu>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import "@testing-library/jest-dom";
import { render, screen, fireEvent } from "test/testUtils";
import { render, screen } from "test/testUtils";
import { JSFunctionSettings } from "./JSFunctionSettings";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { JSObjectFactory } from "test/factories/Actions/JSObject";
Expand Down Expand Up @@ -31,8 +31,6 @@ describe("JSFunctionSettings", () => {
/>,
);

fireEvent.click(screen.getByRole("button"));

expect(screen.getByLabelText(actions[0].name)).toBeDisabled();
});

Expand All @@ -47,8 +45,6 @@ describe("JSFunctionSettings", () => {
/>,
);

fireEvent.click(screen.getByRole("button"));

expect(screen.getAllByRole("switch")).toHaveLength(actions.length);
});

Expand All @@ -74,8 +70,6 @@ describe("JSFunctionSettings", () => {
/>,
);

fireEvent.click(screen.getByRole("button"));

const switchElement1 = screen.getByLabelText(updatedJSActions[0].name);
const switchElement2 = screen.getByLabelText(updatedJSActions[1].name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import { createMessage, JS_EDITOR_SETTINGS } from "ee/constants/messages";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import { ToolbarSettingsPopover } from "IDE";

interface Props {
disabled: boolean;
Expand Down Expand Up @@ -73,8 +72,6 @@ export const JSFunctionSettings = (props: Props) => {
FEATURE_FLAG.release_actions_redesign_enabled,
);

const [isOpen, setIsOpen] = useState(false);

// If the feature flag is disabled, render the old version of the component
if (!isActionRedesignEnabled) {
return (
Expand All @@ -88,25 +85,18 @@ export const JSFunctionSettings = (props: Props) => {

// Render the new version of the component
return (
<ToolbarSettingsPopover
Comment thread
ankitakinger marked this conversation as resolved.
dataTestId={"t--js-editor-SETTINGS"}
handleOpenChange={setIsOpen}
isOpen={isOpen}
title={createMessage(JS_EDITOR_SETTINGS.TITLE)}
>
<Flex flexDirection="column" gap="spaces-4" w="100%">
<Text kind="heading-xs">
{createMessage(JS_EDITOR_SETTINGS.ON_LOAD_TITLE)}
</Text>
{props.actions.map((action) => (
<FunctionSettingRow
action={action}
disabled={props.disabled}
key={action.id}
onUpdateSettings={props.onUpdateSettings}
/>
))}
</Flex>
</ToolbarSettingsPopover>
<Flex flexDirection="column" gap="spaces-4" w="100%">
<Text kind="heading-xs">
{createMessage(JS_EDITOR_SETTINGS.ON_LOAD_TITLE)}
</Text>
{props.actions.map((action) => (
<FunctionSettingRow
action={action}
disabled={props.disabled}
key={action.id}
onUpdateSettings={props.onUpdateSettings}
/>
))}
</Flex>
Comment thread
hetunandu marked this conversation as resolved.
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import styled from "styled-components";
Comment thread
hetunandu marked this conversation as resolved.
import { Text } from "@appsmith/ads";

export const MenuTitle = styled(Text)`
--button-font-weight: bold;
overflow: hidden;
text-overflow: ellipsis;
max-width: 30ch;
`;