Skip to content

Commit

Permalink
Fix tag error
Browse files Browse the repository at this point in the history
  • Loading branch information
navins94 committed Oct 6, 2023
1 parent bd95b57 commit b930c1e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions frontend/src/modules/flexible-forms/form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function usePrevious(value) {
const getDifferences = (oldObj, newObj) => {
let changes = {}

// Helper function to determine if an object is plain (not an array or null)
const isPlainObject = (obj) =>
obj && typeof obj === 'object' && !Array.isArray(obj)

Expand All @@ -47,16 +46,15 @@ const getDifferences = (oldObj, newObj) => {
changes[key] = nestedChanges
}
} else if (Array.isArray(newObj[key]) && Array.isArray(oldObj[key])) {
// If it's an array, compare the arrays (assumes order matters and items are objects)
for (let i = 0; i < newObj[key].length; i++) {
const arrNestedChanges = getDifferences(oldObj[key][i], newObj[key][i])
if (Object.keys(arrNestedChanges).length) {
if (!changes[key]) changes[key] = []
changes[key][i] = arrNestedChanges
}
}
} else if (oldObj[key] !== newObj[key]) {
changes[key] = newObj[key]
} else if (oldObj?.[key] !== newObj?.[key]) {
changes[key] = newObj?.[key]
}
}

Expand Down

0 comments on commit b930c1e

Please sign in to comment.