-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix(lib): include userid to data response from field plugin #438
fix(lib): include userid to data response from field plugin #438
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
443ef54
to
4439855
Compare
4439855
to
604a79c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ECJ222, thank you for your contribution; this will be a nice addition!
This is what we need to to move forward:
- Update the validation functions. This does not show up as typescript errors because
is
essentially asserts the type. (And corresponding unit tests) - We need the "how to test" section to be filled out (it says that it's optional, but we need it in this instance). We can use the demo and sandbox for this.
After this PR, we will need to follow up with more PRs to perform the release.
@@ -27,7 +27,7 @@ export type LoadedMessage = MessageToPlugin<'loaded'> & { | |||
} | |||
|
|||
// TODO full implementation of validation | |||
export const isLoadedMessage = (data: unknown): data is LoadedMessage => | |||
export const isLoadedMessage = (data: unknown): boolean => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to disable the type narrowing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably explains my warning below 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the warnings you got from the visual editor were from this PR 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are no longer appearing after the last commit 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is broken, I tested the demo with the changes you made by building it and adding the dist/index.js
to My Plugins using the storyfront branch with the changes, and I got this warning while the plugin never loads:
The not loading wasn't related to the warnings, I managed to make it work on the Visual Editor 🎉 So let's fix those warnings and we are ready to go 🚀
Awesome! @Dawntraoz 🫶 Was this the error you were talking about? Uncaught Error: This error can be safely ignored. It is caused by the legacy field plugin API. See issue |
7cb28de
to
34df2be
Compare
Oh no, that error is always there on purpose. I meant the warning messages: |
@@ -33,6 +34,8 @@ export const isStateMessage = (data: unknown): data is StateChangedMessage => | |||
typeof data.language === 'string' && | |||
hasKey(data, 'schema') && | |||
isFieldPluginSchema(data.schema) && | |||
hasKey(data, 'userId') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @ECJ222 🫂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the warning messages:
[Vue warn]: Invalid prop: type check failed for prop "spaceId". Expected Number with value X, got String with value "X"
Oh, I don't think it's related to this PR.
@ECJ222 I think there's a bug in the tests: it's passing the userId and spaceId as strings: It worked before, because the validation function actually does not perform a check on the spaceId property (see the TODO comment) |
Thanks man, I updated it! |
Once this PR gets merged, I will follow up with the release PR. 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks perfect to me! 🎉
Great job @ECJ222, thanks a lot for helping us with this 💙 And thanks to @johannes-lindgren for encouraging testing and validation and helped us review the PR 🫂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}) | ||
}) | ||
|
||
describe('the "language" property', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@Dawntraoz, @demetriusfeijoo, and @ECJ222: regarding the validation: when I wrote the library ~1.5 years ago, I did not include a validation library for two reasons:
However, with a validation library, the problem that I requested changes for earlier would not have happened. We also have this dilemma in the app, which is why I created a new validation library to fit these needs (amongst others): PureParse. Check it out if you're interested 🙂 |
This conversation is interesting 🤔 Maybe @demetriusfeijoo has more insights here, but since I joined the Plugins Team, we have been using https://valibot.dev/ in all our plugins since it seemed perfect for our use cases at the moment. So maybe we can use it here, too, to keep it consistent between all the projects we have and not use a different one per project 🤔 |
What?
This PR includes the userID to the data response retrieved on state change and loaded state from a field plugin as documented within our Field plugin API documentation
Why?
JIRA: SHAPE-7741
How to test? (optional)
To test, run the following commands below (on separate terminals):
yarn dev:lib
.yarn dev:demo
.yarn dev:sandbox
.These commands above should get your sandbox, field-plugin demo, and field-plugin library setup and running successfully.
Copy your currently running local sandbox URL,
http://localhost:7070/,
and place it within the filepackages/field-plugin/src/createFieldPlugin/createFieldPlugin.ts
.This facilitates communication between your sandbox and field plugin through the Iframe when interacting with the rendered Iframe window.
fix.SHAPE-7741.mov
You should find the userId property returned and other plugin-related data from your field plugin demo.