Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore segment order in diff calculation #8880

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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>
Expand Down
Loading