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

docs: dashboard editing example #3983

Open
wants to merge 8 commits into
base: docs/dashboard
Choose a base branch
from

Conversation

sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Dec 6, 2024

Adds dashbard example for an editable dashboard that allows persisting and loading its configuration.

@sissbruecker sissbruecker marked this pull request as ready for review December 9, 2024 09:33
Copy link
Contributor Author

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.

Copy link
Contributor Author

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:

// 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.

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 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[];
Copy link
Contributor Author

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>) => {
Copy link
Contributor Author

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.

Comment on lines 50 to 52
// 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.
Copy link
Member

Choose a reason for hiding this comment

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

Should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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.

2 participants