@@ -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