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: filter out unchanged taxrates from changed list #1914

Merged
merged 7 commits into from
Sep 19, 2024
20 changes: 14 additions & 6 deletions packages/sync-actions/src/tax-categories-actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deepEqual } from 'fast-equals'
import { buildBaseAttributesActions } from './utils/common-actions'
import createBuildArrayActions, {
ADD_ACTIONS,
Expand Down Expand Up @@ -31,12 +32,19 @@ export function actionsMapRates(diff, oldObj, newObj) {
action: 'removeTaxRate',
taxRateId: objectToRemove.id,
}),
[CHANGE_ACTIONS]: (oldObject, updatedObject) => ({
action: 'replaceTaxRate',
taxRateId:
oldObject.id === updatedObject.id ? oldObject.id : updatedObject.id,
taxRate: updatedObject,
}),
[CHANGE_ACTIONS]: (oldObject, updatedObject) => {
// filter out taxRates that were not changed
// so the API doesn't return it with a different id
const { __typename, ...oldObjectWithoutTypename } = oldObject
if (deepEqual(oldObjectWithoutTypename, updatedObject)) return null

return {
action: 'replaceTaxRate',
taxRateId:
oldObject.id === updatedObject.id ? oldObject.id : updatedObject.id,
taxRate: updatedObject,
}
},
})

return handler(diff, oldObj, newObj)
Expand Down