diff --git a/frontend/src/component/common/TooltipResolver/TooltipResolver.tsx b/frontend/src/component/common/TooltipResolver/TooltipResolver.tsx index 8aea828f5c..d4860ac7ff 100644 --- a/frontend/src/component/common/TooltipResolver/TooltipResolver.tsx +++ b/frontend/src/component/common/TooltipResolver/TooltipResolver.tsx @@ -18,7 +18,6 @@ export const TooltipResolver = ({ if (!title && !titleComponent) { return children; } - if (variant === 'custom') { return ( diff --git a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyItem.tsx b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyItem.tsx index d71a619f6d..1cfef9da74 100644 --- a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyItem.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyItem.tsx @@ -12,6 +12,7 @@ import { ConditionallyRender } from 'component/common/ConditionallyRender/Condit import { CopyStrategyIconMenu } from './CopyStrategyIconMenu/CopyStrategyIconMenu'; import { StrategyItemContainer } from 'component/common/StrategyItemContainer/StrategyItemContainer'; import MenuStrategyRemove from './MenuStrategyRemove/MenuStrategyRemove'; +import SplitPreviewSlider from 'component/feature/StrategyTypes/SplitPreviewSlider/SplitPreviewSlider'; interface IStrategyItemProps { environmentId: string; @@ -86,6 +87,9 @@ export const StrategyItem: FC = ({ } > + {strategy.variants ? ( + + ) : null} ); }; diff --git a/frontend/src/component/feature/StrategyTypes/SplitPreviewSlider/SplitPreviewSlider.tsx b/frontend/src/component/feature/StrategyTypes/SplitPreviewSlider/SplitPreviewSlider.tsx index 6ddd8425a0..7d761579e8 100644 --- a/frontend/src/component/feature/StrategyTypes/SplitPreviewSlider/SplitPreviewSlider.tsx +++ b/frontend/src/component/feature/StrategyTypes/SplitPreviewSlider/SplitPreviewSlider.tsx @@ -1,10 +1,9 @@ import { Box, Typography, styled } from '@mui/material'; +import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; +import { TooltipResolver } from 'component/common/TooltipResolver/TooltipResolver'; +import { IFeatureVariant } from 'interfaces/featureToggle'; -type SplitPreviewSliderProps = { - values: number[]; -}; - -const StyledContainer = styled(Box)(({ theme }) => ({ +const StyledContainer = styled(Box)(() => ({ display: 'flex', width: '100%', position: 'relative', @@ -18,55 +17,188 @@ const StyledTrack = styled(Box)(({ theme }) => ({ overflow: 'hidden', })); -const StyledSegment = styled(Box)(({ theme }) => ({ +const StyledSegment = styled(Box)(() => ({ height: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center', + width: '100%', })); -const StyledSegmentTrack = styled(Box)(({ theme }) => ({ - height: theme.spacing(3), +const StyledSegmentTrack = styled(Box, { + shouldForwardProp: prop => prop !== 'index', +})<{ index: number }>(({ theme, index }) => ({ + height: theme.spacing(1.8), width: '100%', position: 'relative', + background: theme.palette.variants[index % theme.palette.variants.length], })); -const SplitPreviewSlider = ({ values }: SplitPreviewSliderProps) => { - if (values.length < 2) { +const StyledHeaderContainer = styled(Box)(({ theme }) => ({ + display: 'flex', + alignItems: 'center', + marginBottom: theme.spacing(1), +})); + +const StyledTypography = styled(Typography)(({ theme }) => ({ + marginY: theme.spacing(1), +})); + +const StyledVariantBoxContainer = styled(Box)(() => ({ + display: 'flex', + alignItems: 'center', + marginLeft: 'auto', +})); + +const StyledVariantBox = styled(Box, { + shouldForwardProp: prop => prop !== 'index', +})<{ index: number }>(({ theme, index }) => ({ + display: 'flex', + alignItems: 'center', + marginRight: theme.spacing(2), + '& div': { + width: theme.spacing(1.6), + height: theme.spacing(1.6), + borderRadius: '50%', + marginRight: theme.spacing(1), + background: + theme.palette.variants[index % theme.palette.variants.length], + }, +})); + +const StyledTypographySubtitle = styled(Typography)(({ theme }) => ({ + marginTop: theme.spacing(1), +})); + +interface ISplitPreviewSliderProps { + variants: IFeatureVariant[]; +} + +const SplitPreviewSlider = ({ variants }: ISplitPreviewSliderProps) => { + if (variants.length < 2) { return null; } return ( ({ marginTop: theme.spacing(2) })}> - ({ marginY: theme.spacing(1) })} - > - Split preview - + - {values.map((value, index) => ( - - ({ - background: - theme.palette.variants[ - index % theme.palette.variants.length - ], - })} - /> - ({ marginTop: theme.spacing(1) })} + + {variants.map((variant, index) => { + const value = variant.weight / 10; + return ( + e.preventDefault()} + titleComponent={ + + } > - {value}% - - - ))} + + {' '} + + + + {value}% + + + + + ); + })} ); }; +const SplitPreviewHeader = ({ variants }: ISplitPreviewSliderProps) => { + return ( + + + Feature variants ({variants.length}) + + + {variants.map((variant, index) => ( + + + + {variant.name} + + + ))} + + + ); +}; + +interface ISplitPreviewTooltip { + variant: IFeatureVariant; + index: number; +} + +const StyledTooltipContainer = styled(Box)(() => ({ + display: 'flex', + flexDirection: 'column', +})); + +const StyledVariantContainer = styled(Box)(() => ({ + display: 'flex', + alignItems: 'center', + minWidth: '250px', +})); + +const StyledPayloadContainer = styled(Box)(({ theme }) => ({ + marginTop: theme.spacing(1), + display: 'flex', + flexDirection: 'column', +})); + +const StyledPayloadLabel = styled(Typography)(({ theme }) => ({ + marginBottom: theme.spacing(1), +})); + +const SplitPreviewTooltip = ({ variant, index }: ISplitPreviewTooltip) => { + return ( + + + + + + + + {variant.weight / 10}% - {variant.name} + + + + {variant.payload ? ( + + + Payload + + + {variant.payload.value}} + elseShow={ + + {variant.payload.value} + + } + /> + + ) : null} + + ); +}; + export default SplitPreviewSlider; diff --git a/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx b/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx index 7d1cb785a8..30177b6d79 100644 --- a/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx +++ b/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx @@ -157,9 +157,7 @@ export const StrategyVariants: FC<{ > Add variant - variant.weight / 10)} - /> + ); };