Skip to content

Add ContextProvider, Context and Hook #16#57

Open
handreyrc wants to merge 4 commits intoserverlessworkflow:mainfrom
handreyrc:add-store
Open

Add ContextProvider, Context and Hook #16#57
handreyrc wants to merge 4 commits intoserverlessworkflow:mainfrom
handreyrc:add-store

Conversation

@handreyrc
Copy link
Copy Markdown
Contributor

Closes #16

Summary

This PR sets up state management for the Diagram Editor component.

Changes

  • Added context provider to make content available in the component scope.
  • Added context to hold state managed properties and functions.
  • Added custom react hook to get access to the context.
  • Added tests for the context provider and context interaction.

Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Copilot AI review requested due to automatic review settings April 2, 2026 13:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DiagramEditorContext with context definition and custom useDiagramEditorContext hook for accessing state
  • Implemented DiagramContextProvider component that initializes and synchronizes state with props, providing state update functions through context
  • Integrated the context provider into DiagramEditor component 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.

Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Copilot AI review requested due to automatic review settings April 2, 2026 14:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Signed-off-by: handreyrc <handrey.cunha@gmail.com>
vi.restoreAllMocks();
});

test("Consume properties from context", async () => {
Copy link
Copy Markdown
Contributor

@lornakelly lornakelly Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it instead of test in another PR lets pick one for consistency @fantonangeli @kumaradityaraj any preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for it

React.useEffect(() => {
updateIsReadOnly(props.isReadOnly);
updateLocale(props.locale);
}, [props, updateIsReadOnly, updateLocale]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@lornakelly
Copy link
Copy Markdown
Contributor

lornakelly commented Apr 3, 2026

Thanks for PR @handreyrc, just a couple of small comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set up context and global context provider component for state management

4 participants