refactor(admin-tenants): simplify list to 2 columns (avatar + name, users)

Reduce tenant grid from 8 columns to 2. Remove status, theme, sso,
active/inactive users, and created columns from the list view.
All details remain accessible on the edit page.

- filter-schema: allow order by description and users only
- data endpoint: return minimal row shape (id, uuid, description,
  status metadata for badge only, is_default, has_avatar, total_users)
- JS grid: 2 visible columns + hidden UUID for navigation
- CSS: add .grid-tenant-profile utility for flex avatar+name layout

Refs: TENANT-LIST-MINIMAL-001
This commit is contained in:
2026-04-22 19:10:48 +02:00
parent d06df56c49
commit 0da785f4b7
5 changed files with 59 additions and 177 deletions

View File

@@ -1,7 +1,6 @@
<?php <?php
use MintyPHP\Domain\Taxonomy\TenantStatus; use MintyPHP\Domain\Taxonomy\TenantStatus;
use MintyPHP\Repository\Tenant\TenantMicrosoftAuthRepository;
use MintyPHP\Service\Access\TenantAuthorizationPolicy; use MintyPHP\Service\Access\TenantAuthorizationPolicy;
use MintyPHP\Support\Guard; use MintyPHP\Support\Guard;
@@ -18,51 +17,23 @@ $filters = gridParseFiltersFromSchemaFile(__DIR__ . '/filter-schema.php');
$order = $filters['order']; $order = $filters['order'];
$dir = $filters['dir']; $dir = $filters['dir'];
$computedOrderKeys = ['theme', 'sso', 'active_users', 'inactive_users']; $computedOrderKeys = ['users'];
$userTenantRepository = app(\MintyPHP\Repository\Tenant\UserTenantRepository::class); $userTenantRepository = app(\MintyPHP\Repository\Tenant\UserTenantRepository::class);
$tenantMicrosoftAuthRepository = app(TenantMicrosoftAuthRepository::class);
$tenantAvatarService = app(\MintyPHP\Service\Tenant\TenantAvatarService::class); $tenantAvatarService = app(\MintyPHP\Service\Tenant\TenantAvatarService::class);
$settingsDefaultsGateway = app(\MintyPHP\Service\Settings\SettingsDefaultsGateway::class); $settingsDefaultsGateway = app(\MintyPHP\Service\Settings\SettingsDefaultsGateway::class);
$settingsAppGateway = app(\MintyPHP\Service\Settings\SettingsAppGateway::class);
$gridUserCountEnricher = app(\MintyPHP\Service\Data\GridUserCountEnricher::class); $gridUserCountEnricher = app(\MintyPHP\Service\Data\GridUserCountEnricher::class);
$fetchRows = static function ( $fetchRows = static function (array $tenantRows) use ($userTenantRepository, $tenantAvatarService, $settingsDefaultsGateway, $gridUserCountEnricher): array {
array $tenantRows,
array $themes,
string $globalDefaultTheme
) use ($userTenantRepository, $tenantMicrosoftAuthRepository, $tenantAvatarService, $settingsDefaultsGateway, $gridUserCountEnricher): array {
$userCounts = $gridUserCountEnricher->computeCounts( $userCounts = $gridUserCountEnricher->computeCounts(
$tenantRows, $tenantRows,
$userTenantRepository->countUsersByTenantIds(...), $userTenantRepository->countUsersByTenantIds(...),
$userTenantRepository->countActiveUsersByTenantIds(...) $userTenantRepository->countActiveUsersByTenantIds(...)
); );
$tenantIds = array_keys($userCounts);
$tenantSsoMap = $tenantMicrosoftAuthRepository->listByTenantIds($tenantIds);
$defaultTenantId = $settingsDefaultsGateway->getDefaultTenantId(); $defaultTenantId = $settingsDefaultsGateway->getDefaultTenantId();
$rows = []; $rows = [];
foreach ($tenantRows as $row) { foreach ($tenantRows as $row) {
$tenantId = (int) ($row['id'] ?? 0); $tenantId = (int) ($row['id'] ?? 0);
$tenantTheme = strtolower(trim((string) ($row['default_theme'] ?? '')));
$themeIsTenantOverride = $tenantTheme !== '' && isset($themes[$tenantTheme]);
$resolvedThemeKey = $themeIsTenantOverride ? $tenantTheme : $globalDefaultTheme;
$resolvedThemeLabel = (string) ($themes[$resolvedThemeKey] ?? ucfirst($resolvedThemeKey));
$themePolicyRaw = $row['allow_user_theme'] ?? null;
$themePolicyMode = 'inherit';
if ($themePolicyRaw !== null && $themePolicyRaw !== '') {
$normalized = strtolower(trim((string) $themePolicyRaw));
if (in_array($normalized, ['1', 'true', 'yes', 'on'], true)) {
$themePolicyMode = 'allow';
} elseif (in_array($normalized, ['0', 'false', 'no', 'off'], true)) {
$themePolicyMode = 'disallow';
}
}
$tenantSso = $tenantSsoMap[$tenantId] ?? null;
$ssoEnabled = !empty($tenantSso['enabled']);
$ssoMicrosoftOnly = $ssoEnabled && !empty($tenantSso['enforce_microsoft_login']);
$counts = $userCounts[$tenantId] ?? ['active_users' => 0, 'inactive_users' => 0]; $counts = $userCounts[$tenantId] ?? ['active_users' => 0, 'inactive_users' => 0];
$tenantStatus = TenantStatus::normalizeOr((string) ($row['status'] ?? ''), TenantStatus::Active); $tenantStatus = TenantStatus::normalizeOr((string) ($row['status'] ?? ''), TenantStatus::Active);
$tenantUuid = (string) ($row['uuid'] ?? ''); $tenantUuid = (string) ($row['uuid'] ?? '');
@@ -75,20 +46,7 @@ $fetchRows = static function (
'status' => $tenantStatus->value, 'status' => $tenantStatus->value,
'status_badge' => $tenantStatus->badgeVariant(), 'status_badge' => $tenantStatus->badgeVariant(),
'status_label' => t($tenantStatus->labelToken()), 'status_label' => t($tenantStatus->labelToken()),
'theme' => [ 'total_users' => $counts['active_users'] + $counts['inactive_users'],
'key' => $resolvedThemeKey,
'label' => t($resolvedThemeLabel),
'is_override' => $themeIsTenantOverride ? 1 : 0,
'policy_mode' => $themePolicyMode,
],
'sso' => [
'enabled' => $ssoEnabled ? 1 : 0,
'microsoft_only' => $ssoMicrosoftOnly ? 1 : 0,
],
'active_users' => $counts['active_users'],
'inactive_users' => $counts['inactive_users'],
'created' => dt($row['created'] ?? ''),
'modified' => dt($row['modified'] ?? ''),
'has_avatar' => $tenantUuid !== '' && $tenantAvatarService->hasAvatar($tenantUuid), 'has_avatar' => $tenantUuid !== '' && $tenantAvatarService->hasAvatar($tenantUuid),
]; ];
} }
@@ -96,13 +54,6 @@ $fetchRows = static function (
return $rows; return $rows;
}; };
$themes = appThemes();
$globalDefaultTheme = $settingsAppGateway->getAppTheme();
if ($globalDefaultTheme === null || !isset($themes[$globalDefaultTheme])) {
$envTheme = strtolower(trim((string) (getenv('APP_THEME') ?: 'light')));
$globalDefaultTheme = isset($themes[$envTheme]) ? $envTheme : 'light';
}
$listOptions = [ $listOptions = [
'limit' => $filters['limit'], 'limit' => $filters['limit'],
'offset' => $filters['offset'], 'offset' => $filters['offset'],
@@ -131,25 +82,10 @@ if (in_array($order, $computedOrderKeys, true)) {
'order' => 'description', 'order' => 'description',
'dir' => 'asc', 'dir' => 'asc',
]); ]);
$rows = $fetchRows($fullResult['rows'] ?? [], $themes, $globalDefaultTheme); $rows = $fetchRows($fullResult['rows'] ?? []);
usort($rows, static function (array $a, array $b) use ($order, $dir): int { usort($rows, static function (array $a, array $b) use ($dir): int {
$valueA = ''; $cmp = ((int) $a['total_users']) <=> ((int) $b['total_users']);
$valueB = '';
if ($order === 'theme') {
$valueA = strtolower((string) ($a['theme']['label'] ?? ''));
$valueB = strtolower((string) ($b['theme']['label'] ?? ''));
} elseif ($order === 'sso') {
$valueA = ((int) $a['sso']['enabled'] * 10) + (int) $a['sso']['microsoft_only'];
$valueB = ((int) $b['sso']['enabled'] * 10) + (int) $b['sso']['microsoft_only'];
} elseif ($order === 'inactive_users') {
$valueA = (int) $a['inactive_users'];
$valueB = (int) $b['inactive_users'];
} else {
$valueA = (int) $a['active_users'];
$valueB = (int) $b['active_users'];
}
$cmp = $valueA <=> $valueB;
if ($cmp === 0) { if ($cmp === 0) {
$cmp = strcasecmp((string) $a['description'], (string) $b['description']); $cmp = strcasecmp((string) $a['description'], (string) $b['description']);
} }
@@ -157,7 +93,7 @@ if (in_array($order, $computedOrderKeys, true)) {
}); });
$rows = array_slice($rows, $filters['offset'], $filters['limit']); $rows = array_slice($rows, $filters['offset'], $filters['limit']);
} else { } else {
$rows = $fetchRows($result['rows'] ?? [], $themes, $globalDefaultTheme); $rows = $fetchRows($result['rows'] ?? []);
} }
gridJsonDataResult($rows, $total); gridJsonDataResult($rows, $total);

