122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
|
|
/**
|
|
* Files browser view-model (AK-P4a §9). Pure function: the loader builds it once
|
|
* server-side, the UI only renders. No React, no Prisma, no app imports
|
|
* (DoD A.3). All texts are i18n keys.
|
|
*
|
|
* URLs (`thumbnailUrl`, `detailHref`) ALWAYS point at the auth-proxy route
|
|
* (AD-23) or internal routes, NEVER at a raw S3 URL — the loader builds them and
|
|
* passes them in here so the VM stays routing-agnostic + pure.
|
|
*/
|
|
export type FilePreviewStatus = "pending" | "generating" | "ready" | "failed" | "not_supported";
|
|
export type FileScanStatus = "pending" | "clean" | "infected" | "skipped";
|
|
export type FileViewMode = "table" | "grid";
|
|
|
|
export interface FileBrowserRow {
|
|
readonly id: string;
|
|
readonly displayName: string;
|
|
readonly mimeType: string;
|
|
readonly sizeBytes: number;
|
|
readonly createdAtIso: string;
|
|
readonly tags: readonly string[];
|
|
readonly source: string;
|
|
readonly previewStatus: FilePreviewStatus;
|
|
readonly scanStatus: FileScanStatus;
|
|
/** Proxy-route URL of the thumbnail (or null while not yet `ready`). */
|
|
readonly thumbnailUrl: string | null;
|
|
/** Internal detail route (e.g. `/acme/files/<id>`). */
|
|
readonly detailHref: string;
|
|
/** Label of the linked target entity (i18n key) or null. */
|
|
readonly linkedEntityLabelKey: string | null;
|
|
}
|
|
|
|
export interface FileBrowserFilterState {
|
|
readonly entityType: string | null;
|
|
readonly mimeGroup: string | null;
|
|
readonly tags: readonly string[];
|
|
readonly assignedToUserId: string | null;
|
|
readonly includeArchived: boolean;
|
|
}
|
|
|
|
export interface FileBrowserData {
|
|
readonly viewMode: FileViewMode;
|
|
readonly rows: readonly FileBrowserRow[];
|
|
readonly filter: FileBrowserFilterState;
|
|
readonly canWrite: boolean;
|
|
readonly canDelete: boolean;
|
|
/** Cursor of the next page (null = last page). */
|
|
readonly nextCursor: string | null;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type FileBrowserVM = VMState<FileBrowserData>;
|
|
|
|
/**
|
|
* Normalized prop-model the UI implementation renders (M015 Subframe-adapter
|
|
* contract). The ui-app adapter maps {@link FileBrowserData} -> this model once,
|
|
* then the ui-subframe / ui-mock renderers stay dumb (hot-swap drill, M017).
|
|
*/
|
|
export interface FileBrowserModelRow {
|
|
readonly id: string;
|
|
readonly displayName: string;
|
|
readonly mimeType: string;
|
|
readonly sizeBytes: number;
|
|
readonly detailHref: string;
|
|
readonly thumbnailUrl: string | null;
|
|
}
|
|
|
|
export interface FileBrowserModel {
|
|
readonly titleKey: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
readonly canWrite: boolean;
|
|
readonly rows: readonly FileBrowserModelRow[];
|
|
readonly rowCount: number;
|
|
}
|
|
|
|
export interface BuildFileBrowserVMInput {
|
|
readonly viewMode?: FileViewMode;
|
|
readonly rows: readonly FileBrowserRow[];
|
|
readonly filter: FileBrowserFilterState;
|
|
readonly canWrite: boolean;
|
|
readonly canDelete: boolean;
|
|
readonly nextCursor?: string | null;
|
|
}
|
|
|
|
export function buildFileBrowserVM(input: BuildFileBrowserVMInput): FileBrowserVM {
|
|
const viewMode: FileViewMode = input.viewMode ?? "table";
|
|
if (input.rows.length === 0) {
|
|
// Empty stays a `ready` state with a plain-text empty state (DoD 23) so the
|
|
// filter/toggle bar and upload CTA remain visible.
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
viewMode,
|
|
rows: [],
|
|
filter: input.filter,
|
|
canWrite: input.canWrite,
|
|
canDelete: input.canDelete,
|
|
nextCursor: null,
|
|
emptyHeadlineKey: "files.browser.empty.headline",
|
|
emptyBodyKey: "files.browser.empty.body",
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
viewMode,
|
|
rows: input.rows,
|
|
filter: input.filter,
|
|
canWrite: input.canWrite,
|
|
canDelete: input.canDelete,
|
|
nextCursor: input.nextCursor ?? null,
|
|
emptyHeadlineKey: "files.browser.empty.headline",
|
|
emptyBodyKey: "files.browser.empty.body",
|
|
},
|
|
};
|
|
}
|