Files
RenewCMS/web/src/lib/activityRetention.ts
T

63 lines
1.8 KiB
TypeScript

import { t } from '@/i18n'
import type { WorkspaceSettings } from '@/composables/useSettings'
import { localDayTime } from '@/lib/activityTime'
export const FOREVER_DAYS = 0
export const SAVED_VISIBLE_MS = 2000
const RANKED_PERIODS = [30, 90, 365, FOREVER_DAYS]
export function retentionOptions() {
return RANKED_PERIODS.map((value) => ({ value, label: periodLabel(value) }))
}
export function periodLabel(days: number) {
switch (days) {
case 30:
return t('30 days')
case 90:
return t('90 days')
case 365:
return t('365 days')
default:
return t('Forever')
}
}
export function periodRank(days: number) {
return RANKED_PERIODS.indexOf(days)
}
export function isShorter(candidate: number, saved: number) {
return periodRank(candidate) < periodRank(saved)
}
export function helperCopy(days: number) {
return days === FOREVER_DAYS
? t('Nothing is removed automatically. The log grows over time.')
: t('Older events are removed automatically.')
}
export function lastCleanupLine(settings: WorkspaceSettings) {
if (!settings.activity_last_cleanup_at) {
return t('Never')
}
const removed = settings.activity_last_cleanup_removed
const count = t(removed === 1 ? '{0} event removed' : '{0} events removed', [removed])
return `${localDayTime(settings.activity_last_cleanup_at)} · ${count}`
}
export function nextCleanupLine(settings: WorkspaceSettings) {
return settings.activity_next_cleanup_at
? localDayTime(settings.activity_next_cleanup_at)
: t('Not scheduled')
}
export function shorteningDescription(settings: WorkspaceSettings) {
return settings.activity_next_cleanup_at
? t("This happens at the next cleanup on {0}. It can't be undone.", [
localDayTime(settings.activity_next_cleanup_at),
])
: t("Older events will be removed at the next cleanup. It can't be undone.")
}