Skip to content

Commit

Permalink
fix: Fixed bugs where global state was not loaded properly (#371)
Browse files Browse the repository at this point in the history
* fix: Fixed bugs where global state was not loaded properly

* fix: Refactored ContiniousParameter filter
  • Loading branch information
thomaslf97 authored Nov 12, 2024
1 parent 7358061 commit 7142844
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -64,7 +62,6 @@ export const useGetParameterList = (
settingType,
methodType,
);

if (inputSettingTypeId)
setting.forEach((m) => {
const temp = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const HandleModelComponent = ({
existingData,
modelId,
}: AddModelDialogProps) => {
const { setAnalogueModel } = usePepmContextStore();
const { setAnalogueModelDefault } = usePepmContextStore();
const [isFileDisplay, setFileDisplay] = useState<boolean>(false);
const [files, setFiles] = useState<FilesProps>(defaultFiles);
const [metadata, setMetadata] =
Expand Down Expand Up @@ -189,7 +189,7 @@ export const HandleModelComponent = ({
const path = generatePath('../:id/details', {
id: modelId,
});
setAnalogueModel(metadata);
setAnalogueModelDefault();
navigate(path);
}}
>
Expand Down
53 changes: 51 additions & 2 deletions src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<boolean>(false);

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -222,7 +270,8 @@ export const ModelMetadataView = ({
}
};

if (analogueModel === analogueModelDefault) return <p>Loading ...</p>;
if (analogueModel === analogueModelDefault && uploadingProgress === undefined)
return <p>Loading ...</p>;

return (
<Styled.Wrapper className="metadata-row">
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ export const usePepmContextStore = create<IPepmContext & IPepmContextActions>()(
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) => {
Expand Down
11 changes: 10 additions & 1 deletion src/pages/Browse/Browse.tsx
Original file line number Diff line number Diff line change
@@ -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<string>();

useEffect(() => {
if (analogueModel !== analogueModelDefault) setAnalogueModelDefault();
}, [analogueModel, setAnalogueModelDefault]);

function clearStatus() {
setUploadStatus(undefined);
}
Expand Down

0 comments on commit 7142844

Please sign in to comment.