diff --git a/frontend/src/AppBuilder/RightSideBar/Inspector/EventManager.jsx b/frontend/src/AppBuilder/RightSideBar/Inspector/EventManager.jsx index 036f437170..f5c2761d9e 100644 --- a/frontend/src/AppBuilder/RightSideBar/Inspector/EventManager.jsx +++ b/frontend/src/AppBuilder/RightSideBar/Inspector/EventManager.jsx @@ -19,15 +19,29 @@ import { EmptyTitle, EmptyDescription, EmptyContent, + Select as RocketSelect, + SelectTrigger, + SelectContent as RocketSelectContent, + SelectItem, + SelectValue, + SelectGroup, + SelectLabel, + Combobox, + ComboboxInput, + ComboboxContent as RocketComboboxContent, + ComboboxList, + ComboboxItem, + ComboboxEmpty, + ToggleGroup as RocketToggleGroup, + ToggleGroupItem as RocketToggleGroupItem, } from '@/components/ui/Rocket'; +import { cn } from '@/lib/utils'; import { GotoApp } from './ActionConfigurationPanels/GotoApp'; import { SwitchPage } from './ActionConfigurationPanels/SwitchPage'; import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'; import useDraggableInPortal from '@/_hooks/useDraggableInPortal'; import _, { get } from 'lodash'; import { componentTypes } from '@/AppBuilder/WidgetManager'; -import Select from '@/_ui/Select'; -import defaultStyles from '@/_ui/Select/styles'; import { useTranslation } from 'react-i18next'; import RunjsParameters from './ActionConfigurationPanels/RunjsParamters'; import { useAppDataActions } from '@/_stores/appDataStore'; @@ -42,11 +56,29 @@ import { deepClone } from '@/_helpers/utilities/utils.helpers'; import useStore from '@/AppBuilder/_stores/store'; import { useEventActions, useEvents } from '@/AppBuilder/_stores/slices/eventsSlice'; import { useModuleContext } from '@/AppBuilder/_contexts/ModuleContext'; -import ToggleGroup from '@/ToolJetUI/SwitchGroup/ToggleGroup'; -import ToggleGroupItem from '@/ToolJetUI/SwitchGroup/ToggleGroupItem'; -import SolidIcon from '@/_ui/Icon/SolidIcons'; -import { components as selectComponents } from 'react-select'; import posthogHelper from '@/modules/common/helpers/posthogHelper'; +import './EventManager.scss'; + +const FieldRow = ({ label, dataCy, children, className }) => ( +
+ + {label} + +
{children}
+
+); + +const POPOVER_MENU_Z = 'tw-z-[1043]'; + +const isDarkThemeActive = () => typeof window !== 'undefined' && window.localStorage?.getItem('darkMode') === 'true'; + +const SelectContent = ({ className, ...props }) => ( + +); + +const ComboboxContent = ({ className, ...props }) => ( + +); export const EventManager = ({ sourceId, @@ -135,53 +167,6 @@ export const EventManager = ({ }); const darkMode = localStorage.getItem('darkMode') === 'true'; - const styles = { - ...defaultStyles(darkMode), - menuPortal: (provided) => ({ ...provided, zIndex: 9999 }), - menuList: (base) => ({ - ...base, - }), - }; - - const actionStyles = { - ...styles, - menuList: (base) => ({ - ...base, - padding: '8px 0 8px 8px', - '&::-webkit-scrollbar': { - width: '10px', - }, - '&::-webkit-scrollbar-track': { - background: 'transparent', - }, - '&::-webkit-scrollbar-thumb': { - background: '#E4E7EB', - border: '1px solid transparent', - backgroundClip: 'content-box', - }, - '&::-webkit-scrollbar-thumb:hover': { - background: '#E4E7EB !important', - border: '1px solid transparent !important', - backgroundClip: 'content-box !important', - }, - '&:hover': { - '&::-webkit-scrollbar-thumb': { - background: '#E4E7EB !important', - border: '1px solid transparent !important', - backgroundClip: 'content-box !important', - }, - }, - }), - group: (base) => ({ - ...base, - padding: 0, - }), - groupHeading: (base) => ({ - ...base, - margin: 0, - padding: '0', - }), - }; const actionLookup = Object.fromEntries(ActionTypes.map((actionType) => [actionType.id, actionType])); @@ -518,29 +503,6 @@ export const EventManager = ({ const moduleInputs = Object.entries(moduleInputDummyQueries).map(([key, value]) => ({ name: value, value: key })); return [...moduleInputs, ...queries]; }; - const formatGroupLabel = (data) => { - if (data.label === 'run-action') return; - return ( -
- ); - }; - - const CustomOption = (props) => { - return ( - -
-
- {props.isSelected && } -
- {props.label} -
-
- ); - }; - function eventPopover(eventHandler, index) { const event = eventHandler?.event || {}; @@ -555,116 +517,111 @@ export const EventManager = ({ variant="ghost" size="medium" iconOnly + leadingVisual={} onClick={() => { setFocusedEventIndex(null); duplicateHandler(index); }} aria-label={t('editor.inspector.eventManager.duplicate', 'Duplicate')} data-cy="event-duplicate-btn" - > - - + > + >
-
-
- {t('editor.inspector.eventManager.enableEvent', 'Enable event')} +
+
+ +
+ handlerChanged(index, 'disabled', !checked)} + aria-label={t('editor.inspector.eventManager.enableEvent', 'Enable event')} + data-cy="event-disabled-toggle" + /> +
+
+ +
+ handlerChanged(index, 'name', value)} + usePortalEditor={false} + component={component} + cyLabel={`event-name`} + /> +
+
-
-
-
-
- {t('editor.inspector.eventManager.eventName', 'Event name')} -
-
- handlerChanged(index, 'name', value)} - usePortalEditor={false} - component={component} - cyLabel={`event-name`} - /> -
-
-
-
- {t('editor.inspector.eventManager.event', 'Event')} -
-
- group.options) - .find((option) => option.value === event.actionId)} - components={{ Option: CustomOption }} - search={false} - onChange={(value) => handlerChanged(index, 'actionId', value)} - placeholder={t('globals.select', 'Select') + '...'} - styles={actionStyles} - useMenuPortal={false} - useCustomStyles={true} - formatGroupLabel={formatGroupLabel} - /> -
-
- -
-
- {t('editor.inspector.eventManager.runOnlyIf', 'Run Only If')} -
-
- handlerChanged(index, 'runOnlyIf', value)} - usePortalEditor={false} - component={component} - cyLabel={`run-only-if`} - /> +
@@ -677,14 +634,11 @@ export const EventManager = ({
)} -
+
{event.actionId === 'show-alert' && ( <> -
-
- {t('editor.inspector.eventManager.message', 'Message')} -
-
+ +
-
-
-
- {t('editor.inspector.eventManager.alertType', 'Alert Type')} -
-
- { - handlerChanged(index, 'modal', value); - }} - placeholder={t('globals.select', 'Select') + '...'} - styles={styles} - useMenuPortal={false} - useCustomStyles={true} - /> -
-
+ + {(() => { + const modalOptions = [...getComponentOptions('Modal'), ...getComponentOptions('ModalV2')]; + const selectedId = event.modal?.id ?? event.modal; + const selected = modalOptions.find((o) => o.value === selectedId) ?? null; + return ( + item?.name ?? ''} + value={selected} + onValueChange={(item) => handlerChanged(index, 'modal', item?.value ?? null)} + > + + + + {(item) => ( + + {item.name} + + )} + + {t('globals.noResultsFound', 'No results found.')} + + + ); + })()} + )} {event.actionId === 'close-modal' && ( -
-
{t('editor.inspector.eventManager.modal', 'Modal')}
-
- { - const query = dataQueries.find((dataquery) => dataquery.id === value); - - // If it is a module editor and the query is not found in the data queries, then it is a module input dummy query - if (isModuleEditor && query === undefined) { - handleQueryChange(index, { - queryId: value, - queryName: moduleInputDummyQueries[value], - parameters: {}, - }); - } else { - const parameters = (query?.options?.parameters ?? []).reduce( - (paramObj, param) => ({ - ...paramObj, - [param.name]: param.defaultValue, - }), - {} - ); - - handleQueryChange(index, { - queryId: query.id, - queryName: query.name, - parameters: parameters, - }); - } - }} - placeholder={t('globals.select', 'Select') + '...'} - styles={styles} - useMenuPortal={false} - useCustomStyles={true} - /> -
-
+ + {(() => { + const queryOptions = constructDataQueryOptions(); + const selected = queryOptions.find((o) => o.value === event?.queryId) ?? null; + return ( +
+ item?.name ?? ''} + value={selected} + onValueChange={(item) => { + const value = item?.value; + if (value == null) return; + const query = dataQueries.find((dataquery) => dataquery.id === value); + if (isModuleEditor && query === undefined) { + handleQueryChange(index, { + queryId: value, + queryName: moduleInputDummyQueries[value], + parameters: {}, + }); + } else { + const parameters = (query?.options?.parameters ?? []).reduce( + (paramObj, param) => ({ + ...paramObj, + [param.name]: param.defaultValue, + }), + {} + ); + handleQueryChange(index, { + queryId: query.id, + queryName: query.name, + parameters: parameters, + }); + } + }} + > + + + + {(item) => ( + + {item.name} + + )} + + {t('globals.noResultsFound', 'No results found.')} + + +
+ ); + })()} +
{event.actionId === 'run-query' && ( )} @@ -856,201 +844,180 @@ export const EventManager = ({ {event.actionId === 'set-localstorage-value' && ( <> -
-
{t('editor.inspector.eventManager.key', 'Key')}
-
- handlerChanged(index, 'key', value)} - usePortalEditor={false} - component={component} - /> -
-
-
-
{t('editor.inspector.eventManager.value', 'Value')}
-
- handlerChanged(index, 'value', value)} - usePortalEditor={false} - component={component} - /> -
-
+ + handlerChanged(index, 'key', value)} + usePortalEditor={false} + component={component} + /> + + + handlerChanged(index, 'value', value)} + usePortalEditor={false} + component={component} + /> + )} {event.actionId === 'generate-file' && ( <> -
-
{t('editor.inspector.eventManager.type', 'Type')}
-
- { - handlerChanged(index, 'table', value); - }} - placeholder={t('globals.select', 'Select') + '...'} - styles={styles} - useMenuPortal={false} - useCustomStyles={true} - /> -
-
-
-
{t('editor.inspector.eventManager.pageIndex', 'Page index')}
-
- handlerChanged(index, 'pageIndex', value)} - usePortalEditor={false} - component={component} - /> -
-
+ + {(() => { + const tableOptions = getComponentOptions('Table'); + const selected = tableOptions.find((o) => o.value === event.table) ?? null; + return ( + item?.name ?? ''} + value={selected} + onValueChange={(item) => handlerChanged(index, 'table', item?.value ?? null)} + > + + + + {(item) => ( + + {item.name} + + )} + + {t('globals.noResultsFound', 'No results found.')} + + + ); + })()} + + + handlerChanged(index, 'pageIndex', value)} + usePortalEditor={false} + component={component} + /> + )} {event.actionId === 'set-custom-variable' && ( <> -
-
{t('editor.inspector.eventManager.key', 'Key')}
-
- handlerChanged(index, 'key', value)} - enablePreview={true} - cyLabel={`event-key`} - component={component} - /> -
-
-
-
{t('editor.inspector.eventManager.value', 'Value')}
-
- handlerChanged(index, 'value', value)} - cyLabel={`variable`} - component={component} - /> -
-
+ + handlerChanged(index, 'key', value)} + enablePreview={true} + cyLabel={`event-key`} + component={component} + /> + + + handlerChanged(index, 'value', value)} + cyLabel={`variable`} + component={component} + /> + )} {event.actionId === 'unset-custom-variable' && ( - <> -
-
{t('editor.inspector.eventManager.key', 'Key')}
-
- handlerChanged(index, 'key', value)} - component={component} - /> -
-
- + + handlerChanged(index, 'key', value)} + component={component} + /> + )} {event.actionId === 'set-page-variable' && ( <> -
-
{t('editor.inspector.eventManager.key', 'Key')}
-
- handlerChanged(index, 'key', value)} - cyLabel={`key`} - component={component} - /> -
-
-
-
{t('editor.inspector.eventManager.value', 'Value')}
-
- handlerChanged(index, 'value', value)} - cyLabel={`variable`} - component={component} - /> -
-
+ + handlerChanged(index, 'key', value)} + cyLabel={`key`} + component={component} + /> + + + handlerChanged(index, 'value', value)} + cyLabel={`variable`} + component={component} + /> + )} {event.actionId === 'unset-page-variable' && ( - <> -
-
{t('editor.inspector.eventManager.key', 'Key')}
-
- handlerChanged(index, 'key', value)} - cyLabel={`key`} - component={component} - /> -
-
- + + handlerChanged(index, 'key', value)} + cyLabel={`key`} + component={component} + /> + )} {event.actionId === 'switch-page' && ( -
-
{t('editor.inspector.eventManager.component', 'Component')}
-
- + {(() => { + const componentOptions = getComponentsOptionsWithoutModalChilds(); + const selected = componentOptions.find((o) => o.value === event.componentId) ?? null; + return ( + item?.name ?? ''} + value={selected} + onValueChange={(item) => handlerChanged(index, 'componentId', item?.value ?? null)} + > + + + + {(item) => ( + + {item.name} + + )} + + {t('globals.noResultsFound', 'No results found.')} + + + ); + })()} + + + handlerChanged(index, 'scrollBehavior', value)} + > + + + + + {[ { name: 'Smooth', value: 'smooth' }, { name: 'Instant', value: 'instant' }, { name: 'Auto', value: 'auto' }, - ]} - value={event.scrollBehavior ?? 'smooth'} - search={false} - onChange={(value) => handlerChanged(index, 'scrollBehavior', value)} - placeholder={t('globals.select', 'Select') + '...'} - styles={styles} - useMenuPortal={false} - useCustomStyles={true} - /> -
-
-
-
Block
-
- { - handlerChanged(index, 'componentId', value); - }} - placeholder={t('globals.select', 'Select') + '...'} - styles={styles} - useMenuPortal={false} - useCustomStyles={true} - /> -
-
-
-
- {t('editor.inspector.eventManager.action', 'Action')} -
-
- { - onChangeHandlerForComponentSpecificActionHandle(value, index, param, event); - }} - placeholder={t('globals.select', 'Select') + '...'} - styles={styles} - useMenuPortal={false} - useCustomStyles={true} - /> -
- ) : ( -
- { - onChangeHandlerForComponentSpecificActionHandle(value, index, param, event); - }} - paramLabel={' '} - paramType={param?.type} - fieldMeta={{ options: param?.options }} - cyLabel={`event-${param.displayName}`} - component={component} - isEventManagerParam={true} - /> -
- )} -
+ ); })} )} {event.actionId === 'toggle-app-mode' && ( <> -
-
{t('editor.inspector.eventManager.appMode', 'App mode')}
-
-