Fix: Show moderator edits in creation submissions

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 19:05:35 +00:00
parent 1a60e4b97c
commit 42d938462a
2 changed files with 66 additions and 18 deletions

View File

@@ -157,21 +157,64 @@ export async function detectChanges(
let hasLocationChange = false;
if (action === 'create') {
// For creates, all fields are "added" - be more permissive to show all data
Object.entries(itemData).forEach(([key, value]) => {
// For creates, exclude only system fields and internal metadata
const systemFields = ['id', 'created_at', 'updated_at', 'slug', 'images', 'image_assignments'];
const shouldShow = !systemFields.includes(key) && value !== null && value !== undefined && value !== '';
// Check if this creation was edited by a moderator
const hasModeratorEdits = originalData && Object.keys(originalData).length > 0;
if (hasModeratorEdits) {
// Compare item_data with original_data to detect moderator changes
const allKeys = new Set([
...Object.keys(itemData),
...Object.keys(originalData)
]);
if (shouldShow) {
fieldChanges.push({
field: key,
oldValue: null,
newValue: value,
changeType: 'added',
});
}
});
allKeys.forEach(key => {
if (!shouldTrackField(key)) return;
const oldValue = originalData[key];
const newValue = itemData[key];
// Skip if both are empty
const oldEmpty = oldValue === null || oldValue === undefined || oldValue === '';
const newEmpty = newValue === null || newValue === undefined || newValue === '';
if (oldEmpty && newEmpty) return;
// Detect the type of change
if (!isEqual(oldValue, newValue)) {
fieldChanges.push({
field: key,
oldValue,
newValue,
changeType: oldEmpty && !newEmpty ? 'added' : // Moderator added new field
newEmpty && !oldEmpty ? 'removed' : // Moderator removed field
'modified', // Moderator changed value
});
} else if (!newEmpty) {
// Field unchanged - show as 'added' (part of original submission)
fieldChanges.push({
field: key,
oldValue: null,
newValue,
changeType: 'added',
});
}
});
} else {
// No moderator edits - show all fields as 'added' (original behavior)
Object.entries(itemData).forEach(([key, value]) => {
const systemFields = ['id', 'created_at', 'updated_at', 'slug', 'images', 'image_assignments'];
const shouldShow = !systemFields.includes(key) && value !== null && value !== undefined && value !== '';
if (shouldShow) {
fieldChanges.push({
field: key,
oldValue: null,
newValue: value,
changeType: 'added',
});
}
});
}
} else if (action === 'edit') {
// Compare each field
const allKeys = new Set([