Skip to content

Commit a064672

Browse files
chore(1-3422): playground strategies list (#9504)
Initial rough work on adapting the playground strategies to the new designs. This PR primarily splits components into Legacy files and adds new replacements. There are *some* updates (including spacing and text color), but nothing juicy yet. However, I wanted to get this in now, before this PR grows even bigger.
1 parent 9547fd9 commit a064672

File tree

8 files changed

+373
-90
lines changed

8 files changed

+373
-90
lines changed

frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureDetails/FeatureDetails.test.tsx

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { screen } from '@testing-library/react';
22
import { render } from 'utils/testRenderer';
3-
import { FeatureDetails } from './FeatureDetails';
3+
import { FeatureDetails as LegacyFeatureDetails } from './LegacyFeatureDetails';
44
import type { PlaygroundFeatureSchema, PlaygroundRequestSchema } from 'openapi';
5+
import { FeatureDetails } from './FeatureDetails';
56

67
const testCases = [
78
{
@@ -10,7 +11,7 @@ const testCases = [
1011
hasUnsatisfiedDependency: true,
1112
isEnabledInCurrentEnvironment: false,
1213
} as PlaygroundFeatureSchema,
13-
expectedText1: 'This feature flag is False in development because',
14+
expectedText1: /This feature flag is False in development because/,
1415
expectedText2:
1516
'parent dependency is not satisfied and the environment is disabled',
1617
},
@@ -20,7 +21,7 @@ const testCases = [
2021
hasUnsatisfiedDependency: true,
2122
isEnabledInCurrentEnvironment: true,
2223
} as PlaygroundFeatureSchema,
23-
expectedText1: 'This feature flag is False in development because',
24+
expectedText1: /This feature flag is False in development because/,
2425
expectedText2: 'parent dependency is not satisfied',
2526
},
2627
{
@@ -29,15 +30,15 @@ const testCases = [
2930
hasUnsatisfiedDependency: false,
3031
isEnabledInCurrentEnvironment: false,
3132
} as PlaygroundFeatureSchema,
32-
expectedText1: 'This feature flag is False in development because',
33+
expectedText1: /This feature flag is False in development because/,
3334
expectedText2: 'the environment is disabled',
3435
},
3536
{
3637
name: 'Feature environment is enabled',
3738
feature: {
3839
isEnabled: true,
3940
} as PlaygroundFeatureSchema,
40-
expectedText1: 'This feature flag is True in development because',
41+
expectedText1: /This feature flag is True in development because/,
4142
expectedText2: 'at least one strategy is True',
4243
},
4344
{
@@ -48,7 +49,7 @@ const testCases = [
4849
data: [{ name: 'custom' }],
4950
},
5051
} as PlaygroundFeatureSchema,
51-
expectedText1: 'This feature flag is Unknown in development because',
52+
expectedText1: /This feature flag is Unknown in development because/,
5253
expectedText2: 'no strategies could be fully evaluated',
5354
},
5455
{
@@ -59,7 +60,7 @@ const testCases = [
5960
data: [{ name: 'custom' }, { name: 'default' }],
6061
},
6162
} as PlaygroundFeatureSchema,
62-
expectedText1: 'This feature flag is Unknown in development because',
63+
expectedText1: /This feature flag is Unknown in development because/,
6364
expectedText2: 'not all strategies could be fully evaluated',
6465
},
6566
{
@@ -70,12 +71,29 @@ const testCases = [
7071
data: [{ name: 'default' }],
7172
},
7273
} as PlaygroundFeatureSchema,
73-
expectedText1: 'This feature flag is False in development because',
74+
expectedText1: /This feature flag is False in development because/,
7475
expectedText2:
7576
'all strategies are either False or could not be fully evaluated',
7677
},
7778
];
7879

