feat: remove diff
This commit is contained in:
@@ -112,57 +112,3 @@ export const sortComparator = (a, b, sortKey) => {
|
||||
SORT_OPTIONS[sortKey] || SORT_OPTIONS.last_activity_at_desc;
|
||||
return sortConfig[sortMethod](a, b, sortDirection);
|
||||
};
|
||||
|
||||
export const deepObjectDiff = (original, updated, maxDepth = 3) => {
|
||||
const changes = {
|
||||
added: {},
|
||||
removed: {},
|
||||
modified: {},
|
||||
};
|
||||
|
||||
function isObject(item) {
|
||||
return item && typeof item === 'object' && !Array.isArray(item);
|
||||
}
|
||||
|
||||
function compareObjects(orig, upd, path = '', depth = 1) {
|
||||
if (depth > maxDepth) {
|
||||
if (JSON.stringify(orig) !== JSON.stringify(upd)) {
|
||||
changes.modified[path] = { from: orig, to: upd };
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all keys from both objects
|
||||
const allKeys = [...new Set([...Object.keys(orig), ...Object.keys(upd)])];
|
||||
|
||||
allKeys.forEach(key => {
|
||||
const currentPath = path ? `${path}.${key}` : key;
|
||||
|
||||
// Handle removed properties
|
||||
if (!Object.keys(upd).includes(key)) {
|
||||
changes.removed[currentPath] = orig[key];
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle added properties
|
||||
if (!Object.keys(orig).includes(key)) {
|
||||
changes.added[currentPath] = upd[key];
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle nested objects
|
||||
if (isObject(orig[key]) && isObject(upd[key])) {
|
||||
compareObjects(orig[key], upd[key], currentPath, depth + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle modified values
|
||||
if (JSON.stringify(orig[key]) !== JSON.stringify(upd[key])) {
|
||||
changes.modified[currentPath] = { from: orig[key], to: upd[key] };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
compareObjects(original, updated);
|
||||
return changes;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user