Skip to content

Commit

Permalink
chore: Disable already selected outcrops.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Aug 30, 2024
1 parent 6633233 commit 0686360
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const OutcropAnalogueGroup = ({
<Dialog.CustomContent>
<OutcropSelect
outcropObject={outcropObject}
outcropGroup={outcropGroup}
setOutcropObject={setOutcropObject}
/>
</Dialog.CustomContent>
Expand Down
10 changes: 10 additions & 0 deletions src/components/OutcropAnalogue/OutcropSelect/OutcropSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ import { OutcropType } from '../OutcropAnalogueGroup/OutcropAnalogueGroup';

export const OutcropSelect = ({
outcropObject,
outcropGroup,
setOutcropObject,
}: {
outcropObject: OutcropType;
outcropGroup: OutcropDto[];
setOutcropObject: React.Dispatch<React.SetStateAction<OutcropType>>;
}) => {
const OutcropData = useFetchOutcropData();
if (OutcropData.isLoading || !OutcropData.data?.success)
return <p>Loading .....</p>;

const filterDisabled = (option: OutcropDto) => {
const caseExists = outcropGroup.filter(
(outcrop) => outcrop.outcropId === option.outcropId,
);
return caseExists.length > 0;
};

return (
<div>
<Autocomplete
Expand Down Expand Up @@ -42,6 +51,7 @@ export const OutcropSelect = ({

setOutcropObject(copyObject);
}}
optionDisabled={filterDisabled}
noOptionsText="No options"
/>

Expand Down

0 comments on commit 0686360

Please sign in to comment.