feat: enhance backup status display and tracking
Added a visual indicator for backups saved today in the admin interface. Updated the backup status type to include a boolean for today's backup existence, and modified relevant components to reflect this change. Enhanced tests to verify the new functionality.
This commit is contained in:
1 parent
747e6e25e0
commit
bf661673c9
6 files changed
+71
-7
No files matched your search
@@ -1248,6 +1248,35 @@ article.shift-card {
|
|||||||
line-height: 1.45;
|
line-height: 1.45;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.desk-note.is-saved {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
min-height: 1.5rem;
|
||||||
|
padding: 0.28rem 0.7rem 0.28rem 0.5rem;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e4edf5;
|
||||||
|
box-shadow: none;
|
||||||
|
color: #4a5563;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desk-note-check {
|
||||||
|
width: 0.8rem;
|
||||||
|
height: 0.8rem;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desk-note-check path {
|
||||||
|
fill: none;
|
||||||
|
stroke: #3b8950;
|
||||||
|
stroke-width: 1.75;
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
|
||||||
.event-dialog {
|
.event-dialog {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: none;
|
max-width: none;
|
||||||
|
|||||||
@@ -301,6 +301,7 @@ function showHome(
|
|||||||
exportError={exportError}
|
exportError={exportError}
|
||||||
backupNote={backup.text}
|
backupNote={backup.text}
|
||||||
backupState={backup.state}
|
backupState={backup.state}
|
||||||
|
backupSavedToday={backup.savedToday}
|
||||||
newEvent={newEvent}
|
newEvent={newEvent}
|
||||||
/>,
|
/>,
|
||||||
{ account: session, status },
|
{ account: session, status },
|
||||||
|
|||||||
+14
-2
@@ -169,6 +169,7 @@ export function AdminHome(props: {
|
|||||||
exportError?: string;
|
exportError?: string;
|
||||||
backupNote: string;
|
backupNote: string;
|
||||||
backupState: 'saved' | 'waiting' | 'behind';
|
backupState: 'saved' | 'waiting' | 'behind';
|
||||||
|
backupSavedToday: boolean;
|
||||||
newEvent?: { values: EventValues; error?: string };
|
newEvent?: { values: EventValues; error?: string };
|
||||||
}) {
|
}) {
|
||||||
const draft = props.newEvent?.values ?? {
|
const draft = props.newEvent?.values ?? {
|
||||||
@@ -186,8 +187,8 @@ export function AdminHome(props: {
|
|||||||
<p class="desk-signed">
|
<p class="desk-signed">
|
||||||
Signed in as <strong>{props.name}</strong>.
|
Signed in as <strong>{props.name}</strong>.
|
||||||
</p>
|
</p>
|
||||||
<p class="desk-note">
|
<p class={props.backupSavedToday ? 'desk-note is-saved' : 'desk-note'}>
|
||||||
<BackupNote text={props.backupNote} />
|
{props.backupSavedToday ? <BackupSavedToday /> : <BackupNote text={props.backupNote} />}
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
<Notice notice={props.notice} />
|
<Notice notice={props.notice} />
|
||||||
@@ -1550,6 +1551,17 @@ function LoginForm(props: { config: AppConfig; error?: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function BackupSavedToday() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<svg class="desk-note-check" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M3.2 8.4 6.4 11.5 12.8 4.8" />
|
||||||
|
</svg>
|
||||||
|
Backup saved today
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function BackupNote(props: { text: string }) {
|
function BackupNote(props: { text: string }) {
|
||||||
const match = /^(.*?)([A-Z][a-z]+ \d{1,2}, \d{4})(.*)$/.exec(props.text);
|
const match = /^(.*?)([A-Z][a-z]+ \d{1,2}, \d{4})(.*)$/.exec(props.text);
|
||||||
if (!match) return <>{props.text}</>;
|
if (!match) return <>{props.text}</>;
|
||||||
|
|||||||
+5
-3
@@ -48,6 +48,8 @@ export type BackupResult = {
|
|||||||
export type BackupStatus = {
|
export type BackupStatus = {
|
||||||
state: 'saved' | 'waiting' | 'behind';
|
state: 'saved' | 'waiting' | 'behind';
|
||||||
text: string;
|
text: string;
|
||||||
|
/** True only when a daily copy exists for today's Central Time date. */
|
||||||
|
savedToday: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,13 +96,13 @@ export function describeBackup(backupsDir: string, now: string): BackupStatus {
|
|||||||
const clock = formatInstantInZone(now, BACKUP_ZONE);
|
const clock = formatInstantInZone(now, BACKUP_ZONE);
|
||||||
if (!newest) {
|
if (!newest) {
|
||||||
const state = clock.time24 < BACKUP_LOCAL_TIME ? 'waiting' : 'behind';
|
const state = clock.time24 < BACKUP_LOCAL_TIME ? 'waiting' : 'behind';
|
||||||
return { state, text: 'No database backup has been saved yet.' };
|
return { state, text: 'No database backup has been saved yet.', savedToday: false };
|
||||||
}
|
}
|
||||||
const label = prettyDate(newest);
|
const label = prettyDate(newest);
|
||||||
const savedToday = newest >= clock.date;
|
const savedToday = newest >= clock.date;
|
||||||
const savedYesterday = newest >= previousDate(clock.date) && clock.time24 < BACKUP_LOCAL_TIME;
|
const savedYesterday = newest >= previousDate(clock.date) && clock.time24 < BACKUP_LOCAL_TIME;
|
||||||
if (savedToday || savedYesterday) return { state: 'saved', text: `Database backup saved ${label}.` };
|
if (savedToday || savedYesterday) return { state: 'saved', text: `Database backup saved ${label}.`, savedToday };
|
||||||
return { state: 'behind', text: `Database backup is behind. The newest saved copy is ${label}.` };
|
return { state: 'behind', text: `Database backup is behind. The newest saved copy is ${label}.`, savedToday: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startBackupRunner(
|
export function startBackupRunner(
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,5 @@
|
|||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
import { mkdtempSync, rmSync } from 'node:fs';
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { afterEach, describe, expect, it } from 'vitest';
|
import { afterEach, describe, expect, it } from 'vitest';
|
||||||
@@ -97,6 +97,18 @@ describe('coordinator sign-in', () => {
|
|||||||
expect(homeHtml).not.toContain('coordinator@example.invalid');
|
expect(homeHtml).not.toContain('coordinator@example.invalid');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows a backup from today as a short status tag', async () => {
|
||||||
|
const { app, db, config } = await buildApp();
|
||||||
|
mkdirSync(path.join(config.dataDir, 'backups'), { recursive: true });
|
||||||
|
writeFileSync(path.join(config.dataDir, 'backups', 'daily-2026-10-14.db'), '');
|
||||||
|
const cookie = await signIn(app, db);
|
||||||
|
const home = await app.request('/admin', { headers: { cookie } });
|
||||||
|
const homeHtml = await home.text();
|
||||||
|
expect(homeHtml).toContain('class="desk-note is-saved"');
|
||||||
|
expect(homeHtml).toContain('Backup saved today');
|
||||||
|
expect(homeHtml).not.toContain('Database backup saved');
|
||||||
|
});
|
||||||
|
|
||||||
it('still accepts a valid link after other guesses from the same network', async () => {
|
it('still accepts a valid link after other guesses from the same network', async () => {
|
||||||
const { app, db } = await buildApp();
|
const { app, db } = await buildApp();
|
||||||
await postLogin(app, 'coordinator@example.invalid');
|
await postLogin(app, 'coordinator@example.invalid');
|
||||||
|
|||||||
@@ -137,21 +137,29 @@ describe('daily database backup', () => {
|
|||||||
expect(describeBackup(root, early)).toEqual({
|
expect(describeBackup(root, early)).toEqual({
|
||||||
state: 'waiting',
|
state: 'waiting',
|
||||||
text: 'No database backup has been saved yet.',
|
text: 'No database backup has been saved yet.',
|
||||||
|
savedToday: false,
|
||||||
});
|
});
|
||||||
expect(describeBackup(root, due)).toEqual({
|
expect(describeBackup(root, due)).toEqual({
|
||||||
state: 'behind',
|
state: 'behind',
|
||||||
text: 'No database backup has been saved yet.',
|
text: 'No database backup has been saved yet.',
|
||||||
|
savedToday: false,
|
||||||
});
|
});
|
||||||
writeFileSync(path.join(root, 'daily-2026-06-14.db'), '');
|
writeFileSync(path.join(root, 'daily-2026-06-14.db'), '');
|
||||||
expect(describeBackup(root, early).text).toBe('Database backup saved June 14, 2026.');
|
expect(describeBackup(root, early)).toEqual({
|
||||||
|
state: 'saved',
|
||||||
|
text: 'Database backup saved June 14, 2026.',
|
||||||
|
savedToday: false,
|
||||||
|
});
|
||||||
expect(describeBackup(root, due)).toEqual({
|
expect(describeBackup(root, due)).toEqual({
|
||||||
state: 'behind',
|
state: 'behind',
|
||||||
text: 'Database backup is behind. The newest saved copy is June 14, 2026.',
|
text: 'Database backup is behind. The newest saved copy is June 14, 2026.',
|
||||||
|
savedToday: false,
|
||||||
});
|
});
|
||||||
writeFileSync(path.join(root, 'daily-2026-06-15.db'), '');
|
writeFileSync(path.join(root, 'daily-2026-06-15.db'), '');
|
||||||
expect(describeBackup(root, due)).toEqual({
|
expect(describeBackup(root, due)).toEqual({
|
||||||
state: 'saved',
|
state: 'saved',
|
||||||
text: 'Database backup saved June 15, 2026.',
|
text: 'Database backup saved June 15, 2026.',
|
||||||
|
savedToday: true,
|
||||||
});
|
});
|
||||||
expect(JSON.stringify(describeBackup(root, due))).not.toContain('/');
|
expect(JSON.stringify(describeBackup(root, due))).not.toContain('/');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user