fix(ui): cascade-remove extracted document attachments when parent is removed (#2432)
When a document (PPTX, DOCX, XLSX, ODP, ODT, ODS) is attached, extracted slide images were left orphaned after removing the parent text entry. This adds a sourceDocumentId field to AttachedFile that links all entries from the same document extraction, and cascades removal of all entries in the group when any one is removed. Fixes #2426 Co-authored-by: chiamsun <chiamsun@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
chiamsun
parent
fe331c093b
commit
2c331e2f8b
@@ -175,6 +175,8 @@ export const useInputStore = create<InputState>()((set, get) => ({
|
||||
if (hasGeneratedFilenameCollision(generatedFilenames, get().attachedFiles)) continue
|
||||
|
||||
const attachedFiles: AttachedFile[] = []
|
||||
const isDocumentExtraction = preparedFiles.length > 1
|
||||
const sourceDocumentId = isDocumentExtraction ? `${Date.now()}-${Math.random().toString(36).slice(2)}` : undefined
|
||||
for (const prepared of preparedFiles) {
|
||||
let dataUrl: string
|
||||
try {
|
||||
@@ -191,6 +193,7 @@ export const useInputStore = create<InputState>()((set, get) => ({
|
||||
filename: prepared.file.name,
|
||||
size: prepared.file.size,
|
||||
source: "local",
|
||||
sourceDocumentId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -202,7 +205,13 @@ export const useInputStore = create<InputState>()((set, get) => ({
|
||||
},
|
||||
|
||||
removeAttachedFile: (id) =>
|
||||
set((s) => ({ attachedFiles: s.attachedFiles.filter((f) => f.id !== id) })),
|
||||
set((s) => {
|
||||
const target = s.attachedFiles.find((f) => f.id === id)
|
||||
if (target?.sourceDocumentId) {
|
||||
return { attachedFiles: s.attachedFiles.filter((f) => f.sourceDocumentId !== target.sourceDocumentId) }
|
||||
}
|
||||
return { attachedFiles: s.attachedFiles.filter((f) => f.id !== id) }
|
||||
}),
|
||||
|
||||
setAttachedFiles: (files) => {
|
||||
attachmentReadGeneration += 1
|
||||
|
||||
Reference in New Issue
Block a user