diff --git a/src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx b/src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx index 0b9a2319..8e7fd5bd 100644 --- a/src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx +++ b/src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx @@ -20,22 +20,26 @@ export const CaseButtons = ({ saved, isProcessed, caseStatus, + hasUnsavedCase, saveCase, runCase, deleteCase, setAlertMessage, + duplicateCase, }: { id: string; caseType: string; saved: boolean; isProcessed?: boolean; caseStatus: ComputeJobStatus; + hasUnsavedCase: boolean; runCase?: () => void; saveCase: () => void; deleteCase: ( computeCaseId: string, ) => Promise; setAlertMessage: (message: string) => void; + duplicateCase: () => void; }) => { const [deleteConfirm, setDeleteConfirm] = useState(false); const [saveConfirm, setSaveConfirm] = useState(false); @@ -72,17 +76,36 @@ export const CaseButtons = ({ )} {caseType === 'Variogram' && ( - - - + <> + {id.length < 3 ? ( + + + + ) : ( + <> + {hasUnsavedCase ? ( + + + + ) : ( + + )} + + )} + )} {caseType === 'Object' ? ( diff --git a/src/features/Compute/CaseGroup/CaseGroup.tsx b/src/features/Compute/CaseGroup/CaseGroup.tsx index 72e8e2d2..5b875e25 100644 --- a/src/features/Compute/CaseGroup/CaseGroup.tsx +++ b/src/features/Compute/CaseGroup/CaseGroup.tsx @@ -19,6 +19,7 @@ import { import { queryClient } from '../../../auth/queryClient'; import { CaseCardComponent } from '../../../components/CaseCardComponent/CaseCardComponent'; import { useAccessToken } from '../../../hooks/useAccessToken'; +import { useFetchCases } from '../../../hooks/useFetchCases'; import * as Styled from './CaseGroup.styled'; import { CaseRow } from './CaseRow/CaseRow'; @@ -38,6 +39,7 @@ export const CaseGroup = ({ runCase: (computeCaseId: string) => void; }) => { const [localList, setLocalList] = useState([]); + const { data } = useFetchCases(); const { modelId } = useParams<{ modelId: string }>(); const { instance, accounts } = useMsal(); const token = useAccessToken(instance, accounts[0]); @@ -298,6 +300,32 @@ export const CaseGroup = ({ } }, [addCase, triggerAddCase]); + const duplicateCase = (id: string) => { + const caseToDuplicate = data?.data.filter((c) => c.computeCaseId === id); + const randomLocalId = Math.floor(Math.random() * 100).toString(); + if (caseToDuplicate) { + const newCase: ComputeCaseDto = { + computeCaseId: randomLocalId, + computeMethod: caseToDuplicate[0].computeMethod, + modelArea: caseToDuplicate[0].modelArea, + inputSettings: caseToDuplicate[0].inputSettings, + jobStatus: ComputeJobStatus.NOT_STARTED, + }; + + const localCasesForMethod = filerLocalList( + caseToDuplicate[0].computeMethod.name, + ); + + if ( + localCasesForMethod.length < 1 && + localCasesForMethod[0] === undefined + ) { + setLocalList([...localList, newCase]); + updateLocalCaseList && updateLocalCaseList('Variogram', true); + } + } + }; + return ( <> {methodName === 'Channel' && ( @@ -378,6 +406,7 @@ export const CaseGroup = ({ removeLocalCase={removeLocalCase} settingsFilter={settingsFilter} variogramFilter={variogramFilter} + duplicateCase={duplicateCase} /> ))} diff --git a/src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx b/src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx index 122a7e8f..439f08af 100644 --- a/src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx +++ b/src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx @@ -33,6 +33,7 @@ export const CaseRow = ({ removeLocalCase, settingsFilter, variogramFilter, + duplicateCase, }: { rowCase: ComputeCaseDto; id: string; @@ -60,6 +61,7 @@ export const CaseRow = ({ variogramFilter?: ( name: string, ) => ListComputeSettingsMethodDto[] | undefined; + duplicateCase?: (id: string) => void; }) => { const [selectedModelArea, setModelArea] = useState(); const [selectedIndicatorParameters, setIndicatorParameters] = @@ -378,6 +380,7 @@ export const CaseRow = ({ defaultArea = areaList.filter( (area) => area.modelAreaId === rowCase[0].modelArea.modelAreaId, ); + setModelArea(defaultArea); } return defaultArea; }, @@ -408,6 +411,17 @@ export const CaseRow = ({ allCasesList.forEach((r) => setNotSavedVariogram(r, 'ContiniousParameter')); }, [caseList, allCasesList, saved]); + const hasUnsavedCase = (id: string) => { + const caseMethod = allCasesList.filter((c) => c.computeCaseId === id)[0] + .computeMethod; + const methodList = allCasesList + .filter( + (c) => c.computeMethod.computeMethodId === caseMethod.computeMethodId, + ) + .filter((i) => i.computeCaseId.length < 4); + return methodList.length > 0; + }; + return ( handleSaveCase(id)} runCase={runRowCase} deleteCase={deleteCase} setAlertMessage={setAlertMessage} + duplicateCase={() => { + duplicateCase && duplicateCase(id); + }} />