fix(ui): remove stale thumbnails in bulkUpload after partial success (#10651)
This commit is contained in:
@@ -264,10 +264,19 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
|
||||
[initializeSharedFormState, hasInitializedState, toggleLoadingOverlay],
|
||||
)
|
||||
|
||||
const removeFile: FormsManagerContext['removeFile'] = React.useCallback((index) => {
|
||||
dispatch({ type: 'REMOVE_FORM', index })
|
||||
const removeThumbnails = React.useCallback((indexes: number[]) => {
|
||||
thumbnailUrlsRef.current = thumbnailUrlsRef.current.filter((_, i) => !indexes.includes(i))
|
||||
setRenderedThumbnails([...thumbnailUrlsRef.current])
|
||||
}, [])
|
||||
|
||||
const removeFile: FormsManagerContext['removeFile'] = React.useCallback(
|
||||
(index) => {
|
||||
dispatch({ type: 'REMOVE_FORM', index })
|
||||
removeThumbnails([index])
|
||||
},
|
||||
[removeThumbnails],
|
||||
)
|
||||
|
||||
const setFormTotalErrorCount: FormsManagerContext['setFormTotalErrorCount'] = React.useCallback(
|
||||
({ errorCount, index }) => {
|
||||
dispatch({
|
||||
@@ -367,7 +376,17 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
|
||||
setLoadingText('')
|
||||
setIsUploading(false)
|
||||
|
||||
const remainingForms = currentForms.filter(({ errorCount }) => errorCount > 0)
|
||||
const remainingForms = []
|
||||
const thumbnailIndexesToRemove = []
|
||||
|
||||
currentForms.forEach(({ errorCount }, i) => {
|
||||
if (errorCount) {
|
||||
remainingForms.push(currentForms[i])
|
||||
} else {
|
||||
thumbnailIndexesToRemove.push(i)
|
||||
}
|
||||
})
|
||||
|
||||
const successCount = Math.max(0, currentForms.length - remainingForms.length)
|
||||
const errorCount = currentForms.length - successCount
|
||||
|
||||
@@ -377,6 +396,10 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
|
||||
if (typeof onSuccess === 'function') {
|
||||
onSuccess(newDocs, errorCount)
|
||||
}
|
||||
|
||||
if (remainingForms.length && thumbnailIndexesToRemove.length) {
|
||||
removeThumbnails(thumbnailIndexesToRemove)
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount) {
|
||||
@@ -398,6 +421,7 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
|
||||
actionURL,
|
||||
activeIndex,
|
||||
forms,
|
||||
removeThumbnails,
|
||||
onSuccess,
|
||||
collectionSlug,
|
||||
getUploadHandler,
|
||||
|
||||
Reference in New Issue
Block a user