Closed mxosman closed 6 months ago
Thanks so much for catching this, @mxosman ! Could you explain why this fixes it? I'm having trouble intuiting why the updated logic is the right fix. It's not clear to me why the
replace SystemMetricKey
logic should only be run if the system is Supervision?
Absolutely! It might be helpful to bring in the few lines above it to add more context (this is before this change):
When a supervision system is disaggregated, we need to replace the systemMetricKey
because it'll be something like SUPERVISION-SUPERVISION_FUNDING
and in disaggregated-mode, we need it to be something like PROBATION-PROBATION_FUNDING
.
The above chunk of code naively assumed it was OK to do a replaceSystemMetricKeyWithNewSystem
on all systemMetricKey
s regardless of sector (even if it was a no-op) because it trusted the useState
check in L79-81 would cover all cases:
selectedSupervisionSubsystem
would be 'SUPERVISION', and the activeSystemMetricKey
would be the same as the systemMetricKey
: SUPERVISION-SUPERVISION_FUNDING
.selectedSupervisionSubsystem
would be the first subsystem in the agency's list (e.g. 'PAROLE'), and the activeSystemMetricKey
would spit out something like PAROLE_PAROLE_FUNDING
selectedSupervisionSubsystem
would be the current non-supervision system (for most cases - more below), and the activeSystemMetricKey
would be the same as the systemMetricKey
: JAILS-JAILS_FUNDING
(for example).What the L79-81 check does not cover is an agency with multiple systems that include a supervision agency w/ enabled subsystems (disaggregated) for a metric. In those cases, the initial value of selectedSupervisionSubsystem
will always be the first enabled subsystem in the agency system's list, because agencySupervisionSubsystems
will have enabled subsystems for the metric - and will replace the systemMetricKey
(e.g. LAW_ENFORCEMENT-LAW_ENFORCEMENT_FUNDING) with PAROLE_PAROLE_FUNDING
(assuming Parole was the first supervision subsystem on the list of the agency's systems).
With this change, the replacement of the system metric key is now isolated to supervision systems and will not run for other sectors. I'm not sure if this long explanation made any sense - please let me know if there are any areas I can clarify further or any thoughts on adjustments to make!
In the meantime, I'll adjust the selectedSupervisionSubsystem
state to be more clear and true to what it is, and add a clarifying comment to help clarify this behavior.
Oh wow that definitely makes sense, thank you for the detailed explanation! I like the idea of adding a short comment about this. Tysm for catching and fixing 🙏
Thank you so so much for your eyes as always, Lili!! 🙏
Description of the change
Fix metric definitions display for agencies with supervision + other non-supervision sectors with similar metrics (e.g. Funding, Staff, etc.) that are disaggregated by subpopulation in the supervision sector.
Huge shout out to @lilidworkin's playbook, as I stumbled into this while testing another PR going through the various agencies.
This one is super sneaky... If you are in an agency that has, for example, Law Enforcement & Supervision sectors - both of which have a Funding metric - and within the Supervision sector, you disaggregate the Funding metric by subpopulations; when you look at the Funding metric's definitions within the Law Enforcement sector, you'll unfortunately see the list of definitions for the first disaggregated supervision subpopulation, and NOT the list of Law Enforcement Funding metric definitions. This only affects multi-sector agencies w/ a supervision sector w/ subpopulations and with similar metrics that are disaggregated in the supervision sector.
This change adds a check for the active system before determining which system-metric key to use. I think originally when I worked on this, I must've mistakenly assumed that if you were in a different sector that checks like
agencySupervisionSubsystems
would come up empty, but this is not true because it's scanning all the sectors belonging to an agency and will always come up if an agency has a supervision agency w/ subsectors.Before:
After:
Type of change
Related issues
Closes #1350
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: