Skip to content

Commit

Permalink
feat: Add GDE select Dialog. (#293)
Browse files Browse the repository at this point in the history
* feat: Add GDE select Dialog.

* feat: Add Gde table view, save Gde row, delete Gde row.

* chore: Cleanup console.log.

* fix: Change wrong title naming from strat column to GDE.
  • Loading branch information
mheggelund authored Jun 10, 2024
1 parent 78b3403 commit 1b386c7
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 6 deletions.
97 changes: 97 additions & 0 deletions src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-disable max-lines-per-function */
import { Autocomplete, AutocompleteChanges } from '@equinor/eds-core-react';
import { GeologicalStandardDto } from '../../../api/generated';
import { useFetchGrossDepData } from '../../../hooks/useFetchGrossDepData';
import { GdeType } from '../GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup';

export const GdeSelect = ({
gdeObject,
setGdeObject,
}: {
gdeObject: GdeType;
setGdeObject: React.Dispatch<React.SetStateAction<GdeType>>;
}) => {
const GdeData = useFetchGrossDepData();

if (GdeData.isLoading || !GdeData.data?.success) return <p>Loading .....</p>;

const Gde = GdeData.data.data.filter(
(g) => g.geologyGroup === 'GrossDepositionalEnvironment',
);

const De = GdeData.data.data.filter(
(g) =>
g.geologyGroup === 'DepositionalEnvironment' &&
g.geologicalStandardParentId ===
gdeObject.grossDepEnv?.geologicalStandardId,
);

const SubEnvironment = GdeData.data.data.filter(
(g) =>
g.geologyGroup === 'Subenvironment' &&
g.geologicalStandardParentId ===
gdeObject.grossDepEnv?.geologicalStandardId,
);

const ArchitecturalElement = GdeData.data.data.filter(
(g) => g.geologyGroup === 'Subenvironment',
);

return (
<div>
<Autocomplete
label="Gross Depositional Environment (GDE)"
options={Gde}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
grossDepEnv: e.selectedItems[0],
});
}}
noOptionsText="No options"
/>

<Autocomplete
label="Depositional Environment"
disabled={gdeObject.grossDepEnv?.geologicalStandardId === undefined}
options={De}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
depEnv: e.selectedItems[0],
});
}}
noOptionsText="No options"
/>

<Autocomplete
label="Subenvironment"
disabled={gdeObject.grossDepEnv?.geologicalStandardId === undefined}
options={SubEnvironment}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
subenv: e.selectedItems[0],
});
}}
noOptionsText="No options"
/>

<Autocomplete
label="Architectural Element"
options={ArchitecturalElement}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
architecturalElements: e.selectedItems,
});
}}
noOptionsText="No options"
/>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import styled from 'styled-components';
import { spacings } from '../../../tokens/spacings';

