Skip to content

feat: Add model to store#62

Open
lornakelly wants to merge 2 commits intoserverlessworkflow:mainfrom
lornakelly:49/add-model-to-store
Open

feat: Add model to store#62
lornakelly wants to merge 2 commits intoserverlessworkflow:mainfrom
lornakelly:49/add-model-to-store

Conversation

@lornakelly
Copy link
Copy Markdown
Contributor

@lornakelly lornakelly commented Apr 13, 2026

Closes: #49

Summary

Adds parsed workflow model and validation errors to the DiagramEditor store, establishing a single source of truth for workflow data accessible throughout the component

Files Modified

  • src/diagram-editor/DiagramEditor.tsx - Added content prop
  • src/store/DiagramEditorContext.tsx - Added model and errors to context type
  • src/store/DiagramEditorContextProvider.tsx - Implemented parsing logic and state management
  • stories/DiagramEditor.stories.ts - Updated with content prop (TODO: add sample workflow)
  • stories/DiagramEditor.tsx - Passed content prop through

Copilot AI review requested due to automatic review settings April 13, 2026 12:19
@lornakelly lornakelly changed the title Add model to store feat: Add model to store Apr 13, 2026
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds workflow parsing to the diagram editor store so consumers can access a parsed workflow model and parsing/validation errors via context.

Changes:

  • Introduces content prop to DiagramEditor and threads it through stories/tests.
  • Parses content inside DiagramEditorContextProvider and exposes model + errors on context.
  • Expands test coverage to validate model/errors behavior for valid/invalid content.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx Adds required content prop and passes it into the context provider.
packages/serverless-workflow-diagram-editor/src/store/DiagramEditorContextProvider.tsx Parses content into model and errors and publishes them on context.
packages/serverless-workflow-diagram-editor/src/store/DiagramEditorContext.tsx Extends context type with model and errors.
packages/serverless-workflow-diagram-editor/tests/store/DiagramEditorContextProvider.test.tsx Updates existing context tests and adds model/errors parsing tests.
packages/serverless-workflow-diagram-editor/tests/diagram-editor/DiagramEditor.test.tsx Updates DiagramEditor test to pass content.
packages/serverless-workflow-diagram-editor/tests/diagram-editor/DiagramEditor.story.test.tsx Updates story test to pass content.
packages/serverless-workflow-diagram-editor/stories/DiagramEditor.tsx Threads content prop into the underlying component.
packages/serverless-workflow-diagram-editor/stories/DiagramEditor.stories.ts Adds content arg placeholder for Storybook.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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 8 out of 8 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: Lorna-Kelly <lornakelly88@gmail.com>
Copy link
Copy Markdown
Member

@fantonangeli fantonangeli left a comment

Choose a reason for hiding this comment

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

Thanks @lornakelly , I suggested a small improvement to reduce the render numbers

Comment on lines +32 to +33
const [model, setModel] = React.useState<Specification.Workflow | null>(null);
const [errors, setErrors] = React.useState<Error[]>([]);
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.

Adding this:

  console.log("######## render");

and changing the content you can see 2 renders because of the useEffect.
The code can be simplified with the following, to avoid re-rendering:

Suggested change
const [model, setModel] = React.useState<Specification.Workflow | null>(null);
const [errors, setErrors] = React.useState<Error[]>([]);
const { model, errors } = React.useMemo(() => parseWorkflow(props.content), [props.content]);

Copy link
Copy Markdown
Contributor Author

@lornakelly lornakelly Apr 14, 2026

Choose a reason for hiding this comment

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

Thanks for the suggestion Fabrizio! Yeah, I think this might introduce issues when editing features comes in but agree for MVP we can move to useMemo and evaluate in next phase when we need to change for editing.

Comment on lines +49 to +53
React.useEffect(() => {
const result = parseWorkflow(props.content);
setModel(result.model);
setErrors(result.errors);
}, [props.content]);
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.

Suggested change
React.useEffect(() => {
const result = parseWorkflow(props.content);
setModel(result.model);
setErrors(result.errors);
}, [props.content]);

Comment on lines +65 to +66
// 2 rendering cycles are expected: 1- first render, 2- content useEffect triggers state update
expect(renderCount).toHaveTextContent(/2/i);
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.

Suggested change
// 2 rendering cycles are expected: 1- first render, 2- content useEffect triggers state update
expect(renderCount).toHaveTextContent(/2/i);
expect(renderCount).toHaveTextContent(/1/i);

Comment on lines +97 to +98
// 4 rendering cycles are expected 1- first render, 2- content useEffect triggers state update, 3- forced by rerender and 4- isReadOnly/locale useeffect state update
expect(renderCount).toHaveTextContent(/4/i);
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.

Suggested change
// 4 rendering cycles are expected 1- first render, 2- content useEffect triggers state update, 3- forced by rerender and 4- isReadOnly/locale useeffect state update
expect(renderCount).toHaveTextContent(/4/i);
expect(renderCount).toHaveTextContent(/3/i);

Comment on lines +129 to +130
// 3 rendering cycles are expected 1- first render, 2- content useEffect triggers state update and 3- forced by rerender
expect(renderCount).toHaveTextContent(/3/i);
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.

Suggested change
// 3 rendering cycles are expected 1- first render, 2- content useEffect triggers state update and 3- forced by rerender
expect(renderCount).toHaveTextContent(/3/i);
expect(renderCount).toHaveTextContent(/2/i);

Signed-off-by: Lorna-Kelly <lornakelly88@gmail.com>
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 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +167 to +171
await waitFor(() => {
// Model is still returned as parsing succeeded but has validation errors
expect(modelElement).toBeInTheDocument();
expect(errorsElement).toHaveTextContent("1");
});
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Asserting an exact error count (\"1\") is brittle: validation can legitimately return multiple errors as rules evolve, causing unrelated test failures. Prefer asserting errors.length > 0 (or checking for a specific error shape/message/code if stable) so the test verifies the intended behavior without over-constraining the exact number.

Copilot uses AI. Check for mistakes.
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.

feat: Add model to store as source of truth

3 participants