Skip to content

Commit fc47a7f

Browse files
committed
implemented forms for connecting section buffers
Signed-off-by: Teo Koon Peng <[email protected]>
1 parent f5178d7 commit fc47a7f

20 files changed

+183
-121
lines changed

diagram-editor/frontend/diagram-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
EditorModeProvider,
3838
} from './editor-mode';
3939
import ExportDiagramDialog from './export-diagram-dialog';
40-
import { defaultEdgeOutputData, EditEdgeForm, EditNodeForm } from './forms';
40+
import { defaultEdgeData, EditEdgeForm, EditNodeForm } from './forms';
4141
import EditScopeForm from './forms/edit-scope-form';
4242
import { NodeManager } from './node-manager';
4343
import {
@@ -562,7 +562,7 @@ function DiagramEditor() {
562562
const newEdge = {
563563
...createBaseEdge(conn.source, conn.target),
564564
type: validEdges[0],
565-
data: defaultEdgeOutputData(validEdges[0]),
565+
data: defaultEdgeData(validEdges[0]),
566566
} as DiagramEditorEdge;
567567

568568
const validationResult = validateEdgeSimple(

diagram-editor/frontend/edges/buffer-edge.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import type { Edge } from '../types/react-flow';
3-
import type { EdgeData } from '.';
3+
import type { SectionBufferSlotData } from './section-edge';
44

55
export type BufferKeySlotData = {
66
type: 'bufferKey';
@@ -12,9 +12,13 @@ export type BufferSeqSlotData = {
1212
seq: number;
1313
};
1414

15-
export type BufferOutputData = { [k: string]: unknown };
16-
// TODO: support section buffer
17-
export type BufferEdge = Edge<EdgeData<BufferOutputData>, 'buffer'>;
15+
export type BufferOutputData = Record<string, never>;
16+
17+
export type BufferEdge = Edge<
18+
BufferOutputData,
19+
BufferKeySlotData | BufferSeqSlotData | SectionBufferSlotData,
20+
'buffer'
21+
>;
1822

1923
export type BufferEdgeProps = Exclude<EdgeProps<BufferEdge>, 'label'>;
2024

diagram-editor/frontend/edges/create-edge.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function createDefaultEdge(
2626
return {
2727
...createBaseEdge(source, target),
2828
type: 'default',
29-
data: { output: {} },
29+
data: { output: {}, input: { type: 'default' } },
3030
};
3131
}
3232

@@ -40,6 +40,7 @@ export function createUnzipEdge(
4040
type: 'unzip',
4141
data: {
4242
output: data,
43+
input: { type: 'default' },
4344
},
4445
};
4546
}
@@ -51,7 +52,7 @@ export function createForkResultOkEdge(
5152
return {
5253
...createBaseEdge(source, target),
5354
type: 'forkResultOk',
54-
data: {},
55+
data: { output: {}, input: { type: 'default' } },
5556
};
5657
}
5758

@@ -62,7 +63,7 @@ export function createForkResultErrEdge(
6263
return {
6364
...createBaseEdge(source, target),
6465
type: 'forkResultErr',
65-
data: {},
66+
data: { output: {}, input: { type: 'default' } },
6667
};
6768
}
6869

@@ -74,7 +75,7 @@ export function createSplitKeyEdge(
7475
return {
7576
...createBaseEdge(source, target),
7677
type: 'splitKey',
77-
data: { output: data },
78+
data: { output: data, input: { type: 'default' } },
7879
};
7980
}
8081

@@ -86,7 +87,7 @@ export function createSplitSeqEdge(
8687
return {
8788
...createBaseEdge(source, target),
8889
type: 'splitSeq',
89-
data: { output: data },
90+
data: { output: data, input: { type: 'default' } },
9091
};
9192
}
9293

@@ -97,7 +98,7 @@ export function createSplitRemainingEdge(
9798
return {
9899
...createBaseEdge(source, target),
99100
type: 'splitRemaining',
100-
data: {},
101+
data: { output: {}, input: { type: 'default' } },
101102
};
102103
}
103104

@@ -121,7 +122,7 @@ export function createStreamOutEdge(
121122
return {
122123
...createBaseEdge(source, target),
123124
type: 'streamOut',
124-
data: { output: data },
125+
data: { output: data, input: { type: 'default' } },
125126
};
126127
}
127128

diagram-editor/frontend/edges/fork-result-err-edge.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
3-
import type { Edge } from '../types/react-flow';
3+
import type { DataEdge } from '.';
44

55
export type ForkResultErrOutputData = Record<string, never>;
6-
export type ForkResultErrEdge = Edge<ForkResultErrOutputData, 'forkResultErr'>;
6+
export type ForkResultErrEdge = DataEdge<
7+
ForkResultErrOutputData,
8+
'forkResultErr'
9+
>;
710

811
export type ForkResultErrEdgeProps = Exclude<
912
EdgeProps<ForkResultErrEdge>,

diagram-editor/frontend/edges/fork-result-ok-edge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
3-
import type { Edge } from '../types/react-flow';
3+
import type { DataEdge } from '.';
44

55
export type ForkResultOkOutputData = Record<string, never>;
6-
export type ForkResultOkEdge = Edge<ForkResultOkOutputData, 'forkResultOk'>;
6+
export type ForkResultOkEdge = DataEdge<ForkResultOkOutputData, 'forkResultOk'>;
77

88
export type ForkResultOkEdgeProps = Exclude<
99
EdgeProps<ForkResultOkEdge>,

diagram-editor/frontend/edges/index.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { StepEdge } from '@xyflow/react';
22
import type { Edge } from '../types/react-flow';
3-
import BufferEdgeComp, {
4-
type BufferEdge,
5-
type BufferKeySlotData,
6-
type BufferSeqSlotData,
7-
} from './buffer-edge';
3+
import BufferEdgeComp, { type BufferEdge } from './buffer-edge';
84
import ForkResultErrEdgeComp, {
95
type ForkResultErrEdge,
106
} from './fork-result-err-edge';
117
import ForkResultOkEdgeComp, {
128
type ForkResultOkEdge,
139
} from './fork-result-ok-edge';
10+
import {
11+
type SectionEdge,
12+
type SectionInputSlotData,
13+
SectionOutputEdgeComp,
14+
} from './section-edge';
1415
import SplitKeyEdgeComp, { type SplitKeyEdge } from './split-key-edge';
1516
import SplitRemainingEdgeComp, {
1617
type SplitRemainingEdge,
@@ -27,13 +28,15 @@ export type { SplitSeqEdge } from './split-seq-edge';
2728
export type { StreamOutEdge } from './stream-out-edge';
2829
export type { UnzipEdge } from './unzip-edge';
2930

30-
export type EdgeData<O extends Record<string, unknown>> = {
31-
output: O;
32-
input?: BufferKeySlotData | BufferSeqSlotData;
33-
};
31+
export type DefaultOutputData = Record<string, never>;
32+
export type DefaultInputData = { type: 'default' };
33+
34+
export type DataEdge<
35+
O extends Record<string, unknown>,
36+
S extends string,
37+
> = Edge<O, DefaultInputData | SectionInputSlotData, S>;
3438

35-
export type DefaultOutputData = { [k: string]: unknown };
36-
export type DefaultEdge = Edge<EdgeData<DefaultOutputData>, 'default'>;
39+
export type DefaultEdge = DataEdge<DefaultOutputData, 'default'>;
3740

3841
export type EdgeMapping = {
3942
default: DefaultEdge;
@@ -45,13 +48,15 @@ export type EdgeMapping = {
4548
splitRemaining: SplitRemainingEdge;
4649
buffer: BufferEdge;
4750
streamOut: StreamOutEdge;
48-
// section: SectionEdge;
51+
section: SectionEdge;
4952
};
5053

5154
export type EdgeTypes = keyof EdgeMapping;
5255

53-
export type EdgeOutputData<K extends keyof EdgeMapping = keyof EdgeMapping> =
54-
EdgeMapping[K]['data']['output'];
56+
export type EdgeData<K extends EdgeTypes = EdgeTypes> = EdgeMapping[K]['data'];
57+
58+
export type EdgeOutputData<K extends EdgeTypes = EdgeTypes> =
59+
EdgeData<K>['output'];
5560

5661
export const EDGE_TYPES = {
5762
default: StepEdge,
@@ -63,7 +68,7 @@ export const EDGE_TYPES = {
6368
splitRemaining: SplitRemainingEdgeComp,
6469
buffer: BufferEdgeComp,
6570
streamOut: StreamOutEdgeComp,
66-
// section: SectionOutputEdgeComp,
71+
section: SectionOutputEdgeComp,
6772
} satisfies Record<EdgeTypes, unknown>;
6873

6974
export type DiagramEditorEdge<T extends EdgeTypes = EdgeTypes> = EdgeMapping[T];
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
3-
import type { Edge } from '../types/react-flow';
4-
import type { EdgeData } from '.';
3+
import type { DataEdge } from '.';
54

65
export type SectionOutputData = {
76
output: string;
87
};
98

10-
export type SectionEdge = Edge<EdgeData<SectionOutputData>, 'section'>;
9+
export type SectionEdge = DataEdge<SectionOutputData, 'section'>;
1110

1211
export type SectionOutputEdgeProps = Exclude<EdgeProps<SectionEdge>, 'label'>;
1312

@@ -17,10 +16,10 @@ export const SectionOutputEdgeComp = memo((props: SectionOutputEdgeProps) => {
1716

1817
export type SectionInputSlotData = {
1918
type: 'sectionInput';
20-
input: string;
19+
inputId: string;
2120
};
2221

2322
export type SectionBufferSlotData = {
2423
type: 'sectionBuffer';
25-
input: string;
24+
inputId: string;
2625
};

diagram-editor/frontend/edges/split-key-edge.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
3-
import type { Edge } from '../types/react-flow';
4-
import type { EdgeData } from '.';
3+
import type { DataEdge } from '.';
54

65
export type SplitKeyOutputData = {
76
key: string;
87
};
9-
export type SplitKeyEdge = Edge<EdgeData<SplitKeyOutputData>, 'splitKey'>;
8+
9+
export type SplitKeyEdge = DataEdge<SplitKeyOutputData, 'splitKey'>;
1010

1111
export type SplitKeyEdgeProps = Exclude<EdgeProps<SplitKeyEdge>, 'label'>;
1212

diagram-editor/frontend/edges/split-remaining-edge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
3-
import type { Edge } from '../types/react-flow';
3+
import type { DataEdge } from '.';
44

55
export type SplitRemainingOutputData = Record<string, never>;
6-
export type SplitRemainingEdge = Edge<
6+
export type SplitRemainingEdge = DataEdge<
77
SplitRemainingOutputData,
88
'splitRemaining'
99
>;

diagram-editor/frontend/edges/split-seq-edge.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { type EdgeProps, StepEdge } from '@xyflow/react';
22
import { memo } from 'react';
3-
import type { Edge } from '../types/react-flow';
4-
import type { EdgeData } from '.';
3+
import type { DataEdge } from '.';
54

65
export type SplitSeqOutputData = {
76
seq: number;
87
};
98

10-
export type SplitSeqEdge = Edge<EdgeData<SplitSeqOutputData>, 'splitSeq'>;
9+
export type SplitSeqEdge = DataEdge<SplitSeqOutputData, 'splitSeq'>;
1110

1211
export type SplitSeqEdgeProps = Exclude<EdgeProps<SplitSeqEdge>, 'label'>;
1312

0 commit comments

Comments
 (0)