Skip to content

Commit

Permalink
adding business units to impact map query
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsingal committed Dec 12, 2023
1 parent d822016 commit e638f26
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ const MoreFilters = () => {
[selectedFilters.locationTypes],
);

const businessUnitIds = useMemo(
() => selectedFilters.businessUnits.map(({ value }) => value),
[selectedFilters.businessUnits],
);

const [counter, setCounter] = useState(0);

// Only the changes are applied when the user clicks on Apply
Expand Down Expand Up @@ -156,6 +161,7 @@ const MoreFilters = () => {
t1SupplierIds,
producerIds,
locationTypes: locationTypesIds,
businessUnitIds,
},
{
...DEFAULT_QUERY_OPTIONS,
Expand All @@ -178,6 +184,7 @@ const MoreFilters = () => {
producerIds,
locationTypes: locationTypesIds,
scenarioIds,
businessUnitIds,
},
DEFAULT_QUERY_OPTIONS,
);
Expand All @@ -190,6 +197,7 @@ const MoreFilters = () => {
originIds,
locationTypes: locationTypesIds,
scenarioIds,
businessUnitIds,
},
DEFAULT_QUERY_OPTIONS,
);
Expand All @@ -202,6 +210,7 @@ const MoreFilters = () => {
originIds,
locationTypes: locationTypesIds,
scenarioIds,
businessUnitIds,
},
DEFAULT_QUERY_OPTIONS,
);
Expand All @@ -213,6 +222,7 @@ const MoreFilters = () => {
t1SupplierIds,
producerIds,
scenarioIds,
businessUnitIds,
},
{
onSuccess: (_locationTypeOptions) => {
Expand All @@ -237,6 +247,7 @@ const MoreFilters = () => {
t1SupplierIds,
producerIds,
locationTypes: locationTypesIds,
scenarioIds,
});

const reviewFilterContent = useCallback(
Expand Down Expand Up @@ -264,7 +275,10 @@ const MoreFilters = () => {
reviewFilterContent('origins', origins, origins);
reviewFilterContent('t1Suppliers', t1Suppliers, t1SupplierOptions);
reviewFilterContent('producers', producers, producerOptions);
reviewFilterContent('businessUnits', businessUnits, businessUnitsOptions);
}, [
businessUnits,
businessUnitsOptions,
locationTypes,
materialOptions,
materials,
Expand Down Expand Up @@ -359,18 +373,9 @@ const MoreFilters = () => {
placeholder="Business Units"
multiple
fitContent
// onChange={(values) => handleChangeFilter('businessUnits', values)}
id="business-units-filter"
/>
{/* <BusinessUnitsFilter
options={businessUnitsOptions}
multiple
current={selectedFilters.businessUnits}
fitContent
loading={businessUnitsOptionsIsLoading}
onChange={(values) => handleChangeFilter('businessUnits', values)}
id="business-units-filter"
/> */}
/>
</div>
<div>
<div className="mb-1">Origins</div>
Expand Down
2 changes: 2 additions & 0 deletions client/src/hooks/business-units/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type BusinessUnitsTreesParams = {
producerIds?: string[];
originIds?: string[];
locationTypes?: string[];
scenarioIds?: string[];
};

export function useBusinessUnits(): ResponseData {
Expand Down Expand Up @@ -105,6 +106,7 @@ export const useBusinessUnitsOptionsTrees = <T = BusinessUnitsOption[]>(
retry: false,
keepPreviousData: true,
refetchOnWindowFocus: false,
placeholderData: { data: [] },
...options,
select: (_businessUnits) =>
recursiveSort(_businessUnits?.data, 'name')?.map((item) =>
Expand Down
2 changes: 2 additions & 0 deletions client/src/hooks/h3-data/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const storeToQueryParams = ({
startYear,
indicator,
materials,
businessUnits,
t1Suppliers,
producers,
origins,
Expand All @@ -34,6 +35,7 @@ export const storeToQueryParams = ({
...(producers?.length ? { producerIds: producers?.map(({ value }) => value) } : {}),
...(origins?.length ? { originIds: origins?.map(({ value }) => value) } : {}),
...(locationTypes?.length ? { locationTypes: locationTypes?.map(({ value }) => value) } : {}),
...(businessUnits?.length ? { businessUnitIds: businessUnits?.map(({ value }) => value) } : {}),
scenarioId: currentScenario,
resolution: origins?.length ? 6 : 4,
};
Expand Down
1 change: 1 addition & 0 deletions client/src/hooks/impact/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type ImpactComparisonParams = {
startYear: number;
endYear: number;
materialIds?: string[];
businessUnitIds?: string[];
originIds?: string[];
supplierIds?: string[];
locationTypes?: string[];
Expand Down
1 change: 1 addition & 0 deletions client/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type ImpactH3APIParams = CommonH3APIParams & {
producerIds?: Supplier['id'][];
scenarioId?: Scenario['id'];
locationTypes?: string[];
businessUnitIds?: BusinessUnits['id'][];
};

export type ContextualH3APIParams = CommonH3APIParams;
Expand Down

0 comments on commit e638f26

Please sign in to comment.