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 workflow nodes configuration #6861

Merged
merged 45 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
dae5f76
feat: allow only a single serverless function action type to be selected
Devessier Aug 28, 2024
e2b1164
feat: get selected node's definition
Devessier Aug 28, 2024
e220ab9
feat: allow updating triggers
Devessier Aug 29, 2024
b0c5a70
feat: allow updating the configuration of code action steps
Devessier Aug 29, 2024
036ac3d
refactor: extract step manipulation functions in separate files
Devessier Aug 29, 2024
579866a
test: write tests for the replaceStep function
Devessier Aug 29, 2024
aa21843
fix: solve merge conflicts artifacts
Devessier Aug 29, 2024
b570931
fix: don't break adding steps when no step was created yet
Devessier Aug 30, 2024
ea250e9
refactor: rename the hook to create new steps
Devessier Aug 30, 2024
542a155
feat: load last published version or draft version conditionally
Devessier Aug 30, 2024
64d20b5
feat: allow none value for serverless function
Devessier Sep 2, 2024
8c0bbb3
feat: set a better label to trigger nodes
Devessier Sep 2, 2024
06ba5a2
feat: fetch draft and published versions and choose which one to use …
Devessier Sep 2, 2024
6b8c2f0
refactor: reuse utility function to find a step
Devessier Sep 2, 2024
90cfc67
refactor: extract code to update triggers and steps in hooks
Devessier Sep 2, 2024
a9cfbe1
refactor: delete useless container element
Devessier Sep 2, 2024
38f2f86
refactor: centralize how we extract object and event types from trigg…
Devessier Sep 2, 2024
3bd7331
refactor: use globally defined constant representing the id of trigge…
Devessier Sep 2, 2024
f78c588
refactor: remove unwanted comments
Devessier Sep 2, 2024
6fe63bf
test: fix failing test
Devessier Sep 2, 2024
2c9b4e5
test: fix failing tests
Devessier Sep 3, 2024
8d530dc
refactor: replace triple-equal checks with calls to the isDefined fun…
Devessier Sep 3, 2024
fb3cfb0
refactor: rename variable
Devessier Sep 3, 2024
9055cd9
fix: fetch only the draft versions for the workflow we want
Devessier Sep 3, 2024
f41923c
refactor: throw inside getStepDefinition function
Devessier Sep 3, 2024
87ed28a
refactor: extract getStepDefaultDefinition function to its own file
Devessier Sep 3, 2024
bdf823e
refactor: fetch the most recently created workflow version and use it…
Devessier Sep 3, 2024
c6f4273
refactor: rename the hook for consistency
Devessier Sep 3, 2024
8fe896c
refactor: inline overkill custom hook
Devessier Sep 3, 2024
29ba4e4
fix: allow user to select only serverless function that have ever bee…
Devessier Sep 3, 2024
2f0a68b
refactor: delete unused states
Devessier Sep 4, 2024
6fae825
refactor: rename workflow diagram state
Devessier Sep 4, 2024
0b89e6e
refactor: rename the state
Devessier Sep 4, 2024
c4b5adb
refactor: rename workflow id state
Devessier Sep 4, 2024
1d3be26
refactor: rename workflow selected node state
Devessier Sep 4, 2024
7a81a6f
refactor: rename diagram component
Devessier Sep 4, 2024
5346d85
refactor: rename the custom nodes components
Devessier Sep 4, 2024
cca7ec8
refactor: rename effect component
Devessier Sep 4, 2024
2f4251c
refactor: rename the hook that creates steps
Devessier Sep 4, 2024
a3d1035
refactor: rename the components for workflow actions and triggers edi…
Devessier Sep 4, 2024
0fbf4ed
refactor: simplify ids
Devessier Sep 4, 2024
7a96ab6
refactor: extract the static list of available actions in another file
Devessier Sep 4, 2024
cbe7030
fix: fix typo in path
Devessier Sep 4, 2024
7d0c695
refactor: extract static array in separate file
Devessier Sep 4, 2024
03a7375
refactor: give a better name to variables
Devessier Sep 4, 2024
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
Prev Previous commit
Next Next commit
refactor: centralize how we extract object and event types from trigg…
…er event name
  • Loading branch information
