mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
refactor: extract add strategy diff (#8877)
This commit is contained in:
parent
0d72cfbba8
commit
6e9b65b09c
@ -284,3 +284,52 @@ test('Deleting strategy after change request is applied diffs against the snapsh
|
||||
await screen.findByText('Deleting strategy variants:');
|
||||
await screen.findByText('snapshot_variant');
|
||||
});
|
||||
|
||||
test('Adding strategy always diffs against undefined strategy', async () => {
|
||||
render(
|
||||
<Routes>
|
||||
<Route
|
||||
path='/projects/:projectId'
|
||||
element={
|
||||
<StrategyChange
|
||||
featureName={feature}
|
||||
environmentName={environmentName}
|
||||
projectId={projectId}
|
||||
changeRequestState='Approved'
|
||||
change={{
|
||||
action: 'addStrategy',
|
||||
id: 1,
|
||||
payload: {
|
||||
...strategy,
|
||||
variants: [
|
||||
{
|
||||
name: 'change_variant',
|
||||
weight: 1000,
|
||||
stickiness: 'default',
|
||||
weightType: 'variable' as const,
|
||||
},
|
||||
],
|
||||
title: 'change_request_title',
|
||||
parameters: {
|
||||
...strategy.parameters,
|
||||
rollout: changeRequestRollout,
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Routes>,
|
||||
{ route: `/projects/${projectId}` },
|
||||
);
|
||||
|
||||
await screen.findByText('+ Adding strategy:');
|
||||
await screen.findByText('change_request_title');
|
||||
|
||||
const viewDiff = await screen.findByText('View Diff');
|
||||
await userEvent.hover(viewDiff);
|
||||
await screen.findByText(`+ name: "flexibleRollout"`);
|
||||
|
||||
await screen.findByText('Setting strategy variants to:');
|
||||
await screen.findByText('change_variant');
|
||||
});
|
||||
|
@ -267,6 +267,56 @@ const UpdateStrategy: FC<{
|
||||
);
|
||||
};
|
||||
|
||||
const AddStrategy: FC<{
|
||||
change: IChangeRequestAddStrategy;
|
||||
actions?: ReactNode;
|
||||
}> = ({ change, actions }) => {
|
||||
return (
|
||||
<>
|
||||
<ChangeItemCreateEditDeleteWrapper>
|
||||
<ChangeItemInfo>
|
||||
<Typography
|
||||
color={
|
||||
change.payload?.disabled
|
||||
? 'action.disabled'
|
||||
: 'success.dark'
|
||||
}
|
||||
>
|
||||
+ Adding strategy:
|
||||
</Typography>
|
||||
<StrategyTooltipLink
|
||||
name={change.payload.name}
|
||||
title={change.payload.title}
|
||||
>
|
||||
<StrategyDiff
|
||||
change={change}
|
||||
currentStrategy={undefined}
|
||||
/>
|
||||
</StrategyTooltipLink>
|
||||
<div>
|
||||
<DisabledEnabledState
|
||||
disabled
|
||||
show={change.payload?.disabled === true}
|
||||
/>
|
||||
</div>
|
||||
</ChangeItemInfo>
|
||||
<div>{actions}</div>
|
||||
</ChangeItemCreateEditDeleteWrapper>
|
||||
<StrategyExecution strategy={change.payload} />
|
||||
{change.payload.variants && change.payload.variants.length > 0 && (
|
||||
<StyledBox>
|
||||
<StyledTypography>
|
||||
Setting strategy variants to:
|
||||
</StyledTypography>
|
||||
<EnvironmentVariantsTable
|
||||
variants={change.payload.variants}
|
||||
/>
|
||||
</StyledBox>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const StrategyChange: FC<{
|
||||
actions?: ReactNode;
|
||||
change:
|
||||
@ -295,49 +345,7 @@ export const StrategyChange: FC<{
|
||||
return (
|
||||
<>
|
||||
{change.action === 'addStrategy' && (
|
||||
<>
|
||||
<ChangeItemCreateEditDeleteWrapper>
|
||||
<ChangeItemInfo>
|
||||
<Typography
|
||||
color={
|
||||
change.payload?.disabled
|
||||
? 'action.disabled'
|
||||
: 'success.dark'
|
||||
}
|
||||
>
|
||||
+ Adding strategy:
|
||||
</Typography>
|
||||
<StrategyTooltipLink
|
||||
name={change.payload.name}
|
||||
title={change.payload.title}
|
||||
>
|
||||
<StrategyDiff
|
||||
change={change}
|
||||
currentStrategy={currentStrategy}
|
||||
/>
|
||||
</StrategyTooltipLink>
|
||||
<div>
|
||||
<DisabledEnabledState
|
||||
disabled
|
||||
show={change.payload?.disabled === true}
|
||||
/>
|
||||
</div>
|
||||
</ChangeItemInfo>
|
||||
<div>{actions}</div>
|
||||
</ChangeItemCreateEditDeleteWrapper>
|
||||
<StrategyExecution strategy={change.payload} />
|
||||
{change.payload.variants &&
|
||||
change.payload.variants.length > 0 && (
|
||||
<StyledBox>
|
||||
<StyledTypography>
|
||||
Setting strategy variants to:
|
||||
</StyledTypography>
|
||||
<EnvironmentVariantsTable
|
||||
variants={change.payload.variants}
|
||||
/>
|
||||
</StyledBox>
|
||||
)}
|
||||
</>
|
||||
<AddStrategy change={change} actions={actions} />
|
||||
)}
|
||||
{change.action === 'deleteStrategy' && (
|
||||
<DeleteStrategy
|
||||
|
Loading…
Reference in New Issue
Block a user