mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +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={
|
||||
<RecentlyUsedConstraints
|
||||
setConstraints={setConstraints}
|
||||
constraints={constraints}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
@ -1,11 +1,15 @@
|
||||
import { styled, Typography } from '@mui/material';
|
||||
import { ConstraintAccordionView } from 'component/common/NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
||||
import { constraintId } from 'component/common/LegacyConstraintAccordion/ConstraintAccordionList/createEmptyConstraint';
|
||||
import { useRecentlyUsedConstraints } from './useRecentlyUsedConstraints';
|
||||
import {
|
||||
useRecentlyUsedConstraints,
|
||||
areConstraintsEqual,
|
||||
} from './useRecentlyUsedConstraints';
|
||||
import type { IConstraint } from 'interfaces/strategy';
|
||||
|
||||
type IRecentlyUsedConstraintsProps = {
|
||||
setConstraints?: React.Dispatch<React.SetStateAction<IConstraint[]>>;
|
||||
constraints?: IConstraint[];
|
||||
};
|
||||
|
||||
const StyledContainer = styled('div')(({ theme }) => ({
|
||||
@ -26,6 +30,7 @@ const StyledConstraintsContainer = styled('div')(({ theme }) => ({
|
||||
|
||||
export const RecentlyUsedConstraints = ({
|
||||
setConstraints,
|
||||
constraints = [],
|
||||
}: IRecentlyUsedConstraintsProps) => {
|
||||
const { items: recentlyUsedConstraints } = useRecentlyUsedConstraints();
|
||||
|
||||
@ -33,11 +38,22 @@ export const RecentlyUsedConstraints = ({
|
||||
return null;
|
||||
}
|
||||
|
||||
const nonSelectedRecentConstraints = recentlyUsedConstraints.filter(
|
||||
(recentConstraint) =>
|
||||
!constraints.some((constraint) =>
|
||||
areConstraintsEqual(constraint, recentConstraint),
|
||||
),
|
||||
);
|
||||
|
||||
if (nonSelectedRecentConstraints.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<StyledContainer>
|
||||
<StyledHeader>Recently used constraints</StyledHeader>
|
||||
<StyledConstraintsContainer>
|
||||
{recentlyUsedConstraints.map((constraint) => (
|
||||
{nonSelectedRecentConstraints.map((constraint) => (
|
||||
<ConstraintAccordionView
|
||||
key={constraint[constraintId]}
|
||||
constraint={constraint}
|
||||
|
@ -47,11 +47,11 @@ export const RecentlyUsedSegments = ({
|
||||
.map((id) => allSegments.find((segment) => segment.id === id))
|
||||
.filter((segment) => segment !== undefined) as ISegment[];
|
||||
|
||||
const filteredSegmentObjects = segmentObjects.filter(
|
||||
const nonSelectedRecentSegments = segmentObjects.filter(
|
||||
(segment) => !segments.some((selected) => selected.id === segment.id),
|
||||
);
|
||||
|
||||
if (filteredSegmentObjects.length === 0) {
|
||||
if (nonSelectedRecentSegments.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ export const RecentlyUsedSegments = ({
|
||||
<StyledContainer>
|
||||
<StyledHeader>Recently used segments</StyledHeader>
|
||||
<StyledSegmentsContainer>
|
||||
{filteredSegmentObjects.map((segment) => (
|
||||
{nonSelectedRecentSegments.map((segment) => (
|
||||
<RecentlyUsedSegmentChip
|
||||
key={segment.id}
|
||||
segment={segment}
|
||||
|
Loading…
Reference in New Issue
Block a user