Skip to content

Commit 5a17ea7

Browse files
jhfclaude
andcommitted
fix: Only enable Save on actual image changes, not ephemeral metadata
Metadata (dataSource, editComment, validFrom/validTo) is context for the save, not persisted independently. Save button should only enable when there's a substantive image change (file selected or delete toggled). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8bf04c1 commit 5a17ea7

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

app/src/components/form/editable-image-field-with-metadata.tsx

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,49 +53,24 @@ export const EditableImageFieldWithMetadata = ({
5353
handleCancel: baseHandleCancel,
5454
} = useEditableFieldState(imageId ?? null, response, isEditing, exitEditMode);
5555

56-
// Track initial metadata to detect changes
57-
const initialMetadata = useRef<{
58-
validFrom: string | null | undefined;
59-
validTo: string | null | undefined;
60-
dataSourceId: string | null | undefined;
61-
editComment: string | null | undefined;
62-
} | null>(null);
63-
6456
// Reset local image state when exiting edit mode (success or cancel)
65-
// and capture initial metadata when entering edit mode
6657
const wasEditing = useRef(isEditing);
6758
useGuardedEffect(
6859
() => {
69-
if (!wasEditing.current && isEditing && currentEdit) {
70-
// Entering edit mode: capture initial metadata snapshot
71-
initialMetadata.current = {
72-
validFrom: currentEdit.validFrom,
73-
validTo: currentEdit.validTo,
74-
dataSourceId: currentEdit.dataSourceId ?? null,
75-
editComment: currentEdit.editComment ?? null,
76-
};
77-
}
7860
if (wasEditing.current && !isEditing) {
79-
// Exiting edit mode: reset all state
8061
setSelectedFile(null);
8162
setDeleteImage(false);
8263
setShowResponse(false);
83-
initialMetadata.current = null;
8464
}
8565
wasEditing.current = isEditing;
8666
},
87-
[isEditing, currentEdit],
67+
[isEditing],
8868
"EditableImageFieldWithMetadata:resetOnExitEdit"
8969
);
9070

71+
// Metadata (dataSource, editComment, validFrom/validTo) is ephemeral context
72+
// for the save — only an actual image change (upload or delete) is substantive
9173
const hasImageChanges = selectedFile !== null || deleteImage;
92-
const hasMetadataChanges = initialMetadata.current !== null && currentEdit !== null && (
93-
currentEdit.validFrom !== initialMetadata.current.validFrom ||
94-
currentEdit.validTo !== initialMetadata.current.validTo ||
95-
(currentEdit.dataSourceId ?? null) !== (initialMetadata.current.dataSourceId ?? null) ||
96-
(currentEdit.editComment ?? null) !== (initialMetadata.current.editComment ?? null)
97-
);
98-
const hasChanges = hasImageChanges || hasMetadataChanges;
9974

10075
const handleCancel = () => {
10176
baseHandleCancel();
@@ -231,7 +206,7 @@ export const EditableImageFieldWithMetadata = ({
231206
<Button
232207
type="button"
233208
onClick={triggerFormSubmit}
234-
disabled={!hasChanges}
209+
disabled={!hasImageChanges}
235210
>
236211
{deleteImage ? "Delete" : selectedFile ? "Upload" : "Save"}
237212
</Button>

0 commit comments

Comments
 (0)