- Added a new skill for managing index and list table layouts in the ERP project, detailing layout and data contracts. - Updated project guidelines to reference the new index layout skill. - Introduced rules for page composition, column definitions, audit fields, action column width, and toolbar functionality. - Created utility functions for computing action column width and formatting audit fields, along with corresponding unit tests to ensure reliability. These changes enhance the application by providing a structured approach to index layouts, improving consistency and usability across the ERP project.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { DateUtils } from '@repo/utils';
|
|
|
|
export const EMPTY_AUDIT_DISPLAY = '-';
|
|
|
|
const AUDIT_TIMESTAMP_FORMAT = 'DD-MM-YYYY, HH:mm';
|
|
|
|
export function resolveAuditValue(
|
|
row: Record<string, unknown> | null | undefined,
|
|
camelKey: string,
|
|
snakeKey: string,
|
|
): unknown {
|
|
if (!row) return undefined;
|
|
const camelValue = row[camelKey];
|
|
if (camelValue !== undefined && camelValue !== null) return camelValue;
|
|
return row[snakeKey];
|
|
}
|
|
|
|
export function formatAuditActor(value: unknown): string {
|
|
if (value === undefined || value === null || value === '') return EMPTY_AUDIT_DISPLAY;
|
|
if (typeof value === 'string') return value;
|
|
if (typeof value === 'object') {
|
|
const actor = value as { username?: unknown; name?: unknown; id?: unknown };
|
|
const label = actor.username ?? actor.name ?? actor.id;
|
|
if (label === undefined || label === null || label === '') return EMPTY_AUDIT_DISPLAY;
|
|
return String(label);
|
|
}
|
|
return String(value);
|
|
}
|
|
|
|
export function formatAuditTimestamp(value: unknown): string {
|
|
if (value === undefined || value === null || value === '') return EMPTY_AUDIT_DISPLAY;
|
|
return new DateUtils(Number(value)).format(AUDIT_TIMESTAMP_FORMAT);
|
|
}
|