-
Notifications
You must be signed in to change notification settings - Fork 528
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
feat(ts): convert menu #4652
feat(ts): convert menu #4652
Conversation
- connectMenu - menu - menuSelect
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9d9657c:
|
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.
let toggleShowMore = () => {}; | ||
function createToggleShowMore( | ||
renderOptions: RenderOptions, | ||
widget: Widget |
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.
passing the "this" to this function is the most natural method I found for show more. refinementList and hierarchicalMenu aren't yet converted, so this is the first widget with this pattern
menu: this.getWidgetRenderState(renderOptions), | ||
menu: { | ||
...renderState.menu, | ||
[attribute]: this.getWidgetRenderState(renderOptions), |
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.
note that this fixes a bug!
// can not use = {} here, since the template could have different constraints | ||
defaultTemplates?: TTemplates, |
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.
not super happy with this, but refinementList for example doesn't pass defaultTemplates at all
menu: { | ||
[attribute: string]: WidgetRenderState< | ||
MenuRendererOptions, | ||
MenuConnectorParams | ||
>; | ||
}; |
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.
same bugfix, as well as noting its omission in the type
// @ts-ignore | ||
menuSelect({ container: undefined }); |
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.
maybe we should bump the ts version so we can use ts-expect-error?
const renderState1 = menu.getWidgetRenderState( | ||
{}, | ||
createInitOptions({ helper }) |
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 test was wrong :o
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.
good job by TS finding it out :)
}); | ||
} | ||
|
||
if (!this._createURL) { | ||
this._createURL = facetValue => | ||
createURL(helper.state.toggleRefinement(attribute, facetValue)); |
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 function is deprecated, toggleFacetRefinement its exact replacement
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.
It looks good to me. Congrats on one less widget in JS :)
Summary
converts the menu-related files to typescript
Result
converted:
fixed a bug in connectMenu#getRenderState (forgotten to nest by attribute)