import { createListPageModule } from '/js/core/app-list-page-module.js';
import { withCurrentListReturn } from '/js/pages/app-list-utils.js';
createListPageModule({
configId: 'admin-system-audit-index',
moduleId: 'admin-system-audit-index',
missingGridMessage: 'System audit grid init failed: Grid.js missing',
initErrorMessage: 'System 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 { gridConfig } = initListPage({
grid: {
gridjs,
container: '#system-audit-grid',
dataUrl: 'audit/system-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.event || 'Event', sort: true },
{ name: labels.channel || 'Channel', sort: true },
{
name: labels.actor || 'Actor',
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: labels.targetType || 'Target type', sort: false },
{
name: labels.requestId || 'Request ID',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`${String(cell).slice(0, 8)}`) : gridjs.html('-')),
},
{
name: labels.errorCode || 'Error code',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`${String(cell)}`) : gridjs.html('-')),
},
{ name: 'ID', hidden: true },
],
sortColumns: ['created_at', 'outcome', 'event_type', 'channel', null, null, null, null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{
variant: row.outcome_badge,
label: String(row.outcome_label || row.outcome || ''),
},
row.event_type,
row.channel,
{
uuid: row.actor_user_uuid || '',
label: row.actor_user_label || '-',
},
row.target_type || '-',
row.request_id || '',
row.error_code || '',
row.id,
]),
rowInteraction: { linkColumn: 2 },
search: gridSearch,
filterSchema,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[8]?.data;
return id ? new URL(`audit/system-audit/view/${id}`, appBase).toString() : '';
},
},
},
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#system-audit-search'],
},
}) || {};
return gridConfig;
},
});