import { createListPageModule } from '/js/core/app-list-page-module.js'; import { withCurrentListReturn } from '/js/pages/app-list-utils.js'; createListPageModule({ configId: 'admin-import-audit-index', moduleId: 'admin-import-audit-index', missingGridMessage: 'Import audit grid init failed: Grid.js missing', initErrorMessage: 'Import audit grid init failed', setup: ({ config, gridjs, appBase, initListPage }) => { const labels = config.labels ?? {}; const gridSearch = config.gridSearch ?? null; const filterSchema = config.filterSchema ?? []; const filterChipMeta = config.filterChipMeta ?? []; const profileLabel = (value) => { const key = String(value || '').toLowerCase(); if (key === 'users') { return labels.users || 'Users'; } if (key === 'departments') { return labels.departments || 'Departments'; } return key || '-'; }; const { gridConfig } = initListPage({ grid: { gridjs, container: '#import-audit-grid', dataUrl: 'audit/import-audit/data', appBase, columns: [ { name: labels.created || 'Created', sort: true }, { name: labels.status || 'Status', sort: true, formatter: (cell) => { if (!cell || typeof cell !== 'object') { return gridjs.html('-'); } return gridjs.html(`${cell.label || '-'}`); }, }, { name: labels.profile || 'Profile', sort: true, formatter: (cell) => profileLabel(cell), }, { name: labels.durationMs || 'Duration (ms)', sort: true, formatter: (cell) => (cell > 0 ? `${cell}` : '-') }, { name: labels.rowsTotal || 'Rows total', sort: true }, { name: labels.createdCount || 'Created count', sort: true }, { name: labels.skippedCount || 'Skipped count', sort: true }, { name: labels.failedCount || 'Failed count', sort: true }, { name: labels.user || 'User', sort: false, formatter: (cell) => { if (!cell || typeof cell !== 'object') { return gridjs.html('-'); } const label = cell.label || '-'; if (!cell.uuid) { return gridjs.html(label); } const url = withCurrentListReturn(new URL(`admin/users/edit/${cell.uuid}`, appBase).toString()); return gridjs.html(`${label}`); }, }, { name: 'ID', hidden: true }, ], sortColumns: ['started_at', 'status', 'profile_key', 'duration_ms', 'rows_total', 'created_count', 'skipped_count', 'failed_count', null, null], paginationLimit: 10, language: config.gridLang ?? {}, mapData: (data) => data.data.map((row) => [ row.started_at, { variant: row.status_badge, label: row.status_label || row.status || '' }, row.profile_key, row.duration_ms, row.rows_total, row.created_count, row.skipped_count, row.failed_count, { uuid: row.user_uuid || '', label: row.user_label || '-' }, row.id, ]), rowInteraction: { linkColumn: 2 }, search: gridSearch, filterSchema, urlSync: true, rowDblClick: { getUrl: (rowData) => { const id = rowData?.cells?.[9]?.data; return id ? new URL(`audit/import-audit/view/${id}`, appBase).toString() : ''; }, }, }, filters: { mode: 'drawer', chipMeta: filterChipMeta, watchInputs: ['#import-audit-search'], }, }) || {}; return gridConfig; }, });