Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Unleash/unleash
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7e5fca71a1fba6e596c3f4d9e7bc94cc1594c760
Choose a base ref
..
head repository: Unleash/unleash
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b1f661c7439103393b0e334e925a7544edf44f94
Choose a head ref
Original file line number Diff line number Diff line change
@@ -333,3 +333,38 @@ test('Adding strategy always diffs against undefined strategy', async () => {
await screen.findByText('Setting strategy variants to:');
await screen.findByText('change_variant');
});

test('Segments order does not matter for diff calculation', async () => {
render(
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Applied'
change={{
action: 'updateStrategy',
id: 1,
payload: {
...strategy,
segments: [3, 2, 1],
snapshot: {
...strategy,
segments: [1, 2, 3],
},
},
}}
/>
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
);

const viewDiff = await screen.findByText('View Diff');
await userEvent.hover(viewDiff);
await screen.findByText('(no changes)');
});
Original file line number Diff line number Diff line change
@@ -28,6 +28,18 @@ const StyledCodeSection = styled('div')(({ theme }) => ({
},
}));

const sortSegments = <T extends { segments?: number[] }>(
item?: T,
): T | undefined => {
if (!item || !item.segments) {
return item;
}
return {
...item,
segments: [...item.segments].sort((a, b) => a - b),
};
};

export const StrategyDiff: FC<{
change:
| IChangeRequestAddStrategy
@@ -38,12 +50,15 @@ export const StrategyDiff: FC<{
const changeRequestStrategy =
change.action === 'deleteStrategy' ? undefined : change.payload;

const sortedCurrentStrategy = sortSegments(currentStrategy);
const sortedChangeRequestStrategy = sortSegments(changeRequestStrategy);

return (
<StyledCodeSection>
<EventDiff
entry={{
preData: omit(currentStrategy, 'sortOrder'),
data: omit(changeRequestStrategy, 'snapshot'),
preData: omit(sortedCurrentStrategy, 'sortOrder'),
data: omit(sortedChangeRequestStrategy, 'snapshot'),
}}
/>
</StyledCodeSection>