Skip to content

Commit

Permalink
feat: filter segments by project on the strategy (#3325)
Browse files Browse the repository at this point in the history
https://linear.app/unleash/issue/2-737/when-listing-segments-project-specific-segments-should-also-be-present

Simple filter on the UI for segments that are either global or for the
specific project.
  • Loading branch information
nunogois committed Mar 16, 2023
1 parent 49d3e8e commit bd17c63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -213,6 +213,7 @@ export const FeatureStrategyForm = ({
<FeatureStrategySegment
segments={segments}
setSegments={setSegments}
projectId={projectId}
/>
}
/>
Expand Down
Expand Up @@ -13,6 +13,7 @@ import { Divider, styled, Typography } from '@mui/material';
interface IFeatureStrategySegmentProps {
segments: ISegment[];
setSegments: React.Dispatch<React.SetStateAction<ISegment[]>>;
projectId: string;
}

const StyledDivider = styled(Divider)(({ theme }) => ({
Expand All @@ -22,6 +23,7 @@ const StyledDivider = styled(Divider)(({ theme }) => ({
export const FeatureStrategySegment = ({
segments: selectedSegments,
setSegments: setSelectedSegments,
projectId,
}: IFeatureStrategySegmentProps) => {
const { segments: allSegments } = useSegments();
const { strategySegmentsLimit } = useSegmentLimits();
Expand All @@ -35,7 +37,11 @@ export const FeatureStrategySegment = ({
return null;
}

const unusedSegments = allSegments.filter(segment => {
const allSelectableSegments = allSegments.filter(
({ project }) => !project || project === projectId
);

const unusedSegments = allSelectableSegments.filter(segment => {
return !selectedSegments.find(selected => selected.id === segment.id);
});

Expand Down

0 comments on commit bd17c63

Please sign in to comment.