diff --git a/src/features/AddModel/ModelMetadata/ModelMetadata.tsx b/src/features/AddModel/ModelMetadata/ModelMetadata.tsx index f44cb619..94462f0a 100644 --- a/src/features/AddModel/ModelMetadata/ModelMetadata.tsx +++ b/src/features/AddModel/ModelMetadata/ModelMetadata.tsx @@ -7,6 +7,8 @@ import { } from '@equinor/eds-core-react'; import MetadataProps, { ErrorType } from '../AddModelDialog/AddModelDialog'; +import { useQuery } from '@tanstack/react-query'; +import { AnalogueList, AnaloguesService } from '../../../api/generated'; import * as Styled from './ModelMetadata.styled'; export const ModelMetadata = ({ @@ -26,6 +28,13 @@ export const ModelMetadata = ({ analogue: ['Analouge1', 'Analouge2'], }; + const { isLoading, data } = useQuery({ + queryKey: ['apiParameters'], + queryFn: () => AnaloguesService.getApiAnalogues(), + }); + + if (isLoading || !data?.success) return

Loading ...

; + const handleInput = (e: AutocompleteChanges, target: string) => { setMetadata({ ...metadata, [target]: e.selectedItems }); }; @@ -76,9 +85,10 @@ export const ModelMetadata = ({ option.name} multiple - onOptionsChange={(e: AutocompleteChanges) => + onOptionsChange={(e: AutocompleteChanges) => setMetadata({ ...metadata, analogue: e.selectedItems }) } > diff --git a/src/features/ModelView/ModelSourceView/ModelSourceView.tsx b/src/features/ModelView/ModelSourceView/ModelSourceView.tsx index 26bc2a2c..7c0c54d3 100644 --- a/src/features/ModelView/ModelSourceView/ModelSourceView.tsx +++ b/src/features/ModelView/ModelSourceView/ModelSourceView.tsx @@ -1,7 +1,7 @@ import { Table, Typography } from '@equinor/eds-core-react'; +import { useQuery } from '@tanstack/react-query'; import { useParams } from 'react-router-dom'; import { AnalogueModelsService, UploadList } from '../../../api/generated'; -import { useQuery } from '@tanstack/react-query'; export const ModelSourceView = () => { const { id } = useParams(); diff --git a/src/pages/Browse/Browse.tsx b/src/pages/Browse/Browse.tsx index fe8dc84e..9001e09f 100644 --- a/src/pages/Browse/Browse.tsx +++ b/src/pages/Browse/Browse.tsx @@ -1,13 +1,16 @@ +/* eslint-disable max-lines-per-function */ import { Button, Snackbar, Typography } from '@equinor/eds-core-react'; -import { useState } from 'react'; -import { Table } from '../../components/Table'; -import * as Styled from './Browse.styled'; import { useMutation } from '@tanstack/react-query'; +import { useState } from 'react'; import { AnalogueModelsService, + ConvertAnalogueModelCommand, CreateAnalogueModelCommand, + JobsService, } from '../../api/generated'; +import { Table } from '../../components/Table'; import { AddModelDialog } from '../../features/AddModel/AddModelDialog/AddModelDialog'; +import * as Styled from './Browse.styled'; enum UploadProcess { STARTED = 'We are uploading your new model. Please keep this browser tab open.', @@ -20,6 +23,12 @@ type MutationContract = { file: Blob; }; +const ModelBody: CreateAnalogueModelCommand = { + name: 'Model test', + description: 'New test of the model', + sourceType: 'ResQML', +}; + export const Browse = () => { const createModel = useMutation({ mutationFn: AnalogueModelsService.postApiAnalogueModels, @@ -34,6 +43,12 @@ export const Browse = () => { }, }); + const convertModelFile = useMutation({ + mutationFn: (modelId: ConvertAnalogueModelCommand) => { + return JobsService.postApiJobsComputeModelConversions(modelId); + }, + }); + const [isAddModelDialog, setAddModelDialog] = useState(false); const [uploadStatus, setUploadStatus] = useState(); @@ -47,26 +62,30 @@ export const Browse = () => { async function uploadModel(file: File) { setUploadStatus(UploadProcess.STARTED); - const modelUpload = await createModel.mutateAsync( - // TODO - { - name: 'testModel', - description: 'description', - sourceType: 'Deltares', - } as CreateAnalogueModelCommand, - ); - - if (createModel?.isSuccess) { + + const modelUpload = await createModel.mutateAsync(ModelBody); + + if (createModel.error === null && modelUpload.success) { toggleDialog(); - const fileUpload = await uploadNCFile.mutateAsync({ + const FileUploadBody: MutationContract = { id: modelUpload.data.analogueModelId ?? '', file: file, - } as MutationContract); + }; + const fileUpload = await uploadNCFile.mutateAsync(FileUploadBody); - if (fileUpload && uploadNCFile.isSuccess) + if (uploadNCFile.error === null && fileUpload.success) { setUploadStatus(UploadProcess.SUCCESS); - else if (!uploadNCFile.isSuccess) { + + const id = modelUpload.data.analogueModelId; + const convert = await convertModelFile.mutateAsync({ + modelId: id, + }); + + // eslint-disable-next-line no-console + console.log(convert); + } else if (uploadNCFile.error) { setUploadStatus(UploadProcess.FAILED); + // TODO: show validation message } } @@ -78,7 +97,7 @@ export const Browse = () => { Browse all models
-
@@ -91,7 +110,7 @@ export const Browse = () => { /> {uploadStatus}