mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-24 01:18:01 +02:00
* refactor: fix environment name text alignment * refactor: use rounded corners for AutocompleteBox * refactor: add tooltips to the strategy segment icons * refactor: add segment limit warnings * refactor: improve segments warning text
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import React from 'react';
|
|
import { Link } from 'react-router-dom';
|
|
import { ISegment } from 'interfaces/segment';
|
|
import { Clear, VisibilityOff, Visibility } from '@material-ui/icons';
|
|
import { useStyles } from './FeatureStrategySegmentChip.styles';
|
|
import ConditionallyRender from 'component/common/ConditionallyRender';
|
|
import { constraintAccordionListId } from 'component/common/ConstraintAccordion/ConstraintAccordionList/ConstraintAccordionList';
|
|
import { Tooltip } from '@material-ui/core';
|
|
|
|
interface IFeatureStrategySegmentListProps {
|
|
segment: ISegment;
|
|
setSegments: React.Dispatch<React.SetStateAction<ISegment[]>>;
|
|
preview?: ISegment;
|
|
setPreview: React.Dispatch<React.SetStateAction<ISegment | undefined>>;
|
|
}
|
|
|
|
export const FeatureStrategySegmentChip = ({
|
|
segment,
|
|
setSegments,
|
|
preview,
|
|
setPreview,
|
|
}: IFeatureStrategySegmentListProps) => {
|
|
const styles = useStyles();
|
|
|
|
const onRemove = () => {
|
|
setSegments(prev => {
|
|
return prev.filter(s => s.id !== segment.id);
|
|
});
|
|
setPreview(prev => {
|
|
return prev === segment ? undefined : prev;
|
|
});
|
|
};
|
|
|
|
const onTogglePreview = () => {
|
|
setPreview(prev => {
|
|
return prev === segment ? undefined : segment;
|
|
});
|
|
};
|
|
|
|
const togglePreviewIcon = (
|
|
<ConditionallyRender
|
|
condition={segment === preview}
|
|
show={<VisibilityOff titleAccess="Hide" className={styles.icon} />}
|
|
elseShow={<Visibility titleAccess="Show" className={styles.icon} />}
|
|
/>
|
|
);
|
|
|
|
const previewIconTooltip =
|
|
segment === preview
|
|
? 'Hide segment constraints'
|
|
: 'Preview segment constraints';
|
|
|
|
return (
|
|
<span className={styles.chip}>
|
|
<Link
|
|
to={`/segments/edit/${segment.id}`}
|
|
target="_blank"
|
|
className={styles.link}
|
|
>
|
|
{segment.name}
|
|
</Link>
|
|
<Tooltip title={previewIconTooltip}>
|
|
<button
|
|
type="button"
|
|
onClick={onTogglePreview}
|
|
className={styles.button}
|
|
aria-expanded={segment === preview}
|
|
aria-controls={constraintAccordionListId}
|
|
>
|
|
{togglePreviewIcon}
|
|
</button>
|
|
</Tooltip>
|
|
<Tooltip title="Remove segment">
|
|
<button
|
|
type="button"
|
|
onClick={onRemove}
|
|
className={styles.button}
|
|
>
|
|
<Clear titleAccess="Remove" className={styles.icon} />
|
|
</button>
|
|
</Tooltip>
|
|
</span>
|
|
);
|
|
};
|