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

Persist some dashboard state to local storage and use it when returning to a dashboard #3973

Merged
merged 14 commits into from
Feb 15, 2024

Conversation

AdityaHegde
Copy link
Collaborator

@AdityaHegde AdityaHegde commented Feb 6, 2024

Checklist

  • Manual verification
  • Unit test coverage
  • E2E test coverage
  • Needs manual QA?

Summary

Issue addressed:

closes #3932

Details:

We are storing the selection of measures, dimensions, selected leaderboard measure and leaderboard sort settings.

Steps to Verify

  1. Create a few dashboards.
  2. Navigate to them and change the settings mentioned in details sections.
  3. Close the page and go back to those dashboards.
  4. The above settings should be retained.

@AdityaHegde AdityaHegde marked this pull request as ready for review February 9, 2024 08:25
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

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

The feature isn't working as expected for me. When I select filters on a dashboard, close the page, then re-open the dashboard, my filters are not applied. Am I missing something? Here's a JAM: https://jam.dev/c/f4899bfc-4d2a-4a16-96fe-83d6bcd7a2fd

I also left various comments inline.


export type PersistentDashboardStore = Readable<PersistentDashboardState> &
ReturnType<typeof persistentDashboardActions>;
export function createPersistentDashboardStore(storeKey: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than creating a new store, did you consider taking our existing dashboard store and persisting it to local storage? Pros/cons? I'm a bit hesitant that we'll have to keep two stores in sync with the same data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A small section of the store is to be persisted. Check the details section for the exact fields. So it made sense to create a new store.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, I didn't realize that only a subset of the store is to be persisted.

Though I'm still wondering if it'd be simpler to persist the store in its entirety, then we can just choose which fields to restore in the restorePersistedDashboardState() function. Then it'd be easy to add/subtract fields we want to restore by just editing that one function.

Else, needing to remember to update both stores, I worry the two stores will often get out-of-sync and the feature will appear buggy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option to avoid synchronization issues – the persisted dashboard store could be a derived store that consumes the root dashboard store

Copy link
Collaborator Author

@AdityaHegde AdityaHegde Feb 14, 2024

Choose a reason for hiding this comment

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

True. We can do that once the immer solution is in. For now it would be too many updates to the local storage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, just opened up an issue to track this: https://github.com/rilldata/rill-private-issues/issues/164

@AdityaHegde
Copy link
Collaborator Author

@ericpgreen2 Check the details section. Only a very small settings are to be persisted as per product.

@ericpgreen2
Copy link
Contributor

@ericpgreen2 Check the details section. Only a very small settings are to be persisted as per product.

Oh, I hadn't realized that. Yes, then for these fields it works like a charm!

@ericpgreen2 ericpgreen2 changed the title Add basic support for storing user perferences for a dashboard Persist some dashboard state to local storage and use it when returning to a dashboard Feb 14, 2024
@AdityaHegde AdityaHegde merged commit 04bf4be into main Feb 15, 2024
4 checks passed
@AdityaHegde AdityaHegde deleted the adityahegde/resotre-user-state branch February 15, 2024 05:08
mindspank pushed a commit that referenced this pull request Feb 23, 2024
…ng to a dashboard (#3973)

* Add basic support for storing user perferences for a dashboard

* Fix tests and lint

* Add sort type to local preferences

* Update proto before merging with preferences

* Reset local preferences on dashboard edit

* Fix leaderboard measure name not persisting

* Fix unit tests

* Decouple user perference and persistent state

* Fix lint

* Remove additionalKey param

* PR comments
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.

Feat: Restore User State
2 participants