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

[Frontend] Clear reports and datapoints state when switching agencies #16

Merged
merged 3 commits into from
Sep 15, 2022

Conversation

terryttsai
Copy link
Contributor

@terryttsai terryttsai commented Sep 14, 2022

Description of the change

https://www.loom.com/share/8ec11e17e8004218859c43a77141a461

Set up reactions to clear reports and datapoints state when user switches agencies.

For the Reports page, we only fetch the reports list when the user navigates to that page, OR the user agency id has changed.

For the Metrics page, we only fetch the datapoints when the user navigates to that page, OR the user agency id has changed.

This means if the user switches agencies while on a different page, we clear, but don't fetch the new data until the user visits a page that needs to load that data, minimizing needless fetches.

Type of change

All pull requests must have at least one of the following labels applied (otherwise the PR will fail):

Label Description
Type: Bug non-breaking change that fixes an issue
Type: Feature non-breaking change that adds functionality
Type: Breaking Change fix or feature that would cause existing functionality to not work as expected
Type: Non-breaking refactor change addresses some tech debt item or prepares for a later change, but does not change functionality
Type: Configuration Change adjusts configuration to achieve some end related to functionality, development, performance, or security
Type: Dependency Upgrade upgrades a project dependency - these changes are not included in release notes

Related issues

Closes #15

Checklists

Development

This box MUST be checked by the submitter prior to merging:

  • Double- and triple-checked that there is no Personally Identifiable Information (PII) being mistakenly added in this pull request

These boxes should be checked by the submitter prior to merging:

  • Tests have been written to cover the code changed/added as part of this pull request

Code review

These boxes should be checked by reviewers prior to merging:

  • This pull request has a descriptive title and information useful to a reviewer
  • This pull request has been moved out of a Draft state, has no "Work In Progress" label, and has assigned reviewers
  • Potential security implications or infrastructural changes have been considered, if relevant

@terryttsai terryttsai requested a review from a team September 14, 2022 20:54
@terryttsai terryttsai force-pushed the terry/clear-mobx-state-when-switching-agencies branch from 38f0cf2 to 67ca814 Compare September 14, 2022 20:58
);
}

deconstructor() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the advice here https://stackoverflow.com/questions/59345330/how-do-you-dispose-a-reaction-defined-in-a-class-constructor to handle disposing of a reaction defined in a mobx class, this might be overkill since at least right now we never need to dispose of this since we never need to de-instantiate any of our mobx stores

Copy link
Collaborator

@lilidworkin lilidworkin left a comment

Choose a reason for hiding this comment

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

@terryttsai this is very cool!

I tried it out locally and one thing I noticed is that if you switch to a different agency while on a particular report, you get an error:
Screen Shot 2022-09-15 at 10 10 35 AM

This is probably fine (I'm not sure what the right behavior should be in this case?) but just wanted to call it out in case there's an easy fix.

@terryttsai
Copy link
Contributor Author

Thanks for calling that out, I put up a fix for this case by navigating you back to the reports list when you try to switch agencies while on a report: https://www.loom.com/share/f99f609f88e44633868835bc80363ef9

I also replace the browser navigation stack so you can't press the back button and go back to that report page since you'd see an error there.

Copy link
Collaborator

@lilidworkin lilidworkin left a comment

Choose a reason for hiding this comment

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

yay!

@terryttsai terryttsai merged commit 608395d into main Sep 15, 2022
@terryttsai terryttsai deleted the terry/clear-mobx-state-when-switching-agencies branch September 15, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Frontend] Clear all report and datapoints state when switching agencies, regardless of what page you're on.
2 participants