Skip to content

Commit

Permalink
refactor: Cleanup and small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Feb 28, 2024
1 parent 70442b5 commit 0ce0cae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
14 changes: 0 additions & 14 deletions src/features/AddModel/AddModelDialog/AddModelDialog.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,13 @@ 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
) {
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';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 (
Expand All @@ -55,7 +55,6 @@ export const MetadataSelect = ({
}
onOptionsChange={(e: AutocompleteChanges<MetadataDto>) => {
handleAddMetadata(e, type);
console.log(e.selectedItems);
}}
/>
);
Expand Down
42 changes: 26 additions & 16 deletions src/features/ModelTable/ModelTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -53,6 +57,10 @@ export const ModelTable = ({
}
};

const hasSelectedOptions = (metadata: MetadataDto[], type: string) => {
return metadata.filter((d) => d.metadataType === type).length > 0;
};

return (
<Styled.Table>
<EdsDataGrid
Expand Down Expand Up @@ -87,11 +95,11 @@ export const ModelTable = ({
size: 150,
cell: ({ row }) => (
<Styled.List>
{row.original.metadata
.filter((data) => data.metadataType === 'Formation')
.map((f) => (
<p key={f.metadataId}>{f.value + ', '}</p>
))}
{hasSelectedOptions(row.original.metadata, 'Formation')
? row.original.metadata
.filter((data) => data.metadataType === 'Formation')
.map((f) => <p key={f.metadataId}>{f.value + ', '}</p>)
: 'Not relevant'}
</Styled.List>
),
},
Expand All @@ -103,11 +111,11 @@ export const ModelTable = ({
size: 150,
cell: ({ row }) => (
<Styled.List>
{row.original.metadata
.filter((data) => data.metadataType === 'Zone')
.map((z) => (
<p key={z.metadataId}>{z.value + ', '}</p>
))}
{hasSelectedOptions(row.original.metadata, 'Zone')
? row.original.metadata
.filter((data) => data.metadataType === 'Zone')
.map((z) => <p key={z.metadataId}>{z.value + ', '}</p>)
: 'Not relevant'}
</Styled.List>
),
},
Expand All @@ -119,11 +127,13 @@ export const ModelTable = ({
size: 200,
cell: ({ row }) => (
<Styled.List>
{row.original.metadata
.filter((data) => data.metadataType === 'Field')
.map((filed) => (
<p key={filed.metadataId}>{filed.value + ', '}</p>
))}
{hasSelectedOptions(row.original.metadata, 'Field')
? row.original.metadata
.filter((data) => data.metadataType === 'Field')
.map((filed) => (
<p key={filed.metadataId}>{filed.value + ', '}</p>
))
: 'Not relevant'}
</Styled.List>
),
},
Expand Down
2 changes: 1 addition & 1 deletion src/features/ModelView/TableDataCell/TableDataCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const TableDataCell = ({
<Typography key={m.metadataId}>{m.value + ', '}</Typography>
))
) : (
<Typography> - </Typography>
<Typography> Not relevant </Typography>
)}
</Styled.DataCell>
);
Expand Down

0 comments on commit 0ce0cae

Please sign in to comment.