refactor(js): migrate audit and addressbook list pages to list factory
This commit is contained in:
@@ -1,77 +1,74 @@
|
||||
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 } from '/js/pages/app-list-utils.js';
|
||||
import { createListPageModule } from '/js/core/app-list-page-module.js';
|
||||
|
||||
const config = readPageConfig('admin-user-lifecycle-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-user-lifecycle-audit-index',
|
||||
moduleId: 'admin-user-lifecycle-audit-index',
|
||||
missingGridMessage: 'User lifecycle audit grid init failed: Grid.js missing',
|
||||
initErrorMessage: 'User lifecycle 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 gridOptions = {
|
||||
gridjs: window.gridjs,
|
||||
container: '#user-lifecycle-audit-grid',
|
||||
dataUrl: 'audit/user-lifecycle-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(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || '-'}</span>`);
|
||||
const { gridConfig } = initListPage({
|
||||
grid: {
|
||||
gridjs,
|
||||
container: '#user-lifecycle-audit-grid',
|
||||
dataUrl: 'audit/user-lifecycle-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(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || '-'}</span>`);
|
||||
},
|
||||
},
|
||||
{ name: labels.action || 'Action', sort: true },
|
||||
{ name: labels.trigger || 'Trigger', sort: true },
|
||||
{ name: labels.targetEmail || 'Target email', sort: false },
|
||||
{ name: labels.targetUuid || 'Target UUID', sort: false },
|
||||
{ name: labels.reasonCode || 'Reason code', sort: false },
|
||||
{ name: labels.restoredAt || 'Restored at', sort: true },
|
||||
{ name: 'ID', hidden: true },
|
||||
],
|
||||
sortColumns: ['created_at', 'status', 'action', 'trigger_type', null, null, null, 'restored_at', null],
|
||||
paginationLimit: 10,
|
||||
language: config.gridLang ?? {},
|
||||
mapData: (data) => data.data.map((row) => [
|
||||
row.created_at,
|
||||
{ variant: row.status_badge, label: row.status_label || row.status || '' },
|
||||
row.action_label || row.action || '-',
|
||||
row.trigger_type_label || row.trigger_type || '-',
|
||||
row.target_user_email || '-',
|
||||
row.target_user_uuid || '-',
|
||||
row.reason_code || '-',
|
||||
row.restored_at || '-',
|
||||
row.id,
|
||||
]),
|
||||
rowInteraction: { linkColumn: 2 },
|
||||
search: gridSearch,
|
||||
filterSchema,
|
||||
urlSync: true,
|
||||
rowDblClick: {
|
||||
getUrl: (rowData) => {
|
||||
const id = rowData?.cells?.[8]?.data;
|
||||
return id ? new URL(`audit/user-lifecycle-audit/view/${id}`, appBase).toString() : '';
|
||||
},
|
||||
},
|
||||
},
|
||||
{ name: labels.action || 'Action', sort: true },
|
||||
{ name: labels.trigger || 'Trigger', sort: true },
|
||||
{ name: labels.targetEmail || 'Target email', sort: false },
|
||||
{ name: labels.targetUuid || 'Target UUID', sort: false },
|
||||
{ name: labels.reasonCode || 'Reason code', sort: false },
|
||||
{ name: labels.restoredAt || 'Restored at', sort: true },
|
||||
{ name: 'ID', hidden: true },
|
||||
],
|
||||
sortColumns: ['created_at', 'status', 'action', 'trigger_type', null, null, null, 'restored_at', null],
|
||||
paginationLimit: 10,
|
||||
language: config.gridLang ?? {},
|
||||
mapData: (data) => data.data.map((row) => [
|
||||
row.created_at,
|
||||
{ variant: row.status_badge, label: row.status_label || row.status || '' },
|
||||
row.action_label || row.action || '-',
|
||||
row.trigger_type_label || row.trigger_type || '-',
|
||||
row.target_user_email || '-',
|
||||
row.target_user_uuid || '-',
|
||||
row.reason_code || '-',
|
||||
row.restored_at || '-',
|
||||
row.id,
|
||||
]),
|
||||
rowInteraction: { linkColumn: 2 },
|
||||
search: gridSearch,
|
||||
filterSchema,
|
||||
urlSync: true,
|
||||
rowDblClick: {
|
||||
getUrl: (rowData) => {
|
||||
const id = rowData?.cells?.[8]?.data;
|
||||
return id ? new URL(`audit/user-lifecycle-audit/view/${id}`, appBase).toString() : '';
|
||||
filters: {
|
||||
mode: 'drawer',
|
||||
chipMeta: filterChipMeta,
|
||||
watchInputs: ['#user-lifecycle-audit-search'],
|
||||
},
|
||||
},
|
||||
};
|
||||
}) || {};
|
||||
|
||||
const { gridConfig } = initStandardListPage({
|
||||
grid: gridOptions,
|
||||
filters: {
|
||||
mode: 'drawer',
|
||||
chipMeta: filterChipMeta,
|
||||
watchInputs: ['#user-lifecycle-audit-search'],
|
||||
},
|
||||
});
|
||||
|
||||
if (!gridConfig || !gridConfig.grid) {
|
||||
warnOnce('UI_INIT_FAIL', 'User lifecycle audit grid init failed', { module: 'admin-user-lifecycle-audit-index', component: 'grid' });
|
||||
}
|
||||
}
|
||||
return gridConfig;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user