|
|
|
@ -58,6 +58,52 @@ function formatSingleObjectDiff(
@@ -58,6 +58,52 @@ function formatSingleObjectDiff(
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getPreviousMatch( |
|
|
|
|
prevSubValues: [string, any][] | null, |
|
|
|
|
nextSubProperty: any |
|
|
|
|
): any | undefined { |
|
|
|
|
if (!prevSubValues) { |
|
|
|
|
return undefined; |
|
|
|
|
} |
|
|
|
|
const previousMatch = prevSubValues.find(([subPreviousKey]) => |
|
|
|
|
isEqual(subPreviousKey, nextSubProperty) |
|
|
|
|
); |
|
|
|
|
return previousMatch ? previousMatch[1] : undefined; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getSubPropertiesDiff( |
|
|
|
|
previousValue: Record<string, any> | undefined, |
|
|
|
|
nextValue: Record<string, any> |
|
|
|
|
): Subproperties[] { |
|
|
|
|
const subPropertiesDiff: Subproperties[] = []; |
|
|
|
|
const prevSubValues = previousValue ? Object.entries(previousValue) : null; |
|
|
|
|
let subDiff: Subproperties["subDiff"]; |
|
|
|
|
Object.entries(nextValue).forEach(([nextSubProperty, nextSubValue]) => { |
|
|
|
|
const previousMatch = getPreviousMatch(prevSubValues, nextSubProperty); |
|
|
|
|
if (isObject(nextSubValue)) { |
|
|
|
|
const data: Subproperties[] = getSubPropertiesDiff( |
|
|
|
|
previousMatch, |
|
|
|
|
nextSubValue |
|
|
|
|
); |
|
|
|
|
if (data && data.length > 0) { |
|
|
|
|
subDiff = data; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (previousMatch) { |
|
|
|
|
subPropertiesDiff.push({ |
|
|
|
|
name: nextSubProperty, |
|
|
|
|
previousValue: previousMatch, |
|
|
|
|
currentValue: nextSubValue, |
|
|
|
|
status: isEqual(previousMatch, nextSubValue) |
|
|
|
|
? STATUS.EQUAL |
|
|
|
|
: STATUS.UPDATED, |
|
|
|
|
...(!!subDiff && { subDiff }), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return subPropertiesDiff; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getObjectDiff( |
|
|
|
|
prevData: ObjectData, |
|
|
|
|
nextData: ObjectData |
|
|
|
@ -80,27 +126,10 @@ export function getObjectDiff(
@@ -80,27 +126,10 @@ export function getObjectDiff(
|
|
|
|
|
const previousValue = prevData[nextProperty]; |
|
|
|
|
|
|
|
|
|
if (isObject(nextValue)) { |
|
|
|
|
const prevSubValues = previousValue |
|
|
|
|
? Object.entries(previousValue) |
|
|
|
|
: null; |
|
|
|
|
const subPropertiesDiff: Subproperties[] = []; |
|
|
|
|
Object.entries(nextValue).forEach(([nextSubProperty, nextSubValue]) => { |
|
|
|
|
if (prevSubValues) { |
|
|
|
|
const previousMatch = prevSubValues.find(([subPreviousKey]) => |
|
|
|
|
isEqual(subPreviousKey, nextSubProperty) |
|
|
|
|
); |
|
|
|
|
if (previousMatch) { |
|
|
|
|
subPropertiesDiff.push({ |
|
|
|
|
name: nextSubProperty, |
|
|
|
|
previousValue: previousMatch[1], |
|
|
|
|
currentValue: nextSubValue, |
|
|
|
|
status: isEqual(previousMatch[1], nextSubValue) |
|
|
|
|
? STATUS.EQUAL |
|
|
|
|
: STATUS.UPDATED, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
const subPropertiesDiff: Subproperties[] = getSubPropertiesDiff( |
|
|
|
|
previousValue, |
|
|
|
|
nextValue |
|
|
|
|
); |
|
|
|
|
const _status = subPropertiesDiff.some( |
|
|
|
|
(property) => property.status !== STATUS.EQUAL |
|
|
|
|
) |
|
|
|
|