refactor(js): migrate audit and addressbook list pages to list factory
This commit is contained in:
@@ -1,147 +1,141 @@
|
||||
import { initStandardListPage } from '/js/core/app-grid-factory.js';
|
||||
import { readPageConfig } from '/js/core/app-page-config.js';
|
||||
import { warnOnce } from '/js/core/app-dom.js';
|
||||
import { getAppBase, withCurrentListReturn } from '/js/pages/app-list-utils.js';
|
||||
import { createListPageModule } from '/js/core/app-list-page-module.js';
|
||||
import { withCurrentListReturn } from '/js/pages/app-list-utils.js';
|
||||
|
||||
const config = readPageConfig('admin-api-audit-index');
|
||||
if (config) {
|
||||
const appBase = getAppBase();
|
||||
const gridSearch = config.gridSearch ?? null;
|
||||
const filterSchema = config.filterSchema ?? [];
|
||||
const filterChipMeta = config.filterChipMeta ?? [];
|
||||
const labels = config.labels ?? {};
|
||||
createListPageModule({
|
||||
configId: 'admin-api-audit-index',
|
||||
moduleId: 'admin-api-audit-index',
|
||||
missingGridMessage: 'API audit grid init failed: Grid.js missing',
|
||||
initErrorMessage: 'API 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 initApiAuditGrid = () => {
|
||||
const gridOptions = {
|
||||
gridjs: window.gridjs,
|
||||
container: '#api-audit-grid',
|
||||
dataUrl: 'audit/api-audit/data',
|
||||
appBase,
|
||||
columns: [
|
||||
{
|
||||
name: labels.created || 'Created',
|
||||
sort: true,
|
||||
},
|
||||
{
|
||||
name: labels.statusCode || 'Status code',
|
||||
sort: true,
|
||||
formatter: (cell) => {
|
||||
if (!cell || typeof cell !== 'object') {
|
||||
return gridjs.html('');
|
||||
}
|
||||
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || ''}</span>`);
|
||||
const { gridConfig } = initListPage({
|
||||
grid: {
|
||||
gridjs,
|
||||
container: '#api-audit-grid',
|
||||
dataUrl: 'audit/api-audit/data',
|
||||
appBase,
|
||||
columns: [
|
||||
{
|
||||
name: labels.created || 'Created',
|
||||
sort: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: labels.method || 'Method',
|
||||
sort: true,
|
||||
formatter: (cell) => {
|
||||
const method = String(cell || '').toUpperCase();
|
||||
return gridjs.html(`<span class="badge" data-variant="neutral">${method}</span>`);
|
||||
{
|
||||
name: labels.statusCode || 'Status code',
|
||||
sort: true,
|
||||
formatter: (cell) => {
|
||||
if (!cell || typeof cell !== 'object') {
|
||||
return gridjs.html('');
|
||||
}
|
||||
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || ''}</span>`);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: labels.path || 'Path',
|
||||
sort: true,
|
||||
},
|
||||
{
|
||||
name: labels.durationMs || 'Duration (ms)',
|
||||
sort: true,
|
||||
formatter: (cell) => (cell > 0 ? `${cell}` : '-'),
|
||||
},
|
||||
{
|
||||
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(`<a href="${url}">${label}</a>`);
|
||||
{
|
||||
name: labels.method || 'Method',
|
||||
sort: true,
|
||||
formatter: (cell) => {
|
||||
const method = String(cell || '').toUpperCase();
|
||||
return gridjs.html(`<span class="badge" data-variant="neutral">${method}</span>`);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: labels.tenant || 'Tenant',
|
||||
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/tenants/edit/${cell.uuid}`, appBase).toString());
|
||||
return gridjs.html(`<a href="${url}">${label}</a>`);
|
||||
{
|
||||
name: labels.path || 'Path',
|
||||
sort: true,
|
||||
},
|
||||
{
|
||||
name: labels.durationMs || 'Duration (ms)',
|
||||
sort: true,
|
||||
formatter: (cell) => (cell > 0 ? `${cell}` : '-'),
|
||||
},
|
||||
{
|
||||
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(`<a href="${url}">${label}</a>`);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: labels.tenant || 'Tenant',
|
||||
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/tenants/edit/${cell.uuid}`, appBase).toString());
|
||||
return gridjs.html(`<a href="${url}">${label}</a>`);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: labels.errorCode || 'Error code',
|
||||
sort: false,
|
||||
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')),
|
||||
},
|
||||
{
|
||||
name: labels.ip || 'IP hash',
|
||||
sort: false,
|
||||
},
|
||||
{
|
||||
name: 'ID',
|
||||
hidden: true,
|
||||
},
|
||||
],
|
||||
sortColumns: ['created_at', 'status_code', 'method', 'path', 'duration_ms', null, null, null, null, null],
|
||||
paginationLimit: 10,
|
||||
language: config.gridLang ?? {},
|
||||
mapData: (data) => data.data.map((row) => [
|
||||
row.created_at,
|
||||
{
|
||||
variant: row.status_badge,
|
||||
label: String(row.status_code || ''),
|
||||
},
|
||||
row.method,
|
||||
row.path,
|
||||
row.duration_ms,
|
||||
{
|
||||
uuid: row.user_uuid || '',
|
||||
label: row.user_label || '-',
|
||||
},
|
||||
{
|
||||
uuid: row.tenant_uuid || '',
|
||||
label: row.tenant_label || '-',
|
||||
},
|
||||
row.error_code || '',
|
||||
row.ip_hash || '',
|
||||
row.id,
|
||||
]),
|
||||
rowInteraction: { linkColumn: 3 },
|
||||
search: gridSearch,
|
||||
filterSchema,
|
||||
urlSync: true,
|
||||
rowDblClick: {
|
||||
getUrl: (rowData) => {
|
||||
const id = rowData?.cells?.[9]?.data;
|
||||
return id ? new URL(`audit/api-audit/view/${id}`, appBase).toString() : '';
|
||||
},
|
||||
},
|
||||
{
|
||||
name: labels.errorCode || 'Error code',
|
||||
sort: false,
|
||||
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')),
|
||||
},
|
||||
{
|
||||
name: labels.ip || 'IP hash',
|
||||
sort: false,
|
||||
},
|
||||
{
|
||||
name: 'ID',
|
||||
hidden: true,
|
||||
},
|
||||
],
|
||||
sortColumns: ['created_at', 'status_code', 'method', 'path', 'duration_ms', null, null, null, null, null],
|
||||
paginationLimit: 10,
|
||||
language: config.gridLang ?? {},
|
||||
mapData: (data) => data.data.map((row) => [
|
||||
row.created_at,
|
||||
{
|
||||
variant: row.status_badge,
|
||||
label: String(row.status_code || ''),
|
||||
},
|
||||
row.method,
|
||||
row.path,
|
||||
row.duration_ms,
|
||||
{
|
||||
uuid: row.user_uuid || '',
|
||||
label: row.user_label || '-',
|
||||
},
|
||||
{
|
||||
uuid: row.tenant_uuid || '',
|
||||
label: row.tenant_label || '-',
|
||||
},
|
||||
row.error_code || '',
|
||||
row.ip_hash || '',
|
||||
row.id,
|
||||
]),
|
||||
rowInteraction: { linkColumn: 3 },
|
||||
search: gridSearch,
|
||||
filterSchema,
|
||||
urlSync: true,
|
||||
rowDblClick: {
|
||||
getUrl: (rowData) => {
|
||||
const id = rowData?.cells?.[9]?.data;
|
||||
return id ? new URL(`audit/api-audit/view/${id}`, appBase).toString() : '';
|
||||
},
|
||||
},
|
||||
};
|
||||
const { gridConfig } = initStandardListPage({
|
||||
grid: gridOptions,
|
||||
filters: {
|
||||
mode: 'drawer',
|
||||
chipMeta: filterChipMeta,
|
||||
watchInputs: ['#api-audit-search'],
|
||||
},
|
||||
});
|
||||
if (!gridConfig || !gridConfig.grid) {
|
||||
warnOnce('UI_INIT_FAIL', 'API audit grid init failed', { module: 'admin-api-audit-index', component: 'grid' });
|
||||
return null;
|
||||
}
|
||||
return gridConfig;
|
||||
};
|
||||
}) || {};
|
||||
|
||||
initApiAuditGrid();
|
||||
}
|
||||
return gridConfig;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user