export const Wrapper = styled.div`
display: flex;
flex-direction: column;
row-gap: ${spacings.MEDIUM};
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* eslint-disable max-lines-per-function */
import {
Button,
Dialog,
Icon,
Table,
Typography,
} from '@equinor/eds-core-react';
import { delete_to_trash as deleteIcon } from '@equinor/eds-icons';
import { useMutation } from '@tanstack/react-query';
import { useState } from 'react';
import {
AddGeologicalGroupForm,
AnalogueModelDetail,
AnalogueModelsService,
GeologicalGroupDto,
GeologicalStandardDto,
} from '../../../api/generated';
import { queryClient } from '../../../auth/queryClient';
import { GdeSelect } from '../GdeSelect/GdeSelect';
import * as Styled from './GrossDepositionEnviromentGroup.styled';

export interface GdeType {
grossDepEnv?: GeologicalStandardDto;
depEnv?: GeologicalStandardDto;
subenv?: GeologicalStandardDto;
architecturalElements?: Array<GeologicalStandardDto>;
}
const defaultGdeData: GdeType = {
grossDepEnv: undefined,
depEnv: undefined,
subenv: undefined,
architecturalElements: [],
};
export const GrossDepositionEnviromentGroup = ({
modelIdParent,
defaultMetadata,
gdeGroups,
deleteGdeRow,
}: {
modelIdParent?: string;
defaultMetadata: AnalogueModelDetail;
gdeGroups: GeologicalGroupDto[];
deleteGdeRow: (geologicalGroupId: string) => Promise<void>;
}) => {
const [showGdeDialog, setShowGdeDialog] = useState<boolean>(false);
const [gdeObject, setGdeObject] = useState<GdeType>(defaultGdeData);
const handleGdeDialog = () => {
setShowGdeDialog(!showGdeDialog);
};

const postGdeRow = useMutation({
mutationFn: ({
id,
requestBody,
}: {
id: string;
requestBody: AddGeologicalGroupForm;
}) => {
return AnalogueModelsService.postApiAnalogueModelsGeologicalGroups(
id,
requestBody,
);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['analogue-model'] });
},
});

const handleAddGde = async () => {
const id = modelIdParent ? modelIdParent : defaultMetadata.analogueModelId;

if (
id &&
gdeObject.grossDepEnv &&
gdeObject.depEnv &&
gdeObject.subenv &&
gdeObject.architecturalElements
) {
const architecturalElementsList: string[] = [];
gdeObject.architecturalElements.map((x) =>
architecturalElementsList.push(x.geologicalStandardId),
);

const postRequestBody: AddGeologicalGroupForm = {
grossDepEnvId: gdeObject.grossDepEnv.geologicalStandardId,
depEnvId: gdeObject.depEnv.geologicalStandardId,
subEnvId: gdeObject.subenv.geologicalStandardId,
architecturalElements:
gdeObject.architecturalElements.length > 0
? architecturalElementsList
: [],
};
const rowUpload = await postGdeRow.mutateAsync({
id: id,
requestBody: postRequestBody,
});
if (rowUpload.success) handleGdeDialog();
}
};

return (
<>
<Styled.Wrapper>
<Typography variant="h3">Gross Depositional Environment</Typography>
<Table>
<Table.Head>
<Table.Row>
<Table.Cell></Table.Cell>
<Table.Cell>Gross Depositional Environment (GDE)</Table.Cell>
<Table.Cell>Depositional Environment</Table.Cell>
<Table.Cell>Subenvironment</Table.Cell>
<Table.Cell>Architectural Element</Table.Cell>
</Table.Row>
</Table.Head>

<Table.Body>
{gdeGroups.map((row) => (
<Table.Row key={row.geologicalGroupId}>
<Table.Cell>
<Button
variant="ghost_icon"
onClick={() => deleteGdeRow(row.geologicalGroupId)}
>
<Icon
data={deleteIcon}
title={'Delete gross deposition enviroment row'}
/>
</Button>
</Table.Cell>
<Table.Cell>{row.grossDepEnv.identifier}</Table.Cell>
<Table.Cell>{row.depEnv.identifier}</Table.Cell>
<Table.Cell>{row.subenv.identifier}</Table.Cell>
<Table.Cell>
<div>
{row.architecturalElements.map((a) => (
<p key={a.geologicalStandardId}>{a.identifier}</p>
))}
</div>
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
<div>
<Button variant="outlined" onClick={handleGdeDialog}>
Add Row
</Button>
</div>
</Styled.Wrapper>

<Dialog open={showGdeDialog}>
<Dialog.Header>Add Gross Deposition Enviroment</Dialog.Header>
<Dialog.CustomContent>
<GdeSelect gdeObject={gdeObject} setGdeObject={setGdeObject} />
</Dialog.CustomContent>
<Dialog.Actions>
<Button onClick={handleAddGde}>Add</Button>
<Button variant="outlined" onClick={handleGdeDialog}>
Close
</Button>
</Dialog.Actions>
</Dialog>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
StratColumnDto,
StratUnitDto,
} from '../../../api/generated';
import { StratColumnType } from '../../../features/HandleModel/HandleModelComponent/HandleModelComponent';
import {
useFetchSmdaCountries,
useFetchSmdaFields,
useFetchSmdaMetadataStratigraphicUnits,
useFetchSmdaStratigraphicColumns,
} from '../../../hooks/useFetchStratColData';
import { StratColumnType } from '../HandleModelComponent/HandleModelComponent';
import * as Styled from './StratigraphicColumnSelect.styled';

export const StratigraphicColumnSelect = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import { spacings } from '../../tokens/spacings';
import { spacings } from '../../../tokens/spacings';

export const Wrapper = styled.div`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-lines-per-function */
import { Button, Icon, Table, Typography } from '@equinor/eds-core-react';
import { delete_to_trash as deleteIcon } from '@equinor/eds-icons';
import { StratigraphicGroupDto } from '../../api/generated';
import { StratigraphicGroupDto } from '../../../api/generated';
import * as Styled from './StratigrapicGroups.styled';

