Skip to content

Commit

Permalink
Merge branch 'main' into add-borehole-put
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt authored Oct 7, 2024
2 parents 21ca443 + 4a0161a commit 5b0c9b9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 65 deletions.
6 changes: 6 additions & 0 deletions src/client/cypress/e2e/detailPage/boreholeform.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ describe("Test for the borehole form.", () => {
sortBy("Name");
clickOnRowWithText("Zena Rath");

evaluateInput("original_name", "Zena Rath");
evaluateInput("alternate_name", "Zena Rath");
evaluateInput("project_name", "Reactive asymmetric alliance");
evaluateSelect("restriction", "");
evaluateSelect("national_interest", "0"); // No
evaluateSelect("spatial_reference_system", "20104002"); // LV03
Expand All @@ -78,6 +81,9 @@ describe("Test for the borehole form.", () => {

returnToOverview();
clickOnRowWithText("Zena Mraz");
evaluateInput("original_name", "Zena Mraz");
evaluateInput("alternate_name", "Zena Mraz");
evaluateInput("project_name", "Ergonomic heuristic installation");
evaluateSelect("restriction", "");
evaluateSelect("national_interest", "1"); // Yes
evaluateSelect("spatial_reference_system", "20104002"); // LV03
Expand Down
4 changes: 2 additions & 2 deletions src/client/cypress/e2e/detailPage/location.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ describe("Tests for 'Location' edit page.", () => {
createBorehole({ "extended.original_name": "PHOTOSQUIRREL" }).as("borehole_id");
cy.get("@borehole_id").then(id => {
goToRouteAndAcceptTerms(`/${id}`);
cy.get('[data-cy="original-name"]').within(() => {
cy.get('[data-cy="original_name-formInput"]').within(() => {
cy.get("input").as("originalNameInput");
});
cy.get('[data-cy="alternate-name"]').within(() => {
cy.get('[data-cy="alternate_name-formInput"]').within(() => {
cy.get("input").as("alternateNameInput");
});

Expand Down
6 changes: 4 additions & 2 deletions src/client/src/pages/detail/detailPageContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DetailPageContent extends React.Component {

constructor(props) {
super(props);
this.checkattribute = false;
this.updateAttributeDelay = {};
this.state = {
tab: 0,
Expand Down Expand Up @@ -286,7 +285,10 @@ class DetailPageContent extends React.Component {
setState={this.setStateBound}
updateBorehole={this.props.updateBorehole}
user={user}></IdentifierSegment>
<NameSegment borehole={borehole} updateChange={this.updateChange} user={user}></NameSegment>
<NameSegment
borehole={borehole}
updateChange={this.updateChange}
editingEnabled={editingEnabled}></NameSegment>
<RestrictionSegment
borehole={borehole}
updateChange={this.updateChange}
Expand Down
99 changes: 38 additions & 61 deletions src/client/src/pages/detail/form/location/nameSegment.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,64 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Card } from "@mui/material";
import { Form, Input } from "semantic-ui-react";
import { Borehole, User } from "../../../../api-lib/ReduxStateInterfaces.ts";
import { Borehole } from "../../../../api-lib/ReduxStateInterfaces.ts";
import { useAuth } from "../../../../auth/useBdmsAuth.tsx";
import { FormContainer } from "../../../../components/form/form.ts";
import { SimpleFormInput } from "../../../../components/form/simpleFormInput.tsx";
import { FormSegmentBox } from "../../../../components/styledComponents";

interface NameSegmentProps {
borehole: Borehole;
updateChange: (key: string, value: string) => void;
user: User;
editingEnabled: boolean;
}

const NameSegment = ({ borehole, updateChange, user }: NameSegmentProps) => {
const NameSegment = ({ borehole, updateChange, editingEnabled }: NameSegmentProps) => {
const [alternateName, setAlternateName] = useState("");
const { t } = useTranslation();
const auth = useAuth();

const isEditable =
borehole?.data.role === "EDIT" && borehole?.data.lock !== null && borehole?.data.lock?.id === user?.data.id;

useEffect(() => {
setAlternateName(borehole.data.custom.alternate_name || borehole.data.extended.original_name);
}, [borehole.data]);

return (
<Card>
<FormSegmentBox>
<Form autoComplete="off" error>
<Form.Group widths="equal">
<FormContainer>
<FormContainer direction="row">
<SimpleFormInput
label={"alternate_name"}
readonly={!editingEnabled}
value={alternateName}
onUpdate={e => {
setAlternateName(e);
updateChange("custom.alternate_name", e);
}}
/>

<SimpleFormInput
label={"project_name"}
value={borehole?.data?.custom.project_name || ""}
readonly={!editingEnabled}
onUpdate={e => {
updateChange("custom.project_name", e);
}}
/>
</FormContainer>
<FormContainer direction="row">
{!auth.anonymousModeEnabled && (
<Form.Field error={borehole.data.extended.original_name === ""} required>
<label>{t("original_name")}</label>
<Input
data-cy="original-name"
autoCapitalize="off"
autoComplete="off"
autoCorrect="off"
onChange={e => {
setAlternateName(e.target.value);
updateChange("extended.original_name", e.target.value);
updateChange("custom.alternate_name", e.target.value);
}}
spellCheck="false"
value={borehole.data.extended.original_name ?? ""}
readOnly={!isEditable}
/>
</Form.Field>
)}
<Form.Field>
<label>{t("project_name")}</label>
<Input
autoCapitalize="off"
autoComplete="off"
autoCorrect="off"
onChange={e => {
updateChange("custom.project_name", e.target.value);
<SimpleFormInput
label={"original_name"}
value={borehole?.data?.extended.original_name || ""}
readonly={!editingEnabled}
onUpdate={e => {
setAlternateName(e);
updateChange("extended.original_name", e);
updateChange("custom.alternate_name", e);
}}
spellCheck="false"
value={borehole.data.custom.project_name ?? ""}
readOnly={!isEditable}
/>
</Form.Field>
</Form.Group>
<Form.Group widths="equal">
<Form.Field>
<label>{t("alternate_name")}</label>
<Input
data-cy="alternate-name"
autoCapitalize="off"
autoComplete="off"
autoCorrect="off"
onChange={e => {
setAlternateName(e.target.value);
updateChange("custom.alternate_name", e.target.value);
}}
spellCheck="false"
value={alternateName}
readOnly={!isEditable}
/>
</Form.Field>
</Form.Group>
</Form>
)}
</FormContainer>
</FormContainer>
</FormSegmentBox>
</Card>
);
Expand Down

0 comments on commit 5b0c9b9

Please sign in to comment.