Skip to content

Commit

Permalink
[ui] Fix/topology formal informal (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhssb authored Nov 21, 2024
2 parents 203fce2 + a4e53a0 commit 85b58f1
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 65 deletions.
26 changes: 14 additions & 12 deletions app/src/app/enterprises/[id]/@header/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ export default async function Slot({
const primaryLegalUnit = hierarchy?.enterprise?.legal_unit?.find(
(lu) => lu.primary_for_enterprise
);
const establishment = hierarchy?.enterprise?.establishment?.[0];
if (!primaryLegalUnit && !establishment) {
throw new Error("No primary legal unit or establishment found");
}
return (
<HeaderSlot
id={id}
unit={primaryLegalUnit || establishment}
error={error}
className="border-enterprise-200 bg-enterprise-100"
/>
);
const primaryEstablishment = hierarchy?.enterprise?.establishment?.find(
(es) => es.primary_for_enterprise
);
if (!primaryLegalUnit && !primaryEstablishment) {
throw new Error("No primary legal unit or establishment found");
}
return (
<HeaderSlot
id={id}
unit={primaryLegalUnit || primaryEstablishment}
error={error}
className="border-enterprise-200 bg-enterprise-100"
/>
);
}
26 changes: 15 additions & 11 deletions app/src/app/enterprises/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,38 @@ export default async function EnterpriseDetailsPage({
const primaryLegalUnit = hierarchy.enterprise?.legal_unit?.find(
(lu) => lu.primary_for_enterprise
);
const establishment = hierarchy.enterprise?.establishment?.[0];
if (!primaryLegalUnit && !establishment) {
const primaryEstablishment = hierarchy.enterprise?.establishment?.find(
(es) => es.primary_for_enterprise
);
const primaryUnit = primaryLegalUnit || primaryEstablishment;

if (!primaryUnit) {
throw new Error("No primary legal unit or establishment found");
}
const unit = primaryLegalUnit || establishment;

return (
<DetailsPage
title="General Info"
subtitle="General information such as name, sector"
>
<GeneralInfoForm values={unit} />
<GeneralInfoForm values={primaryUnit} />
<InfoBox>
<p>
The information above is derived from the{" "}
{primaryLegalUnit ? "primary legal unit" : "establishment"} &nbsp;
The information above is derived from the primary
{primaryLegalUnit ? " legal unit" : " establishment"} &nbsp;
<Link
className="underline"
href={`/${primaryLegalUnit ? "legal-units" : "establishments"}/${unit.id}`}
href={`/${primaryLegalUnit ? "legal-units" : "establishments"}/${primaryUnit.id}`}
>
{unit.name}
{primaryUnit.name}
</Link>
.
</p>
<p>
If you need to update this information, update the{" "}
If you need to update this information, update the primary
{primaryLegalUnit
? "primary legal unit or change the primary legal unit altogether"
: "establishment"}
? " legal unit or change the primary legal unit altogether"
: " establishment"}
.
</p>
</InfoBox>
Expand Down
1 change: 1 addition & 0 deletions app/src/app/search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const fetcher = async (derivedApiSearchParams: URLSearchParams) => {
statisticalVariablesDeriveStateUpdateFromSearchParams(statDefinitions, initialUrlSearchParams)
);
let result = actions.reduce(modifySearchStateReducer, emptySearchState);
result = { ...result, pagination: emptySearchState.pagination };
return result;
};

Expand Down
18 changes: 15 additions & 3 deletions app/src/app/search/search-filter-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ export function modifySearchStateReducer(
api_param_value,
app_param_values,
} = action.payload;
const resetPage =
state.apiSearchParams[api_param_name] !== api_param_value;
return {
...state,
apiSearchParams: { ...state.apiSearchParams, [api_param_name]: api_param_value },
appSearchParams: { ...state.appSearchParams, [app_param_name]: app_param_values },
pagination: { ...state.pagination, pageNumber: 1 },
apiSearchParams: {
...state.apiSearchParams,
[api_param_name]: api_param_value,
},
appSearchParams: {
...state.appSearchParams,
[app_param_name]: app_param_values,
},
pagination: {
...state.pagination,
pageNumber: resetPage ? 1 : state.pagination.pageNumber,
},
};

}
case "reset_all":
return {
Expand Down
83 changes: 44 additions & 39 deletions app/src/components/statistical-unit-hierarchy/topology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ export function Topology({ hierarchy, unitId, unitType }: TopologyProps) {
const primaryLegalUnit = hierarchy.enterprise?.legal_unit?.find(
(lu) => lu.primary_for_enterprise
);
const establishment = hierarchy.enterprise?.establishment?.[0];
const primaryEstablishment = hierarchy.enterprise?.establishment?.find(
(es) => es.primary_for_enterprise
);
const primaryUnit = primaryLegalUnit || primaryEstablishment;

if (!primaryLegalUnit && !establishment) {
if (!primaryUnit) {
return null;
}

Expand Down Expand Up @@ -71,47 +74,49 @@ export function Topology({ hierarchy, unitId, unitType }: TopologyProps) {
<TopologyItem
type="enterprise"
id={hierarchy.enterprise.id}
unit={primaryLegalUnit || establishment}
unit={primaryUnit}
active={
hierarchy.enterprise.id == unitId && unitType === "enterprise"
}
>
{primaryLegalUnit
? hierarchy.enterprise.legal_unit.map((legalUnit) => (
<TopologyItem
key={legalUnit.id}
type="legal_unit"
id={legalUnit.id}
unit={legalUnit}
active={legalUnit.id === unitId && unitType === "legal_unit"}
primary={legalUnit.primary_for_enterprise}
>
{legalUnit.establishment?.map((establishment) => (
<TopologyItem
key={establishment.id}
type="establishment"
id={establishment.id}
unit={establishment}
active={
establishment.id === unitId &&
unitType === "establishment"
}
primary={establishment.primary_for_legal_unit}
/>
))}
</TopologyItem>
))
: hierarchy.enterprise.establishment?.map((establishment) => (
<TopologyItem
key={establishment.id}
type="establishment"
id={establishment.id}
unit={establishment}
active={
establishment.id === unitId && unitType === "establishment"
}
/>
))}
{primaryEstablishment &&
hierarchy.enterprise.establishment?.map((establishment) => (
<TopologyItem
key={establishment.id}
type="establishment"
id={establishment.id}
unit={establishment}
active={
establishment.id === unitId && unitType === "establishment"
}
primary={establishment.primary_for_enterprise}
/>
))}
{primaryLegalUnit &&
hierarchy.enterprise.legal_unit.map((legalUnit) => (
<TopologyItem
key={legalUnit.id}
type="legal_unit"
id={legalUnit.id}
unit={legalUnit}
active={legalUnit.id === unitId && unitType === "legal_unit"}
primary={legalUnit.primary_for_enterprise}
>
{legalUnit.establishment?.map((establishment) => (
<TopologyItem
key={establishment.id}
type="establishment"
id={establishment.id}
unit={establishment}
active={
establishment.id === unitId &&
unitType === "establishment"
}
primary={establishment.primary_for_legal_unit}
/>
))}
</TopologyItem>
))}
</TopologyItem>
</ul>
</>
Expand Down
1 change: 1 addition & 0 deletions app/src/components/statistical-unit-hierarchy/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ declare interface Establishment extends StatisticalUnit {
enterprise_id: string | null;
legal_unit_id: number;
primary_for_legal_unit: boolean;
primary_for_enterprise: boolean;
stat_for_unit?: StatForUnit[];
}

Expand Down

0 comments on commit 85b58f1

Please sign in to comment.