From 0ce0caef62dd2922b2831dd35243f287237e67a0 Mon Sep 17 00:00:00 2001 From: mheggelund Date: Wed, 28 Feb 2024 10:48:11 +0100 Subject: [PATCH] refactor: Cleanup and small fixes. --- .../AddModelDialog/AddModelDialog.hooks.ts | 14 ------- .../MetadataSelect/MetadataSelect.tsx | 7 ++-- src/features/ModelTable/ModelTable.tsx | 42 ++++++++++++------- .../ModelView/TableDataCell/TableDataCell.tsx | 2 +- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/features/AddModel/AddModelDialog/AddModelDialog.hooks.ts b/src/features/AddModel/AddModelDialog/AddModelDialog.hooks.ts index 3e9b00a0..76cfe15e 100644 --- a/src/features/AddModel/AddModelDialog/AddModelDialog.hooks.ts +++ b/src/features/AddModel/AddModelDialog/AddModelDialog.hooks.ts @@ -40,13 +40,6 @@ export const validateValues = ( errors.description = 'Description not provided'; } - if ( - inputValues?.metadata === undefined || - inputValues?.metadata?.filter((m) => m.metadataType === 'Field').length <= 0 - ) { - errors.field = 'Field not selected'; - } - if ( inputValues?.analogues === undefined || inputValues?.analogues?.length <= 0 @@ -54,13 +47,6 @@ export const validateValues = ( errors.analogues = 'Analogues not selected'; } - if ( - inputValues?.metadata === undefined || - inputValues?.metadata?.filter((m) => m.metadataType === 'Zone').length <= 0 - ) { - errors.zone = 'Zone not selected'; - } - if (!files.NC && !isEdit) { errors.file = 'NC file missing'; } diff --git a/src/features/AddModel/ModelMetadata/MetadataSelect/MetadataSelect.tsx b/src/features/AddModel/ModelMetadata/MetadataSelect/MetadataSelect.tsx index 65626672..fc3e2f43 100644 --- a/src/features/AddModel/ModelMetadata/MetadataSelect/MetadataSelect.tsx +++ b/src/features/AddModel/ModelMetadata/MetadataSelect/MetadataSelect.tsx @@ -30,8 +30,8 @@ export const MetadataSelect = ({ }, ]; - const props = - metadata != undefined && metadata!.length > 0 + const selectedOptions = + metadata !== undefined && metadata?.length > 0 ? metadata.filter((m) => m.metadataType === type) : emptyOption; const filteredOptions = data.filter((d) => d.metadataType === type); @@ -40,7 +40,7 @@ export const MetadataSelect = ({ : emptyOption; const intersection = optionList.filter((a) => - props.some((b) => JSON.stringify(a) === JSON.stringify(b)), + selectedOptions.some((b) => JSON.stringify(a) === JSON.stringify(b)), ); return ( @@ -55,7 +55,6 @@ export const MetadataSelect = ({ } onOptionsChange={(e: AutocompleteChanges) => { handleAddMetadata(e, type); - console.log(e.selectedItems); }} /> ); diff --git a/src/features/ModelTable/ModelTable.tsx b/src/features/ModelTable/ModelTable.tsx index 95ca8d43..e8996d6e 100644 --- a/src/features/ModelTable/ModelTable.tsx +++ b/src/features/ModelTable/ModelTable.tsx @@ -4,7 +4,11 @@ import { Button, LinearProgress } from '@equinor/eds-core-react'; import { EdsDataGrid } from '@equinor/eds-data-grid-react'; import { useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; -import { AnalogueModelsService, OpenAPI } from '../../api/generated'; +import { + AnalogueModelsService, + MetadataDto, + OpenAPI, +} from '../../api/generated'; import { useAccessToken } from '../../hooks/useAccessToken'; import * as Styled from './ModelTable.styled'; @@ -53,6 +57,10 @@ export const ModelTable = ({ } }; + const hasSelectedOptions = (metadata: MetadataDto[], type: string) => { + return metadata.filter((d) => d.metadataType === type).length > 0; + }; + return ( ( - {row.original.metadata - .filter((data) => data.metadataType === 'Formation') - .map((f) => ( -

{f.value + ', '}

- ))} + {hasSelectedOptions(row.original.metadata, 'Formation') + ? row.original.metadata + .filter((data) => data.metadataType === 'Formation') + .map((f) =>

{f.value + ', '}

) + : 'Not relevant'}
), }, @@ -103,11 +111,11 @@ export const ModelTable = ({ size: 150, cell: ({ row }) => ( - {row.original.metadata - .filter((data) => data.metadataType === 'Zone') - .map((z) => ( -

{z.value + ', '}

- ))} + {hasSelectedOptions(row.original.metadata, 'Zone') + ? row.original.metadata + .filter((data) => data.metadataType === 'Zone') + .map((z) =>

{z.value + ', '}

) + : 'Not relevant'}
), }, @@ -119,11 +127,13 @@ export const ModelTable = ({ size: 200, cell: ({ row }) => ( - {row.original.metadata - .filter((data) => data.metadataType === 'Field') - .map((filed) => ( -

{filed.value + ', '}

- ))} + {hasSelectedOptions(row.original.metadata, 'Field') + ? row.original.metadata + .filter((data) => data.metadataType === 'Field') + .map((filed) => ( +

{filed.value + ', '}

+ )) + : 'Not relevant'}
), }, diff --git a/src/features/ModelView/TableDataCell/TableDataCell.tsx b/src/features/ModelView/TableDataCell/TableDataCell.tsx index de1e7da3..6499b66d 100644 --- a/src/features/ModelView/TableDataCell/TableDataCell.tsx +++ b/src/features/ModelView/TableDataCell/TableDataCell.tsx @@ -25,7 +25,7 @@ export const TableDataCell = ({ {m.value + ', '} )) ) : ( - - + Not relevant )} );