Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Global state continued #359

Merged
merged 9 commits into from
Nov 5, 2024
19 changes: 10 additions & 9 deletions src/components/AreaCoordinates/AreaCoordinates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ModelAreaTypeDto,
} from '../../api/generated';
import { useFetchCases } from '../../hooks/useFetchCases';
import { useFetchModel } from '../../hooks/useFetchModel';
import { useFetchModelAreas } from '../../hooks/useFetchModelAreas';
import { useMutateAreaCoordinates } from '../../hooks/useMutateAreaCoordinates';
import { ErrorMessage } from '../ErrorMessage/ErrorMessage';
Expand All @@ -29,6 +28,7 @@ import {
validateCoordinates,
} from './hooks/AreaCoordinates.hooks';
import { useModelResults } from './hooks/useModelResults';
import { usePepmContextStore } from '../../hooks/GlobalState';

export type AreaCoordinateType = {
modelAreaId: string;
Expand Down Expand Up @@ -84,7 +84,7 @@ export const AreaCoordinates = ({
const [fallbackAreaCoordinate, setfallbackAreaCoordinate] =
useState<AreaCoordinateType>();
const { modelId } = useParams();
const { data, isLoading } = useFetchModel(modelId);
const { analogueModel } = usePepmContextStore();
const cases = useFetchCases();
const { activeAreaResultList } = useModelResults(
activeArea.name,
Expand All @@ -108,7 +108,8 @@ export const AreaCoordinates = ({
return;
}

const selectableAreas = data?.data?.modelAreas && data?.data?.modelAreas;
const selectableAreas =
analogueModel.modelAreas && analogueModel.modelAreas;

const selectedArea = selectableAreas?.filter(
(area) => area.modelAreaType === changes.selectedItems[0].name,
Expand Down Expand Up @@ -267,7 +268,7 @@ export const AreaCoordinates = ({
setEdit(!edit);
};

if (modelAreas.isLoading || modelAreas.data === undefined || isLoading)
if (modelAreas.isLoading || modelAreas.data === undefined || !analogueModel)
return <p>Loading.....</p>;

return (
Expand Down Expand Up @@ -365,18 +366,18 @@ export const AreaCoordinates = ({
</Styled.CoordinateFields>
)}
</Styled.Selects>
{data && data.data.analogueModelImage === null && (
{analogueModel && analogueModel.analogueModelImage === null && (
<div>
<Typography>
No image is found for this model. Try refreshing the page
</Typography>
</div>
)}
{data?.data.analogueModelId &&
data.data.analogueModelImage?.analogueModelImageId && (
{analogueModel.analogueModelId &&
analogueModel.analogueModelImage?.analogueModelImageId && (
<AnalogueModelImageView
modelId={data?.data.analogueModelId}
imageId={data?.data.analogueModelImage?.analogueModelImageId}
modelId={analogueModel.analogueModelId}
imageId={analogueModel.analogueModelImage?.analogueModelImageId}
coordinateBox={areaCoordinate}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import { Button, Dialog, Snackbar } from '@equinor/eds-core-react';
import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { CoordinateDto } from '../../../api/generated';
import { useFetchModel } from '../../../hooks/useFetchModel';
import { useFetchModelAreas } from '../../../hooks/useFetchModelAreas';
import { AreaCoordinates } from '../AreaCoordinates';
import * as Styled from '../AreaCoordinates.styled';
import { usePepmContextStore } from '../../../hooks/GlobalState';

export type AreaCoordinateType = {
modelAreaId: string;
Expand All @@ -23,16 +22,9 @@ export const CoordinatesDialog = ({
toggleOpen: () => void;
}) => {
const [showSaveAlert, setSaveAlert] = useState(false);

const { modelId } = useParams();

const { data, isLoading } = useFetchModel(modelId);
const { analogueModel } = usePepmContextStore();
const modelAreas = useFetchModelAreas();

// const [activeModelArea, setActiveModelArea] = useState(null);

// const {data, isLoading} = useFetch

function clearStatus() {
setSaveAlert(false);
}
Expand All @@ -41,14 +33,16 @@ export const CoordinatesDialog = ({
toggleOpen();
};

if (modelAreas.isLoading || modelAreas.data === undefined || isLoading)
if (modelAreas.isLoading || modelAreas.data === undefined || !analogueModel)
return <p>Loading.....</p>;

return (
<>
<Styled.Dialog open={open}>
<Dialog.Header>
<Dialog.Title>Manage model areas for {data?.data.name}</Dialog.Title>
<Dialog.Title>
Manage model areas for {analogueModel.name}
</Dialog.Title>
</Dialog.Header>
<Styled.Content>
<AreaCoordinates setSaveAlert={setSaveAlert}></AreaCoordinates>
Expand Down
14 changes: 8 additions & 6 deletions src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
import { ConfirmDialog } from '../../../../components/ConfirmDialog/ConfirmDialog';
import * as Styled from './CaseButtons.styled';
import { useIsOwnerOrAdmin } from '../../../../hooks/useIsOwnerOrAdmin';
import { usePepmContextStore } from '../../../../hooks/GlobalState';

export const CaseButtons = ({
id,
caseType,
saved,
isProcessed,
caseStatus,
hasUnsavedCase,
saveCase,
Expand All @@ -32,7 +32,6 @@ export const CaseButtons = ({
id: string;
caseType: string;
saved: boolean;
isProcessed?: boolean;
caseStatus: ComputeJobStatus;
hasUnsavedCase: boolean;
runCase?: () => void;
Expand All @@ -43,6 +42,7 @@ export const CaseButtons = ({
setAlertMessage: (message: string) => void;
duplicateCase: () => void;
}) => {
const { analogueModel } = usePepmContextStore();
const isOwnerOrAdmin = useIsOwnerOrAdmin();
const [deleteConfirm, setDeleteConfirm] = useState(false);
const [saveConfirm, setSaveConfirm] = useState(false);
Expand Down Expand Up @@ -137,7 +137,7 @@ export const CaseButtons = ({
) : saved ? (
<Tooltip
title={
!isProcessed
!analogueModel.isProcessed
? 'Model not finished processed.'
: caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
Expand All @@ -157,7 +157,9 @@ export const CaseButtons = ({
variant="outlined"
onClick={saved ? runCase : saveCase}
disabled={
!isProcessed || caseStatus === 'Created' || !isOwnerOrAdmin
!analogueModel.isProcessed ||
caseStatus === 'Created' ||
!isOwnerOrAdmin
}
>
<Icon data={PLAY} size={18}></Icon>
Expand All @@ -181,7 +183,7 @@ export const CaseButtons = ({
<>
<Tooltip
title={
!isProcessed
!analogueModel.isProcessed
? 'Model not finished processed.'
: caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
Expand All @@ -205,7 +207,7 @@ export const CaseButtons = ({
variant="outlined"
onClick={runCase}
disabled={
!isProcessed ||
!analogueModel.isProcessed ||
id.length < 3 ||
caseStatus === 'Created' ||
!isOwnerOrAdmin
Expand Down
15 changes: 5 additions & 10 deletions src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useSetSaved } from './hooks/useSetSaved';
import { useMutation } from '@tanstack/react-query';
import { queryClient } from '../../../../auth/queryClient';
import { useParams } from 'react-router-dom';
import { usePepmContextStore } from '../../../../hooks/GlobalState';

export const CaseRow = ({
rowCase,
Expand Down Expand Up @@ -67,6 +68,7 @@ export const CaseRow = ({
}) => {
const [caseError, setCaseError] = useState<string>('');
const { modelId } = useParams<{ modelId: string }>();
const { analogueModel } = usePepmContextStore();

const indicatorSettings = settingsFilter('Indicator');
const netToGrossSettings = settingsFilter('Net-To-Gross');
Expand Down Expand Up @@ -95,14 +97,8 @@ export const CaseRow = ({
continiousParameterSettings,
);

const {
isLoading,
isProcessed,
areaList,
selectedModelArea,
setModelArea,
selectedRowArea,
} = useModelArea(allCasesList);
const { areaList, selectedModelArea, setModelArea, selectedRowArea } =
useModelArea(allCasesList);

const { inputSettingsList } = useGetParameterList(
settingType,
Expand Down Expand Up @@ -278,7 +274,7 @@ export const CaseRow = ({
'Archel',
);

if (isLoading) return <p>Loading ...</p>;
if (!analogueModel) return <p>Loading ...</p>;

return (
<Styled.Case className={id.length <= 3 ? 'local-case' : ''}>
Expand Down Expand Up @@ -380,7 +376,6 @@ export const CaseRow = ({
id={id}
caseType={caseType === 'Object' ? 'Object' : 'Variogram'}
saved={saved}
isProcessed={isProcessed}
caseStatus={rowCase.jobStatus}
hasUnsavedCase={hasUnsavedCase(id)}
saveCase={() => handleSaveCase(id)}
Expand Down
11 changes: 4 additions & 7 deletions src/features/Compute/CaseGroup/CaseRow/hooks/useModelArea.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-disable max-lines-per-function */
import { useCallback, useState } from 'react';
import { ComputeCaseDto, ModelAreaDto } from '../../../../../api/generated';
import { useFetchModel } from '../../../../../hooks/useFetchModel';
import { usePepmContextStore } from '../../../../../hooks/GlobalState';

export const useModelArea = (allCasesList: ComputeCaseDto[]) => {
const [selectedModelArea, setModelArea] = useState<ModelAreaDto[]>();
const { data, isLoading } = useFetchModel();
const { analogueModel } = usePepmContextStore();

const isProcessed = data?.data.isProcessed;
const wholeModelObject: ModelAreaDto[] = [
{
modelAreaId: '',
Expand All @@ -16,8 +15,8 @@ export const useModelArea = (allCasesList: ComputeCaseDto[]) => {
},
];
const areaList: ModelAreaDto[] =
data && data.data.modelAreas
? data.data.modelAreas.concat(wholeModelObject)
analogueModel && analogueModel.modelAreas
? analogueModel.modelAreas.concat(wholeModelObject)
: wholeModelObject;

const selectedRowArea = useCallback(
Expand Down Expand Up @@ -70,8 +69,6 @@ export const useModelArea = (allCasesList: ComputeCaseDto[]) => {
);

return {
isLoading,
isProcessed,
areaList,
selectedModelArea,
setModelArea,
Expand Down
3 changes: 3 additions & 0 deletions src/features/HandleModel/SidePane/SidePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { arrow_back as BACK } from '@equinor/eds-icons';
import { useNavigate } from 'react-router-dom';

import * as Styled from './SidePane.styled';
import { usePepmContextStore } from '../../../hooks/GlobalState';

export const SidePane = ({ uploading }: { uploading: boolean }) => {
const { setAnalogueModelEmpty } = usePepmContextStore();
const navigate = useNavigate();

const backItems: SidebarLinkProps = {
Expand All @@ -29,6 +31,7 @@ export const SidePane = ({ uploading }: { uploading: boolean }) => {
label={backItems.label}
icon={backItems.icon}
onClick={() => {
setAnalogueModelEmpty();
navigate('/');
}}
></Styled.Back>
Expand Down
14 changes: 7 additions & 7 deletions src/features/ModelView/ModelFilesView/ModelFilesView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Table, Typography } from '@equinor/eds-core-react';
import { UploadList } from '../../../api/generated';
import { useFetchModel } from '../../../hooks/useFetchModel';
import * as Styled from './ModelFilesView.styled';
import { usePepmContextStore } from '../../../hooks/GlobalState';

export const ModelFilesView = () => {
const { isLoading, data } = useFetchModel();
const { analogueModel } = usePepmContextStore();

if (isLoading || !data?.success) return <p>Loading ...</p>;
if (!analogueModel) return <p>Loading ...</p>;

return (
<Styled.TableWrapper>
Expand All @@ -21,10 +21,10 @@ export const ModelFilesView = () => {
</Table.Row>
</Table.Head>
<Table.Body>
{data.success &&
(data.data.fileUploads?.length === undefined ||
data.data.fileUploads?.length > 0) ? (
data.data.fileUploads?.map((file: UploadList) => (
{analogueModel &&
(analogueModel.fileUploads?.length === undefined ||
analogueModel.fileUploads?.length > 0) ? (
analogueModel.fileUploads?.map((file: UploadList) => (
<Table.Row key={file.uploadId} className="table-row">
<Table.Cell>{file.originalFileName}</Table.Cell>
<Table.Cell>-</Table.Cell>
Expand Down
Loading