Skip to content

Commit 5064322

Browse files
committed
Change transition conditions & notifiers to be non-nullable
This simplifies consumption
1 parent 6e285d3 commit 5064322

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/components/workflow/define-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const defineWorkflow =
5151
...transition,
5252
from: transition.from ? setOf(many(transition.from)) : undefined,
5353
key: (transition.key ?? uuid.v5(name, input.id)) as ID,
54-
conditions: maybeMany(transition.conditions),
54+
conditions: maybeMany(transition.conditions) ?? [],
5555
notifiers: [
5656
...(input.defaultNotifiers ?? []),
5757
...(maybeMany(transition.notifiers) ?? []),

src/components/workflow/dto/serialized-workflow.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ export class SerializedWorkflow extends DataObject {
171171
relatedStates:
172172
transition.to.relatedStates?.map(serializeState) ?? [],
173173
},
174-
conditions: (transition.conditions ?? []).map((condition) => ({
174+
conditions: transition.conditions.map((condition) => ({
175175
label: condition.description,
176176
})),
177-
notifiers: (transition.notifiers ?? []).map((notifier) => ({
177+
notifiers: transition.notifiers.map((notifier) => ({
178178
label: notifier.description,
179179
})),
180180
permissions: getPermissions(transition),

src/components/workflow/transitions/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type InternalTransition<
2626
name: Names;
2727
key: ID;
2828
from?: ReadonlySet<State>;
29-
conditions?: ReadonlyArray<TransitionCondition<Context>>;
30-
notifiers?: ReadonlyArray<TransitionNotifier<Context>>;
29+
conditions: ReadonlyArray<TransitionCondition<Context>>;
30+
notifiers: ReadonlyArray<TransitionNotifier<Context>>;
3131
}>
3232
>;

src/components/workflow/workflow.flowchart.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ export const WorkflowFlowchart = <W extends Workflow>(workflow: () => W) => {
7575
: `--> ${dynamicToId(t.to)}`;
7676
const endHalf = `${endId}{{ ${t.label} }}:::${t.type} ${to}`;
7777

78-
const conditions = t.conditions
79-
? '--"' + t.conditions.map((c) => c.description).join('\\n') + '"'
80-
: '';
78+
const conditions =
79+
t.conditions.length > 0
80+
? '--"' + t.conditions.map((c) => c.description).join('\\n') + '"'
81+
: '';
8182
const from = (t.from ? [...t.from].map(useState) : ['*(*)']).join(
8283
' & ',
8384
);

src/components/workflow/workflow.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const WorkflowService = <W extends Workflow>(workflow: () => W) => {
5959
);
6060

6161
// Resolve conditions & filter as needed
62-
const conditions = available.flatMap((t) => t.conditions ?? []);
62+
const conditions = available.flatMap((t) => t.conditions);
6363
const resolvedConditions = new Map(
6464
await Promise.all(
6565
[...new Set(conditions)].map(
@@ -69,8 +69,7 @@ export const WorkflowService = <W extends Workflow>(workflow: () => W) => {
6969
),
7070
);
7171
available = available.flatMap((t) => {
72-
const conditions =
73-
t.conditions?.map((c) => resolvedConditions.get(c)!) ?? [];
72+
const conditions = t.conditions.map((c) => resolvedConditions.get(c)!);
7473
if (conditions.some((c) => c.status === 'OMIT')) {
7574
return [];
7675
}

0 commit comments

Comments
 (0)