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

Refactor/object case #187

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -8,3 +8,20 @@ export const AutocompleteWrapper = styled.div`

column-gap: ${spacings.MEDIUM};
`;

export const Required = styled.div`
> label {
color: red;
}
`;

export const AutocompleteRow = styled.div`
display: flex;
flex-direction: row;
flex: end;
column-gap: ${spacings.MEDIUM};

> div {
flex-grow: 1;
}
`;
Original file line number Diff line number Diff line change
@@ -1,54 +1,81 @@
import { Autocomplete, AutocompleteChanges } from '@equinor/eds-core-react';
import { ModelAreaDto } from '../../../../../api/generated';
/* eslint-disable max-lines-per-function */
import {
Autocomplete,
AutocompleteChanges,
Label,
} from '@equinor/eds-core-react';
import { ComputeCaseDto, ModelAreaDto } from '../../../../../api/generated';
import * as Styled from '../CaseOptionSelects.styled';

export const ModelAreaSelect = ({
modelAreas,
selectedModelArea,
disableSelect,
existingCases,
setModelArea,
caseError,
}: {
modelAreas: ModelAreaDto[];
selectedModelArea: ModelAreaDto[] | undefined;
disableSelect?: boolean;
existingCases: ComputeCaseDto[];
setModelArea?: React.Dispatch<
React.SetStateAction<ModelAreaDto[] | undefined>
>;
caseError: string;
}) => {
const filterDisabled = (option: ModelAreaDto) => {
if (!existingCases || existingCases.length === 0 || !option.modelAreaId)
return true;

const caseExists = existingCases
.filter((c) => c.modelArea !== null)
.filter((c) => c.modelArea.modelAreaId === option.modelAreaId);

return caseExists.length > 0;
};

return (
<Styled.AutocompleteWrapper>
<Autocomplete
label="Model area"
readOnly={disableSelect}
options={
modelAreas && modelAreas.length > 0
? modelAreas
: [
{
modelAreaId: '',
modelAreaType: 'Whole Model',
coordinates: [],
},
]
}
selectedOptions={
selectedModelArea &&
selectedModelArea.length > 0 &&
selectedModelArea[0].modelAreaId !== ''
? selectedModelArea
: [
{
modelAreaId: '',
modelAreaType: 'Whole Model',
coordinates: [],
},
]
}
optionLabel={(modelArea) => modelArea.modelAreaType}
onOptionsChange={(changes: AutocompleteChanges<ModelAreaDto>) =>
setModelArea && setModelArea(changes.selectedItems)
}
></Autocomplete>
<Styled.AutocompleteRow>
<Styled.Required>
<Autocomplete
label="Model area"
readOnly={disableSelect}
options={modelAreas && modelAreas.length > 0 ? modelAreas : []}
selectedOptions={
selectedModelArea &&
selectedModelArea.length > 0 &&
selectedModelArea[0].modelAreaId !== ''
? selectedModelArea
: selectedModelArea &&
selectedModelArea.length > 0 &&
selectedModelArea[0].modelAreaType === ''
? [
{
modelAreaId: '',
modelAreaType: 'Whole Model',
coordinates: [],
},
]
: [
{
modelAreaId: '',
modelAreaType: '',
coordinates: [],
},
]
}
optionLabel={(modelArea) => modelArea.modelAreaType}
onOptionsChange={(changes: AutocompleteChanges<ModelAreaDto>) =>
setModelArea && setModelArea(changes.selectedItems)
}
optionDisabled={filterDisabled}
variant={caseError.length > 0 ? 'error' : undefined}
/>
{caseError.length > 0 && <Label label={caseError}></Label>}
</Styled.Required>
</Styled.AutocompleteRow>
</Styled.AutocompleteWrapper>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable max-lines-per-function */
import { useState } from 'react';
import {
ComputeCaseDto,
ListComputeSettingsInputDto,
ListComputeSettingsInputValueDto,
ModelAreaDto,
Expand All @@ -26,6 +28,7 @@ export const VariogramOptionSelect = ({
NetToGrossSettings,
ContiniusParameterSettings,
IndicatorSettings,
existingCases,
}: {
modelAreas: ModelAreaDto[];
caseType: string;
Expand Down Expand Up @@ -57,7 +60,12 @@ export const VariogramOptionSelect = ({
IndicatorSettings?: ListComputeSettingsInputDto[];
NetToGrossSettings?: ListComputeSettingsInputDto[];
ContiniusParameterSettings?: ListComputeSettingsInputDto[];
existingCases: ComputeCaseDto[];
}) => {
// TODO: Case Error handling
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [caseError, setCaseError] = useState<string>('');

// Lage en funksjon som tar inn Liste og Name
const indicatorFamilySettings = IndicatorSettings?.filter(
(value) => value.name === 'Variogram Family Filter',
Expand Down Expand Up @@ -89,6 +97,8 @@ export const VariogramOptionSelect = ({
modelAreas={modelAreas}
selectedModelArea={selectedModelArea}
setModelArea={setModelArea}
existingCases={existingCases}
caseError={caseError}
/>

{setIndicatorParameters && caseType === 'Indicator' && (
Expand Down
13 changes: 8 additions & 5 deletions src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const CaseRow = ({
const [selectedVariogramModels, setVariogramModels] =
useState<ListComputeSettingsInputValueDto[]>();
const [saved, setSaved] = useState<boolean>(true);
const [caseError, setCaseError] = useState<string>('');

const { data } = useQuery({
queryKey: ['analogue-model', modelId],
Expand Down Expand Up @@ -154,8 +155,7 @@ export const CaseRow = ({
}
} else {
// TODO: Error handeling, inform user
// eslint-disable-next-line no-console
console.log('Duplicate case');
// Possibly not necessary anyway. Might never be reached with new limitations on user.
}
} else {
// Case should have no set model area, is a 'whole model' case
Expand All @@ -174,9 +174,7 @@ export const CaseRow = ({
saveCaseAlert();
}
} else {
// TODO: Error handeling, inform user
// eslint-disable-next-line no-console
console.log('Duplicate case');
setCaseError('You must select a model area');
}
}
}
Expand Down Expand Up @@ -253,6 +251,7 @@ export const CaseRow = ({
setParameters={setParameters}
setArchelFilter={setArchelFilter}
setVariogramModels={setVariogramModels}
existingCases={caseList}
/>
)}

Expand All @@ -271,6 +270,7 @@ export const CaseRow = ({
setGrainSize={setGrainSize}
setParameters={setParameters}
setVariogramModels={setVariogramModels}
existingCases={caseList}
/>
)}

Expand All @@ -290,6 +290,7 @@ export const CaseRow = ({
setParameters={setParameters}
setArchelFilter={setArchelFilter}
setVariogramModels={setVariogramModels}
existingCases={caseList}
/>
)}

Expand All @@ -299,6 +300,8 @@ export const CaseRow = ({
modelAreas={areaList ? areaList : []}
selectedModelArea={selectedRowArea(rowCase.computeCaseId)}
setModelArea={setModelArea}
existingCases={caseList}
caseError={caseError}
/>
)}
<CaseButtons
Expand Down