-
Notifications
You must be signed in to change notification settings - Fork 84
fix: normalization merging [ENG-2171] #7078
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
96c8406 to
648ea66
Compare
648ea66 to
d243498
Compare
Greptile OverviewGreptile SummaryThis PR partially rolls back the data normalization feature to fix data update issues in the Action Center fields view. The changes address a mutable Map object mutation bug by adding Key changes:
Trade-offs:
Confidence Score: 4/5
Important Files ChangedFile Analysis
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 2 comments
...-ui/src/features/data-discovery-and-detection/action-center/fields/useNormalizedResources.ts
Outdated
Show resolved
Hide resolved
| _.chain(prev.get(key)).defaultTo(node).merge(node).value(), | ||
| _.chain(prev.get(key)) | ||
| .defaultTo(node) | ||
| .cloneDeep() /** This is needed since we aren't using immutable Maps (yet), and would otherwise mutate referenced objects */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maps use mutable refs.
This can cause lots of issues and is why I typically avoid them but here we are.
Cloning the referenced data before merging leaves the initial value as it should be.
| _.chain(prev.get(key)) | ||
| .defaultTo(node) | ||
| .cloneDeep() /** This is needed since we aren't using immutable Maps (yet), and would otherwise mutate referenced objects */ | ||
| .merge(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lodash merge does not do exactly what we want and would need to be replaced with a mergeWith fn in the future.
This works fine for the current implementation.
...-ui/src/features/data-discovery-and-detection/action-center/fields/useNormalizedResources.ts
Outdated
Show resolved
Hide resolved
fix: normalization merging fix: tests and expected behavior revert: changing from data to currentData
d243498 to
15164b1
Compare
| ]); | ||
| }); | ||
|
|
||
| it("should not mutate data references", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only tests that we are not mutating the refs internally.
Ideally, we should have immutable values when dealing with maps externally but this will most likely require a library.
| const { | ||
| listQuery: { nodes: listNodes, ...listQueryMeta }, | ||
| detailsQuery: { node: resource }, | ||
| detailsQuery: { data: resource }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on the query directly since we aren't updating the node values with the details query.
| .value(); | ||
|
|
||
| const useNodeMap = <Data>( | ||
| initialData?: NodeMap<Data>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing initial data since it's not necessary at the moment + introduces another vector for mutability issues
...-ui/src/features/data-discovery-and-detection/action-center/fields/useNormalizedResources.ts
Outdated
Show resolved
Hide resolved
…ion-center/fields/useNormalizedResources.ts Co-authored-by: Jason Gill <jason.gill@ethyca.com>
Co-authored-by: Jason Gill <jason.gill@ethyca.com>
Ticket ENG-2171
Description Of Changes
Partial rollback of data normalization to fix data updates.
Code Changes
Steps to Confirm
Pre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works