From 2d55d90235a61b558e6fa95acebad748f122a8a5 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Thu, 16 Jan 2025 18:58:25 +0100 Subject: [PATCH 1/4] Update database event selection --- .../utils/generateWorkflowDiagram.ts | 2 +- .../components/WorkflowStepHeader.tsx | 6 +- ...DrawerWorkflowSelectTriggerTypeContent.tsx | 38 +++++++++- .../WorkflowEditTriggerDatabaseEventForm.tsx | 75 ++++--------------- .../constants/DatabaseTriggerName.ts | 5 ++ .../constants/DatabaseTriggerTypes.ts | 25 +++++++ .../constants/ObjectEventTriggers.ts | 8 +- .../{TriggerTypes.ts => OtherTriggerTypes.ts} | 9 +-- .../utils/getTriggerDefaultDefinition.ts | 17 ++++- .../utils/getTriggerStepName.ts | 4 +- 10 files changed, 107 insertions(+), 82 deletions(-) create mode 100644 packages/twenty-front/src/modules/workflow/workflow-trigger/constants/DatabaseTriggerName.ts create mode 100644 packages/twenty-front/src/modules/workflow/workflow-trigger/constants/DatabaseTriggerTypes.ts rename packages/twenty-front/src/modules/workflow/workflow-trigger/constants/{TriggerTypes.ts => OtherTriggerTypes.ts} (62%) diff --git a/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/generateWorkflowDiagram.ts b/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/generateWorkflowDiagram.ts index a760a019cf35..1cdfe811a05f 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/generateWorkflowDiagram.ts +++ b/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/generateWorkflowDiagram.ts @@ -70,7 +70,7 @@ export const generateWorkflowDiagram = ({ trigger.settings.eventName, ); - triggerLabel = `${capitalize(triggerEvent.objectType)} is ${capitalize(triggerEvent.event)}`; + triggerLabel = `Record is ${capitalize(triggerEvent.event)}`; break; } diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx index c5fcba10a700..6bd8f30fd0c2 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx +++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepHeader.tsx @@ -1,9 +1,9 @@ import { TextInput } from '@/ui/field/input/components/TextInput'; +import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; -import React, { useState } from 'react'; -import { useDebouncedCallback } from 'use-debounce'; import { IconComponent } from 'packages/twenty-ui'; -import { useTheme } from '@emotion/react'; +import { useState } from 'react'; +import { useDebouncedCallback } from 'use-debounce'; const StyledHeader = styled.div` background-color: ${({ theme }) => theme.background.secondary}; diff --git a/packages/twenty-front/src/modules/workflow/workflow-trigger/components/RightDrawerWorkflowSelectTriggerTypeContent.tsx b/packages/twenty-front/src/modules/workflow/workflow-trigger/components/RightDrawerWorkflowSelectTriggerTypeContent.tsx index bf8cf359fa58..e4dc9774b856 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-trigger/components/RightDrawerWorkflowSelectTriggerTypeContent.tsx +++ b/packages/twenty-front/src/modules/workflow/workflow-trigger/components/RightDrawerWorkflowSelectTriggerTypeContent.tsx @@ -3,8 +3,9 @@ import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer'; import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages'; import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; import { workflowSelectedNodeState } from '@/workflow/workflow-diagram/states/workflowSelectedNodeState'; +import { DATABASE_TRIGGER_TYPES } from '@/workflow/workflow-trigger/constants/DatabaseTriggerTypes'; +import { OTHER_TRIGGER_TYPES } from '@/workflow/workflow-trigger/constants/OtherTriggerTypes'; import { TRIGGER_STEP_ID } from '@/workflow/workflow-trigger/constants/TriggerStepId'; -import { TRIGGER_TYPES } from '@/workflow/workflow-trigger/constants/TriggerTypes'; import { useUpdateWorkflowVersionTrigger } from '@/workflow/workflow-trigger/hooks/useUpdateWorkflowVersionTrigger'; import { getTriggerDefaultDefinition } from '@/workflow/workflow-trigger/utils/getTriggerDefaultDefinition'; import styled from '@emotion/styled'; @@ -21,6 +22,14 @@ const StyledActionListContainer = styled.div` padding-inline: ${({ theme }) => theme.spacing(2)}; `; +const StyledSectionTitle = styled.span` + color: ${({ theme }) => theme.font.color.tertiary}; + font-size: ${({ theme }) => theme.font.size.sm}; + font-weight: ${({ theme }) => theme.font.weight.medium}; + padding: ${({ theme }) => theme.spacing(2)} ${({ theme }) => theme.spacing(1)} + ${({ theme }) => theme.spacing(1)} ${({ theme }) => theme.spacing(1)}; +`; + export const RightDrawerWorkflowSelectTriggerTypeContent = ({ workflow, }: { @@ -35,14 +44,37 @@ export const RightDrawerWorkflowSelectTriggerTypeContent = ({ return ( - {TRIGGER_TYPES.map((action) => ( + Data + {DATABASE_TRIGGER_TYPES.map((action) => ( + { + await updateTrigger( + getTriggerDefaultDefinition({ + name: action.name, + type: action.type, + activeObjectMetadataItems, + }), + ); + + setWorkflowSelectedNode(TRIGGER_STEP_ID); + + openRightDrawer(RightDrawerPages.WorkflowStepEdit); + }} + /> + ))} + Others + {OTHER_TRIGGER_TYPES.map((action) => ( { await updateTrigger( getTriggerDefaultDefinition({ + name: action.name, type: action.type, activeObjectMetadataItems, }), diff --git a/packages/twenty-front/src/modules/workflow/workflow-trigger/components/WorkflowEditTriggerDatabaseEventForm.tsx b/packages/twenty-front/src/modules/workflow/workflow-trigger/components/WorkflowEditTriggerDatabaseEventForm.tsx index 873c5ab2e745..a84f00bd14ec 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-trigger/components/WorkflowEditTriggerDatabaseEventForm.tsx +++ b/packages/twenty-front/src/modules/workflow/workflow-trigger/components/WorkflowEditTriggerDatabaseEventForm.tsx @@ -29,20 +29,15 @@ export const WorkflowEditTriggerDatabaseEventForm = ({ const { activeObjectMetadataItems } = useFilteredObjectMetadataItems(); - const triggerEvent = isDefined(trigger) - ? splitWorkflowTriggerEventName(trigger.settings.eventName) - : undefined; + const triggerEvent = splitWorkflowTriggerEventName( + trigger.settings.eventName, + ); const availableMetadata: Array> = activeObjectMetadataItems.map((item) => ({ label: item.labelPlural, value: item.nameSingular, })); - const recordTypeMetadata = isDefined(triggerEvent) - ? activeObjectMetadataItems.find( - (item) => item.nameSingular === triggerEvent.objectType, - ) - : undefined; const selectedEvent = isDefined(triggerEvent) ? OBJECT_EVENT_TRIGGERS.find( @@ -52,12 +47,12 @@ export const WorkflowEditTriggerDatabaseEventForm = ({ const headerTitle = isDefined(trigger.name) ? trigger.name - : isDefined(recordTypeMetadata) && isDefined(selectedEvent) - ? `When a ${recordTypeMetadata.labelSingular} is ${selectedEvent.label}` + : isDefined(selectedEvent) + ? selectedEvent.label : '-'; const headerType = isDefined(selectedEvent) - ? `Trigger · Record is ${selectedEvent.label}` + ? `Trigger · ${selectedEvent.label}` : '-'; return ( @@ -92,57 +87,13 @@ export const WorkflowEditTriggerDatabaseEventForm = ({ return; } - triggerOptions.onTriggerUpdate( - isDefined(trigger) && isDefined(triggerEvent) - ? { - ...trigger, - settings: { - ...trigger.settings, - eventName: `${updatedRecordType}.${triggerEvent.event}`, - }, - } - : { - name: headerTitle, - type: 'DATABASE_EVENT', - settings: { - eventName: `${updatedRecordType}.${OBJECT_EVENT_TRIGGERS[0].value}`, - outputSchema: {}, - }, - }, - ); - }} - /> -