Skip to content

Commit a14c0cd

Browse files
Merge pull request #455 from AllenInstitute/feature/robust-cache-messages
feature/robust-cache-messages
2 parents 300f2c2 + 5d176a0 commit a14c0cd

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

packages/core/state/interaction/logics.ts

+32-8
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ const copyFilesLogic = createLogic({
616616
return;
617617
}
618618

619-
const successfulFiles: string[] = [];
619+
const newlyCachedFiles: string[] = [];
620+
const extendedExpirationFiles: string[] = [];
620621
const failedFiles: string[] = [];
621622

622623
Object.entries(cacheStatuses).forEach(([fileId, status]) => {
@@ -625,21 +626,44 @@ const copyFilesLogic = createLogic({
625626
status === "DOWNLOAD_IN_PROGRESS" ||
626627
status === "DOWNLOAD_STARTED"
627628
) {
628-
successfulFiles.push(fileId);
629+
const file = fileDetails.find((f) => f.id === fileId);
630+
const isAlreadyCached = file?.annotations.some(
631+
({ name, values }) =>
632+
name === "Should Be in Local Cache" && values[0] === true
633+
);
634+
(isAlreadyCached ? extendedExpirationFiles : newlyCachedFiles).push(fileId);
629635
} else {
630636
failedFiles.push(fileId);
631637
}
632638
});
633639

634-
// Dispatch net success message. (Assuming some files were successful)
635-
if (successfulFiles.length > 0) {
640+
// Dispatch files queued for download
641+
if (newlyCachedFiles.length > 0) {
642+
const count = newlyCachedFiles.length;
643+
const fileLabel = count === 1 ? "file was" : "files were";
636644
dispatch(
637645
interaction.actions.processSuccess(
638646
"moveFilesSuccess",
639-
`${successfulFiles.length} out of ${
640-
Object.keys(cacheStatuses).length
641-
} files were successfully queued for download to NAS (Vast) from cloud.
642-
Files will be available in the NAS after downloads finish asynchronously`
647+
`${count} ${fileLabel} successfully queued for download to NAS (VAST) from the cloud.
648+
${
649+
count === 1 ? "It will be" : "They will be"
650+
} available in the NAS after the download${
651+
count === 1 ? " finishes" : "s finish"
652+
} asynchronously.`
653+
)
654+
);
655+
}
656+
657+
// Dispatch files with extended expiration dates.
658+
if (extendedExpirationFiles.length > 0) {
659+
const count = extendedExpirationFiles.length;
660+
const fileLabel = count === 1 ? "file's" : "files'";
661+
dispatch(
662+
interaction.actions.processSuccess(
663+
"extendFilesExpirationSuccess",
664+
`${count} ${fileLabel} expiration ${
665+
count === 1 ? "date has" : "dates have"
666+
} been extended.`
643667
)
644668
);
645669
}

0 commit comments

Comments
 (0)