export const StratigrapicGroups = ({
Expand Down
48 changes: 45 additions & 3 deletions src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import {
} from '../../../api/generated';
import { AnalogueModelsService } from '../../../api/generated/services/AnalogueModelsService';
import { queryClient } from '../../../auth/queryClient';
import { StratigrapicGroups } from '../../../components/StratigrapicGroups/StratigrapicGroups';
import { GrossDepositionEnviromentGroup } from '../../../components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup';
import { StratigraphicColumnSelect } from '../../../components/StrategraphicColumn/StratigraphicColumnSelect/StratigraphicColumnSelect';
import { StratigrapicGroups } from '../../../components/StrategraphicColumn/StratigrapicGroups/StratigrapicGroups';
import { useFetchModel } from '../../../hooks/useFetchModel';
import {
HandleModelComponent,
StratColumnType,
} from '../../HandleModel/HandleModelComponent/HandleModelComponent';
import { StratigraphicColumnSelect } from '../../HandleModel/StratigraphicColumnSelect/StratigraphicColumnSelect';
import * as Styled from './ModelMetadataView.styled';

export const defaultStratColumnData: StratColumnType = {
country: undefined,
field: undefined,
Expand Down Expand Up @@ -218,6 +218,24 @@ export const ModelMetadataView = ({
},
});

const deleteGdeCase = useMutation({
mutationFn: ({
analogueModelId,
geologicalGroupId,
}: {
analogueModelId: string;
geologicalGroupId: string;
}) => {
return AnalogueModelsService.deleteApiAnalogueModelsGeologicalGroups(
analogueModelId,
geologicalGroupId,
);
},
onSuccess: () => {
queryClient.invalidateQueries(['analogue-model']);
},
});

const deleteStratColRow = async (stratigraphicGroupId: string) => {
if (modelId) {
const res = await deleteStratColCase.mutateAsync({
Expand All @@ -234,6 +252,22 @@ export const ModelMetadataView = ({
}
};

const deleteGdeRow = async (gdeGroupId: string) => {
if (modelId) {
const res = await deleteGdeCase.mutateAsync({
analogueModelId: modelId,
geologicalGroupId: gdeGroupId,
});
return res;
} else if (modelIdParent) {
const res = await deleteGdeCase.mutateAsync({
analogueModelId: modelIdParent,
geologicalGroupId: gdeGroupId,
});
return res;
}
};

if (isLoading || !data?.success) return <p>Loading ...</p>;

const handleAddStratCol = async () => {
Expand Down Expand Up @@ -327,6 +361,14 @@ export const ModelMetadataView = ({
deleteStratColRow={deleteStratColRow}
/>
</div>
<div>
<GrossDepositionEnviromentGroup
modelIdParent={modelIdParent}
defaultMetadata={defaultMetadata}
gdeGroups={data.data.geologicalGroups}
deleteGdeRow={deleteGdeRow}
/>
</div>
</Styled.Metadata>

<Dialog open={showStratColDialog}>
Expand Down
Loading

0 comments on commit 1b386c7

Please sign in to comment.