Closed nasaownsky closed 5 months ago
Hi again, @mxosman! After tweaking agencies dropdown I came up with this solution. It persists metric pretty well, but the thing is - if metric is enabled for current child agency we viewing and not enabled for the one we want to select next - it will also persists. I tried various approaches, but so far had no success. Mostly I tried to find out if metric is enabled utilizing agencyMetrics
and metricsBySystem
, but the problem is that this metrics info will only update in the future, when we actually select child agency we want to visit. Maybe you have some ideas regarding this issue? I will appreciate any help at this point. Thank you so much!
Hi @nasaownsky! Thank you so much for working on this and for the comment. I'm working on a focused task and will follow up with you as soon as I break away!
I totally see what you're talking about - such a good point. We query the metrics based on the current agency... so there is no way to know in advance what the child agency's list of metrics will be until we switch to it and a request is made. Hmm... still chewing on this.
@nasaownsky - here's an idea. It looks like there's some logic where if the metric search param doesn't exist, it falls back on the first enabled metric. Maybe that will be useful in our case, and we don't need to know whether or not the metric is enabled in advance.
So there's a useEffect
here that we might be able to use:
I can't remember all of the details of why this is setup this way, but this runs every time there's a change in the metrics/system params to keep the data viz store and the URL in sync. I think we can just do a check in L199 - where it's setting the search params for the metric - and see if the currentMetric
metric is enabled. If it is enabled, we can keep using that key -- but if it's not enabled, we can pass undefined
and hopefully it resolves to the first available metric on the next re-render.
LMK if this makes sense?
@mxosman Yes, totally worked, thank you! Please, test my changes and see if there are any issues they can cause!
Description of the change
Added initial logic for metric persistence
Type of change
Related issues
closes #1332
Checklists
Development
This box MUST be checked by the submitter prior to merging:
These boxes should be checked by the submitter prior to merging:
Code review
These boxes should be checked by reviewers prior to merging: