Skip to content
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

introduce middleware support #2220

Merged
merged 2 commits into from
Dec 12, 2023
Merged

Conversation

dholmes2409
Copy link
Contributor

@dholmes2409 dholmes2409 commented Nov 24, 2023

Resolves #2174

Introduces middleware support which can override state actions 'such as UPDATE' allowing for handling of controlled states effectively bypassing the debounce

Copy link

netlify bot commented Nov 24, 2023

Deploy Preview for jsonforms-examples ready!

Name Link
🔨 Latest commit 67e77ff
🔍 Latest deploy log https://app.netlify.com/sites/jsonforms-examples/deploys/65784f032b0ea50008727137
😎 Deploy Preview https://deploy-preview-2220--jsonforms-examples.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@coveralls
Copy link

coveralls commented Nov 24, 2023

Coverage Status

coverage: 83.063% (+0.03%) from 83.033%
when pulling 67e77ff on dholmes2409:master
into 18c0825 on eclipsesource:master.

@dholmes2409 dholmes2409 changed the title WIP: introduce middleware support introduce middleware support Nov 24, 2023
@@ -1100,3 +1101,49 @@ test('JsonForms should use react to additionalErrors update', () => {
expect(wrapper.find('h5').text()).toBe('Foobar');
wrapper.unmount();
});

test('JsonForms should used provided middleware if available', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sdirix if there are any other scenarios you think would be good to add let me know, this was the most immediate one I could think of

Copy link
Member

Choose a reason for hiding this comment

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

Hi! That's already great!

What's tested now is that if the middleware rejects a modification, that then onChangeHandler was not called. We should also check that the rendered value did not change.

It would be good to also test the modification case. For example if the middleware modifies an additional value in addition to the regular update and returns that as the new state. Then the onChange handler should also be given that modified value and the new value should be rendered.

I think then we have all basic cases covered!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a test case for modifying the state value within the middleware, hopefully this covers the modification case. I wasn't fully sure what you meant by Then the onChange handler should also be given that modified value and the new value should be rendered.. Wouldn't the onChange handler only be called if we explicitly call it within the middleware?

Choose a reason for hiding this comment

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

Hi @sdirix 👋, how goes it? Just a reminder that the extra unit test you asked about has been added, and a query as to whether anything else will be needed before this PR can be further progressed?

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Looks very good. There is a small detail which needs to be adapted in the tests. This week is very busy for us, but I think we can merge/release this within 2 weeks.


// then
expect(customMiddleware).toHaveBeenCalledTimes(1);
expect(onChangeHandler).not.toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

To test the onChangeHandler we have to use a timeout, like in the other tests.

Actually the onChangeHandler should have been called 1 times here because the initial rendering of JsonForms will trigger one emit. Then the update afterwards should not trigger one as we do return state in the controlledMiddleware, therefore the state will not be updated and there should not be another emit.


// then
expect(customMiddleware).toHaveBeenCalledTimes(1);
expect(onChangeHandler).not.toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

Same here, in fact the onChangeHandler should have been called 2 times after waiting a bit. The first time because of the initial rendering. The second time because we allow the state update to go through, which should lead to an additional call of onChangeHandler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added those checks now, let me know if the tests are how you were expecting them

sdirix and others added 2 commits December 12, 2023 13:11
This update introduces optional middleware support for our React
bindings, enabling advanced features like controlled mode in JSON Forms
and on-the-fly handling of derived attributes.
@sdirix sdirix merged commit 662d598 into eclipsesource:master Dec 12, 2023
8 checks passed
@sdirix
Copy link
Member

sdirix commented Dec 12, 2023

@dchambers @dholmes2409 Thank you so much for all of the contribution work ❤️ and architecture discussions. Without your help this feature would not arrived so soon.

@dchambers
Copy link

@dchambers @dholmes2409 Thank you so much for all of the contribution work ❤️ and architecture discussions. Without your help this feature would not arrived so soon.

No, thank you helping us land this @sdirix 🙇

@sdirix sdirix linked an issue Jan 10, 2024 that may be closed by this pull request
@sdirix sdirix mentioned this pull request Jan 10, 2024
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.

Data loss when using React controlled style React middleware support
4 participants