Commit e18910f1 authored by Ahmed Awan's avatar Ahmed Awan
Browse files

fix duplicates being pushed to `uploadedDatasets` from upload values

In the case of remote file uploads, for each upload value, we have the entire set of uploads in the `model.outputs` object, which would cause the same dataset to appear multiple times in the `uploadedHistoryItems` object.

For other, non-remote uploads, we typically only have the matching output for the upload value in the `model.outputs` object.
parent 2ccc5851
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -37,10 +37,16 @@ export function monitorUploadedHistoryItems(
        const uploadedDatasets: HistoryItemSummary[] = [];
        uploadValues.value.forEach((model) => {
            const outputs = model.outputs;
            // Some uploads (e.g.: in the case of remote file upload) may have the entire set of uploaded files
            // in the `outputs` object, while typically, the `outputs` object contains each individual upload.
            if (outputs) {
                Object.entries(outputs).forEach((output) => {
                    const outputDetails = output[1] as HistoryItemSummary;
                    // Since there is a possibility of all uploads being in the `outputs` object,
                    // we need to ensure that we only add unique datasets to the list.
                    if (!uploadedDatasets.some((item) => item.id === outputDetails.id)) {
                        uploadedDatasets.push(outputDetails);
                    }
                });
            }
        });