-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance flow handling by integrating forwards dynamically #587
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
Open
stijnpotters1
wants to merge
4
commits into
master
Choose a base branch
from
fix/dynamic-forwards
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1836ca9
Enhance flow handling by integrating forwards resolution and improvin…
stijnpotters1 254ca95
Refactor forwards resolution logic and simplify source handle extraction
stijnpotters1 13ae2a4
Refactor forwards resolution to simplify handling and improve clarity
stijnpotters1 6c21035
Remove Vitest environment declaration from frankdoc-utils.spec.ts
stijnpotters1 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { getHandleTypes } from './use-handle-types' | ||
|
|
||
| describe('getHandleTypes', () => { | ||
| it('returns empty array when typesAllowed is undefined', () => { | ||
| expect(getHandleTypes()).toEqual([]) | ||
| }) | ||
|
|
||
| it('returns empty array when typesAllowed is empty', () => { | ||
| expect(getHandleTypes({})).toEqual([]) | ||
| }) | ||
|
|
||
| it('returns all forwards as-is', () => { | ||
| const result = getHandleTypes({ success: {}, exception: {}, failure: {} }) | ||
| expect(result).toContain('success') | ||
| expect(result).toContain('exception') | ||
| expect(result).toContain('failure') | ||
| }) | ||
|
|
||
| it('maps wildcard * to custom', () => { | ||
| const result = getHandleTypes({ '*': {}, exception: {} }) | ||
| expect(result).toContain('custom') | ||
| expect(result).toContain('exception') | ||
| expect(result).not.toContain('*') | ||
| }) | ||
| }) |
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 |
|---|---|---|
| @@ -1,23 +1,12 @@ | ||
| import { useMemo } from 'react' | ||
| import type { ElementProperty } from '@frankframework/doc-library-core' | ||
|
|
||
| export function useHandleTypes(typesAllowed?: Record<string, ElementProperty>) { | ||
| return useMemo(() => { | ||
| // Always include the 'success' handle, using a Set to avoid duplicates | ||
| const handles = new Set<string>(['success']) | ||
|
|
||
| if (!typesAllowed) return [...handles] | ||
|
|
||
| if ('*' in typesAllowed) { | ||
| handles.add('custom') | ||
| } | ||
| export function getHandleTypes(typesAllowed?: Record<string, ElementProperty>): string[] { | ||
| if (!typesAllowed) return [] | ||
|
|
||
| for (const type of Object.keys(typesAllowed)) { | ||
| if (type !== '*') { | ||
| handles.add(type) | ||
| } | ||
| } | ||
| return Object.keys(typesAllowed).flatMap((type) => (type === '*' ? ['custom'] : [type])) | ||
| } | ||
|
|
||
| return [...handles] | ||
| }, [typesAllowed]) | ||
| export function useHandleTypes(typesAllowed?: Record<string, ElementProperty>) { | ||
| return useMemo(() => getHandleTypes(typesAllowed), [typesAllowed]) | ||
| } |
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
75 changes: 75 additions & 0 deletions
75
src/main/frontend/app/routes/studio/xml-to-json-parser.spec.ts
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,75 @@ | ||
| import { extractSourceHandles, type ResolveForwards } from './xml-to-json-parser' | ||
| import type { ElementProperty } from '@frankframework/doc-library-core' | ||
|
|
||
| function elementFromXml(xml: string): Element { | ||
| const document_ = new DOMParser().parseFromString(xml, 'text/xml') | ||
| return document_.documentElement | ||
| } | ||
|
|
||
| const FORWARDS: Record<string, Record<string, ElementProperty>> = { | ||
| EchoPipe: { success: {}, exception: {} }, | ||
| IfPipe: { exception: {}, '*': {}, else: {} }, | ||
| SwitchPipe: { exception: {}, notFound: {}, empty: {}, '*': {} }, | ||
| } | ||
|
|
||
| const resolveForwards: ResolveForwards = (subtype) => FORWARDS[subtype] | ||
|
|
||
| describe('extractSourceHandles', () => { | ||
| it('creates a handle per <forward> for any element type', () => { | ||
| const element = elementFromXml( | ||
| '<IfPipe name="x"><forward name="exception" path="" /><forward name="then" path="" /><forward name="else" path="" /></IfPipe>', | ||
| ) | ||
| expect(extractSourceHandles(element, resolveForwards)).toEqual([ | ||
| { type: 'exception', index: 1 }, | ||
| { type: 'then', index: 2 }, | ||
| { type: 'else', index: 3 }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('does NOT add an implicit success handle to a routing pipe (IfPipe)', () => { | ||
| const element = elementFromXml( | ||
| '<IfPipe name="x"><forward name="exception" path="" /><forward name="then" path="" /><forward name="else" path="" /></IfPipe>', | ||
| ) | ||
| const handles = extractSourceHandles(element, resolveForwards) | ||
| expect(handles.some((handle) => handle.type === 'success')).toBe(false) | ||
| }) | ||
|
|
||
| it('adds the implicit success fall-through handle for a FixedForwardPipe subclass with only an exception forward', () => { | ||
| const element = elementFromXml('<EchoPipe name="x"><forward name="exception" path="" /></EchoPipe>') | ||
| expect(extractSourceHandles(element, resolveForwards)).toEqual([ | ||
| { type: 'exception', index: 1 }, | ||
| { type: 'success', index: 2 }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('keeps an explicit success forward without duplicating it', () => { | ||
| const element = elementFromXml('<EchoPipe name="x"><forward name="success" path="" /></EchoPipe>') | ||
| expect(extractSourceHandles(element, resolveForwards)).toEqual([{ type: 'success', index: 1 }]) | ||
| }) | ||
|
|
||
| it('uses the FrankDoc default handle when no forwards are declared (EchoPipe -> success)', () => { | ||
| const element = elementFromXml('<EchoPipe name="x" />') | ||
| expect(extractSourceHandles(element, resolveForwards)).toEqual([{ type: 'success', index: 1 }]) | ||
| }) | ||
|
|
||
| it('uses the FrankDoc default handle when no forwards are declared (SwitchPipe -> first routing forward)', () => { | ||
| const element = elementFromXml('<SwitchPipe name="x" />') | ||
| expect(extractSourceHandles(element, resolveForwards)).toEqual([{ type: 'notFound', index: 1 }]) | ||
| }) | ||
|
|
||
| it('falls back to a single success handle when no FrankDoc resolver is provided', () => { | ||
| const element = elementFromXml('<SwitchPipe name="x" />') | ||
| expect(extractSourceHandles(element)).toEqual([{ type: 'success', index: 1 }]) | ||
| }) | ||
|
|
||
| it('keeps adding the implicit success handle without a resolver (legacy behaviour)', () => { | ||
| const element = elementFromXml( | ||
| '<IfPipe name="x"><forward name="then" path="" /><forward name="else" path="" /></IfPipe>', | ||
| ) | ||
| expect(extractSourceHandles(element)).toEqual([ | ||
| { type: 'then', index: 1 }, | ||
| { type: 'else', index: 2 }, | ||
| { type: 'success', index: 3 }, | ||
| ]) | ||
| }) | ||
| }) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why a base value of 31?
I remember seeing this done before and I questioned it back then too, making it a const and having a descriptive name would help a lot