Skip to content

Commit

Permalink
refactor: Improve error messages for model upload and edit. Style pro…
Browse files Browse the repository at this point in the history
…gress component.
  • Loading branch information
mheggelund committed May 2, 2024
1 parent ad6321d commit 5f7b134
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ export const CustomContent = styled.div`
flex-direction: column;
row-gap: ${spacings.X_LARGE};
`;

export const UploadDiv = styled.div`
display: flex;
flex-direction: column;
row-gap: ${spacings.LARGE};
`;

export const ErrorDiv = styled.div`
display: flex;
flex-direction: column;
row-gap: ${spacings.SMALL};
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable max-lines-per-function */
import { Button, LinearProgress, Typography } from '@equinor/eds-core-react';
import _ from 'lodash';
import { useEffect, useState } from 'react';
import { AnalogueModelDetail } from '../../../api/generated';
import { ErrorBanner } from '../../../components/ErrorBanner/ErrorBanner';
import { ModelInputFilesTable } from '../ModelInputFilesTable/ModelInputFilesTable';
import { ModelMetadata } from '../ModelMetadata/ModelMetadata';
import {
Expand Down Expand Up @@ -44,7 +46,6 @@ export const HandleModelComponent = ({
confirm,
edit,
progress,
// cancel,
uploading,
defaultMetadata,
isEdit,
Expand Down Expand Up @@ -117,6 +118,23 @@ export const HandleModelComponent = ({
}
const INIFileContent = () => <p>Not implemented yet...</p>;

const getErroMessageList = () => {
if (_.isEmpty(errors)) return;

const errorList: string[] = [];

Object.keys(errors).forEach(function (key) {
// TODO: Fix the TS error for errors[key]
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const message = errors[key];
errorList.push(message);
});
return errorList;
};

const ErrorList = getErroMessageList();

return (
<Styled.Wrapper>
<Typography variant="h3">
Expand All @@ -141,9 +159,13 @@ export const HandleModelComponent = ({
metadata={metadata}
setMetadata={setMetadata}
/>
{Object.keys(errors).includes('file') && (
<Typography className="error">NC file missing</Typography>
)}
<Styled.ErrorDiv>
{!_.isEmpty(errors) &&
ErrorList !== undefined &&
ErrorList.map((e, i) => {
return <ErrorBanner key={i} text={e} />;
})}
</Styled.ErrorDiv>
</Styled.CustomContent>
<div>
<Button onClick={handleSubmit} disabled={uploading}>
Expand All @@ -153,8 +175,15 @@ export const HandleModelComponent = ({
? 'Wait for model to finish uploading'
: 'Confirm and start uploading'}
</Button>
{uploading && <LinearProgress variant="determinate" value={progress} />}
</div>
{uploading && (
<Styled.UploadDiv>
<Typography variant="h3">
Upload progress: {progress !== undefined && progress.toFixed(0)}%
</Typography>
{<LinearProgress variant="determinate" value={progress} />}
</Styled.UploadDiv>
)}
</Styled.Wrapper>
);
};

0 comments on commit 5f7b134

Please sign in to comment.