Devessier committed Sep 3, 2024
commit 38f2f860b8feae5cec26922a59a683c203b40115
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { Select, SelectOption } from '@/ui/input/components/Select';
import { WorkflowTrigger } from '@/workflow/types/Workflow';
import { splitWorkflowTriggerEventName } from '@/workflow/utils/splitWorkflowTriggerEventName';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconPlaylistAdd } from 'twenty-ui';
Expand Down Expand Up @@ -54,15 +55,17 @@ export const RightDrawerWorkflowEditStepContentTrigger = ({

const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();

const [recordType, event] = trigger.settings.eventName.split('.');
const triggerEvent = splitWorkflowTriggerEventName(
trigger.settings.eventName,
);

const availableMetadata: Array<SelectOption<string>> =
activeObjectMetadataItems.map((item) => ({
label: item.labelPlural,
value: item.nameSingular,
}));
const recordTypeMetadata = activeObjectMetadataItems.find(
(item) => item.nameSingular === recordType,
(item) => item.nameSingular === triggerEvent.objectType,
);
if (recordTypeMetadata === undefined) {
throw new Error(
Expand All @@ -85,7 +88,7 @@ export const RightDrawerWorkflowEditStepContentTrigger = ({
},
];
const eventLabel = availableEvents.find(
(availableEvent) => availableEvent.value === event,
(availableEvent) => availableEvent.value === triggerEvent.event,
);
if (eventLabel === undefined) {
throw new Error('Expected to find the currently selected event type.');
Expand All @@ -112,14 +115,14 @@ export const RightDrawerWorkflowEditStepContentTrigger = ({
dropdownId="right-drawer-workflow-edit-step-trigger-record-type"
Copy link
Contributor

Choose a reason for hiding this comment

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

same for all those id names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

label="Record Type"
fullWidth
value={recordType}
value={triggerEvent.objectType}
options={availableMetadata}
onChange={(updatedRecordType) => {
onUpdateTrigger({
...trigger,
settings: {
...trigger.settings,
eventName: `${updatedRecordType}.${event}`,
eventName: `${updatedRecordType}.${triggerEvent.event}`,
},
});
}}
Expand All @@ -128,14 +131,14 @@ export const RightDrawerWorkflowEditStepContentTrigger = ({
dropdownId="right-drawer-workflow-edit-step-trigger-event-type"
label="Event type"
fullWidth
value={event}
value={triggerEvent.event}
options={availableEvents}
onChange={(updatedEvent) => {
onUpdateTrigger({
...trigger,
settings: {
...trigger.settings,
eventName: `${recordType}.${updatedEvent}`,
eventName: `${triggerEvent.objectType}.${updatedEvent}`,
},
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
WorkflowDiagramEdge,
WorkflowDiagramNode,
} from '@/workflow/types/WorkflowDiagram';
import { splitWorkflowTriggerEventName } from '@/workflow/utils/splitWorkflowTriggerEventName';
import { MarkerType } from '@xyflow/react';
import { v4 } from 'uuid';
import { capitalize } from '~/utils/string/capitalize';
Expand Down Expand Up @@ -60,12 +61,14 @@ export const generateWorkflowDiagram = ({

// Start with the trigger node
const triggerNodeId = 'trigger';
const [triggerObject, triggerEvent] = trigger.settings.eventName.split('.');
const triggerEvent = splitWorkflowTriggerEventName(
trigger.settings.eventName,
);
nodes.push({
id: triggerNodeId,
data: {
nodeType: 'trigger',
label: `${capitalize(triggerObject)} is ${capitalize(triggerEvent)}`,
label: `${capitalize(triggerEvent.objectType)} is ${capitalize(triggerEvent.event)}`,
},
position: {
x: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const splitWorkflowTriggerEventName = (eventName: string) => {
const [objectType, event] = eventName.split('.');
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Add a check for empty string input to prevent potential issues


return {
objectType,
event,
};
};