Skip to content

fix(entities-shared) : KM-1029 objectsAreEqual #2056

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

TT1228
Copy link
Contributor

@TT1228 TT1228 commented Mar 25, 2025

Summary

KM-1029

Make sure objectsAreEqual supports comparison of deeply nested objects and arrays.

@TT1228 TT1228 requested review from kongponents-bot and a team as code owners March 25, 2025 06:50
@TT1228 TT1228 changed the title Fix/km 1029 fix(entities-shared) : KM-1029 objectsAreEqual Mar 25, 2025
@kongponents-bot
Copy link
Collaborator

Preview components from this PR in consuming application

In consuming application project install preview versions of shared packages generated by this PR:

@kong-ui-public/dashboard-renderer@pr-2056
@kong-ui-public/documentation@pr-2056
@kong-ui-public/entities-certificates@pr-2056
@kong-ui-public/entities-consumer-credentials@pr-2056
@kong-ui-public/entities-consumer-groups@pr-2056
@kong-ui-public/entities-consumers@pr-2056
@kong-ui-public/entities-data-plane-nodes@pr-2056
@kong-ui-public/entities-gateway-services@pr-2056
@kong-ui-public/entities-key-sets@pr-2056
@kong-ui-public/entities-keys@pr-2056
@kong-ui-public/entities-plugins@pr-2056
@kong-ui-public/entities-redis-configurations@pr-2056
@kong-ui-public/entities-routes@pr-2056
@kong-ui-public/entities-shared@pr-2056
@kong-ui-public/entities-snis@pr-2056
@kong-ui-public/entities-upstreams-targets@pr-2056
@kong-ui-public/entities-vaults@pr-2056
@kong-ui-public/expressions@pr-2056
@kong-ui-public/forms@pr-2056
@kong-ui-public/tracing@pr-2056

Comment on lines +17 to +29
const deepSort = (obj: Record<string, any>): Record<string, any> => {
if (Array.isArray(obj)) {
return sortBy(obj.map(deepSort), (item: any) => JSON.stringify(item))
} else if (isPlainObject(obj)) {
const sortedObj: Record<string, any> = {}
Object.keys(obj)
.sort()
.forEach((key) => {
sortedObj[key] = deepSort(obj[key])
})
return sortedObj
} else {
return obj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suspicious about this sort operation, in my understanding performing deep equal might not need a sort operation prior to comparison 🤔 Can we try a non-intrusive way for performing the comparison here? For instance, we compare the key first, if we found unmatched key, then the object is not equal, then compare the value, recursively perform the operation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, we can compare the keys first and exit early on any mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants