Skip to content

Commit

Permalink
refactor: Renamed props. Add jobStatus prop. Changed buttons and text…
Browse files Browse the repository at this point in the history
… to reflect caseStatus.
  • Loading branch information
mheggelund committed Jan 3, 2024
1 parent 15d9550 commit 45dcfb7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 36 deletions.
46 changes: 37 additions & 9 deletions src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/* eslint-disable max-lines-per-function */
import { Button, Icon, Tooltip } from '@equinor/eds-core-react';
import {
copy as COPY,
delete_to_trash as DELETE,
play as PLAY,
save as SAVE,
} from '@equinor/eds-icons';
import { ComputeJobStatus } from '../../../../api/generated';
import * as Styled from './CaseButtons.styled';

export const CaseButtons = ({
caseType,
disableRun,
enableRun,
isProcessed,
caseStatus,
saveCase,
runCase,
}: {
caseType: string;
disableRun: boolean;
enableRun: boolean;
isProcessed?: boolean;
caseStatus: ComputeJobStatus;
saveCase: () => void;
runCase?: () => void;
}) => {
Expand Down Expand Up @@ -44,19 +48,43 @@ export const CaseButtons = ({
</Button>
)}

{disableRun ? (
<Tooltip title={!isProcessed ? 'Model not finished processed.' : ''}>
{enableRun ? (
<Tooltip
title={
!isProcessed
? 'Model not finished processed.'
: caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running'
? 'Case are running.'
: ''
}
>
<Button
variant="outlined"
onClick={disableRun ? runCase : saveCase}
disabled={!isProcessed}
onClick={enableRun ? runCase : saveCase}
disabled={
!isProcessed ||
caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running' ||
caseStatus === 'Succeeded'
}
>
<Icon data={PLAY} size={18}></Icon>
Run
{caseStatus !== 'Succeeded' && <Icon data={PLAY} size={18}></Icon>}
{caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running'
? 'Running ... '
: caseStatus === 'Failed'
? 'Run Failed. Re-run Case'
: caseStatus === 'Succeeded'
? 'Success'
: 'Run'}
</Button>
</Tooltip>
) : (
<Button variant="outlined" onClick={disableRun ? runCase : saveCase}>
<Button variant="outlined" onClick={enableRun ? runCase : saveCase}>
<Icon data={SAVE} size={18}></Icon>
Save
</Button>
Expand Down
20 changes: 11 additions & 9 deletions src/features/Compute/CaseGroup/CaseGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { add as ADD, play as PLAY } from '@equinor/eds-icons';
import { useState } from 'react';
import {
ComputeCaseDto,
ComputeJobStatus,
CreateComputeCaseCommandResponse,
CreateComputeCaseInputSettingsForm,
} from '../../../api/generated';
Expand All @@ -12,14 +13,14 @@ import * as Styled from './CaseGroup.styled';
import { CaseRow } from './CaseRow/CaseRow';

export const CaseGroup = ({
caseGroup,
caseList,
methodName,
localCaseList,
saveObjectCase,
saveCaseAlert,
runCase,
}: {
caseGroup: ComputeCaseDto[];
caseList: ComputeCaseDto[];
methodName: string;
localCaseList?: ComputeCaseDto[];
saveObjectCase?: (
Expand Down Expand Up @@ -50,6 +51,7 @@ export const CaseGroup = ({
name: '',
},
inputSettings: [],
jobStatus: ComputeJobStatus.NOT_STARTED,
};

if (localObjectCaseList.length < 1) {
Expand Down Expand Up @@ -104,18 +106,18 @@ export const CaseGroup = ({

<CaseCardComponent
title={methodName}
key={caseGroup.length > 0 ? caseGroup[0].computeCaseId : null}
key={caseList.length > 0 ? caseList[0].computeCaseId : null}
>
<Styled.CaseList>
{methodName === 'Channel' ? (
<>
{caseGroup.concat(localObjectCaseList).map((c, index) => (
{caseList.concat(localObjectCaseList).map((c, index) => (
<CaseRow
rowCase={c}
key={index}
id={c.computeCaseId}
caseList={caseGroup.concat(localObjectCaseList)}
caseGroup={caseGroup}
allCasesList={caseList.concat(localObjectCaseList)}
caseList={caseList}
saveObjectCase={saveObjectCase}
saveCaseAlert={saveCaseAlert}
runCase={runCase}
Expand All @@ -126,15 +128,15 @@ export const CaseGroup = ({
) : (
<>
{localCaseList &&
caseGroup
caseList
.concat(localCaseList)
.map((c, index) => (
<CaseRow
rowCase={c}
key={index}
id={c.computeCaseId}
caseList={caseGroup.concat(localCaseList)}
caseGroup={caseGroup}
allCasesList={caseList.concat(localCaseList)}
caseList={caseList}
saveObjectCase={saveObjectCase}
saveCaseAlert={saveCaseAlert}
runCase={runCase}
Expand Down
27 changes: 14 additions & 13 deletions src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import * as Styled from './CaseRow.Styled';
export const CaseRow = ({
rowCase,
id,
allCasesList,
caseList,
caseGroup,
saveObjectCase,
saveCaseAlert,
runCase,
removeLocalCase,
}: {
rowCase: ComputeCaseDto;
id: string;
allCasesList: ComputeCaseDto[];
caseList: ComputeCaseDto[];
caseGroup: ComputeCaseDto[];
saveObjectCase?: (
modelAreaId: string,
computeMethodId: string,
Expand Down Expand Up @@ -113,14 +113,14 @@ export const CaseRow = ({

const saveCase = async (id: string) => {
// Checks if Case already exists in the db
const caseExists = caseGroup.filter((c) => c.computeCaseId === id);
const caseExists = caseList.filter((c) => c.computeCaseId === id);

if (caseExists.length > 0) {
// Handle updates and PUT request
// Check if model area has changed
// Check if the new settings already exists
} else {
const row = caseList.filter((c) => c.computeCaseId === id);
const row = allCasesList.filter((c) => c.computeCaseId === id);

// Check if the instance is an Object case and right data/methods is provided
// TODO: Seperate into own method, take type as argument. Support all types not just Channel cases
Expand All @@ -135,10 +135,10 @@ export const CaseRow = ({
) {
// filters out cases without defined model area, 'Whole model'
// Checks if given model area already exists
const checkDuplicateType = caseGroup
const checkDuplicateType = caseList
.filter((c) => c.modelArea !== null)
.filter(
(ca) => ca.modelArea.name === selectedModelArea[0].modelAreaType,
(cl) => cl.modelArea.name === selectedModelArea[0].modelAreaType,
);

if (checkDuplicateType.length === 0) {
Expand All @@ -160,7 +160,7 @@ export const CaseRow = ({
} else {
// Case should have no set model area, is a 'whole model' case
// Checks if 'whole model' case already exists
const checkDuplicate = caseGroup.filter((c) => c.modelArea === null);
const checkDuplicate = caseList.filter((c) => c.modelArea === null);

if (checkDuplicate.length <= 0) {
const res = await saveObjectCase(
Expand All @@ -185,7 +185,7 @@ export const CaseRow = ({

const selectedRowArea = useCallback(
(rowId: string) => {
const rowCase = caseList.filter((c) => c.computeCaseId === rowId);
const rowCase = allCasesList.filter((c) => c.computeCaseId === rowId);

// Set default selected area to empty
let defaultArea: ModelAreaDto[] = [
Expand Down Expand Up @@ -217,7 +217,7 @@ export const CaseRow = ({
}
return defaultArea;
},
[areaList, caseList, selectedModelArea],
[areaList, allCasesList, selectedModelArea],
);

const modelAreas = data && data.data.modelAreas;
Expand All @@ -228,10 +228,10 @@ export const CaseRow = ({
setSaved(false);
}
}
caseList
.filter((c) => !caseGroup.includes(c))
allCasesList
.filter((c) => !caseList.includes(c))
.forEach((r) => setNotSaved(r));
}, [caseGroup, caseList, id, saved]);
}, [caseList, allCasesList, id, saved]);

return (
<Styled.Case>
Expand Down Expand Up @@ -303,10 +303,11 @@ export const CaseRow = ({
)}
<CaseButtons
caseType={saveObjectCase ? 'Object' : 'Variogram'}
disableRun={saved}
enableRun={saved}
isProcessed={data?.data.isProcessed}
saveCase={() => saveCase(id)}
runCase={runRowCase}
caseStatus={rowCase.jobStatus}
/>
</Styled.CaseRow>
</Styled.Case>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ModelPages/Compute/ComputeObject/ComputeObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ComputeObject = () => {
requestBody,
);
},
onSuccess: (data) => {
onSuccess: () => {
queryClient.refetchQueries();
},
});
Expand Down Expand Up @@ -113,7 +113,7 @@ export const ComputeObject = () => {
<Styled.Case>
<ComputeHeader caseInfo={ObjectCaseInfo} />
<CaseGroup
caseGroup={channel !== undefined && channel.length > 0 ? channel : []}
caseList={channel !== undefined && channel.length > 0 ? channel : []}
methodName={ObjectCaseInfo.type}
saveObjectCase={saveObjectCase}
saveCaseAlert={saveCaseAlert}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useParams } from 'react-router-dom';
import {
AnalogueModelComputeCasesService,
ComputeCaseDto,
ComputeJobStatus,
} from '../../../../api/generated';
import { CaseGroup } from '../../../../features/Compute/CaseGroup/CaseGroup';
import { ComputeHeader } from '../../../../features/Compute/ComputeHeader/ComputeHeader';
Expand Down Expand Up @@ -97,6 +98,7 @@ export const ComputeVariogram = () => {
name: '',
},
inputSettings: [],
jobStatus: ComputeJobStatus.NOT_STARTED,
};

if (methodName === 'Indicator' && localIndicatorCaseList.length < 1) {
Expand Down Expand Up @@ -167,7 +169,7 @@ export const ComputeVariogram = () => {
</Styled.ButtonDiv>

<CaseGroup
caseGroup={
caseList={
Indicator !== undefined && Indicator.length > 0 ? Indicator : []
}
methodName="Indicator"
Expand All @@ -177,7 +179,7 @@ export const ComputeVariogram = () => {
saveCaseAlert={saveCaseAlert}
/>
<CaseGroup
caseGroup={
caseList={
NetToGross !== undefined && NetToGross.length > 0 ? NetToGross : []
}
methodName="Net-to-gross"
Expand All @@ -188,7 +190,7 @@ export const ComputeVariogram = () => {
/>

<CaseGroup
caseGroup={
caseList={
ContiniousParameter !== undefined && ContiniousParameter.length > 0
? ContiniousParameter
: []
Expand Down

0 comments on commit 45dcfb7

Please sign in to comment.