Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trigger selection design #9717

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
WorkflowDiagramEdge,
WorkflowDiagramNode,
} from '@/workflow/workflow-diagram/types/WorkflowDiagram';
import { DATABASE_TRIGGER_EVENTS } from '@/workflow/workflow-trigger/constants/DatabaseTriggerEvents';

import { TRIGGER_STEP_ID } from '@/workflow/workflow-trigger/constants/TriggerStepId';
import { capitalize } from 'twenty-shared';
import { isDefined } from 'twenty-ui';
import { v4 } from 'uuid';

Expand Down Expand Up @@ -70,7 +70,10 @@ export const generateWorkflowDiagram = ({
trigger.settings.eventName,
);

triggerLabel = `${capitalize(triggerEvent.objectType)} is ${capitalize(triggerEvent.event)}`;
triggerLabel =
DATABASE_TRIGGER_EVENTS.find(
bosiraphael marked this conversation as resolved.
Show resolved Hide resolved
(event) => event.value === triggerEvent.event,
)?.label ?? '';

thomtrp marked this conversation as resolved.
Show resolved Hide resolved
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
}: {
Expand All @@ -35,14 +44,37 @@ export const RightDrawerWorkflowSelectTriggerTypeContent = ({

return (
<StyledActionListContainer>
{TRIGGER_TYPES.map((action) => (
<StyledSectionTitle>Data</StyledSectionTitle>
{DATABASE_TRIGGER_TYPES.map((action) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Duplicate onClick handler logic between DATABASE_TRIGGER_TYPES and OTHER_TRIGGER_TYPES. Consider extracting to a shared function.

<MenuItem
key={action.name}
LeftIcon={action.icon}
text={action.name}
onClick={async () => {
await updateTrigger(
getTriggerDefaultDefinition({
name: action.name,
type: action.type,
activeObjectMetadataItems,
}),
);

setWorkflowSelectedNode(TRIGGER_STEP_ID);

openRightDrawer(RightDrawerPages.WorkflowStepEdit);
}}
/>
))}
<StyledSectionTitle>Others</StyledSectionTitle>
{OTHER_TRIGGER_TYPES.map((action) => (
<MenuItem
key={action.type}
key={action.name}
LeftIcon={action.icon}
text={action.name}
onClick={async () => {
await updateTrigger(
getTriggerDefaultDefinition({
name: action.name,
type: action.type,
activeObjectMetadataItems,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WorkflowDatabaseEventTrigger } from '@/workflow/types/Workflow';
import { splitWorkflowTriggerEventName } from '@/workflow/utils/splitWorkflowTriggerEventName';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepHeader } from '@/workflow/workflow-steps/components/WorkflowStepHeader';
import { OBJECT_EVENT_TRIGGERS } from '@/workflow/workflow-trigger/constants/ObjectEventTriggers';
import { DATABASE_TRIGGER_EVENTS } from '@/workflow/workflow-trigger/constants/DatabaseTriggerEvents';
import { useTheme } from '@emotion/react';
import { IconPlaylistAdd, isDefined } from 'twenty-ui';

Expand All @@ -29,35 +29,30 @@ export const WorkflowEditTriggerDatabaseEventForm = ({

const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();

const triggerEvent = isDefined(trigger)
? splitWorkflowTriggerEventName(trigger.settings.eventName)
: undefined;
const triggerEvent = splitWorkflowTriggerEventName(
trigger.settings.eventName,
);

const availableMetadata: Array<SelectOption<string>> =
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(
? DATABASE_TRIGGER_EVENTS.find(
(availableEvent) => availableEvent.value === triggerEvent.event,
)
: undefined;

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 (
Expand Down Expand Up @@ -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: {},
},
},
);
}}
/>
<Select
dropdownId="workflow-edit-trigger-event-type"
label="Event type"
fullWidth
value={triggerEvent?.event}
emptyOption={{ label: 'Select an option', value: '' }}
options={OBJECT_EVENT_TRIGGERS}
disabled={triggerOptions.readonly}
onChange={(updatedEvent) => {
if (triggerOptions.readonly === true) {
return;
}

triggerOptions.onTriggerUpdate(
isDefined(trigger) && isDefined(triggerEvent)
? {
...trigger,
settings: {
...trigger.settings,
eventName: `${triggerEvent.objectType}.${updatedEvent}`,
},
}
: {
name: headerTitle,
type: 'DATABASE_EVENT',
settings: {
eventName: `${availableMetadata?.[0].value}.${updatedEvent}`,
outputSchema: {},
},
},
);
triggerOptions.onTriggerUpdate({
...trigger,
settings: {
...trigger.settings,
eventName: `${updatedRecordType}.${triggerEvent.event}`,
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
},
});
}}
/>
</WorkflowStepBody>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SelectOption } from '@/ui/input/components/Select';

import { DatabaseTriggerName } from '@/workflow/workflow-trigger/constants/DatabaseTriggerName';

export const DATABASE_TRIGGER_EVENTS: Array<SelectOption<string>> = [
{
label: DatabaseTriggerName.RECORD_IS_CREATED,
value: 'created',
},
{
label: DatabaseTriggerName.RECORD_IS_UPDATED,
value: 'updated',
},
{
label: DatabaseTriggerName.RECORD_IS_DELETED,
value: 'deleted',
},
];
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum DatabaseTriggerName {
RECORD_IS_CREATED = 'Record is Created',
RECORD_IS_UPDATED = 'Record is Updated',
RECORD_IS_DELETED = 'Record is Deleted',
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { WorkflowTriggerType } from '@/workflow/types/Workflow';
import { DatabaseTriggerName } from '@/workflow/workflow-trigger/constants/DatabaseTriggerName';
import { IconClick, IconComponent, IconPlus, IconTrash } from 'twenty-ui';

export const DATABASE_TRIGGER_TYPES: Array<{
name: DatabaseTriggerName;
type: WorkflowTriggerType;
icon: IconComponent;
}> = [
{
name: DatabaseTriggerName.RECORD_IS_CREATED,
type: 'DATABASE_EVENT',
icon: IconPlus,
},
{
name: DatabaseTriggerName.RECORD_IS_UPDATED,
type: 'DATABASE_EVENT',
icon: IconClick,
},
{
name: DatabaseTriggerName.RECORD_IS_DELETED,
type: 'DATABASE_EVENT',
icon: IconTrash,
},
];

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { WorkflowTriggerType } from '@/workflow/types/Workflow';
import { IconComponent, IconSettingsAutomation } from 'twenty-ui';

export const TRIGGER_TYPES: Array<{
export const OTHER_TRIGGER_TYPES: Array<{
name: string;
type: WorkflowTriggerType;
icon: IconComponent;
}> = [
{
name: 'Database Event',
type: 'DATABASE_EVENT',
icon: IconSettingsAutomation,
},
{
name: 'Manual Trigger',
name: 'Launch manually',
type: 'MANUAL',
icon: IconSettingsAutomation,
},
Expand Down
Loading
Loading