Skip to content

Commit 7ed6461

Browse files
committed
chore: clean up
1 parent 3d77112 commit 7ed6461

File tree

3 files changed

+12
-53
lines changed

3 files changed

+12
-53
lines changed

web/src/lib/services/workflow.service.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ export const getActionsByContext = (
5757
return availableActions.filter((action) => action.supportedContexts.includes(context));
5858
};
5959

60-
/**
61-
* Remap configs when items are reordered (drag-drop)
62-
* Moves config from old index to new index position
63-
*/
6460
export const remapConfigsOnReorder = (
6561
configs: Record<string, unknown>,
6662
prefix: 'filter' | 'action',
@@ -111,30 +107,19 @@ export const remapConfigsOnRemove = (
111107
return newConfigs;
112108
};
113109

114-
/**
115-
* Initialize filter configurations from existing workflow
116-
* Uses index-based keys to support multiple filters of the same type
117-
*/
118-
export const initializeFilterConfigs = (workflow: WorkflowResponseDto): Record<string, unknown> => {
110+
export const initializeConfigs = (
111+
type: 'action' | 'filter',
112+
workflow: WorkflowResponseDto,
113+
): Record<string, unknown> => {
119114
const configs: Record<string, unknown> = {};
120115

121-
if (workflow.filters) {
116+
if (workflow.filters && type == 'filter') {
122117
for (const [index, workflowFilter] of workflow.filters.entries()) {
123118
configs[`filter_${index}`] = workflowFilter.filterConfig ?? {};
124119
}
125120
}
126121

127-
return configs;
128-
};
129-
130-
/**
131-
* Initialize action configurations from existing workflow
132-
* Uses index-based keys to support multiple actions of the same type
133-
*/
134-
export const initializeActionConfigs = (workflow: WorkflowResponseDto): Record<string, unknown> => {
135-
const configs: Record<string, unknown> = {};
136-
137-
if (workflow.actions) {
122+
if (workflow.actions && type == 'action') {
138123
for (const [index, workflowAction] of workflow.actions.entries()) {
139124
configs[`action_${index}`] = workflowAction.actionConfig ?? {};
140125
}
@@ -175,9 +160,6 @@ export const buildWorkflowPayload = (
175160
};
176161
};
177162

178-
/**
179-
* Parse JSON workflow and update state
180-
*/
181163
export const parseWorkflowJson = (
182164
jsonString: string,
183165
availableTriggers: PluginTriggerResponseDto[],
@@ -200,10 +182,8 @@ export const parseWorkflowJson = (
200182
try {
201183
const parsed = JSON.parse(jsonString);
202184

203-
// Find trigger
204185
const trigger = availableTriggers.find((t) => t.type === parsed.triggerType);
205186

206-
// Parse filters (using index-based keys to support multiple of same type)
207187
const filters: PluginFilterResponseDto[] = [];
208188
const filterConfigs: Record<string, unknown> = {};
209189
if (Array.isArray(parsed.filters)) {
@@ -217,7 +197,6 @@ export const parseWorkflowJson = (
217197
}
218198
}
219199

220-
// Parse actions (using index-based keys to support multiple of same type)
221200
const actions: PluginActionResponseDto[] = [];
222201
const actionConfigs: Record<string, unknown> = {};
223202
if (Array.isArray(parsed.actions)) {
@@ -252,9 +231,6 @@ export const parseWorkflowJson = (
252231
}
253232
};
254233

255-
/**
256-
* Check if workflow has changes compared to previous version
257-
*/
258234
export const hasWorkflowChanged = (
259235
previousWorkflow: WorkflowResponseDto,
260236
enabled: boolean,
@@ -266,36 +242,30 @@ export const hasWorkflowChanged = (
266242
filterConfigs: Record<string, unknown>,
267243
actionConfigs: Record<string, unknown>,
268244
): boolean => {
269-
// Check enabled state
270245
if (enabled !== previousWorkflow.enabled) {
271246
return true;
272247
}
273248

274-
// Check name or description
275249
if (name !== (previousWorkflow.name ?? '') || description !== (previousWorkflow.description ?? '')) {
276250
return true;
277251
}
278252

279-
// Check trigger
280253
if (triggerType !== previousWorkflow.triggerType) {
281254
return true;
282255
}
283256

284-
// Check filters order/items
285257
const previousFilterIds = previousWorkflow.filters?.map((f) => f.pluginFilterId) ?? [];
286258
const currentFilterIds = orderedFilters.map((f) => f.id);
287259
if (JSON.stringify(previousFilterIds) !== JSON.stringify(currentFilterIds)) {
288260
return true;
289261
}
290262

291-
// Check actions order/items
292263
const previousActionIds = previousWorkflow.actions?.map((a) => a.pluginActionId) ?? [];
293264
const currentActionIds = orderedActions.map((a) => a.id);
294265
if (JSON.stringify(previousActionIds) !== JSON.stringify(currentActionIds)) {
295266
return true;
296267
}
297268

298-
// Check filter configs (using index-based keys)
299269
const previousFilterConfigs: Record<string, unknown> = {};
300270
for (const [index, wf] of (previousWorkflow.filters ?? []).entries()) {
301271
previousFilterConfigs[`filter_${index}`] = wf.filterConfig ?? {};
@@ -304,7 +274,6 @@ export const hasWorkflowChanged = (
304274
return true;
305275
}
306276

307-
// Check action configs (using index-based keys)
308277
const previousActionConfigs: Record<string, unknown> = {};
309278
for (const [index, wa] of (previousWorkflow.actions ?? []).entries()) {
310279
previousActionConfigs[`action_${index}`] = wa.actionConfig ?? {};
@@ -316,9 +285,6 @@ export const hasWorkflowChanged = (
316285
return false;
317286
};
318287

319-
/**
320-
* Update a workflow via API
321-
*/
322288
export const handleUpdateWorkflow = async (
323289
workflowId: string,
324290
name: string,

web/src/lib/utils/workflow.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const getComponentDefaultValue = (component: ComponentConfig): unknown =>
3333
return component.defaultValue;
3434
}
3535

36-
// Initialize with appropriate empty value based on component type
3736
if (component.type === 'multiselect' || (component.type === 'text' && component.subType === 'people-picker')) {
3837
return [];
3938
}

web/src/routes/(user)/utilities/workflows/[workflowId]/+page.svelte

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
getFiltersByContext,
1616
handleUpdateWorkflow,
1717
hasWorkflowChanged,
18-
initializeActionConfigs,
19-
initializeFilterConfigs,
18+
initializeConfigs,
2019
parseWorkflowJson,
2120
remapConfigsOnRemove,
2221
remapConfigsOnReorder,
@@ -95,8 +94,8 @@
9594
),
9695
);
9796
98-
let filterConfigs: Record<string, unknown> = $derived(initializeFilterConfigs(editWorkflow));
99-
let actionConfigs: Record<string, unknown> = $derived(initializeActionConfigs(editWorkflow));
97+
let filterConfigs: Record<string, unknown> = $derived(initializeConfigs('filter', editWorkflow));
98+
let actionConfigs: Record<string, unknown> = $derived(initializeConfigs('action', editWorkflow));
10099
101100
$effect(() => {
102101
editWorkflow.triggerType = triggerType;
@@ -129,7 +128,6 @@
129128
actionConfigs,
130129
);
131130
132-
// Update the previous workflow state to the new values
133131
previousWorkflow = updated;
134132
editWorkflow = updated;
135133
@@ -200,7 +198,6 @@
200198
),
201199
);
202200
203-
// Drag and drop handlers
204201
let draggedFilterIndex: number | null = $state(null);
205202
let draggedActionIndex: number | null = $state(null);
206203
let dragOverFilterIndex: number | null = $state(null);
@@ -252,7 +249,6 @@
252249
return;
253250
}
254251
255-
// Remap configs to follow the new order
256252
actionConfigs = remapConfigsOnReorder(actionConfigs, 'action', draggedActionIndex, index, selectedActions.length);
257253
258254
const newActions = [...selectedActions];
@@ -266,12 +262,12 @@
266262
dragOverActionIndex = null;
267263
};
268264
269-
const handleAddStep = async (type?: 'action' | 'filter') => {
270-
const result = (await modalManager.show(AddWorkflowStepModal, {
265+
const handleAddStep = async (type: 'action' | 'filter') => {
266+
const result = await modalManager.show(AddWorkflowStepModal, {
271267
filters: supportFilters,
272268
actions: supportActions,
273269
type,
274-
})) as { type: 'filter' | 'action'; item: PluginFilterResponseDto | PluginActionResponseDto } | undefined;
270+
});
275271
276272
if (result) {
277273
if (result.type === 'filter') {
@@ -283,13 +279,11 @@
283279
};
284280
285281
const handleRemoveFilter = (index: number) => {
286-
// Remap configs to account for the removed item
287282
filterConfigs = remapConfigsOnRemove(filterConfigs, 'filter', index, selectedFilters.length);
288283
selectedFilters = selectedFilters.filter((_, i) => i !== index);
289284
};
290285
291286
const handleRemoveAction = (index: number) => {
292-
// Remap configs to account for the removed item
293287
actionConfigs = remapConfigsOnRemove(actionConfigs, 'action', index, selectedActions.length);
294288
selectedActions = selectedActions.filter((_, i) => i !== index);
295289
};

0 commit comments

Comments
 (0)