-
Notifications
You must be signed in to change notification settings - Fork 531
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(panel): smoother accessing of widgetRenderState #4558
feat(panel): smoother accessing of widgetRenderState #4558
Conversation
src/widgets/panel/panel.tsx
Outdated
@@ -259,9 +259,8 @@ const panel: PanelWidget = widgetParams => { | |||
const [renderOptions] = args; | |||
|
|||
const options = { | |||
...(widget.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.
possible without casting since I reuse the type for TWidget for widgetFactory
collapsed({ widgetRenderState }) { | ||
return widgetRenderState.canRefine; | ||
collapsed({ canRefine }) { | ||
return canRefine === false; |
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.
your example used to be wrong
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 9a8b4db:
|
@@ -151,11 +151,13 @@ storiesOf('Basics/Panel', module) | |||
withHits( | |||
({ search, container }) => { | |||
const breadcrumbInPanel = panel<typeof breadcrumb>({ | |||
collapsed({ widgetRenderState }) { | |||
return widgetRenderState.canRefine; | |||
collapsed({ canRefine }) { |
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 usage is much better and eventually what we want to enable in next major version so if there can't be collision with the IS instance (which is also passed and spread) that's great!
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.
Yeah, I didn't realize there cannot be collision. This looks so much better.
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.
as far as I can tell there's no collision here, so this doesn't even need a major :)
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.
Yeah, it makes sense there is no collision :)
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.
looks nice!
}; | ||
> = RenderOptions & ReturnType<TWidget>['getWidgetRenderState'] extends ( | ||
renderOptions: any | ||
) => infer TRenderState |
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.
didn't know about infer
. looks nice 👍
* update panel * add a story * provide an empty object to widgetRenderState by default * add generic to panel * update the story to infer the type instead of importing and using the type itself * extract to PanelRenderOptions * clean the code * fix type error * feat(panel): smoother accessing of widgetRenderState (#4558) * WIP * now it works * better example * revert for lower ts used here * gotta be more generic * WIP trying to replace any with unknown * add UnknownWidgetFactory * parenthesis, move back to any (unknown is stricter than any) * reuse UnknownWidgetFactory in panel component Co-authored-by: Haroen Viaene <[email protected]>
* update panel * add a story * provide an empty object to widgetRenderState by default * add generic to panel * update the story to infer the type instead of importing and using the type itself * extract to PanelRenderOptions * clean the code * fix type error * feat(panel): smoother accessing of widgetRenderState (#4558) * WIP * now it works * better example * revert for lower ts used here * gotta be more generic * WIP trying to replace any with unknown * add UnknownWidgetFactory * parenthesis, move back to any (unknown is stricter than any) * reuse UnknownWidgetFactory in panel component Co-authored-by: Haroen Viaene <[email protected]>
* update panel * add a story * provide an empty object to widgetRenderState by default * add generic to panel * update the story to infer the type instead of importing and using the type itself * extract to PanelRenderOptions * clean the code * fix type error * feat(panel): smoother accessing of widgetRenderState (#4558) * WIP * now it works * better example * revert for lower ts used here * gotta be more generic * WIP trying to replace any with unknown * add UnknownWidgetFactory * parenthesis, move back to any (unknown is stricter than any) * reuse UnknownWidgetFactory in panel component Co-authored-by: Haroen Viaene <[email protected]>
this kinda works @eunjae-lee, although some parts still seem to be inferred as any. The public API works though
I also made a small change: not using widgetRenderState as key, but spreading the renderer. This way the usage is so much smoother (and you can use it for the templates too, which comes up from time to time)