-
Notifications
You must be signed in to change notification settings - Fork 10
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
Persist form state and validation in Workspace #61
Conversation
Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Tyler Ohlsen <[email protected]>
public/pages/workflow_detail/component_details/input_fields/select_field.tsx
Show resolved
Hide resolved
Signed-off-by: Tyler Ohlsen <[email protected]>
const [edges, setEdges, onEdgesChange] = useEdgesState([]); | ||
|
||
// Listener for node additions or deletions to propagate to parent component | ||
const nodesLength = useStore( | ||
(state) => Array.from(state.nodeInternals.values()).length || 0 |
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.
would the nodes.length not be updated to use here?
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.
It's a custom hook that will be updated when the node internals change (node added/deleted/etc.). See docs and similar example: https://reactflow.dev/docs/api/hooks/use-store/
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.
And similar to the example, we listen for when the value changes on our useEffect on line 56-58
function onNodesChange(nodes: ReactFlowComponent[]): void { | ||
const updatedComponentIds = nodes.map((node) => node.id); | ||
const existingComponentIds = Object.keys(formValues); | ||
const updatedSchemaObj = cloneDeep(formSchema.fields) as WorkspaceSchemaObj; |
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.
why do we clone formSchema.fields. We don't set it to formSchema.fields earlier
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.
We extract the fields which is the underlying object, update it if necessary (like removing the component ID on line 119), and re-generate the schema on line 128.
Signed-off-by: Tyler Ohlsen <[email protected]> (cherry picked from commit 10810e3)
Signed-off-by: Tyler Ohlsen <[email protected]> (cherry picked from commit 10810e3) Co-authored-by: Tyler Ohlsen <[email protected]>
Description
At a high level, this PR adds 2 main functionalities:
More details:
TextField
andSelectField
input components with formik using formik's Field componentinput_fields
into thecomponent_details
modulename
andvalue
field toIComponentField
to generate formik values from component data, or vice versa.onNodesChange()
fn in resizable_workspace used for updating the forms and schema when a component is added or removed from the Workspace. This is done by passing this fn to the workspace, where we use formik'suseStore
custom hook to listen on node count changes, which we then trigger theonNodesChange
callback fnReactFlowProvider
to a higher-level component so we can moveuseOnSelectionChange
to resizable_workspace. This simplifies the downstream components. And, 2/ Updates css styling to control when a component is selected or not.Demo video showing form state:
screen-capture.19.webm
Demo video showing selection state (added after prev. demo video):
screen-capture.20.webm
Issues Resolved
Makes progress on #8, #10
Check List
--signoff
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.