-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(workspace-forking): stop a remapped custom block losing every input, and let its target inputs be configured at sync time #6871
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6822967
fix(workspace-forking): stop a remapped custom block losing every input
icecrasher321 5a92fcd
feat(workspace-forking): configure a repointed custom block's inputs …
icecrasher321 7b2fa42
fix(workspace-forking): namespace, type, and single-source a custom b…
icecrasher321 8973f61
fix(workspace-forking): keep an unset custom-block boolean unset
icecrasher321 ac84737
fix(workspace-forking): let an optional custom-block boolean return t…
icecrasher321 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
54 changes: 54 additions & 0 deletions
54
apps/sim/ee/workspace-forking/components/fork-sync/custom-block-input-control.test.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,54 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| CUSTOM_BLOCK_BOOLEAN_FALSE, | ||
| CUSTOM_BLOCK_BOOLEAN_TRUE, | ||
| CUSTOM_BLOCK_BOOLEAN_UNSET, | ||
| customBlockBooleanOptions, | ||
| customBlockInputControl, | ||
| } from '@/ee/workspace-forking/components/fork-sync/custom-block-input-control' | ||
|
|
||
| describe('customBlockInputControl', () => { | ||
| it('matches how the canvas renders each field type', () => { | ||
| // Mirrors `subBlockTypeForField`: a field configured here must behave the way it will | ||
| // once the block is open in the editor. | ||
| expect(customBlockInputControl('boolean')).toBe('switch') | ||
| expect(customBlockInputControl('object')).toBe('textarea') | ||
| expect(customBlockInputControl('array')).toBe('textarea') | ||
| expect(customBlockInputControl('string')).toBe('input') | ||
| expect(customBlockInputControl('number')).toBe('input') | ||
| }) | ||
|
|
||
| it('falls back to a plain input for an unknown or absent type', () => { | ||
| expect(customBlockInputControl('something-new')).toBe('input') | ||
| expect(customBlockInputControl(undefined)).toBe('input') | ||
| }) | ||
| }) | ||
|
|
||
| describe('customBlockBooleanOptions', () => { | ||
| it('lets an OPTIONAL flag return to the workflow default', () => { | ||
| // Without this a single click permanently pins the flag: a two-segment switch has no | ||
| // transition back to "nothing selected", so every later sync would keep overriding the | ||
| // child's declared default. | ||
| const options = customBlockBooleanOptions(false) | ||
|
|
||
| expect(options.map((o) => o.value)).toEqual([ | ||
| CUSTOM_BLOCK_BOOLEAN_TRUE, | ||
| CUSTOM_BLOCK_BOOLEAN_FALSE, | ||
| CUSTOM_BLOCK_BOOLEAN_UNSET, | ||
| ]) | ||
| }) | ||
|
|
||
| it('offers a REQUIRED flag only real values', () => { | ||
| // The Sync gate demands a value, so "unset" is not a state it can end in — offering it | ||
| // would present a choice that cannot be submitted. | ||
| const options = customBlockBooleanOptions(true) | ||
|
|
||
| expect(options.map((o) => o.value)).toEqual([ | ||
| CUSTOM_BLOCK_BOOLEAN_TRUE, | ||
| CUSTOM_BLOCK_BOOLEAN_FALSE, | ||
| ]) | ||
| }) | ||
| }) |
60 changes: 60 additions & 0 deletions
60
apps/sim/ee/workspace-forking/components/fork-sync/custom-block-input-control.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,60 @@ | ||
| /** | ||
| * Which control the sync modal renders for a repointed custom block's input, derived from the | ||
| * field type its Start block declares. | ||
| * | ||
| * Mirrors `subBlockTypeForField` in `@/blocks/custom/build-config`, which decides the same thing | ||
| * for the canvas — a field the user configures here must read and behave the way it will once | ||
| * the block is open in the editor. | ||
| */ | ||
| export type CustomBlockInputControl = 'switch' | 'textarea' | 'input' | ||
|
|
||
| export function customBlockInputControl(fieldType: string | undefined): CustomBlockInputControl { | ||
| switch (fieldType) { | ||
| // Stored as a real boolean on the canvas (its sub-block is a `switch`), so it must be | ||
| // toggled here rather than typed — a text field would persist the string `'true'`. | ||
| case 'boolean': | ||
| return 'switch' | ||
| // Authored as JSON and parsed by the executor before the child receives it. | ||
| case 'object': | ||
| case 'array': | ||
| return 'textarea' | ||
| default: | ||
| return 'input' | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The two string values a boolean input round-trips through the string-valued dependent store. | ||
| * `replaceCustomBlockInputs` turns them back into a real boolean on apply, because the canvas | ||
| * stores a `switch` sub-block as one. | ||
| */ | ||
| export const CUSTOM_BLOCK_BOOLEAN_TRUE = 'true' | ||
| export const CUSTOM_BLOCK_BOOLEAN_FALSE = 'false' | ||
|
|
||
| /** | ||
| * The unset value. Distinct from `false`: it means the sync writes no value at all, so the | ||
| * target workflow's Start field keeps whatever default it declares. | ||
| */ | ||
| export const CUSTOM_BLOCK_BOOLEAN_UNSET = '' | ||
|
|
||
| const BOOLEAN_VALUE_OPTIONS = [ | ||
| { value: CUSTOM_BLOCK_BOOLEAN_TRUE, label: 'True' }, | ||
| { value: CUSTOM_BLOCK_BOOLEAN_FALSE, label: 'False' }, | ||
| ] as const | ||
|
|
||
| const BOOLEAN_OPTIONAL_OPTIONS = [ | ||
| ...BOOLEAN_VALUE_OPTIONS, | ||
| // Trails the two real values: choosing one is the common action, returning to the default | ||
| // is the escape hatch. Without it a single click would permanently pin an optional flag, | ||
| // since a two-segment switch has no transition back to "nothing selected". | ||
| { value: CUSTOM_BLOCK_BOOLEAN_UNSET, label: 'Default' }, | ||
| ] as const | ||
|
|
||
| /** | ||
| * Segments for a boolean input. An OPTIONAL field gets a third `Default` segment so the user | ||
| * can stop overriding the child workflow's declared default; a REQUIRED one does not, because | ||
| * the Sync gate demands a value and "unset" is not a state it can end in. | ||
| */ | ||
| export function customBlockBooleanOptions(required: boolean) { | ||
| return required ? BOOLEAN_VALUE_OPTIONS : BOOLEAN_OPTIONAL_OPTIONS | ||
| } |
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
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.