View File

@@ -18,7 +18,7 @@ return gridFilterSchema([
'status' => ['type' => 'enum', 'allowed' => TenantStatus::values(), 'default' => '', 'lowercase' => true], 'status' => ['type' => 'enum', 'allowed' => TenantStatus::values(), 'default' => '', 'lowercase' => true],
'order' => [ 'order' => [
'type' => 'order', 'type' => 'order',
'allowed' => ['description', 'status', 'theme', 'sso', 'active_users', 'inactive_users', 'created', 'modified'], 'allowed' => ['description', 'users'],
'default' => 'description', 'default' => 'description',
], ],
'dir' => ['type' => 'dir', 'default' => 'asc'], 'dir' => ['type' => 'dir', 'default' => 'asc'],

View File

@@ -44,17 +44,8 @@ $pageConfig = [
'gridLang' => $gridLang, 'gridLang' => $gridLang,
'labels' => [ 'labels' => [
'avatar' => t('Avatar'), 'avatar' => t('Avatar'),
'description' => t('Description'), 'tenant' => t('Tenant'),
'status' => t('Status'), 'users' => t('Users'),
'theme' => t('Theme'),
'sso' => t('SSO'),
'activeUsers' => t('Active users'),
'inactiveUsers' => t('Inactive users'),
'created' => t('Created'),
'active' => t('Active'),
'default' => t('Default'),
'microsoftOnly' => t('Microsoft only'),
'inactive' => t('Inactive'),
], ],
]; ];
?> ?>

View File

@@ -203,6 +203,21 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.grid-tenant-profile {
display: inline-flex;
align-items: center;
gap: 0.75rem;
min-width: 0;
}
.grid-tenant-profile-name-text {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: 500;
}
.gridjs-loading-bar:after { .gridjs-loading-bar:after {
background-image: linear-gradient( background-image: linear-gradient(
90deg, 90deg,

View File

@@ -1,5 +1,5 @@
import { createListPageModule } from '../core/app-list-page-module.js'; import { createListPageModule } from '../core/app-list-page-module.js';
import { badgeHtml, escapeHtml } from './app-list-utils.js'; import { escapeHtml } from './app-list-utils.js';
createListPageModule({ createListPageModule({
configId: 'admin-tenants-index', configId: 'admin-tenants-index',
@@ -7,54 +7,19 @@ createListPageModule({
missingGridMessage: 'Tenants grid init failed: Grid.js missing', missingGridMessage: 'Tenants grid init failed: Grid.js missing',
initErrorMessage: 'Tenants grid init failed', initErrorMessage: 'Tenants grid init failed',
setup: ({ config, gridjs, appBase, initListPage }) => { setup: ({ config, gridjs, appBase, initListPage }) => {
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? []; const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? []; const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {}; const labels = config.labels ?? {};
const tenantUuidIndex = 8; const tenantUuidIndex = 2;
const tenantDescriptionIndex = 1;
const formatBadge = (value) => badgeHtml(gridjs, value);
const initialsForRow = (row) => { const initialsForRow = (row) => {
const descriptionCell = row?.cells?.[tenantDescriptionIndex]?.data; const descriptionCell = row?.cells?.[0]?.data;
const label = typeof descriptionCell === 'object' && descriptionCell !== null const label = typeof descriptionCell === 'object' && descriptionCell !== null
? String(descriptionCell.label ?? '') ? String(descriptionCell.label ?? '')
: String(descriptionCell ?? ''); : String(descriptionCell ?? '');
const initial = label.trim().charAt(0).toUpperCase(); const initial = label.trim().charAt(0).toUpperCase();
return initial || '?'; return initial || '?';
}; };
const formatStatus = (value) => {
if (!value || typeof value !== 'object') {
return gridjs.html('-');
}
const variant = String(value.variant || 'neutral');
const label = String(value.label || '-');
return gridjs.html(`<span class="badge" data-variant="${variant}">${label}</span>`);
};
const formatTheme = (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
const themeLabel = escapeHtml(cell.label ?? '');
const label = cell.is_override ? themeLabel : `${themeLabel} (${escapeHtml(labels.default || 'Default')})`;
return gridjs.html(label);
};
const formatSso = (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
if (!cell.enabled) {
return gridjs.html(escapeHtml(labels.inactive || 'Inactive'));
}
if (cell.microsoft_only) {
return gridjs.html(escapeHtml(labels.microsoftOnly || 'Microsoft only'));
}
return gridjs.html(escapeHtml(labels.active || 'Active'));
};
const formatCount = (value) => {
const number = Number(value ?? 0);
return Number.isFinite(number) ? number : 0;
};
const { gridConfig } = initListPage({ const { gridConfig } = initListPage({
grid: { grid: {
@@ -64,84 +29,59 @@ createListPageModule({
appBase, appBase,
columns: [ columns: [
{ {
name: labels.avatar || 'Avatar', name: labels.tenant || 'Tenant',
sort: false, sort: true,
width: '75%',
formatter: (cell, row) => { formatter: (cell, row) => {
if (!cell) { const hasAvatar = cell?.has_avatar ? 1 : 0;
const uuid = encodeURIComponent(String(cell?.uuid ?? ''));
let avatarHtml = '';
if (hasAvatar && uuid) {
const src = new URL(`admin/tenants/avatar-file?uuid=${uuid}&size=64`, appBase).toString();
avatarHtml = `<img class="grid-avatar grid-avatar-tenant" src="${src}" alt="" loading="lazy">`;
} else {
const initials = escapeHtml(initialsForRow(row)); const initials = escapeHtml(initialsForRow(row));
return gridjs.html(`<span class="grid-avatar grid-avatar-tenant grid-avatar-placeholder">${initials}</span>`); avatarHtml = `<span class="grid-avatar grid-avatar-tenant grid-avatar-placeholder">${initials}</span>`;
} }
const uuid = encodeURIComponent(String(cell));
const src = new URL(`admin/tenants/avatar-file?uuid=${uuid}&size=64`, appBase).toString(); const nameText = escapeHtml(String(cell?.label ?? ''));
const full = new URL(`admin/tenants/avatar-file?uuid=${uuid}&size=256`, appBase).toString();
return gridjs.html(`<a data-fslightbox="tenant-avatars" href="${full}"><img class="grid-avatar grid-avatar-tenant" src="${src}" alt="" loading="lazy"></a>`); return gridjs.html(
`<div class="grid-tenant-profile">` +
`${avatarHtml}` +
`<span class="grid-tenant-profile-name-text">${nameText}</span>` +
`</div>`
);
}, },
}, },
{ {
name: labels.description || 'Description', name: labels.users || 'Users',
sort: true, sort: true,
width: '25%',
formatter: (cell) => { formatter: (cell) => {
if (!cell || typeof cell !== 'object') { const number = Number(cell ?? 0);
return gridjs.html(escapeHtml(String(cell ?? ''))); return gridjs.html(String(Number.isFinite(number) ? number : 0));
}
const label = escapeHtml(cell.label ?? '');
return gridjs.html(label);
}, },
}, },
{
name: labels.status || 'Status',
sort: false,
formatter: (cell) => formatStatus(cell),
},
{
name: labels.theme || 'Theme',
sort: true,
formatter: (cell) => formatTheme(cell),
},
{
name: labels.sso || 'SSO',
sort: true,
formatter: (cell) => formatSso(cell),
},
{
name: labels.activeUsers || 'Active users',
sort: true,
formatter: (cell) => formatCount(cell),
},
{
name: labels.inactiveUsers || 'Inactive users',
sort: true,
formatter: (cell) => formatCount(cell),
},
{
name: labels.created || 'Created',
sort: true,
formatter: (cell) => formatBadge(cell),
},
{ {
name: 'UUID', name: 'UUID',
hidden: true, hidden: true,
}, },
], ],
sortColumns: [null, 'description', 'status', 'theme', 'sso', 'active_users', 'inactive_users', 'created', null], sortColumns: ['description', 'users', null],
paginationLimit: 10, paginationLimit: 10,
language: config.gridLang ?? {}, language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [ mapData: (data) => data.data.map((row) => [
row.has_avatar ? row.uuid : '',
{ {
label: row.description, uuid: row.uuid ?? '',
is_default: row.is_default ? 1 : 0, label: row.description ?? '',
has_avatar: row.has_avatar ? 1 : 0,
}, },
{ variant: row.status_badge || 'neutral', label: row.status_label || row.status || '-' }, row.total_users ?? 0,
row.theme ?? null,
row.sso ?? null,
row.active_users ?? 0,
row.inactive_users ?? 0,
row.created,
row.uuid, row.uuid,
]), ]),
rowInteraction: { linkColumn: 1 }, rowInteraction: { linkColumn: 0 },
search: gridSearch, search: config.gridSearch ?? null,
filterSchema, filterSchema,
urlSync: true, urlSync: true,
rowDataset: (row) => ({ rowDataset: (row) => ({