80+
testCases.forEach(({ name, feature, expectedText1, expectedText2 }) => {
81+
test(`${name} (legacy)`, async () => {
82+
render(
83+
<LegacyFeatureDetails
84+
feature={feature}
85+
input={
86+
{ environment: 'development' } as PlaygroundRequestSchema
87+
}
88+
onClose={() => {}}
89+
/>,
90+
);
91+
92+
await screen.findByText(expectedText1);
93+
await screen.findByText(expectedText2);
94+
});
95+
});
96+
7997
testCases.forEach(({ name, feature, expectedText1, expectedText2 }) => {
8098
test(name, async () => {
8199
render(
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,32 @@
11
import type { PlaygroundFeatureSchema, PlaygroundRequestSchema } from 'openapi';
2-
import { Alert, IconButton, Typography, useTheme, styled } from '@mui/material';
2+
import { Alert, Typography, useTheme, styled, IconButton } from '@mui/material';
33
import { PlaygroundResultChip } from '../../PlaygroundResultChip/PlaygroundResultChip';
44
import CloseOutlined from '@mui/icons-material/CloseOutlined';
55
import type React from 'react';
6-
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
76
import {
87
checkForEmptyValues,
98
hasCustomStrategies,
109
hasOnlyCustomStrategies,
1110
} from './helpers';
1211

13-
const StyledDivWrapper = styled('div')({
12+
const HeaderRow = styled('div')({
1413
display: 'flex',
1514
justifyContent: 'space-between',
1615
width: '100%',
1716
});
1817

19-
const StyledDivTitleRow = styled('div')(({ theme }) => ({
18+
const HeaderGroup = styled('hgroup')(({ theme }) => ({
2019
display: 'inline-flex',
2120
alignItems: 'center',
2221
gap: theme.spacing(1.5),
23-
marginTop: theme.spacing(1.5),
2422
}));
2523

26-
const StyledDivAlertRow = styled('div')(({ theme }) => ({
27-
margin: theme.spacing(1, 0),
24+
const StyledTypographyName = styled('h3')(({ theme }) => ({
25+
fontWeight: 'bold',
26+
fontSize: theme.typography.subtitle1.fontSize,
27+
margin: 0,
2828
}));
2929

30-
const StyledDivDescriptionRow = styled('div')(({ theme }) => ({
31-
margin: theme.spacing(1, 0.5),
32-
}));
33-
34-
const StyledTypographyName = styled(Typography)(({ theme }) => ({
35-
fontWeight: 600,
36-
padding: theme.spacing(0.5),
37-
}));
38-
39-
const StyledIconButton = styled(IconButton)({
40-
textAlign: 'right',
41-
});
42-
4330
interface PlaygroundFeatureResultDetailsProps {
4431
feature: PlaygroundFeatureSchema;
4532
input?: PlaygroundRequestSchema;
@@ -57,7 +44,7 @@ export const FeatureDetails = ({
5744
return [
5845
`This feature flag is True in ${input?.environment} because `,
5946
'at least one strategy is True',
60-
theme.palette.success.main,
47+
theme.palette.success.contrastText,
6148
];
6249

6350
if (
@@ -67,43 +54,43 @@ export const FeatureDetails = ({
6754
return [
6855
`This feature flag is False in ${input?.environment} because `,
6956
'parent dependency is not satisfied and the environment is disabled',
70-
theme.palette.error.main,
57+
theme.palette.error.contrastText,
7158
];
7259
}
7360

7461
if (!feature.isEnabledInCurrentEnvironment)
7562
return [
7663
`This feature flag is False in ${input?.environment} because `,
7764
'the environment is disabled',
78-
theme.palette.error.main,
65+
theme.palette.error.contrastText,
7966
];
8067

8168
if (hasOnlyCustomStrategies(feature))
8269
return [
8370
`This feature flag is Unknown in ${input?.environment} because `,
8471
'no strategies could be fully evaluated',
85-
theme.palette.warning.main,
72+
theme.palette.warning.contrastText,
8673
];
8774

8875
if (hasCustomStrategies(feature))
8976
return [
9077
`This feature flag is Unknown in ${input?.environment} because `,
9178
'not all strategies could be fully evaluated',
92-
theme.palette.warning.main,
79+
theme.palette.warning.contrastText,
9380
];
9481

9582
if (feature.hasUnsatisfiedDependency) {
9683
return [
9784
`This feature flag is False in ${input?.environment} because `,
9885
'parent dependency is not satisfied',
99-
theme.palette.error.main,
86+
theme.palette.error.contrastText,
10087
];
10188
}
10289

10390
return [
10491
`This feature flag is False in ${input?.environment} because `,
10592
'all strategies are either False or could not be fully evaluated',
106-
theme.palette.error.main,
93+
theme.palette.error.contrastText,
10794
];
10895
})();
10996

@@ -124,61 +111,43 @@ export const FeatureDetails = ({
124111

125112
return (
126113
<>
127-
<StyledDivWrapper>
128-
<StyledDivTitleRow>
129-
<StyledTypographyName variant={'subtitle1'}>
130-
{feature.name}
131-
</StyledTypographyName>
132-
<ConditionallyRender
133-
condition={feature?.strategies?.result !== 'unknown'}
134-
show={() => (
114+
<HeaderRow>
115+
<HeaderGroup>
116+
<StyledTypographyName>{feature.name}</StyledTypographyName>
117+
<p>
118+
{feature?.strategies?.result !== 'unknown' ? (
135119
<PlaygroundResultChip
120+
tabindex={-1}
136121
enabled={feature.isEnabled}
137122
label={feature.isEnabled ? 'True' : 'False'}
138123
/>
139-
)}
140-
elseShow={() => (
124+
) : (
141125
<PlaygroundResultChip
126+
tabindex={-1}
142127
enabled='unknown'
143128
label={'Unknown'}
144129
showIcon={false}
145130
/>
146131
)}
147-
/>
148-
</StyledDivTitleRow>
149-
<StyledIconButton onClick={onCloseClick}>
132+
</p>
133+
</HeaderGroup>
134+
<IconButton aria-label='Close' onClick={onCloseClick}>
150135
<CloseOutlined />
151-
</StyledIconButton>
152-
</StyledDivWrapper>
153-
<StyledDivDescriptionRow>
154-
<Typography variant='body1' component='span'>
155-
{description}
156-
</Typography>
157-
<Typography variant='subtitle1' color={color} component='span'>
136+
</IconButton>
137+
</HeaderRow>
138+
<p>
139+
{description}
140+
<Typography color={color} component='span'>
158141
{reason}
159142
</Typography>
160-
<Typography variant='body1' component='span'>
161-
.
162-
</Typography>
163-
</StyledDivDescriptionRow>
164-
<ConditionallyRender
165-
condition={Boolean(noValueTxt)}
166-
show={
167-
<StyledDivAlertRow>
168-
<Alert color={'info'}>{noValueTxt}</Alert>
169-
</StyledDivAlertRow>
170-
}
171-
/>
172-
<ConditionallyRender
173-
condition={Boolean(customStrategiesTxt)}
174-
show={
175-
<StyledDivAlertRow>
176-
<Alert severity='warning' color='info'>
177-
{customStrategiesTxt}
178-
</Alert>
179-
</StyledDivAlertRow>
180-
}
181-
/>
143+
.
144+
</p>
145+
{noValueTxt ? <Alert color={'info'}>{noValueTxt}</Alert> : null}
146+
{customStrategiesTxt ? (
147+
<Alert severity='warning' color='info'>
148+
{customStrategiesTxt}
149+
</Alert>
150+
) : null}
182151
</>
183152
);
184153
};

0 commit comments

Comments
 (0)