-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
78b3403
commit 1b386c7
Showing
9 changed files
with
337 additions
and
6 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
9 changes: 9 additions & 0 deletions
9
...ositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup.styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
`; |
166 changes: 166 additions & 0 deletions
166
...ossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...grapicGroups/StratigrapicGroups.styled.ts → ...grapicGroups/StratigrapicGroups.styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...StratigrapicGroups/StratigrapicGroups.tsx → ...StratigrapicGroups/StratigrapicGroups.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.