From 5bfe0db355c10ad884f9badf7ffc036ba291af52 Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 11:37:50 +0200 Subject: [PATCH 1/8] wip --- .../src/api-lib/ReduxStateInterfaces.ts | 3 + .../src/pages/detail/detailPageContent.jsx | 2 +- .../form/location/restrictionSegment.jsx | 95 -------------- .../form/location/restrictionSegment.tsx | 116 ++++++++++++++++++ 4 files changed, 120 insertions(+), 96 deletions(-) delete mode 100644 src/client/src/pages/detail/form/location/restrictionSegment.jsx create mode 100644 src/client/src/pages/detail/form/location/restrictionSegment.tsx diff --git a/src/client/src/api-lib/ReduxStateInterfaces.ts b/src/client/src/api-lib/ReduxStateInterfaces.ts index 0a2ccbb59..7fa4b80a6 100644 --- a/src/client/src/api-lib/ReduxStateInterfaces.ts +++ b/src/client/src/api-lib/ReduxStateInterfaces.ts @@ -57,6 +57,9 @@ interface Workflow { } interface BoreholeAttributes { + national_interest: boolean; + restriction_until: dateFns; + restriction: number; workgroup: Workgroup; workflow: Workflow; id: number; diff --git a/src/client/src/pages/detail/detailPageContent.jsx b/src/client/src/pages/detail/detailPageContent.jsx index 920d4a426..f4be2abf8 100644 --- a/src/client/src/pages/detail/detailPageContent.jsx +++ b/src/client/src/pages/detail/detailPageContent.jsx @@ -19,7 +19,7 @@ import WaterIngress from "./form/hydrogeology/waterIngress.jsx"; import IdentifierSegment from "./form/location/indentifierSegment.jsx"; import LocationSegment from "./form/location/locationSegment.tsx"; import NameSegment from "./form/location/nameSegment.tsx"; -import RestrictionSegment from "./form/location/restrictionSegment.jsx"; +import RestrictionSegment from "./form/location/restrictionSegment.tsx"; import ChronostratigraphyPanel from "./form/stratigraphy/chronostratigraphy/chronostratigraphyPanel.jsx"; import Lithology from "./form/stratigraphy/lithology"; import LithostratigraphyPanel from "./form/stratigraphy/lithostratigraphy/lithostratigraphyPanel.jsx"; diff --git a/src/client/src/pages/detail/form/location/restrictionSegment.jsx b/src/client/src/pages/detail/form/location/restrictionSegment.jsx deleted file mode 100644 index f8b55522c..000000000 --- a/src/client/src/pages/detail/form/location/restrictionSegment.jsx +++ /dev/null @@ -1,95 +0,0 @@ -import { useTranslation } from "react-i18next"; -import { Card, FormControl, FormControlLabel, RadioGroup } from "@mui/material"; -import { Form } from "semantic-ui-react"; -import _ from "lodash"; -import moment from "moment"; -import DateField from "../../../../components/legacyComponents/dateField.jsx"; -import DomainDropdown from "../../../../components/legacyComponents/domain/dropdown/domainDropdown.jsx"; -import TranslationText from "../../../../components/legacyComponents/translationText.jsx"; -import { FormSegmentBox } from "../../../../components/styledComponents"; -import { DisabledRadio } from "../styledComponents.jsx"; - -const RestrictionSegment = props => { - const { borehole, updateChange, user } = props; - const { t } = useTranslation(); - const isEditable = - borehole?.data.role === "EDIT" && borehole?.data.lock !== null && borehole?.data.lock?.id === user?.data.id; - - return ( - - -
- - - - { - updateChange("restriction", selected.id, false); - }} - schema="restriction" - selected={borehole.data.restriction} - readOnly={!isEditable} - /> - - - - { - updateChange("restriction_until", selected, false); - }} - isEditable={isEditable} - /> - - - - - - - { - let value = e.target.value === "TRUE" ? true : e.target.value === "FALSE" ? false : null; - updateChange("national_interest", value, false); - }}> - } - label={} - /> - } - label={} - /> - } - label={} - /> - - - - -
-
-
- ); -}; - -export default RestrictionSegment; diff --git a/src/client/src/pages/detail/form/location/restrictionSegment.tsx b/src/client/src/pages/detail/form/location/restrictionSegment.tsx new file mode 100644 index 000000000..689ad5413 --- /dev/null +++ b/src/client/src/pages/detail/form/location/restrictionSegment.tsx @@ -0,0 +1,116 @@ +import { FormProvider, useForm } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { Card, FormControl, FormControlLabel, RadioGroup } from "@mui/material"; +import { Form } from "semantic-ui-react"; +import { Borehole, User } from "../../../../api-lib/ReduxStateInterfaces.ts"; +import { FormContainer, FormInput, FormSelect, FormValueType } from "../../../../components/form/form.ts"; +import { FormDomainSelect } from "../../../../components/form/formDomainSelect.tsx"; +import TranslationText from "../../../../components/legacyComponents/translationText.jsx"; +import { FormSegmentBox } from "../../../../components/styledComponents"; +import { DisabledRadio } from "../styledComponents.jsx"; + +interface RestrictionSegmentProps { + borehole: Borehole; + user: User; +} + +const RestrictionSegment = ({ borehole, updateChange, user }: RestrictionSegmentProps) => { + const { t } = useTranslation(); + const formMethods = useForm({ + mode: "all", + }); + + const restriction = formMethods.watch("restriction"); + + const isEditable = + borehole?.data.role === "EDIT" && borehole?.data.lock !== null && borehole?.data.lock?.id === user?.data.id; + + return ( + + + + + { + if (e !== 20111003) { + formMethods.setValue("restriction_until", null); + } + updateChange("restriction", e ?? null, false); + }} + /> + + { + updateChange("restriction_until", selected, false); + }} + /> + + { + const value = e === 1 ? true : e === 0 ? false : null; + updateChange("national_interest", value, false); + }} + /> + + + + + { + const value = e.target.value === "TRUE" ? true : e.target.value === "FALSE" ? false : null; + updateChange("national_interest", value, false); + }}> + } + label={} + /> + } + label={} + /> + } + label={} + /> + + + + + + + + ); +}; + +export default RestrictionSegment; From 0befd1d2c9249836dd0f6df603d37df16987d92c Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 12:26:16 +0200 Subject: [PATCH 2/8] Add boolean form select --- .../src/components/form/formBooleanSelect.tsx | 29 +++++++++++++++++++ src/client/src/components/form/formSelect.tsx | 4 +-- .../bulkedit/bulkEditForm.tsx | 11 ++----- 3 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 src/client/src/components/form/formBooleanSelect.tsx diff --git a/src/client/src/components/form/formBooleanSelect.tsx b/src/client/src/components/form/formBooleanSelect.tsx new file mode 100644 index 000000000..830eb986e --- /dev/null +++ b/src/client/src/components/form/formBooleanSelect.tsx @@ -0,0 +1,29 @@ +import { FC } from "react"; +import { useTranslation } from "react-i18next"; +import { FormSelect } from "./form"; +import { FormSelectProps } from "./formSelect.tsx"; + +export interface FormBooleanSelectProps extends FormSelectProps { + label: string; + selected?: boolean | undefined; +} + +export const FormBooleanSelect: FC = props => { + const { label, selected, onUpdate } = props; + const { t } = useTranslation(); + const value = selected === true ? 1 : selected === false ? 0 : 2; + + return ( + (onUpdate ? onUpdate(e === 1 ? true : e === 0 ? false : null) : null)} + values={[ + { key: 1, name: t("yes") }, + { key: 0, name: t("no") }, + { key: 2, name: t("np") }, + ]} + /> + ); +}; diff --git a/src/client/src/components/form/formSelect.tsx b/src/client/src/components/form/formSelect.tsx index 0f4f70ac9..29d574d90 100644 --- a/src/client/src/components/form/formSelect.tsx +++ b/src/client/src/components/form/formSelect.tsx @@ -11,11 +11,11 @@ export interface FormSelectProps { required?: boolean; disabled?: boolean; readonly?: boolean; - selected?: number; + selected?: number | boolean; values?: FormSelectValue[]; sx?: SxProps; className?: string; - onUpdate?: (value: number) => void; + onUpdate?: (value: number | boolean | null) => void; } export interface FormSelectValue { diff --git a/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx b/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx index 8875381b0..27afdcdd7 100644 --- a/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx +++ b/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx @@ -22,9 +22,9 @@ import WorkgroupSelect from "../../../pages/overview/sidePanelContent/commons/wo import { AlertContext } from "../../alert/alertContext.tsx"; import { CancelButton, SaveButton } from "../../buttons/buttons"; import { FormValueType } from "../../form/form.ts"; +import { FormBooleanSelect } from "../../form/formBooleanSelect.tsx"; import { FormDomainSelect } from "../../form/formDomainSelect.tsx"; import { FormInput } from "../../form/formInput.tsx"; -import { FormSelect } from "../../form/formSelect.tsx"; import { StackFullWidth } from "../../styledComponents.ts"; import { BulkEditFormField, BulkEditFormProps, BulkEditFormValue } from "./BulkEditFormProps.ts"; @@ -168,15 +168,10 @@ export const BulkEditForm = ({ selected, loadBoreholes }: BulkEditFormProps) => if (field.type === FormValueType.Boolean) { return ( - { onFieldValueChange(field, e); }} From 8a611bc3fd1e8c7e49278acd3eb35ede51e78591 Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 12:29:04 +0200 Subject: [PATCH 3/8] Add common segment props interface --- .../src/pages/detail/detailPageContent.jsx | 3 +- .../location/cantonMunicipalitySegment.tsx | 15 ++++++---- .../location/coordinateSegmentInterfaces.ts | 10 ++----- .../form/location/coordinatesSegment.tsx | 2 +- .../detail/form/location/elevationSegment.tsx | 28 ++++++------------- .../detail/form/location/locationSegment.tsx | 24 ++++++++-------- .../detail/form/location/segmentInterface.ts | 11 ++++++++ 7 files changed, 45 insertions(+), 48 deletions(-) create mode 100644 src/client/src/pages/detail/form/location/segmentInterface.ts diff --git a/src/client/src/pages/detail/detailPageContent.jsx b/src/client/src/pages/detail/detailPageContent.jsx index f4be2abf8..31cf9554f 100644 --- a/src/client/src/pages/detail/detailPageContent.jsx +++ b/src/client/src/pages/detail/detailPageContent.jsx @@ -296,11 +296,10 @@ class DetailPageContent extends React.Component { + editingEnabled={editingEnabled}> { +const CantonMunicipalitySegment = ({ + country, + canton, + municipality, + editingEnabled, +}: CantonMunicipalitySegmentProps) => { const formMethods = useForm({ mode: "all", }); @@ -47,7 +52,7 @@ const CantonMunicipalitySegment = ({ country, canton, municipality, isEditable } ), }} - readonly={!isEditable} + readonly={!editingEnabled} /> ), }} - readonly={!isEditable} + readonly={!editingEnabled} /> ), }} - readonly={!isEditable} + readonly={!editingEnabled} /> diff --git a/src/client/src/pages/detail/form/location/coordinateSegmentInterfaces.ts b/src/client/src/pages/detail/form/location/coordinateSegmentInterfaces.ts index 02004d732..276b3f770 100644 --- a/src/client/src/pages/detail/form/location/coordinateSegmentInterfaces.ts +++ b/src/client/src/pages/detail/form/location/coordinateSegmentInterfaces.ts @@ -1,4 +1,5 @@ import { Borehole } from "../../../../api-lib/ReduxStateInterfaces.ts"; +import { SegmentProps } from "./segmentInterface.ts"; export enum ReferenceSystemCode { LV95 = 20104001, @@ -66,18 +67,11 @@ export interface FormValues { location_precision: string; } -export interface CoordinatesSegmentProps { - borehole: Borehole; - updateChange: ( - fieldName: keyof Borehole["data"] | "location", - value: string | number | null | (number | string | null)[], - to?: boolean, - ) => void; +export interface CoordinatesSegmentProps extends SegmentProps { updateNumber: (fieldName: keyof Borehole["data"], value: number | null) => void; mapPointChange: boolean; setMapPointChange: React.Dispatch>; showLabeling: boolean; - editingEnabled: boolean; } export interface Location { diff --git a/src/client/src/pages/detail/form/location/coordinatesSegment.tsx b/src/client/src/pages/detail/form/location/coordinatesSegment.tsx index 539a2d8de..b170bbe88 100644 --- a/src/client/src/pages/detail/form/location/coordinatesSegment.tsx +++ b/src/client/src/pages/detail/form/location/coordinatesSegment.tsx @@ -418,7 +418,7 @@ const CoordinatesSegment: React.FC = ({ selected={currentReferenceSystem ?? referenceSystems.LV95.code} readonly={!editingEnabled} className={isCoordinateExtraction ? "ai" : ""} - onUpdate={e => onReferenceSystemChange(e)} + onUpdate={e => onReferenceSystemChange(e as number)} values={Object.entries(referenceSystems).map(([, value]) => ({ key: value.code, name: value.name, diff --git a/src/client/src/pages/detail/form/location/elevationSegment.tsx b/src/client/src/pages/detail/form/location/elevationSegment.tsx index c4815f5a1..8470eec8d 100644 --- a/src/client/src/pages/detail/form/location/elevationSegment.tsx +++ b/src/client/src/pages/detail/form/location/elevationSegment.tsx @@ -1,34 +1,24 @@ import { FC, useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; -import { Borehole, User } from "../../../../api-lib/ReduxStateInterfaces.ts"; +import { Borehole } from "../../../../api-lib/ReduxStateInterfaces.ts"; import { useDomains } from "../../../../api/fetchApiV2"; import { FormContainer, FormInput, FormValueType } from "../../../../components/form/form.ts"; import { FormDomainSelect } from "../../../../components/form/formDomainSelect.tsx"; import { Codelist } from "../../../../components/legacyComponents/domain/domainInterface.ts"; import { parseFloatWithThousandsSeparator } from "../../../../components/legacyComponents/formUtils.js"; import { FormSegmentBox } from "../../../../components/styledComponents.ts"; +import { SegmentProps } from "./segmentInterface.ts"; -interface ElevationSegmentProps { - borehole: Borehole; - user: User; - updateChange: ( - fieldName: keyof Borehole["data"] | "location", - value: string | number | null | (number | string | null)[], - to?: boolean, - ) => void; +interface ElevationSegmentProps extends SegmentProps { updateNumber: (fieldName: keyof Borehole["data"], value: number | null) => void; } - -const ElevationSegment: FC = ({ borehole, user, updateChange, updateNumber }) => { +const ElevationSegment: FC = ({ borehole, updateChange, updateNumber, editingEnabled }) => { const { data: domains } = useDomains(); const formMethods = useForm({ mode: "all", defaultValues: borehole.data, }); - // --- Derived states --- - const isEditable: boolean = - borehole?.data.role === "EDIT" && borehole?.data.lock !== null && borehole?.data.lock?.id === user?.data.id; useEffect(() => { formMethods.reset(borehole.data); @@ -44,7 +34,7 @@ const ElevationSegment: FC = ({ borehole, user, updateCha label="elevation_z" value={borehole.data.elevation_z ?? ""} type={FormValueType.Text} - readonly={!isEditable} + readonly={!editingEnabled} withThousandSeparator={true} onUpdate={e => updateNumber("elevation_z", e === "" ? null : parseFloatWithThousandsSeparator(e))} /> @@ -52,7 +42,7 @@ const ElevationSegment: FC = ({ borehole, user, updateCha fieldName={"elevation_precision"} label={"elevation_precision"} schemaName={"elevation_precision"} - readonly={!isEditable} + readonly={!editingEnabled} selected={borehole.data.elevation_precision} onUpdate={e => { updateChange("elevation_precision", e ?? null, false); @@ -65,14 +55,14 @@ const ElevationSegment: FC = ({ borehole, user, updateCha label="reference_elevation" value={borehole.data.reference_elevation ?? ""} type={FormValueType.Text} - readonly={!isEditable} + readonly={!editingEnabled} withThousandSeparator={true} onUpdate={e => updateNumber("reference_elevation", e === "" ? null : parseFloatWithThousandsSeparator(e))} /> { @@ -84,7 +74,7 @@ const ElevationSegment: FC = ({ borehole, user, updateCha { diff --git a/src/client/src/pages/detail/form/location/locationSegment.tsx b/src/client/src/pages/detail/form/location/locationSegment.tsx index c00ea7225..3a4e4b469 100644 --- a/src/client/src/pages/detail/form/location/locationSegment.tsx +++ b/src/client/src/pages/detail/form/location/locationSegment.tsx @@ -1,29 +1,22 @@ import { useState } from "react"; import { Card, Stack } from "@mui/material"; import _ from "lodash"; -import { Borehole, User } from "../../../../api-lib/ReduxStateInterfaces"; +import { Borehole } from "../../../../api-lib/ReduxStateInterfaces.ts"; import PointComponent from "../../../../components/map/pointComponent.jsx"; import { FormSegmentBox } from "../../../../components/styledComponents"; import CantonMunicipalitySegment from "./cantonMunicipalitySegment"; import CoordinatesSegment from "./coordinatesSegment"; import ElevationSegment from "./elevationSegment"; +import { SegmentProps } from "./segmentInterface.ts"; -interface LocationSegmentProps { - borehole: Borehole; - user: User; - updateChange: ( - fieldName: keyof Borehole["data"] | "location", - value: string | number | null | (number | string | null)[], - to?: boolean, - ) => void; - updateNumber: (fieldName: keyof Borehole["data"], value: number | null) => void; +interface LocationSegmentProps extends SegmentProps { showLabeling: boolean; editingEnabled: boolean; + updateNumber: (fieldName: keyof Borehole["data"], value: number | null) => void; } const LocationSegment = ({ borehole, - user, updateChange, updateNumber, showLabeling, @@ -45,7 +38,12 @@ const LocationSegment = ({ showLabeling={showLabeling} editingEnabled={editingEnabled} /> - + @@ -67,7 +65,7 @@ const LocationSegment = ({ country={borehole.data.custom.country} canton={borehole.data.custom.canton} municipality={borehole.data.custom.municipality} - isEditable={editingEnabled} + editingEnabled={editingEnabled} /> ); diff --git a/src/client/src/pages/detail/form/location/segmentInterface.ts b/src/client/src/pages/detail/form/location/segmentInterface.ts new file mode 100644 index 000000000..52a856778 --- /dev/null +++ b/src/client/src/pages/detail/form/location/segmentInterface.ts @@ -0,0 +1,11 @@ +import { Borehole } from "../../../../api-lib/ReduxStateInterfaces.ts"; + +export interface SegmentProps { + borehole: Borehole; + updateChange: ( + fieldName: keyof Borehole["data"] | "location", + value: string | number | boolean | null | (number | string | null)[], + to?: boolean, + ) => void; + editingEnabled: boolean; +} From 8c17468cefc0504614f30d5c6876f1ecb1a8fb7b Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 12:34:51 +0200 Subject: [PATCH 4/8] Add restriction segment styles --- .../src/api-lib/ReduxStateInterfaces.ts | 2 +- src/client/src/components/form/formInput.tsx | 4 +- src/client/src/components/styledComponents.ts | 2 +- .../form/location/restrictionSegment.tsx | 72 +++---------------- 4 files changed, 14 insertions(+), 66 deletions(-) diff --git a/src/client/src/api-lib/ReduxStateInterfaces.ts b/src/client/src/api-lib/ReduxStateInterfaces.ts index 7fa4b80a6..ba939e848 100644 --- a/src/client/src/api-lib/ReduxStateInterfaces.ts +++ b/src/client/src/api-lib/ReduxStateInterfaces.ts @@ -58,7 +58,7 @@ interface Workflow { interface BoreholeAttributes { national_interest: boolean; - restriction_until: dateFns; + restriction_until: Date; restriction: number; workgroup: Workgroup; workflow: Workflow; diff --git a/src/client/src/components/form/formInput.tsx b/src/client/src/components/form/formInput.tsx index deea454b4..15b541d4b 100644 --- a/src/client/src/components/form/formInput.tsx +++ b/src/client/src/components/form/formInput.tsx @@ -16,7 +16,7 @@ export interface FormInputProps { type?: FormValueType; multiline?: boolean; rows?: number; - value?: string | number; + value?: string | number | Date; sx?: SxProps; className?: string; inputProps?: InputProps; @@ -43,7 +43,7 @@ export const FormInput: FC = ({ const { t } = useTranslation(); const { formState, register, setValue } = useFormContext(); - const getDefaultValue = (value: string | number | undefined) => { + const getDefaultValue = (value: string | number | Date | undefined) => { if (value == undefined) { return ""; } else if (type === FormValueType.DateTime) { diff --git a/src/client/src/components/styledComponents.ts b/src/client/src/components/styledComponents.ts index 3a32fb1a3..0843b32fd 100644 --- a/src/client/src/components/styledComponents.ts +++ b/src/client/src/components/styledComponents.ts @@ -42,7 +42,7 @@ export const MainContentBox = styled(Box)({ }); export const FormSegmentBox = styled(Box)({ - padding: theme.spacing(2), + padding: theme.spacing(3), }); export const DialogHeaderContainer = styled(Box)({ diff --git a/src/client/src/pages/detail/form/location/restrictionSegment.tsx b/src/client/src/pages/detail/form/location/restrictionSegment.tsx index 689ad5413..6bb1db8fe 100644 --- a/src/client/src/pages/detail/form/location/restrictionSegment.tsx +++ b/src/client/src/pages/detail/form/location/restrictionSegment.tsx @@ -1,30 +1,18 @@ import { FormProvider, useForm } from "react-hook-form"; -import { useTranslation } from "react-i18next"; -import { Card, FormControl, FormControlLabel, RadioGroup } from "@mui/material"; -import { Form } from "semantic-ui-react"; -import { Borehole, User } from "../../../../api-lib/ReduxStateInterfaces.ts"; -import { FormContainer, FormInput, FormSelect, FormValueType } from "../../../../components/form/form.ts"; +import { Card } from "@mui/material"; +import { FormContainer, FormInput, FormValueType } from "../../../../components/form/form.ts"; +import { FormBooleanSelect } from "../../../../components/form/formBooleanSelect.tsx"; import { FormDomainSelect } from "../../../../components/form/formDomainSelect.tsx"; -import TranslationText from "../../../../components/legacyComponents/translationText.jsx"; import { FormSegmentBox } from "../../../../components/styledComponents"; -import { DisabledRadio } from "../styledComponents.jsx"; +import { SegmentProps } from "./segmentInterface.ts"; -interface RestrictionSegmentProps { - borehole: Borehole; - user: User; -} - -const RestrictionSegment = ({ borehole, updateChange, user }: RestrictionSegmentProps) => { - const { t } = useTranslation(); +const RestrictionSegment = ({ borehole, updateChange, editingEnabled }: SegmentProps) => { const formMethods = useForm({ mode: "all", }); const restriction = formMethods.watch("restriction"); - const isEditable = - borehole?.data.role === "EDIT" && borehole?.data.lock !== null && borehole?.data.lock?.id === user?.data.id; - return ( @@ -34,7 +22,7 @@ const RestrictionSegment = ({ borehole, updateChange, user }: RestrictionSegment fieldName={"restriction"} label={"restriction"} schemaName={"restriction"} - readonly={!isEditable} + readonly={!editingEnabled} selected={borehole.data.restriction} onUpdate={e => { if (e !== 20111003) { @@ -48,7 +36,7 @@ const RestrictionSegment = ({ borehole, updateChange, user }: RestrictionSegment fieldName="restriction_until" label="restriction_until" disabled={restriction !== 20111003} - readonly={!isEditable || restriction !== 20111003} + readonly={!editingEnabled || restriction !== 20111003} value={borehole.data.restriction_until} type={FormValueType.Date} onUpdate={selected => { @@ -56,56 +44,16 @@ const RestrictionSegment = ({ borehole, updateChange, user }: RestrictionSegment }} /> - { - const value = e === 1 ? true : e === 0 ? false : null; - updateChange("national_interest", value, false); + updateChange("national_interest", e, false); }} /> - - - - - { - const value = e.target.value === "TRUE" ? true : e.target.value === "FALSE" ? false : null; - updateChange("national_interest", value, false); - }}> - } - label={} - /> - } - label={} - /> - } - label={} - /> - - - From 69b8d697e50d3fb84e4ec2eb8638e3d714941fa8 Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 14:20:08 +0200 Subject: [PATCH 5/8] Remove unused dependency --- .../src/components/legacyComponents/bulkedit/bulkEditForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx b/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx index 27afdcdd7..c6c842ac4 100644 --- a/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx +++ b/src/client/src/components/legacyComponents/bulkedit/bulkEditForm.tsx @@ -189,7 +189,7 @@ export const BulkEditForm = ({ selected, loadBoreholes }: BulkEditFormProps) => /> ); }, - [onFieldValueChange, t], + [onFieldValueChange], ); return ( From 96766446bc43dcfdd0b54249aa9556170c799253 Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 14:38:26 +0200 Subject: [PATCH 6/8] Fix cypress test --- .../cypress/e2e/detailPage/boreholeform.cy.js | 13 ++++++++++--- src/client/cypress/e2e/helpers/formHelpers.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/client/cypress/e2e/detailPage/boreholeform.cy.js b/src/client/cypress/e2e/detailPage/boreholeform.cy.js index fea44273f..671e3f59a 100644 --- a/src/client/cypress/e2e/detailPage/boreholeform.cy.js +++ b/src/client/cypress/e2e/detailPage/boreholeform.cy.js @@ -1,4 +1,4 @@ -import { evaluateSelect, setSelect } from "../helpers/formHelpers"; +import { evaluateSelect, isDisabled, setSelect } from "../helpers/formHelpers"; import { createBorehole, goToRouteAndAcceptTerms, newEditableBorehole } from "../helpers/testHelpers"; describe("Test for the borehole form.", () => { @@ -8,7 +8,7 @@ describe("Test for the borehole form.", () => { // fill all legacy dropdowns on location tab cy.get('[data-cy="domain-dropdown"]') - .should("have.length", 2) + .should("have.length", 1) .each(el => cy.wrap(el).click().find('[role="option"]').last().click()); const locationDropdownValues = []; @@ -18,16 +18,23 @@ describe("Test for the borehole form.", () => { locationDropdownValues.push(value); }) .then(() => { - expect(locationDropdownValues).to.deep.eq(["ID Kernlager", "not specified"]); + expect(locationDropdownValues).to.deep.eq(["ID Kernlager"]); }); // fills and evaluates all mui dropdowns on location tab + setSelect("restriction", 2); + isDisabled("restriction_until", true); + setSelect("restriction", 3); + isDisabled("restriction_until", false); + setSelect("national_interest", 2); setSelect("spatial_reference_system", 0); setSelect("location_precision", 2); setSelect("elevation_precision", 2); setSelect("qt_reference_elevation", 2); setSelect("reference_elevation_type", 4); + evaluateSelect("restriction", "20111003"); + evaluateSelect("national_interest", "2"); evaluateSelect("spatial_reference_system", "20104001"); evaluateSelect("location_precision", "20113002"); evaluateSelect("elevation_precision", "20114002"); diff --git a/src/client/cypress/e2e/helpers/formHelpers.js b/src/client/cypress/e2e/helpers/formHelpers.js index fd6374728..26bc01051 100644 --- a/src/client/cypress/e2e/helpers/formHelpers.js +++ b/src/client/cypress/e2e/helpers/formHelpers.js @@ -1,5 +1,20 @@ import { createBaseSelector } from "./testHelpers"; +/** + * Checks if a form element is disabled. + * @param {string} fieldName The name of the form element. + * @param {boolean} isDisabled The expected disabled state. + * @param {string} parent (optional) The parent of the form element. + */ +export const isDisabled = (fieldName, isDisabled = true, parent) => { + const selector = createBaseSelector(parent) + `[data-cy^="${fieldName}-form"] .Mui-disabled`; + if (isDisabled) { + cy.get(selector).should("exist"); + } else { + cy.get(selector).should("not.exist"); + } +}; + /** * Sets the value for an input form element. * @param {string} fieldName The name of the input field. From 7a8fefe5df4fa6f5f34923cb901ef10ad5f64fff Mon Sep 17 00:00:00 2001 From: MiraGeowerkstatt Date: Tue, 1 Oct 2024 14:42:28 +0200 Subject: [PATCH 7/8] Use constant for code --- .../pages/detail/form/location/restrictionSegment.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/client/src/pages/detail/form/location/restrictionSegment.tsx b/src/client/src/pages/detail/form/location/restrictionSegment.tsx index 6bb1db8fe..02b33791f 100644 --- a/src/client/src/pages/detail/form/location/restrictionSegment.tsx +++ b/src/client/src/pages/detail/form/location/restrictionSegment.tsx @@ -12,6 +12,7 @@ const RestrictionSegment = ({ borehole, updateChange, editingEnabled }: SegmentP }); const restriction = formMethods.watch("restriction"); + const restrictionUntilCode = 20111003; return ( @@ -25,25 +26,23 @@ const RestrictionSegment = ({ borehole, updateChange, editingEnabled }: SegmentP readonly={!editingEnabled} selected={borehole.data.restriction} onUpdate={e => { - if (e !== 20111003) { + if (e !== restrictionUntilCode) { formMethods.setValue("restriction_until", null); } updateChange("restriction", e ?? null, false); }} /> - { updateChange("restriction_until", selected, false); }} /> - Date: Tue, 1 Oct 2024 15:28:23 +0200 Subject: [PATCH 8/8] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4c9e2472..c072d76d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - Updated the style of bulk edit form. - Hide the `help` button in the navigation bar in read-only mode. - Hide the `original_name` field in the borehole detail view in read-only mode. -- Updated the style of the coordinates and elevation segment in the location tab. +- Updated the style of the location tab. ### Fixed