Skip to content

Build your personal knowledge base with Trilium Notes

feat(attachments): mark a scheduled erasure with a badge, not a banner

Elian Doran6af95bb2dc63
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 3f5c2969b5..beb7a8590d 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2228,9 +2228,9 @@
"close": "Close"
},
"attachment_detail_2": {
- "will_be_deleted_in": "This attachment will be automatically deleted in {{time}}",
- "will_be_deleted_soon": "This attachment will be automatically deleted soon",
- "deletion_reason": ", because the attachment is not linked in the note's content. To prevent deletion, add the attachment link back into the content or convert the attachment into note.",
+ "deletion_badge": "Deleted in {{time}}",
+ "deletion_badge_soon": "Deleted soon",
+ "deletion_badge_tooltip": "This attachment will be deleted automatically, because it is not linked in the note's content. To keep it, add the attachment link back into the content or convert the attachment into a note.",
"role_and_size": "Role: {{role}}, size: {{size}}, MIME: {{- mimeType}}",
"link_copied": "Attachment reference copied to clipboard.",
"unrecognized_role": "Unrecognized attachment role '{{role}}'."
diff --git a/apps/client/src/widgets/type_widgets/Attachment.css b/apps/client/src/widgets/type_widgets/Attachment.css
index a8d088463d..d432179ca2 100644
--- a/apps/client/src/widgets/type_widgets/Attachment.css
+++ b/apps/client/src/widgets/type_widgets/Attachment.css
@@ -134,8 +134,17 @@
filter: contrast(10%);
}
-.attachment-detail-wrapper .attachment-deletion-warning {
- margin: 0.5em 0;
+/*
+ * The countdown to an unlinked attachment's erasure. Outlined, like the mark against a system attribute
+ * name, so a list of attachments keeps its rhythm where a banner used to break it — but in the colour the
+ * "Delete attachment" entry gives its own icon, since this is the one badge here reporting a loss to come.
+ */
+.attachment-deletion-badge {
+ --color: var(--dropdown-item-icon-destructive-color);
+ flex-shrink: 0;
+ /* Held against the far end of the row rather than trailing the MIME type, which is as long as the
+ type happens to be — so the badge sits in the same place down a list of attachments. */
+ margin-inline-start: auto;
}
/* #endregion */
diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsx
index c88dec8680..9a828397ce 100644
--- a/apps/client/src/widgets/type_widgets/Attachment.tsx
+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx
@@ -22,7 +22,7 @@ import utils from "../../services/utils";
import ws from "../../services/ws";
import { showImageCompressionDialog } from "../dialogs/image_compression/image_compression_dialog";
import ActionButton from "../react/ActionButton";
-import Admonition from "../react/Admonition";
+import { Badge } from "../react/Badge";
import Button from "../react/Button";
import Dropdown from "../react/Dropdown";
import FormFileUpload from "../react/FormFileUpload";
@@ -276,10 +276,9 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, view
mimeType: attachment.mime
})}
</div>
- <div style="flex: 1 1;" />
+ {scheduledForErasureSince && <DeletionBadge utcDateScheduledForErasureSince={scheduledForErasureSince} />}
</div>
- {scheduledForErasureSince && <DeletionAlert utcDateScheduledForErasureSince={scheduledForErasureSince} />}
{textContent && <TextPreview content={textContent} mime={attachment.mime} />}
{isZoomableImage ? (
<div key="image-viewer" ref={imageViewerWrapper} className="attachment-content-wrapper attachment-image-viewer">
@@ -313,20 +312,31 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, view
);
}
-function DeletionAlert({ utcDateScheduledForErasureSince }: { utcDateScheduledForErasureSince: string }) {
+/**
+ * Marks an attachment the cleanup job has scheduled for erasure, on the row it belongs to rather than in
+ * a block of its own: the countdown is a state the attachment is in, not something to act on right now,
+ * and a banner between the title and the preview pushed every following attachment down the list for it.
+ * What to do about it — link it back, or convert it to a note — is a sentence too long for a pill, so it
+ * goes in the tooltip, next to the two menu entries that carry it out.
+ */
+function DeletionBadge({ utcDateScheduledForErasureSince }: { utcDateScheduledForErasureSince: string }) {
const scheduledSinceTimestamp = utils.parseDate(utcDateScheduledForErasureSince)?.getTime();
// use default value (30 days in seconds) from options_init as fallback, in case getInt returns null
const intervalMs = (options.getInt("eraseUnusedAttachmentsAfterSeconds") || 2592000) * 1000;
- const deletionTimestamp = scheduledSinceTimestamp + intervalMs;
- const willBeDeletedInMs = deletionTimestamp - Date.now();
+ const willBeDeletedInMs = scheduledSinceTimestamp !== undefined
+ ? scheduledSinceTimestamp + intervalMs - Date.now()
+ : undefined;
return (
- <Admonition className="attachment-deletion-warning" type="warning">
- { willBeDeletedInMs >= 60000
- ? t("attachment_detail_2.will_be_deleted_in", { time: utils.formatTimeInterval(willBeDeletedInMs) })
- : t("attachment_detail_2.will_be_deleted_soon")}
- {t("attachment_detail_2.deletion_reason")}
- </Admonition>
+ <Badge
+ outline
+ className="attachment-deletion-badge"
+ icon="bx bx-trash"
+ text={willBeDeletedInMs !== undefined && willBeDeletedInMs >= 60000
+ ? t("attachment_detail_2.deletion_badge", { time: utils.formatTimeInterval(willBeDeletedInMs) })
+ : t("attachment_detail_2.deletion_badge_soon")}
+ tooltip={t("attachment_detail_2.deletion_badge_tooltip")}
+ />
);
}