-
Notifications
You must be signed in to change notification settings - Fork 3.8k
JSON Block Definition interface #9402
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
base: main
Are you sure you want to change the base?
Conversation
|
@gonfunko bump, will this be considered? 👀 |
|
Yes, sorry for the delay on this! Will try to get you an initial review this week, thank you for the ping on it. |
gonfunko
left a comment
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.
This looks promising; added a couple notes. I'd like to run this by my colleagues before merging, but as you may have seen we're transitioning from Google to the Raspberry Pi Foundation so it may be a couple weeks until things are settled.
| interface CommonArg { | ||
| name?: string; | ||
| } | ||
|
|
||
| /** Input Args */ | ||
| interface InputValueArg extends CommonArg { | ||
| type: 'input_value'; | ||
| check?: string | string[]; | ||
| align?: FieldsAlign | ||
| } | ||
| interface InputStatementArg extends CommonArg { | ||
| type: 'input_statement'; | ||
| check?: string | string[]; | ||
| } | ||
| interface InputDummyArg extends CommonArg { | ||
| type: 'input_dummy'; | ||
| } | ||
|
|
||
| /** Field Args */ | ||
| interface FieldInputArg extends CommonArg{ | ||
| type: 'field_input' | ||
| text: string | ||
| } | ||
|
|
||
| interface FieldNumberArg extends CommonArg { | ||
| type: 'field_number'; | ||
| value?: number; | ||
| min?: number; | ||
| max?: number; | ||
| precision?: number; | ||
| } | ||
|
|
||
| interface FieldDropdownArg extends CommonArg { | ||
| type: 'field_dropdown'; | ||
| options: [string, string][]; | ||
| } | ||
|
|
||
| interface FieldCheckboxArg extends CommonArg { | ||
| type: 'field_checkbox'; | ||
| checked?: boolean | 'TRUE' | 'FALSE'; | ||
| } | ||
|
|
||
| interface FieldImageArg { | ||
| type: 'field_image'; | ||
| src: string; | ||
| width: number; | ||
| height: number; | ||
| alt?: string; | ||
| flipRtl?: boolean | 'TRUE' | 'FALSE'; | ||
| } | ||
|
|
||
| interface FieldVariableArg extends CommonArg { | ||
| type: 'field_variable' | ||
| variable: string | null | ||
| } |
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.
Each of the Field classes defines and exports a FieldXYZFromJsonConfig interface, which I think should be used in place of these to avoid duplication/skew.
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.
ohh, didn't know these configs existed 👀
interface FieldInputArg extends FieldTextInputFromJsonConfig {
name: string
type: 'field_input'
}
interface FieldNumberArg extends FieldNumberFromJsonConfig {
name: string
type: 'field_number'
}
// ...wdyt 🤔
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.
@gonfunko bump again, hope this finds you well since there was all the migration from google to rpf and stuff 👀
I would definitely want to include your suggested changes, but before I do, can you run this and lmk if it works?
Thanks 😃
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.
Thanks for the bump, and yes, we're all moved over and all is well. The approach to the interfaces you proposed in your prior comment makes sense to me, so updating it along those lines sounds good.
|
converted this to draft, will implement @gonfunko's review feedback sooner or later :> |
The basics
The details
Resolves
Implements JSON Block Definition interface proposed in #9387
Proposed Changes
Introduces a new
JsonBlockDefinitionincore/interfaces/core/interfaces/i_json_block_definition.tswithJsonBlockDefinitionandBlockArgdefinitionsBlock.jsonInit,jsonInitFactory,defineBlocksWithJsonArrayandcreateBlockDefinitionsFromJsonArrayto use the new interfaceinterpolateto use the newBlockArgtypeblocks/to explicitly set'output': nullto match the default behaviour in the block factoryAnyDuringMigrationusage for JSON block definitionsReason for Changes
Makes it easier to write valid JSON Block definitions without having to always rely on the block factory
Test Coverage
I ran the unit test suite and manually loaded the playground with the updated blocks to ensure they still render and connect correctly
Documentation
Not needed
Additional Information
I found another issue while testing (unrelated to this) in the default Playground, when
Categories: (typed variables)is selected, the colour category errors out because of an invalidcolour_pickerdefinition