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

feat: useForm for isochrone tool #17

Merged
merged 2 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/components/map/panels/toolbox/Toolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ToolboxPanel = () => {
setDefaultRoute={setDefaultRoute}
/>
}
disablePadding
/>
);
};
Expand Down
56 changes: 36 additions & 20 deletions apps/web/components/map/panels/toolbox/tools/InputLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ import { useProjectLayers } from "@/lib/api/projects";
import { useParams } from "next/navigation";

import type { SelectChangeEvent } from "@mui/material";
import type { UseFormGetValues, UseFormRegister } from "react-hook-form";
import type { PostJoin, PostAggregate } from "@/lib/validations/tools";

interface PickLayerProps {
register: UseFormRegister<PostJoin> | UseFormRegister<PostAggregate>;
getValues: UseFormGetValues<PostJoin> | UseFormGetValues<PostAggregate>;
multiple?: boolean;
inputValues: string | string[];
setInputValues: (value: string | string[]) => void;
layerTypes: string[];
// inputValues: string | string[];
// setInputValues: (value: string | string[]) => void;
// layerTypes: string[];
}

const InputLayer = (props: PickLayerProps) => {
const { multiple = false, inputValues, setInputValues, layerTypes } = props;
const {
register,
// getValues,
multiple = false,
// inputValues,
// setInputValues,
// layerTypes
} = props;

const theme = useTheme();
const { t } = useTranslation("maps");
Expand All @@ -34,16 +45,17 @@ const InputLayer = (props: PickLayerProps) => {
typeof projectId === "string" ? projectId : "",
);

const handleSingleChange = (event: SelectChangeEvent) => {
setInputValues(event.target.value as string);
const handleSingleChange = (_: SelectChangeEvent) => {
// setInputValues(event.target.value as string);
};

const handleMultipleChange = (event: SelectChangeEvent, inputNr: number) => {
const multipleValues =
typeof inputValues !== "string" ? [...inputValues] : ["", ""];
multipleValues[inputNr] = event.target.value as string;
const handleMultipleChange = (_: SelectChangeEvent, inputNr: number) => {
console.log(inputNr);
// const multipleValues =
// typeof inputValues !== "string" ? [...inputValues] : ["", ""];
// multipleValues[inputNr] = event.target.value as string;

setInputValues(multipleValues);
// setInputValues(multipleValues);
};

return (
Expand All @@ -68,7 +80,8 @@ const InputLayer = (props: PickLayerProps) => {
</InputLabel>
<Select
label={t("panels.tools.select_layer")}
value={inputValues[0]}
// value={inputValues[0]}
{...register("")}
onChange={(event: SelectChangeEvent) =>
handleMultipleChange(event, 0)
}
Expand Down Expand Up @@ -140,16 +153,19 @@ const InputLayer = (props: PickLayerProps) => {
</InputLabel>
<Select
label={t("panels.tools.select_layer")}
value={inputValues}
// value={inputValues}
{...register("")}
onChange={handleSingleChange}
>
{projectLayers ? projectLayers.map((layer) =>
layerTypes.includes(layer.feature_layer_geometry_type) ? (
<MenuItem value={layer.layer_id} key={v4()}>
{layer.name}
</MenuItem>
) : null,
) : null}
{projectLayers
? projectLayers.map((layer) =>
layerTypes.includes(layer.feature_layer_geometry_type) ? (
<MenuItem value={layer.layer_id} key={v4()}>
{layer.name}
</MenuItem>
) : null,
)
: null}
</Select>
</FormControl>
</Box>
Expand Down
35 changes: 21 additions & 14 deletions apps/web/components/map/panels/toolbox/tools/SaveResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ import { v4 } from "uuid";
import { useTranslation } from "@/i18n/client";
import { useGetUniqueLayerName } from "@/hooks/map/ToolsHooks";

import type { SelectChangeEvent } from "@mui/material";
// import type { SelectChangeEvent } from "@mui/material";
import type { UseFormRegister } from "react-hook-form";
import type { PostAggregate, PostJoin } from "@/lib/validations/tools";
import type { PostIsochrone } from "@/lib/validations/isochrone";

interface SaveResultProps {
outputName: string | undefined;
setOutputName: (value: string) => void;
folderSaveId: string | undefined;
setFolderSaveID: (value: string) => void;
register: UseFormRegister<PostJoin> | UseFormRegister<PostAggregate> | UseFormRegister<PostIsochrone>;
watch: PostJoin | PostAggregate | PostIsochrone;
// outputName: string | undefined;
// setOutputName: (value: string) => void;
// folderSaveId: string | undefined;
// setFolderSaveID: (value: string) => void;
}

const SaveResult = (props: SaveResultProps) => {
const { outputName, setOutputName, folderSaveId, setFolderSaveID } = props;
const {
register,
watch,
} = props;


const theme = useTheme();
const { t } = useTranslation("maps");

const { folders } = useFolders();

const { uniqueName } = useGetUniqueLayerName(outputName ? outputName : "");
const { uniqueName } = useGetUniqueLayerName(watch.result_target.layer_name ? watch.result_target.layer_name : "");

return (
<Box display="flex" flexDirection="column" gap={theme.spacing(2)}>
Expand Down Expand Up @@ -93,9 +102,10 @@ const SaveResult = (props: SaveResultProps) => {
value={uniqueName ? uniqueName : ""}
label="Name"
size="small"
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setOutputName(event.target.value as string)
}
{...register("result_target.layer_name")}
// onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
// setOutputName(event.target.value as string)
// }
/>
</Box>
<Typography variant="body1" sx={{ color: "black" }}>
Expand All @@ -108,10 +118,7 @@ const SaveResult = (props: SaveResultProps) => {
</InputLabel>
<Select
label={t("panels.tools.select_option")}
value={folderSaveId}
onChange={(event: SelectChangeEvent) =>
setFolderSaveID(event.target.value as string)
}
{...register("result_target.folder_id")}
>
{folders
? folders.map((folder) => (
Expand Down
Loading
Loading