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

[Publisher][Superagencies] Add dropdown for child agencies #1314

Merged
merged 14 commits into from Apr 29, 2024
2 changes: 1 addition & 1 deletion publisher/src/components/DataViz/MetricsDataChart.tsx
Expand Up @@ -348,8 +348,8 @@ export const MetricsDataChart: React.FC = observer(() => {

{/* Data Visualization */}
<Styled.PanelContainerRight>
<ChildAgenciesDropdown view="data" />
<Styled.MobileDatapointsControls>
<ChildAgenciesDropdown view="data" />
<Styled.CurrentMetricsSystem isSuperagency={isSuperagency}>
{formatSystemName(currentSystem)}
</Styled.CurrentMetricsSystem>
Expand Down
7 changes: 6 additions & 1 deletion publisher/src/components/Menu/Menu.tsx
Expand Up @@ -199,7 +199,12 @@ const Menu: React.FC = () => {
const superagencyId = userStore.isAgencySuperagency(agencyId)
? agencyId
: currentAgency?.super_agency_id;
if (superagencyId) agencyStore.getChildAgencies(String(superagencyId));
const userHasAccessToSuperagency = userStore.userAgencies?.find(
(agency) => agency.id === Number(superagencyId)
);

if (superagencyId && userHasAccessToSuperagency)
agencyStore.getChildAgencies(String(superagencyId));
}, [agencyId, currentAgency, agencyStore, userStore]);
mxosman marked this conversation as resolved.
Show resolved Hide resolved

return (
Expand Down
Expand Up @@ -31,7 +31,7 @@ export const DropdownWrapper = styled.div`
padding-bottom: 10px;
& ${CustomDropdown} {
width: 100%;
max-width: 360px;
max-width: 420px;
border: 1px solid ${palette.highlight.grey2};
padding: 0 12px;

Expand Down
Expand Up @@ -38,8 +38,9 @@ export const ChildAgenciesDropdown: React.FC<{
const isSuperagency = userStore.isAgencySuperagency(agencyId);
const superagencyId = currentAgency?.super_agency_id ?? agencyId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry - suggested change here to make this a bit more accurate:

  const superagencyId = isSuperagency
    ? agencyId
    : currentAgency?.super_agency_id;


const isChildAgency =
!currentAgency?.is_superagency && !!currentAgency?.super_agency_id;
const isChildAgency = superagencyChildAgencies?.some(
(childAgency) => childAgency.id === currentAgency?.id
);
mxosman marked this conversation as resolved.
Show resolved Hide resolved
mxosman marked this conversation as resolved.
Show resolved Hide resolved

const currentSuperagency = userStore.userAgencies?.find(
(agency) => agency.id === superagencyId
Expand Down