Skip to content

Commit

Permalink
Fix workflow icons
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Jan 23, 2025
1 parent 5e1402a commit 6f19de8
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { WorkflowDiagramStepNodeData } from '@/workflow/workflow-diagram/types/W
import { getWorkflowNodeIcon } from '@/workflow/workflow-diagram/utils/getWorkflowNodeIcon';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconTable } from 'twenty-ui';

const StyledStepNodeLabelIconContainer = styled.div`
align-items: center;
Expand All @@ -23,7 +24,7 @@ export const WorkflowDiagramStepNodeBase = ({
}) => {
const theme = useTheme();

const Icon = getWorkflowNodeIcon(data);
const Icon = getWorkflowNodeIcon(data) ?? IconTable;

const renderStepIcon = () => {
switch (data.nodeType) {
Expand Down Expand Up @@ -69,9 +70,7 @@ export const WorkflowDiagramStepNodeBase = ({
</StyledStepNodeLabelIconContainer>
);
}
case 'CREATE_RECORD':
case 'UPDATE_RECORD':
case 'DELETE_RECORD': {
default: {
return (
<StyledStepNodeLabelIconContainer>
<Icon
Expand All @@ -85,8 +84,6 @@ export const WorkflowDiagramStepNodeBase = ({
}
}
}

return assertUnreachable(data);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
WorkflowTriggerType,
} from '@/workflow/types/Workflow';
import { Edge, Node } from '@xyflow/react';
import { IconComponent } from 'twenty-ui';

export type WorkflowDiagramNode = Node<WorkflowDiagramNodeData>;
export type WorkflowDiagramEdge = Edge;
Expand All @@ -17,6 +18,7 @@ export type WorkflowDiagramStepNodeData =
nodeType: 'trigger';
triggerType: WorkflowTriggerType;
name: string;
icon?: IconComponent;
}
| {
nodeType: 'action';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
WorkflowDiagramNode,
} from '@/workflow/workflow-diagram/types/WorkflowDiagram';
import { DATABASE_TRIGGER_EVENTS } from '@/workflow/workflow-trigger/constants/DatabaseTriggerEvents';
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 { isDefined } from 'twenty-ui';
import { IconComponent, isDefined } from 'twenty-ui';
import { v4 } from 'uuid';

export const generateWorkflowDiagram = ({
Expand Down Expand Up @@ -58,10 +60,14 @@ export const generateWorkflowDiagram = ({

if (isDefined(trigger)) {
let triggerLabel: string;
let triggerIcon: IconComponent | undefined;

switch (trigger.type) {
case 'MANUAL': {
triggerLabel = 'Manual Trigger';
triggerIcon = OTHER_TRIGGER_TYPES.find(
(item) => item.type === trigger.type,
)?.icon;

break;
}
Expand All @@ -75,6 +81,10 @@ export const generateWorkflowDiagram = ({
(event) => event.value === triggerEvent.event,
)?.label ?? '';

triggerIcon = DATABASE_TRIGGER_TYPES.find(
(event) => triggerLabel === event.name,
)?.icon;

break;
}
default: {
Expand All @@ -91,6 +101,7 @@ export const generateWorkflowDiagram = ({
nodeType: 'trigger',
triggerType: trigger.type,
name: isDefined(trigger.name) ? trigger.name : triggerLabel,
icon: triggerIcon,
},
position: {
x: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
import {
WorkflowActionType,
WorkflowTriggerType,
} from '@/workflow/types/Workflow';
import { assertUnreachable } from '@/workflow/utils/assertUnreachable';
import {
IconAddressBook,
IconCode,
IconHandMove,
IconMail,
IconPlaylistAdd,
} from 'twenty-ui';
import { WorkflowDiagramStepNodeData } from '@/workflow/workflow-diagram/types/WorkflowDiagram';
import { OTHER_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/OtherActions';
import { RECORD_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/RecordActions';

export const getWorkflowNodeIcon = (
data:
| {
nodeType: 'trigger';
triggerType: WorkflowTriggerType;
}
| {
nodeType: 'action';
actionType: WorkflowActionType;
},
data: WorkflowDiagramStepNodeData,
) => {
switch (data.nodeType) {
case 'trigger': {
switch (data.triggerType) {
case 'DATABASE_EVENT': {
return IconPlaylistAdd;
}
case 'MANUAL': {
return IconHandMove;
}
}

return assertUnreachable(data.triggerType);
return data.icon;
}
case 'action': {
switch (data.actionType) {
case 'CODE': {
return IconCode;
}
case 'CODE':
case 'SEND_EMAIL': {
return IconMail;
return OTHER_ACTIONS.find(
(action) => action.type === data.actionType,
)?.icon;
}
case 'CREATE_RECORD':
case 'UPDATE_RECORD':
case 'DELETE_RECORD': {
return IconAddressBook;
return RECORD_ACTIONS.find(
(action) => action.type === data.actionType,
)?.icon;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { useViewOrDefaultViewFromPrefetchedViews } from '@/views/hooks/useViewOr
import { WorkflowCreateRecordAction } from '@/workflow/types/Workflow';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepHeader } from '@/workflow/workflow-steps/components/WorkflowStepHeader';
import { RECORD_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/RecordActions';
import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';
import { useTheme } from '@emotion/react';
import { useEffect, useState } from 'react';
import {
HorizontalSeparator,
IconAddressBook,
IconPlus,
isDefined,
useIcons,
useIcons
} from 'twenty-ui';
import { JsonValue } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';
Expand Down Expand Up @@ -162,6 +163,9 @@ export const WorkflowEditActionFormCreateRecord = ({
}, [saveAction]);

const headerTitle = isDefined(action.name) ? action.name : `Create Record`;
const headerIcon = RECORD_ACTIONS.find(
(item) => item.type === action.type,
)?.icon ?? IconPlus;

return (
<>
Expand All @@ -176,7 +180,7 @@ export const WorkflowEditActionFormCreateRecord = ({
name: newName,
});
}}
Icon={IconAddressBook}
Icon={headerIcon}
iconColor={theme.font.color.tertiary}
initialTitle={headerTitle}
headerType="Action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { useTheme } from '@emotion/react';
import { useEffect, useState } from 'react';
import {
HorizontalSeparator,
IconAddressBook,
IconTrash,
isDefined,
useIcons,
useIcons
} from 'twenty-ui';

import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { RECORD_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/RecordActions';
import { JsonValue } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';

Expand Down Expand Up @@ -110,6 +111,9 @@ export const WorkflowEditActionFormDeleteRecord = ({
}, [saveAction]);

const headerTitle = isDefined(action.name) ? action.name : `Delete Record`;
const headerIcon = RECORD_ACTIONS.find(
(item) => item.type === action.type,
)?.icon ?? IconTrash;

return (
<>
Expand All @@ -124,7 +128,7 @@ export const WorkflowEditActionFormDeleteRecord = ({
name: newName,
});
}}
Icon={IconAddressBook}
Icon={headerIcon}
iconColor={theme.font.color.tertiary}
initialTitle={headerTitle}
headerType="Action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { workflowIdState } from '@/workflow/states/workflowIdState';
import { WorkflowSendEmailAction } from '@/workflow/types/Workflow';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepHeader } from '@/workflow/workflow-steps/components/WorkflowStepHeader';
import { OTHER_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/OtherActions';
import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';
import { useTheme } from '@emotion/react';
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { IconMail, IconPlus, isDefined } from 'twenty-ui';
import { IconPlus, IconSend, isDefined } from 'twenty-ui';
import { JsonValue } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';

Expand Down Expand Up @@ -165,6 +166,9 @@ export const WorkflowEditActionFormSendEmail = ({
});

const headerTitle = isDefined(action.name) ? action.name : 'Send Email';
const headerIcon = OTHER_ACTIONS.find(
(item) => item.type === action.type,
)?.icon ?? IconSend;

return (
!loading && (
Expand All @@ -180,7 +184,7 @@ export const WorkflowEditActionFormSendEmail = ({
name: newName,
});
}}
Icon={IconMail}
Icon={headerIcon}
iconColor={theme.color.blue}
initialTitle={headerTitle}
headerType="Email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
import { serverlessFunctionTestDataFamilyState } from '@/workflow/states/serverlessFunctionTestDataFamilyState';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowEditActionFormServerlessFunctionFields } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionFormServerlessFunctionFields';
import { OTHER_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/OtherActions';
import { WORKFLOW_SERVERLESS_FUNCTION_TAB_LIST_COMPONENT_ID } from '@/workflow/workflow-steps/workflow-actions/constants/WorkflowServerlessFunctionTabListComponentId';
import { getWrongExportedFunctionMarkers } from '@/workflow/workflow-steps/workflow-actions/utils/getWrongExportedFunctionMarkers';
import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';
Expand Down Expand Up @@ -270,6 +271,11 @@ export const WorkflowEditActionFormServerlessFunction = ({
setFunctionInput(action.settings.input.serverlessFunctionInput);
}, [action]);

const headerTitle = isDefined(action.name) ? action.name : 'Code - Serverless Function';
const headerIcon = OTHER_ACTIONS.find(
(item) => item.type === action.type,
)?.icon ?? IconCode;

return (
!loading && (
<StyledContainer>
Expand All @@ -284,9 +290,9 @@ export const WorkflowEditActionFormServerlessFunction = ({
onTitleChange={(newName: string) => {
updateAction({ name: newName });
}}
Icon={IconCode}
Icon={headerIcon}
iconColor={theme.color.orange}
initialTitle={action.name || 'Code - Serverless Function'}
initialTitle={headerTitle}
headerType="Code"
/>
<WorkflowStepBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useTheme } from '@emotion/react';
import { useEffect, useState } from 'react';
import {
HorizontalSeparator,
IconAddressBook,
IconRefreshDot,
isDefined,
useIcons,
useIcons
} from 'twenty-ui';

import { formatFieldMetadataItemAsFieldDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition';
Expand All @@ -16,6 +16,7 @@ import { FormMultiSelectFieldInput } from '@/object-record/record-field/form-typ
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepHeader } from '@/workflow/workflow-steps/components/WorkflowStepHeader';
import { WorkflowSingleRecordPicker } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowSingleRecordPicker';
import { RECORD_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/RecordActions';
import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';
import { JsonValue } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';
Expand Down Expand Up @@ -157,6 +158,9 @@ export const WorkflowEditActionFormUpdateRecord = ({
}, [saveAction]);

const headerTitle = isDefined(action.name) ? action.name : `Update Record`;
const headerIcon = RECORD_ACTIONS.find(
(item) => item.type === action.type,
)?.icon ?? IconRefreshDot;

return (
<>
Expand All @@ -171,7 +175,7 @@ export const WorkflowEditActionFormUpdateRecord = ({
name: newName,
});
}}
Icon={IconAddressBook}
Icon={headerIcon}
iconColor={theme.font.color.tertiary}
initialTitle={headerTitle}
headerType="Action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { splitWorkflowTriggerEventName } from '@/workflow/utils/splitWorkflowTri
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepHeader } from '@/workflow/workflow-steps/components/WorkflowStepHeader';
import { DATABASE_TRIGGER_EVENTS } from '@/workflow/workflow-trigger/constants/DatabaseTriggerEvents';
import { DATABASE_TRIGGER_TYPES } from '@/workflow/workflow-trigger/constants/DatabaseTriggerTypes';
import { useTheme } from '@emotion/react';
import { IconPlaylistAdd, isDefined, useIcons } from 'twenty-ui';

Expand Down Expand Up @@ -57,6 +58,10 @@ export const WorkflowEditTriggerDatabaseEventForm = ({
? `Trigger · ${selectedEvent.label}`
: '-';

const headerIcon = DATABASE_TRIGGER_TYPES.find(
(event) => event.name === selectedEvent?.label,
)?.icon ?? IconPlaylistAdd;

return (
<>
<WorkflowStepHeader
Expand All @@ -70,7 +75,7 @@ export const WorkflowEditTriggerDatabaseEventForm = ({
name: newName,
});
}}
Icon={IconPlaylistAdd}
Icon={headerIcon}
iconColor={theme.font.color.tertiary}
initialTitle={headerTitle}
headerType={headerType}
Expand Down
Loading

0 comments on commit 6f19de8

Please sign in to comment.