1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-08 01:15:49 +02:00

update strategy border for playground

This commit is contained in:
Tymoteusz Czech 2022-08-08 09:50:49 +02:00
parent 85858cf11f
commit e432ae45e0
7 changed files with 98 additions and 128 deletions

View File

@ -26,6 +26,8 @@ export const useStyles = makeStyles()(theme => ({
actions: { actions: {
marginLeft: 'auto', marginLeft: 'auto',
display: 'flex', display: 'flex',
minHeight: theme.spacing(6),
alignItems: 'center',
}, },
resultChip: { resultChip: {
marginLeft: 'auto', marginLeft: 'auto',

View File

@ -17,6 +17,7 @@ interface IStrategyItemContainerProps {
onDragEnd?: DragEventHandler<HTMLButtonElement>; onDragEnd?: DragEventHandler<HTMLButtonElement>;
actions?: ReactNode; actions?: ReactNode;
orderNumber?: number; orderNumber?: number;
className?: string;
} }
const DragIcon = styled(IconButton)(({ theme }) => ({ const DragIcon = styled(IconButton)(({ theme }) => ({
@ -44,6 +45,7 @@ export const StrategyItemContainer: FC<IStrategyItemContainerProps> = ({
actions, actions,
children, children,
orderNumber, orderNumber,
className,
}) => { }) => {
const { classes: styles } = useStyles(); const { classes: styles } = useStyles();
const Icon = getFeatureStrategyIcon(strategy.name); const Icon = getFeatureStrategyIcon(strategy.name);
@ -54,8 +56,7 @@ export const StrategyItemContainer: FC<IStrategyItemContainerProps> = ({
condition={orderNumber !== undefined} condition={orderNumber !== undefined}
show={<StyledIndexLabel>{orderNumber}</StyledIndexLabel>} show={<StyledIndexLabel>{orderNumber}</StyledIndexLabel>}
/> />
<Box className={classNames(styles.container, className)}>
<div className={styles.container}>
<div <div
className={classNames(styles.header, { className={classNames(styles.header, {
[styles.headerDraggable]: Boolean(onDragStart), [styles.headerDraggable]: Boolean(onDragStart),
@ -89,7 +90,7 @@ export const StrategyItemContainer: FC<IStrategyItemContainerProps> = ({
<div className={styles.actions}>{actions}</div> <div className={styles.actions}>{actions}</div>
</div> </div>
<div className={styles.body}>{children}</div> <div className={styles.body}>{children}</div>
</div> </Box>
</Box> </Box>
); );
}; };

View File

@ -4,11 +4,13 @@ export const useStyles = makeStyles()(theme => ({
popoverPaper: { popoverPaper: {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
alignItems: 'flex-start', // alignItems: 'flex-start',
padding: theme.spacing(6), padding: theme.spacing(6),
maxWidth: '728px', // maxWidth: '728px',
width: 728,
maxWidth: '100%',
height: 'auto', height: 'auto',
overflowY: 'scroll', overflowY: 'auto',
backgroundColor: theme.palette.tertiary.light, backgroundColor: theme.palette.tertiary.light,
}, },
})); }));

View File

@ -1,13 +1,10 @@
import { import { PlaygroundResultStrategyLists } from './PlaygroundResultStrategyList/playgroundResultStrategyLists';
PlaygroundResultStrategyLists, import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
WrappedPlaygroundResultStrategyList,
} from './PlaygroundResultStrategyList/playgroundResultStrategyLists';
import { ConditionallyRender } from '../../../../../common/ConditionallyRender/ConditionallyRender';
import React from 'react';
import { import {
PlaygroundFeatureSchema, PlaygroundFeatureSchema,
PlaygroundRequestSchema, PlaygroundRequestSchema,
} from '../../../../../../hooks/api/actions/usePlayground/playground.model'; } from 'hooks/api/actions/usePlayground/playground.model';
import { Alert } from '@mui/material';
interface PlaygroundResultFeatureStrategyListProps { interface PlaygroundResultFeatureStrategyListProps {
feature: PlaygroundFeatureSchema; feature: PlaygroundFeatureSchema;
@ -19,24 +16,24 @@ export const PlaygroundResultFeatureStrategyList = ({
input, input,
}: PlaygroundResultFeatureStrategyListProps) => { }: PlaygroundResultFeatureStrategyListProps) => {
return ( return (
<>
<ConditionallyRender <ConditionallyRender
condition={ condition={
!feature.isEnabledInCurrentEnvironment && !feature.isEnabledInCurrentEnvironment &&
Boolean(feature?.strategies?.data) Boolean(feature?.strategies?.data)
} }
show={ show={
<WrappedPlaygroundResultStrategyList <Alert severity={'info'} color={'info'}>
strategies={feature?.strategies?.data!} If environment would be enabled then this feature would
feature={feature} be {feature.strategies.result ? 'TRUE' : 'FALSE'} and
input={input} the strategies would evaluate like this:{' '}
/> </Alert>
} }
elseShow={ />
<PlaygroundResultStrategyLists <PlaygroundResultStrategyLists
strategies={feature?.strategies?.data!} strategies={feature?.strategies?.data || []}
input={input} input={input}
/> />
} </>
/>
); );
}; };

View File

@ -34,4 +34,7 @@ export const useStyles = makeStyles()(theme => ({
borderRadius: theme.shape.borderRadiusMedium, borderRadius: theme.shape.borderRadiusMedium,
background: theme.palette.background.default, background: theme.palette.background.default,
}, },
successBorder: {
border: `1px solid ${theme.palette.success.main}`,
},
})); }));

View File

@ -1,11 +1,4 @@
import { Box, styled, Typography, useTheme } from '@mui/material'; import { useTheme } from '@mui/material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
import {
formatStrategyName,
getFeatureStrategyIcon,
} from 'utils/strategyNames';
import StringTruncator from 'component/common/StringTruncator/StringTruncator';
import { PlaygroundResultChip } from '../../../../PlaygroundResultChip/PlaygroundResultChip'; import { PlaygroundResultChip } from '../../../../PlaygroundResultChip/PlaygroundResultChip';
import { import {
PlaygroundStrategySchema, PlaygroundStrategySchema,
@ -13,6 +6,8 @@ import {
} from 'hooks/api/actions/usePlayground/playground.model'; } from 'hooks/api/actions/usePlayground/playground.model';
import { PlaygroundResultStrategyExecution } from './PlaygroundResultStrategyExecution/PlaygroundResultStrategyExecution'; import { PlaygroundResultStrategyExecution } from './PlaygroundResultStrategyExecution/PlaygroundResultStrategyExecution';
import { useStyles } from './PlaygroundResultFeatureStrategyItem.styles'; import { useStyles } from './PlaygroundResultFeatureStrategyItem.styles';
import { StrategyItemContainer } from 'component/common/StrategyItemContainer/StrategyItemContainer';
import { objectId } from 'utils/objectId';
interface IPlaygroundResultFeatureStrategyItemProps { interface IPlaygroundResultFeatureStrategyItemProps {
strategy: PlaygroundStrategySchema; strategy: PlaygroundStrategySchema;
@ -21,66 +16,32 @@ interface IPlaygroundResultFeatureStrategyItemProps {
compact: boolean; compact: boolean;
} }
const StyledItemWrapper = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
margin: theme.spacing(0.5, 0),
gap: theme.spacing(1),
}));
export const PlaygroundResultFeatureStrategyItem = ({ export const PlaygroundResultFeatureStrategyItem = ({
strategy, strategy,
input, input,
index, index,
compact, compact,
}: IPlaygroundResultFeatureStrategyItemProps) => { }: IPlaygroundResultFeatureStrategyItemProps) => {
const { result, name } = strategy; const { result } = strategy;
const { classes: styles } = useStyles(); const { classes: styles } = useStyles();
const theme = useTheme(); const theme = useTheme();
const Icon = getFeatureStrategyIcon(strategy.name);
const label = const label =
result.evaluationStatus === 'incomplete' result.evaluationStatus === 'incomplete'
? 'Unevaluated' ? 'Unevaluated'
: result.enabled : result.enabled
? 'True' ? 'True'
: 'False'; : 'False';
const border =
result.enabled && result.evaluationStatus === 'complete'
? `1px solid ${theme.palette.success.main}`
: `1px solid ${theme.palette.divider}`;
return ( return (
<Box <StrategyItemContainer
sx={{ className={
width: '100%', result.enabled && result.evaluationStatus === 'complete'
position: 'relative', ? styles.successBorder
paddingRight: compact ? '12px' : 0, : undefined
ml: '-12px', }
}} strategy={{ ...strategy, id: `${objectId(strategy)}` }}
> orderNumber={index + 1}
<ConditionallyRender actions={
condition={index > 0}
show={<StrategySeparator text="OR" />}
/>
<StyledItemWrapper sx={{ mr: 2 }}>
<Typography
variant={'subtitle1'}
color={'text.secondary'}
sx={{ ml: 1 }}
>
{index + 1}
</Typography>
<Box className={styles.innerContainer} sx={{ border }}>
<div className={styles.header}>
<div className={styles.headerName}>
<Icon className={styles.icon} />
<StringTruncator
maxWidth="150"
maxLength={15}
text={formatStrategyName(name)}
/>
</div>
<PlaygroundResultChip <PlaygroundResultChip
showIcon={false} showIcon={false}
enabled={result.enabled} enabled={result.enabled}
@ -91,16 +52,13 @@ export const PlaygroundResultFeatureStrategyItem = ({
: 'default' : 'default'
} }
/> />
</div> }
<div className={styles.body}> >
<PlaygroundResultStrategyExecution <PlaygroundResultStrategyExecution
strategyResult={strategy} strategyResult={strategy}
input={input} input={input}
percentageFill={theme.palette.tertiary.light} percentageFill={theme.palette.tertiary.light}
/> />
</div> </StrategyItemContainer>
</Box>
</StyledItemWrapper>
</Box>
); );
}; };

View File

@ -1,11 +1,12 @@
import { Alert, Box, styled, Typography } from '@mui/material';
import { import {
PlaygroundFeatureSchema, PlaygroundFeatureSchema,
PlaygroundStrategySchema, PlaygroundStrategySchema,
PlaygroundRequestSchema, PlaygroundRequestSchema,
} from '../../../../../../../hooks/api/actions/usePlayground/playground.model'; } from 'hooks/api/actions/usePlayground/playground.model';
import { ConditionallyRender } from '../../../../../../common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { Alert, styled, Typography } from '@mui/material';
import { PlaygroundResultFeatureStrategyItem } from './PlaygroundResultFeatureStrategyItem/PlaygroundResultFeatureStrategyItem'; import { PlaygroundResultFeatureStrategyItem } from './PlaygroundResultFeatureStrategyItem/PlaygroundResultFeatureStrategyItem';
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
const StyledAlertWrapper = styled('div')(({ theme }) => ({ const StyledAlertWrapper = styled('div')(({ theme }) => ({
display: 'flex', display: 'flex',
@ -34,8 +35,7 @@ export const PlaygroundResultStrategyLists = ({
strategies, strategies,
input, input,
compact = false, compact = false,
}: PlaygroundResultStrategyListProps) => { }: PlaygroundResultStrategyListProps) => (
return (
<ConditionallyRender <ConditionallyRender
condition={strategies.length > 0} condition={strategies.length > 0}
show={ show={
@ -44,7 +44,13 @@ export const PlaygroundResultStrategyLists = ({
variant={'subtitle1'} variant={'subtitle1'}
sx={{ mt: 2, ml: 1, mb: 2, color: 'text.secondary' }} sx={{ mt: 2, ml: 1, mb: 2, color: 'text.secondary' }}
>{`Strategies (${strategies.length})`}</Typography> >{`Strategies (${strategies.length})`}</Typography>
<Box sx={{ width: '100%' }}>
{strategies.map((strategy, index) => ( {strategies.map((strategy, index) => (
<>
<ConditionallyRender
condition={index > 0}
show={<StrategySeparator text="OR" />}
/>
<PlaygroundResultFeatureStrategyItem <PlaygroundResultFeatureStrategyItem
key={strategy.id} key={strategy.id}
strategy={strategy} strategy={strategy}
@ -52,12 +58,13 @@ export const PlaygroundResultStrategyLists = ({
compact={compact} compact={compact}
input={input} input={input}
/> />
</>
))} ))}
</Box>
</> </>
} }
/> />
); );
};
interface WrappedPlaygroundResultStrategyListProps interface WrappedPlaygroundResultStrategyListProps
extends PlaygroundResultStrategyListProps { extends PlaygroundResultStrategyListProps {