-
Notifications
You must be signed in to change notification settings - Fork 15
Include service settings metadata in export/import JSON #1018
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
Merged
ffrose
merged 5 commits into
buerokratt:dev
from
1AhmedYasser:Include-service-settings-metadata-in-export/import-JSON
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ebce0db
chore(963): Added Service settings to service import/export
1AhmedYasser 3743cde
chore(963): Fixed format and lint
1AhmedYasser 293e115
chore(963): Add import only flow option
1AhmedYasser 6b26790
fix(963): fix format
1AhmedYasser b4ab075
fix(963): Addressed comments
1AhmedYasser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import { Edge, Node } from '@xyflow/react'; | ||
| import { updateFlowInputRules } from 'services/flow-builder'; | ||
| import useServiceStore from 'store/new-services.store'; | ||
| import { StepType } from 'types'; | ||
| import { generateUniqueId, generateUniqueLabel } from 'utils/flow-utils'; | ||
|
|
||
| export const appendFlowNodes = ( | ||
| currentNodes: Node[], | ||
| currentEdges: Edge[], | ||
| importedNodes: Node[], | ||
| importedEdges: Edge[], | ||
| ): { nodes: Node[]; edges: Edge[] } => { | ||
| const nodesToAdd = importedNodes.filter((node) => node.type !== 'start' && node.type !== 'ghost'); | ||
| const importedIds = new Set(nodesToAdd.map((node) => node.id)); | ||
| const edgesToAdd = importedEdges.filter((edge) => importedIds.has(edge.source) && importedIds.has(edge.target)); | ||
|
|
||
| if (nodesToAdd.length === 0) { | ||
| return { nodes: currentNodes, edges: currentEdges }; | ||
| } | ||
|
|
||
| const store = useServiceStore.getState(); | ||
| const idMap = new Map<string, string>(); | ||
| const processedLabels = new Set<string>(); | ||
|
|
||
| const newNodes = nodesToAdd.map((node) => { | ||
| const newId = generateUniqueId(); | ||
| idMap.set(node.id, newId); | ||
|
|
||
| const labelContext = [...currentNodes]; | ||
| processedLabels.forEach((label) => { | ||
| labelContext.push({ id: 'virtual', data: { label }, position: { x: 0, y: 0 } }); | ||
| }); | ||
| const uniqueLabel = generateUniqueLabel(node.data?.label as string, labelContext); | ||
| processedLabels.add(uniqueLabel); | ||
|
|
||
| return { | ||
| ...node, | ||
| id: newId, | ||
| selected: false, | ||
| data: { | ||
| ...node.data, | ||
| label: uniqueLabel, | ||
| onDelete: store.onDelete, | ||
| setClickedNode: store.setClickedNode, | ||
| onEdit: store.handleNodeEdit, | ||
| update: updateFlowInputRules, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const newEdges = edgesToAdd.map((edge) => ({ | ||
| ...edge, | ||
| id: generateUniqueId(), | ||
| source: idMap.get(edge.source) ?? edge.source, | ||
| target: idMap.get(edge.target) ?? edge.target, | ||
| })); | ||
|
|
||
| const ghostNodes: Node[] = []; | ||
| const ghostEdges: Edge[] = []; | ||
|
|
||
| const addGhost = (sourceId: string, x: number, y: number, label: string) => { | ||
| const ghostNode: Node = { | ||
| id: generateUniqueId(), | ||
| type: 'ghost', | ||
| position: { x, y }, | ||
| data: { type: 'ghost' }, | ||
| className: 'ghost', | ||
| selectable: false, | ||
| draggable: false, | ||
| }; | ||
| ghostEdges.push({ | ||
| id: generateUniqueId(), | ||
| source: sourceId, | ||
| target: ghostNode.id, | ||
| type: 'step', | ||
| animated: true, | ||
| deletable: false, | ||
| label, | ||
| }); | ||
| ghostNodes.push(ghostNode); | ||
| }; | ||
|
|
||
| nodesToAdd.forEach((node) => { | ||
| const newId = idMap.get(node.id); | ||
| if (!newId) return; | ||
|
|
||
| const stepType = node.data?.stepType; | ||
| if (stepType === StepType.Condition || stepType === StepType.Input) { | ||
| ['Success', 'Failure'].forEach((label, index) => { | ||
| if (!edgesToAdd.some((edge) => edge.source === node.id && edge.label === label)) { | ||
| addGhost(newId, node.position.x + 200, node.position.y + index * 100, label); | ||
| } | ||
| }); | ||
| } else if (stepType === StepType.MultiChoiceQuestion) { | ||
| const buttons = (node.data?.multiChoiceQuestion as { buttons?: { title?: unknown }[] })?.buttons ?? [ | ||
| { title: 'Jah' }, | ||
| { title: 'Ei' }, | ||
| ]; | ||
| buttons.forEach((button, index) => { | ||
| if (!edgesToAdd.some((edge) => edge.source === node.id && edge.label === button.title)) { | ||
| const title = typeof button.title === 'string' ? button.title : String(button.title ?? ''); | ||
|
Check warning on line 101 in GUI/src/utils/append-flow-nodes.ts
|
||
| addGhost(newId, node.position.x + 200, node.position.y + index * 100, title); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| const endNodes = nodesToAdd.filter((node) => !edgesToAdd.some((edge) => edge.source === node.id)); | ||
| const skipEndGhost = new Set([ | ||
| StepType.FinishingStepEnd, | ||
| StepType.FinishingStepRedirect, | ||
| StepType.DynamicChoices, | ||
| StepType.Condition, | ||
| StepType.Input, | ||
| StepType.MultiChoiceQuestion, | ||
| ]); | ||
|
|
||
| endNodes.forEach((node) => { | ||
| const newId = idMap.get(node.id); | ||
| if (!newId || skipEndGhost.has(node.data?.stepType as StepType)) return; | ||
| addGhost(newId, node.position.x, node.position.y, '+'); | ||
| }); | ||
|
|
||
| return { | ||
| nodes: [...currentNodes, ...newNodes, ...ghostNodes], | ||
| edges: [...currentEdges, ...newEdges, ...ghostEdges], | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.