Skip to content

Commit 7efe5c5

Browse files
chore: implement design for disabled environments in playground (#9544)
Adds the new design for strategy lists in disabled environments. ![image](https://github.com/user-attachments/assets/3d7c4e05-1a49-4a87-a6fa-b7491d86fab2)
1 parent cf1ba8f commit 7efe5c5

File tree

2 files changed

+40
-87
lines changed

2 files changed

+40
-87
lines changed

frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureStrategyList/PlaygroundResultsFeatureStrategyList.tsx

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
1-
import {
2-
PlaygroundResultStrategyLists,
3-
WrappedPlaygroundResultStrategyList,
4-
} from './StrategyList/PlaygroundResultStrategyLists';
1+
import { PlaygroundResultStrategyLists } from './StrategyList/PlaygroundResultStrategyLists';
52
import type { PlaygroundFeatureSchema, PlaygroundRequestSchema } from 'openapi';
6-
import { Alert } from '@mui/material';
3+
import { Alert, styled } from '@mui/material';
4+
import type { FC } from 'react';
75

86
interface PlaygroundResultFeatureStrategyListProps {
97
feature: PlaygroundFeatureSchema;
108
input?: PlaygroundRequestSchema;
119
}
1210

11+
const StyledAlert = styled(Alert)(({ theme }) => ({
12+
marginInline: `var(--popover-inline-padding, ${theme.spacing(4)})`,
13+
}));
14+
15+
const UnevaluatedUnsatisfiedInfo: FC<{ feature: PlaygroundFeatureSchema }> = ({
16+
feature,
17+
}) => {
18+
if (!feature?.strategies?.data) {
19+
return null;
20+
}
21+
22+
let text: string | undefined;
23+
24+
if (
25+
feature.hasUnsatisfiedDependency &&
26+
!feature.isEnabledInCurrentEnvironment
27+
) {
28+
text =
29+
'If the environment was enabled and parent dependencies were satisfied';
30+
} else if (feature.hasUnsatisfiedDependency) {
31+
text = 'If parent dependencies were satisfied';
32+
} else if (!feature.isEnabledInCurrentEnvironment) {
33+
text = 'If the environment was enabled';
34+
} else {
35+
return;
36+
}
37+
38+
return (
39+
<StyledAlert severity={'info'} color={'info'}>
40+
{text}, then this feature flag would be{' '}
41+
{feature.strategies?.result ? 'TRUE' : 'FALSE'} with strategies
42+
evaluated like this:
43+
</StyledAlert>
44+
);
45+
};
46+
1347
export const PlaygroundResultFeatureStrategyList = ({
1448
feature,
1549
input,
@@ -32,21 +66,9 @@ export const PlaygroundResultFeatureStrategyList = ({
3266
);
3367
}
3468

35-
if (
36-
(feature.hasUnsatisfiedDependency ||
37-
!feature.isEnabledInCurrentEnvironment) &&
38-
Boolean(feature?.strategies?.data)
39-
) {
40-
return (
41-
<WrappedPlaygroundResultStrategyList
42-
feature={feature}
43-
input={input}
44-
/>
45-
);
46-
}
47-
4869
return (
4970
<>
71+
<UnevaluatedUnsatisfiedInfo feature={feature} />
5072
<PlaygroundResultStrategyLists
5173
strategies={enabledStrategies || []}
5274
input={input}

frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureStrategyList/StrategyList/PlaygroundResultStrategyLists.tsx

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { Alert, styled } from '@mui/material';
22
import type {
33
PlaygroundStrategySchema,
44
PlaygroundRequestSchema,
5-
PlaygroundFeatureSchema,
65
} from 'openapi';
7-
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
86
import {
97
StyledContentList,
108
StyledListItem,
@@ -96,70 +94,3 @@ export const PlaygroundResultStrategyLists = ({
9694
</div>
9795
);
9896
};
99-
100-
interface IWrappedPlaygroundResultStrategyListProps {
101-
feature: PlaygroundFeatureSchema;
102-
input?: PlaygroundRequestSchema;
103-
}
104-
105-
const resolveHintText = (feature: PlaygroundFeatureSchema) => {
106-
if (
107-
feature.hasUnsatisfiedDependency &&
108-
!feature.isEnabledInCurrentEnvironment
109-
) {
110-
return 'If the environment was enabled and parent dependencies were satisfied';
111-
}
112-
if (feature.hasUnsatisfiedDependency) {
113-
return 'If parent dependencies were satisfied';
114-
}
115-
if (!feature.isEnabledInCurrentEnvironment) {
116-
return 'If the environment was enabled';
117-
}
118-
return '';
119-
};
120-
121-
export const WrappedPlaygroundResultStrategyList = ({
122-
feature,
123-
input,
124-
}: IWrappedPlaygroundResultStrategyListProps) => {
125-
const enabledStrategies = feature.strategies?.data?.filter(
126-
(strategy) => !strategy.disabled,
127-
);
128-
const disabledStrategies = feature.strategies?.data?.filter(
129-
(strategy) => strategy.disabled,
130-
);
131-
132-
const showDisabledStrategies = disabledStrategies?.length > 0;
133-
134-
return (
135-
<StyledAlertWrapper sx={{ pb: 1, mt: 2 }}>
136-
<StyledAlert severity={'info'} color={'warning'}>
137-
{resolveHintText(feature)}, then this feature flag would be{' '}
138-
{feature.strategies?.result ? 'TRUE' : 'FALSE'} with strategies
139-
evaluated like this:{' '}
140-
</StyledAlert>
141-
<StyledListWrapper>
142-
<PlaygroundResultStrategyLists
143-
strategies={enabledStrategies || []}
144-
input={input}
145-
titlePrefix={showDisabledStrategies ? 'Enabled' : undefined}
146-
/>
147-
</StyledListWrapper>
148-
<ConditionallyRender
149-
condition={showDisabledStrategies}
150-
show={
151-
<StyledListWrapper>
152-
<PlaygroundResultStrategyLists
153-
strategies={disabledStrategies}
154-
input={input}
155-
titlePrefix={'Disabled'}
156-
infoText={
157-
'Disabled strategies are not evaluated for the overall result.'
158-
}
159-
/>
160-
</StyledListWrapper>
161-
}
162-
/>
163-
</StyledAlertWrapper>
164-
);
165-
};

0 commit comments

Comments
 (0)