-
Notifications
You must be signed in to change notification settings - Fork 197
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
docs: dashboard editing example #3983
base: docs/dashboard
Are you sure you want to change the base?
Conversation
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.
There's another issue with the Lit example where clicking "Apply" after moving widgets, the dashboard reverts to the order.
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 seems like this assumption isn't true for the Lit version:
docs/frontend/demo/component/dashboard/dashboard-editable.ts
Lines 49 to 51 in a24ab8a
// Stores the current dashboard configuration. The vaadin-dashboard component | |
// will modify this array in place when editing, so there is no need to | |
// update it using events. |
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've added listeners for all modifications to update the widgets state, which solves the issue.
As discussed internally, there is a separate issue with widgets losing focus in move mode, but it doesn't look like it's an issue with the example setup.
.renderer="${this.renderWidget}" | ||
@dashboard-item-moved="${(e: DashboardItemMovedEvent<WidgetConfig>) => { | ||
// Store updated widgets after user has modified them | ||
this.widgets = e.detail.items as WidgetConfig[]; |
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.
Used a cast here so that the example doesn't have to deal with the Array<DashboardSectionItem | DashboardItem>
type. This needs to happen somewhere in this component, otherwise we'd also need to deal with this structure in the Java service used in the example. Not great, but having to deal with sections in an example that doesn't use them seems worse?
} | ||
|
||
// Render function should be memoized to avoid unnecessary re-renders | ||
const renderWidget = useCallback(({ item }: DashboardReactRendererProps<WidgetConfig>) => { |
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 discussed, put the renderer function into a useCallback
to avoid re-rendering widgets.
// Stores the current dashboard configuration. The Dashboard component will | ||
// modify this array in place when editing, so there is no need to update it | ||
// using events. |
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.
Should be removed
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.
Done
Adds dashbard example for an editable dashboard that allows persisting and loading its configuration.