mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-28 17:55:15 +02:00
feat: now recently used constraints are not shown if already in use (#9984)
This commit is contained in:
parent
9bd69a852e
commit
aa885b9afd
@ -139,6 +139,7 @@ export const FeatureStrategyConstraintAccordionList = forwardRef<
|
|||||||
show={
|
show={
|
||||||
<RecentlyUsedConstraints
|
<RecentlyUsedConstraints
|
||||||
setConstraints={setConstraints}
|
setConstraints={setConstraints}
|
||||||
|
constraints={constraints}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import { styled, Typography } from '@mui/material';
|
import { styled, Typography } from '@mui/material';
|
||||||
import { ConstraintAccordionView } from 'component/common/NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
import { ConstraintAccordionView } from 'component/common/NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
||||||
import { constraintId } from 'component/common/LegacyConstraintAccordion/ConstraintAccordionList/createEmptyConstraint';
|
import { constraintId } from 'component/common/LegacyConstraintAccordion/ConstraintAccordionList/createEmptyConstraint';
|
||||||
import { useRecentlyUsedConstraints } from './useRecentlyUsedConstraints';
|
import {
|
||||||
|
useRecentlyUsedConstraints,
|
||||||
|
areConstraintsEqual,
|
||||||
|
} from './useRecentlyUsedConstraints';
|
||||||
import type { IConstraint } from 'interfaces/strategy';
|
import type { IConstraint } from 'interfaces/strategy';
|
||||||
|
|
||||||
type IRecentlyUsedConstraintsProps = {
|
type IRecentlyUsedConstraintsProps = {
|
||||||
setConstraints?: React.Dispatch<React.SetStateAction<IConstraint[]>>;
|
setConstraints?: React.Dispatch<React.SetStateAction<IConstraint[]>>;
|
||||||
|
constraints?: IConstraint[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledContainer = styled('div')(({ theme }) => ({
|
const StyledContainer = styled('div')(({ theme }) => ({
|
||||||
@ -26,6 +30,7 @@ const StyledConstraintsContainer = styled('div')(({ theme }) => ({
|
|||||||
|
|
||||||
export const RecentlyUsedConstraints = ({
|
export const RecentlyUsedConstraints = ({
|
||||||
setConstraints,
|
setConstraints,
|
||||||
|
constraints = [],
|
||||||
}: IRecentlyUsedConstraintsProps) => {
|
}: IRecentlyUsedConstraintsProps) => {
|
||||||
const { items: recentlyUsedConstraints } = useRecentlyUsedConstraints();
|
const { items: recentlyUsedConstraints } = useRecentlyUsedConstraints();
|
||||||
|
|
||||||
@ -33,11 +38,22 @@ export const RecentlyUsedConstraints = ({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nonSelectedRecentConstraints = recentlyUsedConstraints.filter(
|
||||||
|
(recentConstraint) =>
|
||||||
|
!constraints.some((constraint) =>
|
||||||
|
areConstraintsEqual(constraint, recentConstraint),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (nonSelectedRecentConstraints.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
<StyledHeader>Recently used constraints</StyledHeader>
|
<StyledHeader>Recently used constraints</StyledHeader>
|
||||||
<StyledConstraintsContainer>
|
<StyledConstraintsContainer>
|
||||||
{recentlyUsedConstraints.map((constraint) => (
|
{nonSelectedRecentConstraints.map((constraint) => (
|
||||||
<ConstraintAccordionView
|
<ConstraintAccordionView
|
||||||
key={constraint[constraintId]}
|
key={constraint[constraintId]}
|
||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
|
@ -47,11 +47,11 @@ export const RecentlyUsedSegments = ({
|
|||||||
.map((id) => allSegments.find((segment) => segment.id === id))
|
.map((id) => allSegments.find((segment) => segment.id === id))
|
||||||
.filter((segment) => segment !== undefined) as ISegment[];
|
.filter((segment) => segment !== undefined) as ISegment[];
|
||||||
|
|
||||||
const filteredSegmentObjects = segmentObjects.filter(
|
const nonSelectedRecentSegments = segmentObjects.filter(
|
||||||
(segment) => !segments.some((selected) => selected.id === segment.id),
|
(segment) => !segments.some((selected) => selected.id === segment.id),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filteredSegmentObjects.length === 0) {
|
if (nonSelectedRecentSegments.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ export const RecentlyUsedSegments = ({
|
|||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
<StyledHeader>Recently used segments</StyledHeader>
|
<StyledHeader>Recently used segments</StyledHeader>
|
||||||
<StyledSegmentsContainer>
|
<StyledSegmentsContainer>
|
||||||
{filteredSegmentObjects.map((segment) => (
|
{nonSelectedRecentSegments.map((segment) => (
|
||||||
<RecentlyUsedSegmentChip
|
<RecentlyUsedSegmentChip
|
||||||
key={segment.id}
|
key={segment.id}
|
||||||
segment={segment}
|
segment={segment}
|
||||||
|
Loading…
Reference in New Issue
Block a user