From 7142844d19768c640236cb6c40bafb9e29da1e2d Mon Sep 17 00:00:00 2001 From: Thomas Lund Fagermyr <35408743+thomaslf97@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:43:01 +0100 Subject: [PATCH] fix: Fixed bugs where global state was not loaded properly (#371) * fix: Fixed bugs where global state was not loaded properly * fix: Refactored ContiniousParameter filter --- .../CaseRow/hooks/useGetParameterList.tsx | 9 ++-- .../HandleModelComponent.tsx | 4 +- .../ModelMetadataView/ModelMetadataView.tsx | 53 ++++++++++++++++++- src/hooks/GlobalState.tsx | 7 +++ src/pages/Browse/Browse.tsx | 11 +++- 5 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/features/Compute/CaseGroup/CaseRow/hooks/useGetParameterList.tsx b/src/features/Compute/CaseGroup/CaseRow/hooks/useGetParameterList.tsx index ec2c3556..5c945990 100644 --- a/src/features/Compute/CaseGroup/CaseRow/hooks/useGetParameterList.tsx +++ b/src/features/Compute/CaseGroup/CaseRow/hooks/useGetParameterList.tsx @@ -41,11 +41,9 @@ export const useGetParameterList = ( case 'ContiniousParameter': if (continiousParameterSettings) - selectedId = - continiousParameterSettings && - continiousParameterSettings[0].inputSettings.filter( - (i) => (i.inputSettingTypeId = setting[0].inputSettingValueId), - )[0].inputSettingTypeId; + selectedId = continiousParameterSettings[0].inputSettings.filter( + (i) => i.name === methodType, + )[0].inputSettingTypeId; return selectedId; } } @@ -64,7 +62,6 @@ export const useGetParameterList = ( settingType, methodType, ); - if (inputSettingTypeId) setting.forEach((m) => { const temp = { diff --git a/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx b/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx index 41190b92..b52f5964 100644 --- a/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx +++ b/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx @@ -67,7 +67,7 @@ export const HandleModelComponent = ({ existingData, modelId, }: AddModelDialogProps) => { - const { setAnalogueModel } = usePepmContextStore(); + const { setAnalogueModelDefault } = usePepmContextStore(); const [isFileDisplay, setFileDisplay] = useState(false); const [files, setFiles] = useState(defaultFiles); const [metadata, setMetadata] = @@ -189,7 +189,7 @@ export const HandleModelComponent = ({ const path = generatePath('../:id/details', { id: modelId, }); - setAnalogueModel(metadata); + setAnalogueModelDefault(); navigate(path); }} > diff --git a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx index e787c875..ad58f286 100644 --- a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx +++ b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx @@ -26,6 +26,14 @@ import { analogueModelDefault, usePepmContextStore, } from '../../../hooks/GlobalState'; +import { useFetchOutcropData } from '../../../hooks/useFetchOutcropData'; +import { + useFetchSmdaCountries, + useFetchSmdaFields, + useFetchSmdaMetadataStratigraphicUnits, + useFetchSmdaStratigraphicColumns, +} from '../../../hooks/useFetchStratColData'; +import { useFetchGrossDepData } from '../../../hooks/useFetchGrossDepData'; export const ModelMetadataView = ({ modelIdParent, @@ -35,7 +43,22 @@ export const ModelMetadataView = ({ uploadingProgress?: number; }) => { const isOwnerOrAdmin = useIsOwnerOrAdmin(); - const { analogueModel, analogueModelImageURL } = usePepmContextStore(); + const { + analogueModel, + analogueModelImageURL, + setOutcrops, + setCountries, + setFields, + setStratigraphicColumns, + setStratigraphicUnits, + setGeologicalStandards, + } = usePepmContextStore(); + const outcropData = useFetchOutcropData(); + const countryData = useFetchSmdaCountries(); + const fieldData = useFetchSmdaFields(); + const stratColumnData = useFetchSmdaStratigraphicColumns(); + const stratUnitData = useFetchSmdaMetadataStratigraphicUnits(); + const geologyStandards = useFetchGrossDepData(); const [isAddModelDialog, setAddModelDialog] = useState(false); @@ -65,6 +88,31 @@ export const ModelMetadataView = ({ [generateThumbnail], ); + useEffect(() => { + if (countryData.data?.data) setCountries(countryData.data.data); + if (fieldData.data?.data) setFields(fieldData.data.data); + if (stratColumnData.data?.data) + setStratigraphicColumns(stratColumnData.data.data); + if (stratUnitData.data?.data) + setStratigraphicUnits(stratUnitData.data.data); + if (outcropData.data?.data) setOutcrops(outcropData.data.data); + if (geologyStandards.data?.data) + setGeologicalStandards(geologyStandards.data.data); + }, [ + geologyStandards.data?.data, + outcropData.data?.data, + countryData.data?.data, + fieldData.data?.data, + setGeologicalStandards, + setCountries, + setOutcrops, + setFields, + setStratigraphicColumns, + setStratigraphicUnits, + stratColumnData.data?.data, + stratUnitData.data?.data, + ]); + useEffect(() => { if ( modelId && @@ -222,7 +270,8 @@ export const ModelMetadataView = ({ } }; - if (analogueModel === analogueModelDefault) return

Loading ...

; + if (analogueModel === analogueModelDefault && uploadingProgress === undefined) + return

Loading ...

; return ( diff --git a/src/hooks/GlobalState.tsx b/src/hooks/GlobalState.tsx index 49bc4e43..dbe33dfc 100644 --- a/src/hooks/GlobalState.tsx +++ b/src/hooks/GlobalState.tsx @@ -110,6 +110,13 @@ export const usePepmContextStore = create()( set((state) => { state.analogueModel = analogueModelDefault; state.analogueModelImageURL = ''; + state.analogueModelImageMetadata = undefined; + state.stratigraphicColumns = []; + state.geologyStandards = []; + state.computeCases = []; + state.computeSettings = []; + state.objectResults = []; + state.variogramResults = []; }), setAnalogueModelImage: (image: string) => set((state) => { diff --git a/src/pages/Browse/Browse.tsx b/src/pages/Browse/Browse.tsx index 8aa8fb94..0a6064ae 100644 --- a/src/pages/Browse/Browse.tsx +++ b/src/pages/Browse/Browse.tsx @@ -1,16 +1,25 @@ /* eslint-disable max-lines */ /* eslint-disable max-lines-per-function */ import { Button, Snackbar, Typography } from '@equinor/eds-core-react'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { ModelTable } from '../../features/ModelTable/ModelTable'; import * as Styled from './Browse.styled'; import { useIsOwnerOrAdmin } from '../../hooks/useIsOwnerOrAdmin'; +import { + analogueModelDefault, + usePepmContextStore, +} from '../../hooks/GlobalState'; export const Browse = () => { + const { analogueModel, setAnalogueModelDefault } = usePepmContextStore(); const isOwnerOrAdmin = useIsOwnerOrAdmin(); const [uploadStatus, setUploadStatus] = useState(); + useEffect(() => { + if (analogueModel !== analogueModelDefault) setAnalogueModelDefault(); + }, [analogueModel, setAnalogueModelDefault]); + function clearStatus() { setUploadStatus(undefined); }