mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Deduplicate delivery documents by filename
This commit is contained in:
@@ -189,12 +189,45 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
return;
|
||||
}
|
||||
const documents: File[] = [];
|
||||
const documentNameToIndex = new Map<string, number>();
|
||||
let sequentialDocumentIndex = 0;
|
||||
|
||||
const deliveriesPayload = values.deliveries.map((d) => {
|
||||
let documentIndex = 0;
|
||||
let documentIndex = -1;
|
||||
|
||||
if (d.document && d.document instanceof File) {
|
||||
const fileName = d.document.name;
|
||||
|
||||
if (documentNameToIndex.has(fileName)) {
|
||||
documentIndex = documentNameToIndex.get(fileName)!;
|
||||
} else {
|
||||
documents.push(d.document);
|
||||
documentIndex = documents.length - 1;
|
||||
documentIndex = sequentialDocumentIndex;
|
||||
documentNameToIndex.set(fileName, documentIndex);
|
||||
sequentialDocumentIndex++;
|
||||
}
|
||||
} else if (d.document_path) {
|
||||
const pathFileName =
|
||||
d.document_path.split('/').pop() || d.document_path;
|
||||
|
||||
if (documentNameToIndex.has(pathFileName)) {
|
||||
documentIndex = documentNameToIndex.get(pathFileName)!;
|
||||
} else {
|
||||
documentIndex = sequentialDocumentIndex;
|
||||
documentNameToIndex.set(pathFileName, documentIndex);
|
||||
sequentialDocumentIndex++;
|
||||
}
|
||||
} else if (d.document && !(d.document instanceof File)) {
|
||||
const existingDocFileName =
|
||||
d.document.path.split('/').pop() || d.document.path;
|
||||
|
||||
if (documentNameToIndex.has(existingDocFileName)) {
|
||||
documentIndex = documentNameToIndex.get(existingDocFileName)!;
|
||||
} else {
|
||||
documentIndex = sequentialDocumentIndex;
|
||||
documentNameToIndex.set(existingDocFileName, documentIndex);
|
||||
sequentialDocumentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user