Skip to content

Commit

Permalink
feat: visualize feature variants on cr (#4809)
Browse files Browse the repository at this point in the history
Adds a view over feature strategy variants on addStrategy or
editStrategy action
  • Loading branch information
FredrikOseberg authored Sep 22, 2023
1 parent 4f5f1f3 commit cefbf01
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { screen } from '@testing-library/react';

import { Routes, Route } from 'react-router-dom';

import { render } from 'utils/testRenderer';
import { ChangeRequest } from './ChangeRequest';
import {
Expand Down Expand Up @@ -96,3 +99,51 @@ test('Display default disable feature', async () => {
expect(screen.getByText('Disabled')).toBeInTheDocument();
expect(screen.getByText('Feature status will change')).toBeInTheDocument();
});

test('Displays feature strategy variants table', async () => {
render(
<Routes>
<Route
path={'projects/:projectId/features/:featureId/strategies/edit'}
element={
<ChangeRequest
changeRequest={changeRequestWithDefaultChange({
id: 0,
action: 'addStrategy',
payload: {
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '100',
stickiness: 'default',
groupId: 'test123',
},
variants: [
{
name: 'variant1',
stickiness: 'default',
weight: 500,
weightType: 'fix',
},
{
name: 'variant2',
stickiness: 'default',
weight: 500,
weightType: 'fix',
},
],
},
})}
/>
}
/>
</Routes>,
{
route: 'projects/default/features/colors/strategies/edit?environmentId=development&strategyId=2e4f0555-518b-45b3-b0cd-a32cca388a92',
}
);

expect(
screen.getByText('Updating feature variants to:')
).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useCurrentStrategy } from './hooks/useCurrentStrategy';
import { Badge } from 'component/common/Badge/Badge';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { flexRow } from 'themes/themeStyles';
import { EnvironmentVariantsTable } from 'component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsCard/EnvironmentVariantsTable/EnvironmentVariantsTable';

export const ChangeItemWrapper = styled(Box)({
display: 'flex',
Expand All @@ -42,6 +43,14 @@ const ChangeItemInfo: FC = styled(Box)(({ theme }) => ({
gap: theme.spacing(1),
}));

const StyledBox: FC = styled(Box)(({ theme }) => ({
marginTop: theme.spacing(2),
}));

const StyledTypography: FC = styled(Typography)(({ theme }) => ({
margin: `${theme.spacing(1)} 0`,
}));

const hasNameField = (payload: unknown): payload is { name: string } =>
typeof payload === 'object' && payload !== null && 'name' in payload;

Expand Down Expand Up @@ -118,6 +127,19 @@ export const StrategyChange: VFC<{
environmentName
);

const isStrategyAction =
change.action === 'addStrategy' || change.action === 'updateStrategy';

const featureStrategyVariantsDisplay =
isStrategyAction && change.payload.variants ? (
<StyledBox>
<StyledTypography>
Updating feature variants to:
</StyledTypography>
<EnvironmentVariantsTable variants={change.payload.variants} />
</StyledBox>
) : null;

return (
<>
{change.action === 'addStrategy' && (
Expand Down Expand Up @@ -149,6 +171,7 @@ export const StrategyChange: VFC<{
<div>{actions}</div>
</ChangeItemCreateEditWrapper>
<StrategyExecution strategy={change.payload} />
{featureStrategyVariantsDisplay}
</>
)}
{change.action === 'deleteStrategy' && (
Expand Down Expand Up @@ -215,6 +238,7 @@ export const StrategyChange: VFC<{
}
/>
<StrategyExecution strategy={change.payload} />
{featureStrategyVariantsDisplay}
</>
)}
</>
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/component/changeRequest/changeRequest.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ type ChangeRequestEnabled = { enabled: boolean };

type ChangeRequestAddStrategy = Pick<
IFeatureStrategy,
'parameters' | 'constraints' | 'segments' | 'title' | 'disabled'
| 'parameters'
| 'constraints'
| 'segments'
| 'title'
| 'disabled'
| 'variants'
> & { name: string };

type ChangeRequestEditStrategy = ChangeRequestAddStrategy & { id: string };
Expand Down

0 comments on commit cefbf01

Please sign in to comment.