Skip to content

Commit 369cc1a

Browse files
committed
fix(validation): sync tracked files after validation
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> (cherry picked from commit 368f6f5) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent ae3341b commit 369cc1a

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/views/Validation.vue

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ import { openDocument } from '../utils/viewer.js'
129129
import { getStatusLabel } from '../utils/fileStatus.js'
130130
import { FILE_STATUS, SIGN_REQUEST_STATUS } from '../constants.js'
131131
import logger from '../logger.js'
132+
import { useFilesStore } from '../store/files.js'
132133
import { useSignStore } from '../store/sign.js'
133134
import { useSidebarStore } from '../store/sidebar.js'
134135
import type {
@@ -289,6 +290,7 @@ function isLoadedValidationFileDocument(document: ValidationFileRecord | null):
289290
290291
const signStore = useSignStore()
291292
const sidebarStore = useSidebarStore()
293+
const filesStore = useFilesStore()
292294
const instance = getCurrentInstance()
293295
const EXPIRATION_WARNING_DAYS = 30
294296
@@ -692,6 +694,57 @@ function setValidationError(message: string, timeout = 5000) {
692694
}
693695
}
694696
697+
function getTrackedFileId(file: ValidationFileRecord | ValidatedChildFileRecord): number | null {
698+
const fileId = toNumber(file.id)
699+
if (fileId !== null && Object.hasOwn(filesStore.files, fileId)) {
700+
return fileId
701+
}
702+
703+
if (typeof file.uuid === 'string' && file.uuid.length > 0) {
704+
const trackedByUuid = toNumber(filesStore.getFileIdByUuid(file.uuid))
705+
if (trackedByUuid !== null) {
706+
return trackedByUuid
707+
}
708+
}
709+
710+
const nodeId = toNumber(file.nodeId)
711+
if (nodeId !== null) {
712+
const trackedByNodeId = toNumber(filesStore.getFileIdByNodeId(nodeId))
713+
if (trackedByNodeId !== null) {
714+
return trackedByNodeId
715+
}
716+
}
717+
718+
return null
719+
}
720+
721+
function syncValidatedDocumentToFilesStore(validationDocument: ValidationFileRecord) {
722+
const pendingFiles: Array<ValidationFileRecord | ValidatedChildFileRecord> = [validationDocument]
723+
724+
while (pendingFiles.length > 0) {
725+
const currentFile = pendingFiles.shift()
726+
if (!currentFile) {
727+
continue
728+
}
729+
730+
const trackedFileId = getTrackedFileId(currentFile)
731+
if (trackedFileId !== null) {
732+
const storeFilePayload = {
733+
...currentFile,
734+
id: trackedFileId,
735+
} as Parameters<typeof filesStore.addFile>[0]
736+
void filesStore.addFile(storeFilePayload, { detailsLoaded: true })
737+
}
738+
739+
const nestedFiles = 'files' in currentFile && Array.isArray(currentFile.files)
740+
? currentFile.files
741+
: []
742+
if (nestedFiles.length > 0) {
743+
pendingFiles.push(...nestedFiles.filter((file): file is ValidatedChildFileRecord => isRecord(file)))
744+
}
745+
}
746+
}
747+
695748
function openUuidDialog() {
696749
validationErrorMessage.value = null
697750
getUUID.value = true
@@ -733,6 +786,9 @@ function handleValidationSuccess(data: unknown) {
733786
&& document.value.files.length > 0
734787
&& document.value.files.every(file => isSignedStatus(file.status))
735788
const signerCompleted = isCurrentSignerSigned()
789+
if (isSignedDoc || allFilesSigned || signerCompleted) {
790+
syncValidatedDocumentToFilesStore(normalizedDocument)
791+
}
736792
if ((isSignedDoc || allFilesSigned || signerCompleted) && (isAfterSigned.value || shouldFireAsyncConfetti.value)) {
737793
const capabilities = getCapabilities() as { libresign?: { config?: Record<string, unknown> } } | undefined
738794
if (capabilities?.libresign?.config?.['show-confetti'] === true) {

0 commit comments

Comments
 (0)