refactor(document): move statusDotClass and statusLabel to document domain
These functions describe DocumentStatus display logic (dot colours, readable labels) and belong in the document domain. They were incorrectly placed in personFormat.ts. Moving them to documentStatusLabel.ts removes the person → document dependency and prepares the codebase for the boundaries/dependencies ESLint rule. Refs #410 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { statusDotClass, statusLabel } from '$lib/person/personFormat';
|
import {
|
||||||
|
statusDotClass,
|
||||||
type DocumentStatus = 'PLACEHOLDER' | 'UPLOADED' | 'TRANSCRIBED' | 'REVIEWED' | 'ARCHIVED';
|
statusLabel,
|
||||||
|
type DocumentStatus
|
||||||
|
} from '$lib/document/documentStatusLabel';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
status: DocumentStatus;
|
status: DocumentStatus;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { formatDocumentStatus } from './documentStatusLabel';
|
import { formatDocumentStatus, statusDotClass, statusLabel } from './documentStatusLabel';
|
||||||
|
|
||||||
describe('formatDocumentStatus', () => {
|
describe('formatDocumentStatus', () => {
|
||||||
it('maps PLACEHOLDER to correct label', () => {
|
it('maps PLACEHOLDER to correct label', () => {
|
||||||
@@ -26,3 +26,47 @@ describe('formatDocumentStatus', () => {
|
|||||||
expect(formatDocumentStatus('SOMETHING_NEW')).toBe('Unbekannt');
|
expect(formatDocumentStatus('SOMETHING_NEW')).toBe('Unbekannt');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('statusDotClass', () => {
|
||||||
|
it('PLACEHOLDER → bg-gray-400', () => {
|
||||||
|
expect(statusDotClass('PLACEHOLDER')).toBe('bg-gray-400');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('UPLOADED → bg-emerald-500', () => {
|
||||||
|
expect(statusDotClass('UPLOADED')).toBe('bg-emerald-500');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('TRANSCRIBED → bg-blue-400', () => {
|
||||||
|
expect(statusDotClass('TRANSCRIBED')).toBe('bg-blue-400');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('REVIEWED → bg-amber-400', () => {
|
||||||
|
expect(statusDotClass('REVIEWED')).toBe('bg-amber-400');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ARCHIVED → bg-emerald-600', () => {
|
||||||
|
expect(statusDotClass('ARCHIVED')).toBe('bg-emerald-600');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('statusLabel', () => {
|
||||||
|
it('PLACEHOLDER → "Platzhalter"', () => {
|
||||||
|
expect(statusLabel('PLACEHOLDER')).toBe('Platzhalter');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('UPLOADED → "Hochgeladen"', () => {
|
||||||
|
expect(statusLabel('UPLOADED')).toBe('Hochgeladen');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('TRANSCRIBED → "Transkribiert"', () => {
|
||||||
|
expect(statusLabel('TRANSCRIBED')).toBe('Transkribiert');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('REVIEWED → "Geprüft"', () => {
|
||||||
|
expect(statusLabel('REVIEWED')).toBe('Geprüft');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ARCHIVED → "Archiviert"', () => {
|
||||||
|
expect(statusLabel('ARCHIVED')).toBe('Archiviert');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
|
|
||||||
/**
|
export type DocumentStatus = 'PLACEHOLDER' | 'UPLOADED' | 'TRANSCRIBED' | 'REVIEWED' | 'ARCHIVED';
|
||||||
* Maps a document status string to a localised human-readable label.
|
|
||||||
* Falls back to "Unknown" for unrecognised values.
|
|
||||||
*/
|
|
||||||
export function formatDocumentStatus(status: string): string {
|
export function formatDocumentStatus(status: string): string {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'PLACEHOLDER':
|
case 'PLACEHOLDER':
|
||||||
@@ -20,3 +18,22 @@ export function formatDocumentStatus(status: string): string {
|
|||||||
return m.doc_status_unknown();
|
return m.doc_status_unknown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function statusDotClass(status: DocumentStatus): string {
|
||||||
|
switch (status) {
|
||||||
|
case 'PLACEHOLDER':
|
||||||
|
return 'bg-gray-400';
|
||||||
|
case 'UPLOADED':
|
||||||
|
return 'bg-emerald-500';
|
||||||
|
case 'TRANSCRIBED':
|
||||||
|
return 'bg-blue-400';
|
||||||
|
case 'REVIEWED':
|
||||||
|
return 'bg-amber-400';
|
||||||
|
case 'ARCHIVED':
|
||||||
|
return 'bg-emerald-600';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function statusLabel(status: string): string {
|
||||||
|
return formatDocumentStatus(status);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import {
|
import { getInitials, abbreviateName, formatXsMeta, personAvatarColor } from './personFormat';
|
||||||
getInitials,
|
|
||||||
abbreviateName,
|
|
||||||
formatXsMeta,
|
|
||||||
personAvatarColor,
|
|
||||||
statusDotClass,
|
|
||||||
statusLabel
|
|
||||||
} from './personFormat';
|
|
||||||
import { formatDate } from '$lib/shared/utils/date';
|
import { formatDate } from '$lib/shared/utils/date';
|
||||||
|
|
||||||
// ─── getInitials ─────────────────────────────────────────────────────────────
|
// ─── getInitials ─────────────────────────────────────────────────────────────
|
||||||
@@ -146,51 +139,3 @@ describe('formatDate', () => {
|
|||||||
expect(formatDate('1944-01-01', 'short')).toBe('01.01.1944');
|
expect(formatDate('1944-01-01', 'short')).toBe('01.01.1944');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ─── statusDotClass ──────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('statusDotClass', () => {
|
|
||||||
it('PLACEHOLDER → bg-gray-400', () => {
|
|
||||||
expect(statusDotClass('PLACEHOLDER')).toBe('bg-gray-400');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('UPLOADED → bg-emerald-500', () => {
|
|
||||||
expect(statusDotClass('UPLOADED')).toBe('bg-emerald-500');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('TRANSCRIBED → bg-blue-400', () => {
|
|
||||||
expect(statusDotClass('TRANSCRIBED')).toBe('bg-blue-400');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('REVIEWED → bg-amber-400', () => {
|
|
||||||
expect(statusDotClass('REVIEWED')).toBe('bg-amber-400');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('ARCHIVED → bg-emerald-600', () => {
|
|
||||||
expect(statusDotClass('ARCHIVED')).toBe('bg-emerald-600');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ─── statusLabel ─────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
describe('statusLabel', () => {
|
|
||||||
it('PLACEHOLDER → "Platzhalter"', () => {
|
|
||||||
expect(statusLabel('PLACEHOLDER')).toBe('Platzhalter');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('UPLOADED → "Hochgeladen"', () => {
|
|
||||||
expect(statusLabel('UPLOADED')).toBe('Hochgeladen');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('TRANSCRIBED → "Transkribiert"', () => {
|
|
||||||
expect(statusLabel('TRANSCRIBED')).toBe('Transkribiert');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('REVIEWED → "Geprüft"', () => {
|
|
||||||
expect(statusLabel('REVIEWED')).toBe('Geprüft');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('ARCHIVED → "Archiviert"', () => {
|
|
||||||
expect(statusLabel('ARCHIVED')).toBe('Archiviert');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { formatDocumentStatus } from '$lib/document/documentStatusLabel';
|
|
||||||
import { formatDate } from '$lib/shared/utils/date';
|
import { formatDate } from '$lib/shared/utils/date';
|
||||||
|
|
||||||
type Person = { firstName?: string | null; lastName: string; displayName: string };
|
type Person = { firstName?: string | null; lastName: string; displayName: string };
|
||||||
type DocumentStatus = 'PLACEHOLDER' | 'UPLOADED' | 'TRANSCRIBED' | 'REVIEWED' | 'ARCHIVED';
|
|
||||||
type DocForMeta = {
|
type DocForMeta = {
|
||||||
sender?: Person | null;
|
sender?: Person | null;
|
||||||
receivers?: Person[];
|
receivers?: Person[];
|
||||||
@@ -75,22 +73,3 @@ export function formatXsMeta(doc: DocForMeta): string {
|
|||||||
export function personAvatarColor(personId: string): string {
|
export function personAvatarColor(personId: string): string {
|
||||||
return AVATAR_PALETTE[djb2(personId) % AVATAR_PALETTE.length];
|
return AVATAR_PALETTE[djb2(personId) % AVATAR_PALETTE.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function statusDotClass(status: DocumentStatus): string {
|
|
||||||
switch (status) {
|
|
||||||
case 'PLACEHOLDER':
|
|
||||||
return 'bg-gray-400';
|
|
||||||
case 'UPLOADED':
|
|
||||||
return 'bg-emerald-500';
|
|
||||||
case 'TRANSCRIBED':
|
|
||||||
return 'bg-blue-400';
|
|
||||||
case 'REVIEWED':
|
|
||||||
return 'bg-amber-400';
|
|
||||||
case 'ARCHIVED':
|
|
||||||
return 'bg-emerald-600';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function statusLabel(status: string): string {
|
|
||||||
return formatDocumentStatus(status);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user