Skip to content

Commit

Permalink
chore: Small pr changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Oct 3, 2024
1 parent 920bb6c commit 19b943e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export const validateValues = (
const errors: ErrorType = {};

if (inputValues?.name === undefined || inputValues?.name === '') {
errors.name = ' ';
errors.name = 'You must name your model';
}

if (
inputValues?.description === undefined ||
inputValues?.description === ''
) {
errors.description = ' ';
errors.description = 'You must add a description';
}

if (files && !isEdit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Typography,
} from '@equinor/eds-core-react';
import { error_outlined } from '@equinor/eds-icons';
import _ from 'lodash';
import { useEffect, useState } from 'react';
import { generatePath, useNavigate } from 'react-router-dom';
import {
Expand Down Expand Up @@ -88,7 +87,7 @@ export const HandleModelComponent = ({
const [fileSize, setFileSize] = useState(0);
const [rawFile, setrawFile] = useState<File>();

const [errors, setErrors] = useState({});
const [errors, setErrors] = useState<ErrorType>({});
const navigate = useNavigate();

useHandleModelComponent(
Expand Down Expand Up @@ -137,23 +136,6 @@ 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>
{progress !== undefined && progress <= 0 && (
Expand All @@ -180,9 +162,7 @@ export const HandleModelComponent = ({
metadata={metadata}
setMetadata={setMetadata}
/>
<Styled.ErrorDiv>
{!_.isEmpty(errors) && ErrorList !== undefined && ErrorList}
</Styled.ErrorDiv>
<Styled.ErrorDiv>{errors.file && errors.file}</Styled.ErrorDiv>
</>
)}
</Styled.CustomContent>
Expand Down
6 changes: 2 additions & 4 deletions src/features/HandleModel/ModelMetadata/ModelMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ModelMetadata = ({
setMetadata({ ...metadata, name: e.currentTarget.value })
}
/>
{errors.name && <Label label="You must name your model"></Label>}
{errors.name && <Label label={errors.name}></Label>}
</Styled.InputfieldRequired>
<Styled.InputfieldRequired>
<Styled.TextInput
Expand All @@ -42,9 +42,7 @@ export const ModelMetadata = ({
rows={4}
rowsMax={8}
/>
{errors.description && (
<Label label="You must add a description"></Label>
)}
{errors.description && <Label label={errors.description}></Label>}
</Styled.InputfieldRequired>
</Styled.Form>
</Styled.ModelMetadata>
Expand Down
28 changes: 15 additions & 13 deletions src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export const defaultStratColumnData: StratColumnType = {

export const ModelMetadataView = ({
modelIdParent,
isAddUploading,
uploadingProgress,
}: {
modelIdParent?: string;
isAddUploading?: boolean;
uploadingProgress?: number;
}) => {
const { isLoading, data } = useFetchModel(
modelIdParent ? modelIdParent : undefined,
Expand Down Expand Up @@ -272,7 +272,7 @@ export const ModelMetadataView = ({

return (
<Styled.Wrapper>
{!isAddUploading && (
{uploadingProgress === undefined && (
<Styled.DescriptionMeta>
<>
{data.data.description && (
Expand All @@ -298,16 +298,18 @@ export const ModelMetadataView = ({
/>
</Styled.DescriptionMeta>
)}
{isAddUploading && (
<Styled.UploadingMeta>
<Typography variant="body_long">
While your model is being uploaded, you can add some metadata like
outcrop analogue, stratigraphic column, or gross depositional
environment. Please note that at least one type of metadata is
required for PEPM models before they can be approved later on.
</Typography>
</Styled.UploadingMeta>
)}
{uploadingProgress !== undefined &&
uploadingProgress >= 0 &&
uploadingProgress < 100 && (
<Styled.UploadingMeta>
<Typography variant="body_long">
While your model is being uploaded, you can add some metadata like
outcrop analogue, stratigraphic column, or gross depositional
environment. Please note that at least one type of metadata is
required for PEPM models before they can be approved later on.
</Typography>
</Styled.UploadingMeta>
)}

<Typography variant="h3" as="h2">
Model metadata
Expand Down
5 changes: 3 additions & 2 deletions src/pages/AddModel/AddModel.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sort-imports */
/* eslint-disable max-lines */
/* eslint-disable max-lines-per-function */
import { Snackbar, Typography } from '@equinor/eds-core-react';
Expand All @@ -12,8 +13,8 @@ import {
AnalogueModelsService,
ConvertAnalogueModelCommand,
CreateAnalogueModelCommand,
JobsService,
JobStatus,
JobsService,
MetadataDto,
UploadFileType,
UploadsService,
Expand Down Expand Up @@ -313,7 +314,7 @@ export const AddModel = () => {
<>
<ModelMetadataView
modelIdParent={modelId}
isAddUploading={progress > 0}
uploadingProgress={progress}
/>
</>
)}
Expand Down

0 comments on commit 19b943e

Please sign in to comment.