Compare commits
2 Commits
4581fc0b1f
...
74cc4c8722
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74cc4c8722 | ||
|
|
548bc60747 |
@@ -3,6 +3,7 @@ import { onDestroy } from 'svelte';
|
|||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
import ImportStatusCard from './ImportStatusCard.svelte';
|
import ImportStatusCard from './ImportStatusCard.svelte';
|
||||||
import type { ImportStatus } from './types.js';
|
import type { ImportStatus } from './types.js';
|
||||||
|
import { withCsrf } from '$lib/shared/cookies';
|
||||||
|
|
||||||
let backfillResult: number | null = $state(null);
|
let backfillResult: number | null = $state(null);
|
||||||
let backfillLoading = $state(false);
|
let backfillLoading = $state(false);
|
||||||
@@ -61,7 +62,7 @@ async function fetchImportStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function triggerImport() {
|
async function triggerImport() {
|
||||||
const res = await fetch('/api/admin/trigger-import', { method: 'POST' });
|
const res = await fetch('/api/admin/trigger-import', withCsrf({ method: 'POST' }));
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
importStatus = await res.json();
|
importStatus = await res.json();
|
||||||
if (importStatus!.state === 'RUNNING') {
|
if (importStatus!.state === 'RUNNING') {
|
||||||
@@ -83,7 +84,7 @@ async function fetchThumbnailStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function triggerThumbnails() {
|
async function triggerThumbnails() {
|
||||||
const res = await fetch('/api/admin/generate-thumbnails', { method: 'POST' });
|
const res = await fetch('/api/admin/generate-thumbnails', withCsrf({ method: 'POST' }));
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
thumbnailStatus = await res.json();
|
thumbnailStatus = await res.json();
|
||||||
if (thumbnailStatus!.state === 'RUNNING') {
|
if (thumbnailStatus!.state === 'RUNNING') {
|
||||||
@@ -106,7 +107,7 @@ async function backfillVersions() {
|
|||||||
backfillLoading = true;
|
backfillLoading = true;
|
||||||
backfillResult = null;
|
backfillResult = null;
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/admin/backfill-versions', { method: 'POST' });
|
const res = await fetch('/api/admin/backfill-versions', withCsrf({ method: 'POST' }));
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
backfillResult = data.count;
|
backfillResult = data.count;
|
||||||
@@ -120,7 +121,7 @@ async function backfillFileHashes() {
|
|||||||
backfillHashesLoading = true;
|
backfillHashesLoading = true;
|
||||||
backfillHashesResult = null;
|
backfillHashesResult = null;
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/admin/backfill-file-hashes', { method: 'POST' });
|
const res = await fetch('/api/admin/backfill-file-hashes', withCsrf({ method: 'POST' }));
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
backfillHashesResult = data.count;
|
backfillHashesResult = data.count;
|
||||||
|
|||||||
@@ -42,14 +42,9 @@ function reasonLabel(code: string): string {
|
|||||||
aria-label={m.admin_system_import_status_running()}
|
aria-label={m.admin_system_import_status_running()}
|
||||||
class="inline-block h-5 w-5 animate-spin rounded-full border-2 border-ink-3 border-t-brand-mint motion-reduce:animate-none"
|
class="inline-block h-5 w-5 animate-spin rounded-full border-2 border-ink-3 border-t-brand-mint motion-reduce:animate-none"
|
||||||
></span>
|
></span>
|
||||||
<div>
|
<p class="font-sans text-xs font-bold tracking-widest text-ink-3 uppercase">
|
||||||
<p data-testid="processed-count" class="text-base font-bold text-ink">
|
{m.admin_system_import_status_running()}
|
||||||
{importStatus.processed}
|
</p>
|
||||||
</p>
|
|
||||||
<p class="font-sans text-xs font-bold tracking-widest text-ink-3 uppercase">
|
|
||||||
{m.admin_system_import_status_running()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{:else if importStatus?.state === 'DONE'}
|
{:else if importStatus?.state === 'DONE'}
|
||||||
<div class="mb-4 rounded-sm border border-green-200 bg-green-50 p-4 text-green-700">
|
<div class="mb-4 rounded-sm border border-green-200 bg-green-50 p-4 text-green-700">
|
||||||
|
|||||||
@@ -26,15 +26,17 @@ describe('ImportStatusCard', () => {
|
|||||||
await expect.element(getByTestId('spinner')).toBeInTheDocument();
|
await expect.element(getByTestId('spinner')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows processed count at text-base while RUNNING', async () => {
|
it('shows no processed count while RUNNING (spinner only, no misleading 0)', async () => {
|
||||||
|
// The whole document load commits in one transaction, so a live count would sit at 0
|
||||||
|
// until the end. Show just the spinner + "running" label instead of a stuck "0".
|
||||||
const { getByTestId } = render(ImportStatusCard, {
|
const { getByTestId } = render(ImportStatusCard, {
|
||||||
props: {
|
props: {
|
||||||
importStatus: makeStatus({ state: 'RUNNING', statusCode: 'IMPORT_RUNNING', processed: 7 }),
|
importStatus: makeStatus({ state: 'RUNNING', statusCode: 'IMPORT_RUNNING', processed: 0 }),
|
||||||
ontrigger: () => {}
|
ontrigger: () => {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect.element(getByTestId('processed-count')).toHaveTextContent('7');
|
await expect.element(getByTestId('processed-count')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows processed count while DONE', async () => {
|
it('shows processed count while DONE', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user