From 3246d5b260cbbb1a5a52443c5a1781c145075419 Mon Sep 17 00:00:00 2001 From: Thomas L Fagermyr Date: Tue, 12 Nov 2024 13:26:27 +0100 Subject: [PATCH] fix: Fixed bugs where global state was not loaded properly --- .../HandleModelComponent.tsx | 4 +- .../ModelMetadataView/ModelMetadataView.tsx | 53 ++++++++++++++++++- src/hooks/GlobalState.tsx | 7 +++ src/pages/Browse/Browse.tsx | 11 +++- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx b/src/features/HandleModel/HandleModelComponent/HandleModelComponent.tsx index 41190b9..b52f596 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 e787c87..ad58f28 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 49bc4e4..dbe33df 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 8aa8fb9..0a6064a 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); }