Skip to content

Commit

Permalink
feat: filter gde by equinor code (#345)
Browse files Browse the repository at this point in the history
* chore: Add filter by number option to SortList.

* chore: Add equinor code to gde list name. Filter and sort Gde options by numbers.
  • Loading branch information
mheggelund authored Oct 17, 2024
1 parent 1a97e19 commit 2c8d0cb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
45 changes: 37 additions & 8 deletions src/components/GrossDepositionEnviroment/GdeSelect/GdeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<StyledDialog.AutocompleteList>
<Autocomplete
label="Gross Depositional Environment (GDE)"
options={sortList(Gde)}
optionLabel={(option) => option.identifier}
options={sortList(Gde, true)}
optionLabel={(option) => setDisplayName(option)}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
grossDepEnv: e.selectedItems[0],
depEnv: undefined,
subenv: undefined,
});
setErrors({});
}}
Expand All @@ -67,14 +93,16 @@ export const GdeSelect = ({
<Autocomplete
label="Depositional Environment"
disabled={gdeObject.grossDepEnv?.geologicalStandardId === undefined}
options={sortList(De)}
optionLabel={(option) => option.identifier}
options={sortList(De, true)}
optionLabel={(option) => setDisplayName(option)}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
depEnv: e.selectedItems[0],
subenv: undefined,
});
}}
selectedOptions={gdeObject.depEnv ? [gdeObject.depEnv] : []}
noOptionsText="No options"
variant={
error.DEnv && gdeObject.grossDepEnv !== undefined
Expand All @@ -91,14 +119,15 @@ export const GdeSelect = ({
<Autocomplete
label="Subenvironment"
disabled={gdeObject.grossDepEnv?.geologicalStandardId === undefined}
options={sortList(SubEnvironment)}
optionLabel={(option) => option.identifier}
options={filterByCode(sortList(SubEnvironment, true))}
optionLabel={(option) => setDisplayName(option)}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
subenv: e.selectedItems[0],
});
}}
selectedOptions={gdeObject.subenv ? [gdeObject.subenv] : []}
noOptionsText="No options"
variant={
error.subEnv && gdeObject.grossDepEnv !== undefined
Expand All @@ -115,8 +144,8 @@ export const GdeSelect = ({
<Autocomplete
label="Architectural Element"
multiple
options={sortList(ArchitecturalElement)}
optionLabel={(option) => option.identifier}
options={sortList(ArchitecturalElement, true)}
optionLabel={(option) => setDisplayName(option)}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
...gdeObject,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/SortList.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down

0 comments on commit 2c8d0cb

Please sign in to comment.