diff --git a/src/features/AddModel/ModelMetadata/ModelMetadata.tsx b/src/features/AddModel/ModelMetadata/ModelMetadata.tsx index 679a8009..3f2f7a8b 100644 --- a/src/features/AddModel/ModelMetadata/ModelMetadata.tsx +++ b/src/features/AddModel/ModelMetadata/ModelMetadata.tsx @@ -44,21 +44,6 @@ export const ModelMetadata = ({ enabled: !!token, }); - const setSelectedMetadataOptions = (type: string) => { - if (!isLoading && data?.data) { - const dataProps = data.data.filter((z) => z.metadataType === type); - - const selectedProps = metadata?.metadata.filter( - (m) => m.metadataType === type, - ); - - return dataProps.filter( - (c) => - selectedProps.findIndex((x: MetadataDto) => x.value === c.value) > -1, - ); - } - }; - const setSelectedAnalogueOptions = () => { if (analougeData.data?.success && metadata.analogue) { const analogue = metadata?.analogue; @@ -123,33 +108,25 @@ export const ModelMetadata = ({ - d.metadataType === 'Field')} - optionLabel={(option) => option.value} - selectedOptions={setSelectedMetadataOptions('Field')} - multiple - onOptionsChange={(e: AutocompleteChanges) => - handleAddMetadata(e, 'Field') - } - > + type="Field" + data={data.data} + metadata={metadata.metadata} + isLoading={isLoading} + handleAddMetadata={handleAddMetadata} + /> {errors.field && } - d.metadataType === 'Formation', - )} - optionLabel={(option) => option.value} - selectedOptions={setSelectedMetadataOptions('Formation')} - multiple - onOptionsChange={(e: AutocompleteChanges) => - handleAddMetadata(e, 'Formation') - } - > + type="Formation" + data={data.data} + metadata={metadata.metadata} + isLoading={isLoading} + handleAddMetadata={handleAddMetadata} + /> {errors.formation && ( )} @@ -176,17 +153,14 @@ export const ModelMetadata = ({ )} - d.metadataType === 'Zone')} - optionLabel={(option) => option.value} - selectedOptions={setSelectedMetadataOptions('Zone')} - multiple - onOptionsChange={(e: AutocompleteChanges) => - handleAddMetadata(e, 'Zone') - } - > + type="Zone" + data={data.data} + metadata={metadata.metadata} + isLoading={isLoading} + handleAddMetadata={handleAddMetadata} + /> {errors.zone && } @@ -195,3 +169,49 @@ export const ModelMetadata = ({ ); }; + +const MetadataSelect = ({ + type, + data, + metadata, + isLoading, + className, + handleAddMetadata, +}: { + type: string; + data: MetadataDto[]; + metadata: MetadataDto[]; + isLoading: boolean; + className: string; + handleAddMetadata: ( + e: AutocompleteChanges, + type: string, + ) => void; +}) => { + const setSelectedMetadataOptions = (type: string) => { + if (!isLoading && data) { + const dataProps = data.filter((z) => z.metadataType === type); + + const selectedProps = metadata.filter((m) => m.metadataType === type); + + return dataProps.filter( + (c) => + selectedProps.findIndex((x: MetadataDto) => x.value === c.value) > -1, + ); + } + }; + + return ( + d.metadataType === type)} + optionLabel={(option) => option.value} + selectedOptions={setSelectedMetadataOptions(type)} + multiple + onOptionsChange={(e: AutocompleteChanges) => + handleAddMetadata(e, type) + } + > + ); +}; diff --git a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx index cc59fbca..17960fed 100644 --- a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx +++ b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx @@ -209,7 +209,9 @@ const DataCell = ({ {metadata?.filter((m) => m.metadataType === type).length ? ( metadata ?.filter((m) => m.metadataType === type) - .map((m) => {m.value}) + .map((m) => ( + {m.value + ', '} + )) ) : ( - No Zone selected - )}