Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/metadata cleanup #332

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Autocomplete, AutocompleteChanges } from '@equinor/eds-core-react';
import { GeologicalStandardDto } from '../../../api/generated';
import { useFetchGrossDepData } from '../../../hooks/useFetchGrossDepData';
import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled';
import { sortList } from '../../../utils/SortList';
import { GdeType } from '../GrossDepositionEnviromentGroup/GrossDepositionEnviromentGroup';

export const GdeSelect = ({
Expand Down Expand Up @@ -42,7 +43,7 @@ export const GdeSelect = ({
<StyledDialog.AutocompleteList>
<Autocomplete
label="Gross Depositional Environment (GDE)"
options={Gde}
options={sortList(Gde)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
Expand All @@ -56,7 +57,7 @@ export const GdeSelect = ({
<Autocomplete
label="Depositional Environment"
disabled={gdeObject.grossDepEnv?.geologicalStandardId === undefined}
options={De}
options={sortList(De)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
Expand All @@ -70,7 +71,7 @@ export const GdeSelect = ({
<Autocomplete
label="Subenvironment"
disabled={gdeObject.grossDepEnv?.geologicalStandardId === undefined}
options={SubEnvironment}
options={sortList(SubEnvironment)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
Expand All @@ -84,7 +85,7 @@ export const GdeSelect = ({
<Autocomplete
label="Architectural Element"
multiple
options={ArchitecturalElement}
options={sortList(ArchitecturalElement)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<GeologicalStandardDto>) => {
setGdeObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Autocomplete, AutocompleteChanges } from '@equinor/eds-core-react';
import { OutcropDto } from '../../../api/generated';
import { useFetchOutcropData } from '../../../hooks/useFetchOutcropData';
import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled';
import { sortList } from '../../../utils/SortList';
import { OutcropType } from '../OutcropAnalogueGroup/OutcropAnalogueGroup';

export const OutcropSelect = ({
Expand All @@ -29,7 +30,7 @@ export const OutcropSelect = ({
<StyledDialog.AutocompleteList>
<Autocomplete
label="Analogue"
options={OutcropData.data.data}
options={sortList(OutcropData.data.data)}
optionLabel={(option) => option.name}
onOptionsChange={(e: AutocompleteChanges<OutcropDto>) => {
const copyObject: OutcropType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useFetchSmdaStratigraphicColumns,
} from '../../../hooks/useFetchStratColData';
import * as StyledDialog from '../../../styles/addRowDialog/AddRowDialog.styled';
import { sortList } from '../../../utils/SortList';

export const StratigraphicColumnSelect = ({
stratColumnObject,
Expand Down Expand Up @@ -61,9 +62,7 @@ export const StratigraphicColumnSelect = ({
<StyledDialog.AutocompleteList>
<Autocomplete
label="Country"
options={filterCountries.sort((a, b) =>
a.identifier.localeCompare(b.identifier),
)}
options={sortList(filterCountries)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<CountryDto>) => {
setStratColumnObject({
Expand All @@ -82,8 +81,10 @@ export const StratigraphicColumnSelect = ({
<Autocomplete
disabled={stratColumnObject.country === undefined}
label="Field"
options={fieldData.data.data.filter(
(field) => field.countryId === stratColumnObject.country?.countryId,
options={sortList(
fieldData.data.data.filter(
(field) => field.countryId === stratColumnObject.country?.countryId,
),
)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<FieldDto>) => {
Expand All @@ -101,13 +102,15 @@ export const StratigraphicColumnSelect = ({
<Autocomplete
disabled={stratColumnObject.country === undefined}
label="Stratigraphic column"
options={stratColumnData.data.data.filter(
(c) =>
stratColumnObject.country !== undefined &&
c.countries.filter(
(country) =>
country.countryId === stratColumnObject.country?.countryId,
).length !== 0,
options={sortList(
stratColumnData.data.data.filter(
(c) =>
stratColumnObject.country !== undefined &&
c.countries.filter(
(country) =>
country.countryId === stratColumnObject.country?.countryId,
).length !== 0,
),
)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<StratColumnDto>) => {
Expand All @@ -128,12 +131,15 @@ export const StratigraphicColumnSelect = ({
<Autocomplete
disabled={stratColumnObject.stratColumn === undefined}
label="Level 1 (group)"
options={stratUnitData.data.data
.filter((s) => s.level === 1)
.filter(
(c) =>
c.stratColumnId === stratColumnObject.stratColumn?.stratColumnId,
)}
options={sortList(
stratUnitData.data.data
.filter((s) => s.level === 1)
.filter(
(c) =>
c.stratColumnId ===
stratColumnObject.stratColumn?.stratColumnId,
),
)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<StratUnitDto>) =>
setStratColumnObject({
Expand All @@ -152,16 +158,19 @@ export const StratigraphicColumnSelect = ({
<Autocomplete
disabled={stratColumnObject.level1 === undefined}
label="Level 2 (formation)"
options={stratUnitData.data.data
.filter((s) => s.level === 2)
.filter(
(c) =>
c.stratColumnId === stratColumnObject.stratColumn?.stratColumnId,
)
.filter(
(x) =>
x.stratUnitParentId === stratColumnObject.level1?.stratUnitId,
)}
options={sortList(
stratUnitData.data.data
.filter((s) => s.level === 2)
.filter(
(c) =>
c.stratColumnId ===
stratColumnObject.stratColumn?.stratColumnId,
)
.filter(
(x) =>
x.stratUnitParentId === stratColumnObject.level1?.stratUnitId,
),
)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<StratUnitDto>) =>
setStratColumnObject({
Expand All @@ -179,16 +188,19 @@ export const StratigraphicColumnSelect = ({
<Autocomplete
disabled={stratColumnObject.level2 === undefined}
label="Level 3 (formation/subzone)"
options={stratUnitData.data.data
.filter((s) => s.level === 3)
.filter(
(c) =>
c.stratColumnId === stratColumnObject.stratColumn?.stratColumnId,
)
.filter(
(x) =>
x.stratUnitParentId === stratColumnObject.level2?.stratUnitId,
)}
options={sortList(
stratUnitData.data.data
.filter((s) => s.level === 3)
.filter(
(c) =>
c.stratColumnId ===
stratColumnObject.stratColumn?.stratColumnId,
)
.filter(
(x) =>
x.stratUnitParentId === stratColumnObject.level2?.stratUnitId,
),
)}
optionLabel={(option) => option.identifier}
onOptionsChange={(e: AutocompleteChanges<StratUnitDto>) =>
setStratColumnObject({
Expand Down
15 changes: 15 additions & 0 deletions src/utils/SortList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export const sortList = (data: any) => {
if (data.length === 0) {
return data;
} else if (data.length !== 0 && data[0]['identifier'] !== undefined) {
return data.sort((a: any, b: any) =>
a.identifier.localeCompare(b.identifier),
);
} else if (data[0]['name'] !== undefined) {
return data.sort((a: any, b: any) => a.name.localeCompare(b.name));
} else {
console.log('Data has no identifier or name');
return data;
}
};