diff --git a/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx b/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx index b99b7fab..2a95d50e 100644 --- a/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx +++ b/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx @@ -4,14 +4,21 @@ import { GeologicalStandardDto } from '../../../api/generated'; import { useFetchGrossDepData } from '../../../hooks/useFetchGrossDepData'; import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled'; import { sortList } from '../../../utils/SortList'; -import { GdeType } from '../GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup'; +import { + GDEErrorType, + GdeType, +} from '../GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup'; export const GdeSelect = ({ gdeObject, setGdeObject, + error, + setErrors, }: { gdeObject: GdeType; setGdeObject: React.Dispatch>; + error: GDEErrorType; + setErrors: React.Dispatch>; }) => { const GdeData = useFetchGrossDepData(); @@ -50,8 +57,11 @@ export const GdeSelect = ({ ...gdeObject, grossDepEnv: e.selectedItems[0], }); + setErrors({}); }} noOptionsText="No options" + variant={error.GDE ? 'error' : undefined} + helperText={error.GDE ? error.GDE : undefined} /> ); diff --git a/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GDE.hooks.ts b/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GDE.hooks.ts new file mode 100644 index 00000000..a891c6f2 --- /dev/null +++ b/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GDE.hooks.ts @@ -0,0 +1,21 @@ +import { GDEErrorType, GdeType } from './GrossDepositionEnviromentGroup'; + +export const validateInput = async (gdeObject: GdeType) => { + const errorObject: GDEErrorType = {}; + const message = 'Value missing'; + + if (gdeObject.grossDepEnv === undefined) { + errorObject.GDE = message; + } + if (gdeObject.depEnv === undefined) { + errorObject.DEnv = message; + } + if (gdeObject.subenv === undefined) { + errorObject.subEnv = message; + } + if (gdeObject.architecturalElements?.length === 0) { + errorObject.AEl = message; + } + + return errorObject; +}; diff --git a/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup.tsx b/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup.tsx index 48447eb7..59c606e6 100644 --- a/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup.tsx +++ b/src/components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup.tsx @@ -22,6 +22,8 @@ import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled' import { GdeSelect } from '../GdeSelect/GdeSelect'; import * as Styled from './GrossDepositionEnviromentGroup.styled'; +import { validateInput } from './GDE.hooks'; + export interface GdeType { grossDepEnv?: GeologicalStandardDto; depEnv?: GeologicalStandardDto; @@ -34,6 +36,13 @@ const defaultGdeData: GdeType = { subenv: undefined, architecturalElements: [], }; + +export type GDEErrorType = { + GDE?: string; + DEnv?: string; + subEnv?: string; + AEl?: string; +}; export const GrossDepositionEnviromentGroup = ({ modelIdParent, defaultMetadata, @@ -49,6 +58,8 @@ export const GrossDepositionEnviromentGroup = ({ }) => { const [showGdeDialog, setShowGdeDialog] = useState(false); const [gdeObject, setGdeObject] = useState(defaultGdeData); + const [errors, setErrors] = useState({}); + const handleGdeDialog = () => { setShowGdeDialog(!showGdeDialog); }; @@ -73,13 +84,16 @@ export const GrossDepositionEnviromentGroup = ({ const handleAddGde = async () => { const id = modelIdParent ? modelIdParent : defaultMetadata.analogueModelId; + const err = await validateInput(gdeObject); + setErrors(err); if ( id && gdeObject.grossDepEnv && gdeObject.depEnv && gdeObject.subenv && - gdeObject.architecturalElements + gdeObject.architecturalElements && + gdeObject.architecturalElements.length > 0 ) { const architecturalElementsList: string[] = []; gdeObject.architecturalElements.map((x) => @@ -162,7 +176,12 @@ export const GrossDepositionEnviromentGroup = ({ Add Gross Deposition Enviroment - + diff --git a/src/components/OutcropAnalogue/OutcropAnalogueGroup/OutcropAnalogueGroup.tsx b/src/components/OutcropAnalogue/OutcropAnalogueGroup/OutcropAnalogueGroup.tsx index 5e37b0f5..1934408e 100644 --- a/src/components/OutcropAnalogue/OutcropAnalogueGroup/OutcropAnalogueGroup.tsx +++ b/src/components/OutcropAnalogue/OutcropAnalogueGroup/OutcropAnalogueGroup.tsx @@ -34,6 +34,10 @@ const defaultOutcropData: OutcropType = { basins: [], }; +export type OutcropErrorType = { + Analogue?: string; +}; + export const OutcropAnalogueGroup = ({ modelIdParent, defaultMetadata, @@ -44,8 +48,10 @@ export const OutcropAnalogueGroup = ({ outcropGroup: OutcropDto[]; }) => { const [showOutcropDialog, setShowOutcropDialog] = useState(false); + const [errors, setErrors] = useState({}); const [outcropObject, setOutcropObject] = useState(defaultOutcropData); + const useOutcrop = useOutcropAnalouge(); const handleOutcropDialog = () => { @@ -53,8 +59,20 @@ export const OutcropAnalogueGroup = ({ setOutcropObject(defaultOutcropData); }; + const validateInput = async (outcropObject: OutcropType) => { + const errorObject: OutcropErrorType = {}; + + if (outcropObject.outcropId === undefined) { + errorObject.Analogue = 'Value missing'; + } + + return errorObject; + }; + const handleAddOutcropAnalogue = async () => { const id = modelIdParent ? modelIdParent : defaultMetadata.analogueModelId; + const err = await validateInput(outcropObject); + setErrors(err); if (id && outcropObject.outcropId) { const postRequestBody: AddAnalogueModelOutcropForm = { @@ -139,6 +157,7 @@ export const OutcropAnalogueGroup = ({ outcropObject={outcropObject} outcropGroup={outcropGroup} setOutcropObject={setOutcropObject} + error={errors} /> diff --git a/src/components/OutcropAnalogue/OutcropSelect/OutcropSelect.tsx b/src/components/OutcropAnalogue/OutcropSelect/OutcropSelect.tsx index adb1defd..5161e336 100644 --- a/src/components/OutcropAnalogue/OutcropSelect/OutcropSelect.tsx +++ b/src/components/OutcropAnalogue/OutcropSelect/OutcropSelect.tsx @@ -4,15 +4,20 @@ import { OutcropDto } from '../../../api/generated'; import { useFetchOutcropData } from '../../../hooks/useFetchOutcropData'; import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled'; import { sortList } from '../../../utils/SortList'; -import { OutcropType } from '../OutcropAnalogueGroup/OutcropAnalogueGroup'; +import { + OutcropErrorType, + OutcropType, +} from '../OutcropAnalogueGroup/OutcropAnalogueGroup'; export const OutcropSelect = ({ outcropObject, outcropGroup, + error, setOutcropObject, }: { outcropObject: OutcropType; outcropGroup: OutcropDto[]; + error: OutcropErrorType; setOutcropObject: React.Dispatch>; }) => { const OutcropData = useFetchOutcropData(); @@ -55,6 +60,8 @@ export const OutcropSelect = ({ }} optionDisabled={filterDisabled} noOptionsText="No options" + variant={error.Analogue ? 'error' : undefined} + helperText={error.Analogue ? error.Analogue : undefined} /> >; + error: StratColumnErrorType; + setErrors: React.Dispatch>; }) => { const countryData = useFetchSmdaCountries(); const fieldData = useFetchSmdaFields(); @@ -74,8 +81,11 @@ export const StratigraphicColumnSelect = ({ level2: undefined, level3: undefined, }); + setErrors({}); }} noOptionsText="No options" + variant={error.country ? 'error' : undefined} + helperText={error.country ? error.country : undefined} /> option.identifier} - onOptionsChange={(e: AutocompleteChanges) => + onOptionsChange={(e: AutocompleteChanges) => { setStratColumnObject({ ...stratColumnObject, level1: e.selectedItems[0], level2: undefined, level3: undefined, - }) - } + }); + setErrors({}); + }} selectedOptions={ stratColumnObject.level1 ? [stratColumnObject.level1] : [] } noOptionsText="No options" + variant={ + error.level1 && stratColumnObject.stratColumn !== undefined + ? 'error' + : undefined + } + helperText={ + error.level1 && stratColumnObject.stratColumn !== undefined + ? error.level1 + : undefined + } /> option.identifier} - onOptionsChange={(e: AutocompleteChanges) => + onOptionsChange={(e: AutocompleteChanges) => { setStratColumnObject({ ...stratColumnObject, level2: e.selectedItems[0], level3: undefined, - }) - } + }); + setErrors({}); + }} selectedOptions={ stratColumnObject.level2 ? [stratColumnObject.level2] : [] } noOptionsText="No options" + variant={ + error.level2 && stratColumnObject.level1 !== undefined + ? 'error' + : undefined + } + helperText={ + error.level2 && stratColumnObject.level1 !== undefined + ? error.level2 + : undefined + } /> { + const errorObject: StratColumnErrorType = {}; + const message = 'Value missing'; + + if (stratColObject.country === undefined) { + errorObject.country = message; + } + if (stratColObject.field === undefined) { + errorObject.field = message; + } + if (stratColObject.stratColumn === undefined) { + errorObject.stratColumn = message; + } + if (stratColObject.level1 === undefined) { + errorObject.level1 = message; + } + if (stratColObject.level2 === undefined) { + errorObject.level2 = message; + } + if (stratColObject.level3 === undefined) { + errorObject.level3 = message; + } + + return errorObject; +}; diff --git a/src/components/StrategraphicColumn/StratigrapicGroups/StratigrapicGroups.tsx b/src/components/StrategraphicColumn/StratigrapicGroups/StratigrapicGroups.tsx index 986e5772..6f6ed301 100644 --- a/src/components/StrategraphicColumn/StratigrapicGroups/StratigrapicGroups.tsx +++ b/src/components/StrategraphicColumn/StratigrapicGroups/StratigrapicGroups.tsx @@ -1,23 +1,77 @@ /* eslint-disable max-lines-per-function */ -import { Button, Icon, Table, Typography } from '@equinor/eds-core-react'; +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 { + AddStatigraphicGroupForm, + AnalogueModelDetail, + AnalogueModelsService, + CountryDto, DeleteStratigraphicGroupCommandResponse, + FieldDto, + StratColumnDto, + StratUnitDto, + // eslint-disable-next-line sort-imports StratigraphicGroupDto, } from '../../../api/generated'; +import { queryClient } from '../../../auth/queryClient'; +import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled'; +import { StratigraphicColumnSelect } from '../StratigraphicColumnSelect/StratigraphicColumnSelect'; +import { validateInput } from './StratigrapicGroups.hooks'; import * as Styled from './StratigrapicGroups.styled'; +export interface StratColumnType { + country?: CountryDto; + field?: FieldDto; + stratColumn?: StratColumnDto; + level1?: StratUnitDto; + level2?: StratUnitDto; + level3?: StratUnitDto; +} +export const defaultStratColumnData: StratColumnType = { + country: undefined, + field: undefined, + stratColumn: undefined, + level1: undefined, + level2: undefined, + level3: undefined, +}; + +export type StratColumnErrorType = { + country?: string; + field?: string; + stratColumn?: string; + level1?: string; + level2?: string; + level3?: string; +}; + export const StratigrapicGroups = ({ + modelIdParent, + defaultMetadata, stratColumnGroups, - handleStratColDialog, deleteStratColRow, }: { + modelIdParent?: string; + defaultMetadata: AnalogueModelDetail; stratColumnGroups: StratigraphicGroupDto[]; - handleStratColDialog: () => void; deleteStratColRow: ( stratigraphicGroupId: string, ) => Promise; }) => { + const [stratColumnObject, setStratColumnObject] = useState( + defaultStratColumnData, + ); + const [showStratColDialog, setShowStratColDialog] = useState(false); + const [errors, setErrors] = useState({}); + const filterUnitLevel = (row: StratigraphicGroupDto, level: number) => { return row.stratUnits.filter((unit) => unit.level === level); }; @@ -26,6 +80,71 @@ export const StratigrapicGroups = ({ await deleteStratColRow(id); }; + const postSmdaMetadataRow = useMutation({ + mutationFn: ({ + id, + requestBody, + }: { + id: string; + requestBody: AddStatigraphicGroupForm; + }) => { + return AnalogueModelsService.postApiAnalogueModelsStratigraphicGroups( + id, + requestBody, + ); + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['analogue-model'] }); + }, + }); + + const handleAddStratCol = async () => { + const id = modelIdParent ? modelIdParent : defaultMetadata.analogueModelId; + const err = await validateInput(stratColumnObject); + setErrors(err); + if ( + id && + stratColumnObject.country && + stratColumnObject.field && + stratColumnObject.stratColumn && + stratColumnObject.level1 && + stratColumnObject.level2 + ) { + const stratUnitList: string[] = []; + if (stratColumnObject.level1 !== undefined) + stratUnitList.push(stratColumnObject.level1.stratUnitId); + if ( + stratColumnObject.level1 !== undefined && + stratColumnObject.level2 !== undefined + ) + stratUnitList.push(stratColumnObject.level2.stratUnitId); + if ( + stratColumnObject.level1 !== undefined && + stratColumnObject.level2 !== undefined && + stratColumnObject.level3 !== undefined + ) + stratUnitList.push(stratColumnObject.level3.stratUnitId); + + const postRequestBody: AddStatigraphicGroupForm = { + countryId: stratColumnObject.country.countryId, + fieldId: stratColumnObject.field.fieldId, + stratigraphicColumnId: stratColumnObject.stratColumn.stratColumnId, + stratigraphicUnitIds: stratUnitList.length > 0 ? stratUnitList : [], + }; + + const rowUpload = await postSmdaMetadataRow.mutateAsync({ + id: id, + requestBody: postRequestBody, + }); + if (rowUpload.success) handleStratColDialog(); + } + }; + + const handleStratColDialog = () => { + setShowStratColDialog(!showStratColDialog); + setStratColumnObject(defaultStratColumnData); + }; + return ( @@ -106,6 +225,23 @@ export const StratigrapicGroups = ({ Add stratigraphic column… + + Add stratigraphic column + + + + + + + + ); }; diff --git a/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx b/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx index c69f5f1f..b5d25f43 100644 --- a/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx +++ b/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx @@ -10,13 +10,7 @@ import { import { error_outlined } from '@equinor/eds-icons'; import { useEffect, useState } from 'react'; import { generatePath, useNavigate } from 'react-router-dom'; -import { - AnalogueModelDetail, - CountryDto, - FieldDto, - StratColumnDto, - StratUnitDto, -} from '../../../api/generated'; +import { AnalogueModelDetail } from '../../../api/generated'; import { ModelInputFilesTable } from '../ModelInputFilesTable/ModelInputFilesTable'; import { ModelMetadata } from '../ModelMetadata/ModelMetadata'; import { @@ -61,14 +55,6 @@ const defaultFiles = { NC: undefined, INI: undefined, }; -export interface StratColumnType { - country?: CountryDto; - field?: FieldDto; - stratColumn?: StratColumnDto; - level1?: StratUnitDto; - level2?: StratUnitDto; - level3?: StratUnitDto; -} export const HandleModelComponent = ({ confirm, diff --git a/src/features/ModelTable/ModelTable.tsx b/src/features/ModelTable/ModelTable.tsx index 4cba947f..057f37c7 100644 --- a/src/features/ModelTable/ModelTable.tsx +++ b/src/features/ModelTable/ModelTable.tsx @@ -116,7 +116,9 @@ export const ModelTable = () => { cell: ({ row }) => ( {row.original.stratigraphicGroups.map((i) => ( -

{i.country.identifier},

+

+ {i.country.identifier},{' '} +

))}
), @@ -129,7 +131,9 @@ export const ModelTable = () => { cell: ({ row }) => ( {row.original.stratigraphicGroups.map((i) => ( -

{i.field.identifier},

+

+ {i.field.identifier},{' '} +

))}
), @@ -142,7 +146,7 @@ export const ModelTable = () => { cell: ({ row }) => ( {row.original.stratigraphicGroups.map((i) => ( -

+

{i.stratColumn.identifier},{' '}

))} @@ -157,7 +161,7 @@ export const ModelTable = () => { cell: ({ row }) => ( {getRowGroup(row.original.stratigraphicGroups).map((i) => ( -

{i.identifier},

+

{i.identifier},

))}
), diff --git a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx index 494ac4c7..bc292f2b 100644 --- a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx +++ b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx @@ -1,13 +1,12 @@ /* eslint-disable max-lines */ /* eslint-disable max-lines-per-function */ -import { Button, Dialog, Typography } from '@equinor/eds-core-react'; +import { Button, Typography } from '@equinor/eds-core-react'; import { useMutation } from '@tanstack/react-query'; import { useState } from 'react'; import { useParams } from 'react-router-dom'; import { AddAnalogueModelMetadataCommandForm, AddMetadataDto, - AddStatigraphicGroupForm, AnalogueModelDetail, AnalogueModelMetadataService, AnalogueModelSourceType, @@ -19,21 +18,10 @@ import { AnalogueModelsService } from '../../../api/generated/services/AnalogueM import { queryClient } from '../../../auth/queryClient'; import { GrossDepositionEnviromentGroup } from '../../../components/GrossDepositionEnviroment/GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup'; import { OutcropAnalogueGroup } from '../../../components/OutcropAnalogue/OutcropAnalogueGroup/OutcropAnalogueGroup'; -import { StratigraphicColumnSelect } from '../../../components/StrategraphicColumn/StratigraphicColumnSelect/StratigraphicColumnSelect'; import { StratigrapicGroups } from '../../../components/StrategraphicColumn/StratigrapicGroups/StratigrapicGroups'; import { useFetchModel } from '../../../hooks/useFetchModel'; -import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled'; -import { StratColumnType } from '../../HandleModel/HandleModelComponent/HandleModelComponent'; import { EditNameDescription } from '../EditNameDescription/EditNameDescription'; import * as Styled from './ModelMetadataView.styled'; -export const defaultStratColumnData: StratColumnType = { - country: undefined, - field: undefined, - stratColumn: undefined, - level1: undefined, - level2: undefined, - level3: undefined, -}; export const ModelMetadataView = ({ modelIdParent, @@ -46,10 +34,7 @@ export const ModelMetadataView = ({ modelIdParent ? modelIdParent : undefined, ); const [isAddModelDialog, setAddModelDialog] = useState(false); - const [stratColumnObject, setStratColumnObject] = useState( - defaultStratColumnData, - ); - const [showStratColDialog, setShowStratColDialog] = useState(false); + const { modelId } = useParams(); const defaultMetadata: AnalogueModelDetail = { analogueModelId: data?.data.analogueModelId @@ -68,7 +53,6 @@ export const ModelMetadataView = ({ geologicalGroups: [], processingStatus: JobStatus.UNKNOWN, }; - const { modelId } = useParams(); function toggleEditMetadata() { setAddModelDialog(!isAddModelDialog); @@ -139,29 +123,6 @@ export const ModelMetadataView = ({ toggleEditMetadata(); }; - const handleStratColDialog = () => { - setShowStratColDialog(!showStratColDialog); - setStratColumnObject(defaultStratColumnData); - }; - - const postSmdaMetadataRow = useMutation({ - mutationFn: ({ - id, - requestBody, - }: { - id: string; - requestBody: AddStatigraphicGroupForm; - }) => { - return AnalogueModelsService.postApiAnalogueModelsStratigraphicGroups( - id, - requestBody, - ); - }, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ['analogue-model'] }); - }, - }); - const deleteStratColCase = useMutation({ mutationFn: ({ analogueModelId, @@ -232,44 +193,6 @@ export const ModelMetadataView = ({ if (isLoading || !data?.success) return

Loading ...

; - const handleAddStratCol = async () => { - const id = modelIdParent ? modelIdParent : defaultMetadata.analogueModelId; - if ( - id && - stratColumnObject.country && - stratColumnObject.field && - stratColumnObject.stratColumn - ) { - const stratUnitList: string[] = []; - if (stratColumnObject.level1 !== undefined) - stratUnitList.push(stratColumnObject.level1.stratUnitId); - if ( - stratColumnObject.level1 !== undefined && - stratColumnObject.level2 !== undefined - ) - stratUnitList.push(stratColumnObject.level2.stratUnitId); - if ( - stratColumnObject.level1 !== undefined && - stratColumnObject.level2 !== undefined && - stratColumnObject.level3 !== undefined - ) - stratUnitList.push(stratColumnObject.level3.stratUnitId); - - const postRequestBody: AddStatigraphicGroupForm = { - countryId: stratColumnObject.country.countryId, - fieldId: stratColumnObject.field.fieldId, - stratigraphicColumnId: stratColumnObject.stratColumn.stratColumnId, - stratigraphicUnitIds: stratUnitList.length > 0 ? stratUnitList : [], - }; - - const rowUpload = await postSmdaMetadataRow.mutateAsync({ - id: id, - requestBody: postRequestBody, - }); - if (rowUpload.success) handleStratColDialog(); - } - }; - return ( {uploadingProgress === undefined && ( @@ -324,8 +247,9 @@ export const ModelMetadataView = ({
@@ -337,22 +261,6 @@ export const ModelMetadataView = ({ deleteGdeRow={deleteGdeRow} /> - - - Add stratigraphic column - - - - - - - -
); };