Skip to content

Commit

Permalink
feat: add scenario to aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Aug 8, 2024
1 parent 8721e33 commit f86e5ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import type { SelectorItem } from "@/types/map/common";
import type { IndicatorBaseProps } from "@/types/map/toolbox";

import useLayerFields from "@/hooks/map/CommonHooks";
import { useLayerByGeomType, useLayerDatasetId, useStatisticValues } from "@/hooks/map/ToolsHooks";
import {
useLayerByGeomType,
useLayerDatasetId,
useScenarioItems,
useStatisticValues,
} from "@/hooks/map/ToolsHooks";
import { useAppDispatch, useAppSelector } from "@/hooks/store/ContextHooks";

import FormLabelHelper from "@/components/common/FormLabelHelper";
Expand Down Expand Up @@ -67,6 +72,10 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => {

const [fieldGroup, setFieldGroup] = useState<LayerFieldType[] | undefined>([]);

// Scenario
const { scenarioItems } = useScenarioItems(projectId as string);
const [selectedScenario, setSelectedScenario] = useState<SelectorItem | undefined>(undefined);

const areaTypes: SelectorItem[] = useMemo(() => {
return [
{
Expand Down Expand Up @@ -120,6 +129,10 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => {
payload["source_group_by_field"] = fieldGroup.map((field) => field.name);
}

if (selectedScenario) {
payload["scenario_id"] = selectedScenario.value;
}

const schema = type === "point" ? aggregatePointSchema : aggregatePolygonSchema;
const computeApi = type === "point" ? computeAggregatePoint : computeAggregatePolygon;
try {
Expand Down Expand Up @@ -150,6 +163,7 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => {
setStatisticAdvancedOptions(true);
setWeightPolygonByIntersectingArea(false);
setFieldGroup([]);
setSelectedScenario(undefined);
};

return (
Expand Down Expand Up @@ -335,6 +349,32 @@ const Aggregate = ({ onBack, onClose, type }: AggregateProps) => {
</>
}
/>

{/* SCENARIO */}
<SectionHeader
active={isValid}
alwaysActive={true}
label={t("scenario")}
icon={ICON_NAME.SCENARIO}
disableAdvanceOptions={true}
/>
<SectionOptions
active={isValid}
baseOptions={
<>
<Selector
selectedItems={selectedScenario}
setSelectedItems={(item: SelectorItem[] | SelectorItem | undefined) => {
setSelectedScenario(item as SelectorItem);
}}
items={scenarioItems}
label={t("scenario")}
placeholder={t("select_scenario")}
tooltip={t("choose_scenario")}
/>
</>
}
/>
</Box>
</>
}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/lib/validations/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export const bufferSchema = z.object({
distance_step: z.number(),
polygon_union: z.boolean(),
polygon_difference: z.boolean(),
scenario_id: z.string().optional(),
});

export type PostBuffer = z.infer<typeof bufferSchema>;
Expand All @@ -201,6 +202,7 @@ export const aggregatePointSchema = z.object({
field: z.string(),
}),
source_group_by_field: z.string().array().optional(),
scenario_id: z.string().optional(),
});

export const aggregatePolygonSchema = aggregatePointSchema.extend({
Expand Down

0 comments on commit f86e5ac

Please sign in to comment.