Repository navigation
Conversation
🦋 Changeset detectedLatest commit: a57ce71 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for openworkflow-editor ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🟡 Changes recommended
Batched host loads can incorrectly emit onChange for externally supplied content, and editors without change callbacks unnecessarily serialize the entire workflow on every edit, undo, and redo.
2 open issues
What changed in this PR
Adds a ref-based callback that delivers serialized workflow content to host applications after editor changes, supporting the integration described in #299. It also makes validation errors follow the current model through undo and redo.
Changes:
- Adds
setOnChangeCallbackand isolates host callback exceptions. - Derives validation errors from the displayed model.
- Adds callback documentation, a demonstration story, shared toolbar code, and regression tests.
| File | Description |
|---|---|
packages/open-workflow-diagram-editor/tests/store/DiagramEditorContextProvider.test.tsx |
Tests validation and form errors across history changes. |
packages/open-workflow-diagram-editor/tests/store/DiagramEditorContextProvider.onChange.test.tsx |
Tests callback payloads, registration, origins, and error isolation. |
packages/open-workflow-diagram-editor/tests/lib/invokeSafely.test.ts |
Tests asynchronous rethrow behavior. |
packages/open-workflow-diagram-editor/tests/diagram-editor/DiagramEditor.test.tsx |
Checks the expanded ref API. |
packages/open-workflow-diagram-editor/stories/features/UndoRedo.stories.tsx |
Reuses the shared toolbar and updates API examples. |
packages/open-workflow-diagram-editor/stories/features/shared/EditorToolbarLayout.tsx |
Extracts reusable toolbar and content dialogs. |
packages/open-workflow-diagram-editor/stories/features/OnChangeCallback.stories.tsx |
Demonstrates and documents callback integration. |
packages/open-workflow-diagram-editor/src/store/DiagramEditorContextProvider.tsx |
Implements callback delivery and model-derived validation. |
packages/open-workflow-diagram-editor/src/lib/invokeSafely.ts |
Isolates synchronous host callback exceptions. |
packages/open-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx |
Declares and documents the callback API. |
.changeset/fix-errors-after-undo-redo.md |
Records the validation fix as a patch release. |
.changeset/add-onChange-callback.md |
Records the callback API as a minor release. |
Review effort: Balanced
|
@handreyrc Still reviewing but a small thing I noticed, in the undo story - the undo is not enabled if you make an edit in sidepanel, only works if you first use SetContent in toolbar, after that it recognises changes in sidepanel as well |
I ported and refactored the code to make it simpler once this code is reference for the editor integration. |
|
Thanks @handreyrc Looks good but worth rebasing with feature branch and test how it works when you remove an optional field clicking x and make sure its all good |
Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
fee6b85 to
d3e59d8
Compare
It is rebased! What really matters are the model changes. If we have a model change we have a new snapshot in the history (undo/redo) and the onChange callback is executed. |
fantonangeli
left a comment
There was a problem hiding this comment.
This LGTM, I only have a question about the panel.
There was a problem hiding this comment.
@handreyrc Instead of implementing a custom OutputPanel, I would evaluate the Action feature of StoryBook which is built-in and integrated in SB panel already.
https://storybook.js.org/docs/essentials/actions
Wdyt?
There was a problem hiding this comment.
@fantonangeli Ok, Done!
Check the tab "Actions" in the addons panel.
…ons tab in the addons panel Signed-off-by: Handrey Cunha <handrey.cunha@gmail.com>
|
This PR is good enough to be merged! Thanks |

Closes #299
This PR adds an
onChangecallback to the diagram editor ref API and fixes validation errors going stale after undo/redo, applying the following approach:setOnChangeCallbacktoDiagramEditorRef: Lets the host register (or clear withnull/undefined) a function that receives the latest serialized content after every change made inside the editor (side-panel edits, undo, redo). It is never called for content arriving through thecontentprop orsetContent(), so callingsetContent()from inside the callback is safe.onContentChangeand the new on-change callback) run throughinvokeSafely, so an exception can no longer break the editor. The error is rethrown asynchronously so the host's global error handling still sees it. A serialization failure is ignored and nothing is reported.How it works
The callback runs only when the origin of the change is the editor itself.
undo()/redo()(button, shortcut or API)setContent()called by the hostcontentprop is updated by the hostBecause external changes never trigger the callback, a host can safely forward the received content somewhere and write it back without creating a loop.
Changes
setOnChangeCallbacktoDiagramEditorRefindiagram-editor/DiagramEditor.tsx, with documentation for it and forsetContent(). Also tightened a few doc comments and added explicitReact.JSX.Elementreturn types.lib/invokeSafely.ts: runs a host function and rethrows any error viaqueueMicrotask.store/DiagramEditorContextProvider.tsx:useImperativeHandle.onContentChangeand the on-change callback viainvokeSafely, and skips reporting on serialization failure.errorsstate withparseErrorsplus a memoizedvalidationErrorsderived frommodel.UndoRedo.stories.tsxinto the sharedstories/features/shared/EditorToolbarLayout.tsx.OnChangeCallback.stories.tsxstory.invokeSafely.test.ts,DiagramEditorContextProvider.onChange.test.tsx, additional cases inDiagramEditorContextProvider.test.tsx, and an update toDiagramEditor.test.tsx.How to test