Add ContextProvider, Context and Hook #16#57
Add ContextProvider, Context and Hook #16#57handreyrc wants to merge 4 commits intoserverlessworkflow:mainfrom
Conversation
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR implements context-based state management for the Diagram Editor component by introducing a context provider pattern with a custom React hook. The implementation allows the editor to manage and access shared state (read-only mode and locale settings) throughout the component tree.
Changes:
- Created
DiagramEditorContextwith context definition and customuseDiagramEditorContexthook for accessing state - Implemented
DiagramContextProvidercomponent that initializes and synchronizes state with props, providing state update functions through context - Integrated the context provider into
DiagramEditorcomponent to wrap the diagram rendering - Added comprehensive unit tests covering context consumption, prop change reactivity, and render optimization
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/store/diagramEditorContext.ts |
Defines context type with state and update functions; exports hook for consuming context |
src/store/DiagramEditorContextProvider.tsx |
Implements provider component that manages state initialization and synchronization with parent props |
src/diagram-editor/DiagramEditor.tsx |
Integrates context provider to wrap diagram component and pass editor props through context |
tests/store/DiagramEditorContextProvider.test.tsx |
Comprehensive test suite verifying context consumption, prop reactivity, and re-render behavior |
src/react-flow/diagram/Diagram.tsx |
Minor whitespace cleanup (blank line removal) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/serverless-workflow-diagram-editor/src/store/diagramEditorContext.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/serverless-workflow-diagram-editor/src/store/DiagramEditorContext.tsx
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/store/DiagramEditorContextProvider.tsx
Outdated
Show resolved
Hide resolved
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| test("Consume properties from context", async () => { |
There was a problem hiding this comment.
I used it instead of test in another PR lets pick one for consistency @fantonangeli @kumaradityaraj any preference?
| React.useEffect(() => { | ||
| updateIsReadOnly(props.isReadOnly); | ||
| updateLocale(props.locale); | ||
| }, [props, updateIsReadOnly, updateLocale]); |
There was a problem hiding this comment.
props - I think this means is wil run every time as it would be a new reference on every render, better to be explicit for now. I dont think we will have many more props in the future where the dependency array would have too many? If so we can rethink then?
[props.isReadOnly, props.locale, updateIsReadOnly, updateLocale]
|
Thanks for PR @handreyrc, just a couple of small comments |
Closes #16
Summary
This PR sets up state management for the Diagram Editor component.
Changes