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, diff --git a/src/utils/SortList.ts b/src/utils/SortList.ts index de0f0cb..a53ffb6 100644 --- a/src/utils/SortList.ts +++ b/src/utils/SortList.ts @@ -1,7 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -export const sortList = (data: any) => { +export const sortList = (data: any, byNmber?: boolean) => { if (data.length === 0) { return data; + } else if (byNmber) { + return data.sort((a: any, b: any) => a.equinorCode - b.equinorCode); } else if (data.length !== 0 && data[0]['identifier'] !== undefined) { return data.sort((a: any, b: any) => a.identifier.localeCompare(b.identifier),