From 634268701f68ba5da1041a909ddf170b5c0aac83 Mon Sep 17 00:00:00 2001 From: mheggelund Date: Thu, 17 Oct 2024 09:22:33 +0200 Subject: [PATCH] chore: Add equinor code to gde list name. Filter and sort Gde options by numbers. --- .../GdeSelect/GdeSelect.tsx | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx b/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx index 2a95d50..5c4d7fc 100644 --- a/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx +++ b/src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx @@ -46,16 +46,42 @@ export const GdeSelect = ({ (g) => g.geologyGroup === 'ArchitecturalElement', ); + const setDisplayName = (option: GeologicalStandardDto) => { + return option.equinorCode + ' ' + option.identifier; + }; + + const intToArray = (number: number) => { + return Array.from(number.toString()).map(Number); + }; + + const filterByCode = (data: GeologicalStandardDto[]) => { + if (gdeObject.depEnv === undefined) return []; + + const equinorCodeString = gdeObject.depEnv.equinorCode.toString(); + const firstTwoNumbersArray = intToArray( + parseInt(equinorCodeString.slice(0, 2)), + ); + const filteredList = data.filter( + (d) => + intToArray(d.equinorCode)[0] === firstTwoNumbersArray[0] && + intToArray(d.equinorCode)[1] === firstTwoNumbersArray[1], + ); + + return filteredList; + }; + return ( option.identifier} + options={sortList(Gde, true)} + optionLabel={(option) => setDisplayName(option)} onOptionsChange={(e: AutocompleteChanges) => { setGdeObject({ ...gdeObject, grossDepEnv: e.selectedItems[0], + depEnv: undefined, + subenv: undefined, }); setErrors({}); }} @@ -67,14 +93,16 @@ export const GdeSelect = ({ option.identifier} + options={sortList(De, true)} + optionLabel={(option) => setDisplayName(option)} onOptionsChange={(e: AutocompleteChanges) => { setGdeObject({ ...gdeObject, depEnv: e.selectedItems[0], + subenv: undefined, }); }} + selectedOptions={gdeObject.depEnv ? [gdeObject.depEnv] : []} noOptionsText="No options" variant={ error.DEnv && gdeObject.grossDepEnv !== undefined @@ -91,14 +119,15 @@ export const GdeSelect = ({ option.identifier} + options={filterByCode(sortList(SubEnvironment, true))} + optionLabel={(option) => setDisplayName(option)} onOptionsChange={(e: AutocompleteChanges) => { setGdeObject({ ...gdeObject, subenv: e.selectedItems[0], }); }} + selectedOptions={gdeObject.subenv ? [gdeObject.subenv] : []} noOptionsText="No options" variant={ error.subEnv && gdeObject.grossDepEnv !== undefined @@ -115,8 +144,8 @@ export const GdeSelect = ({ option.identifier} + options={sortList(ArchitecturalElement, true)} + optionLabel={(option) => setDisplayName(option)} onOptionsChange={(e: AutocompleteChanges) => { setGdeObject({ ...gdeObject,