fix: wrap model data in named objects and fix renderGuardMulti empty check

This commit is contained in:
2026-06-23 00:08:40 +00:00
parent b673e87c9b
commit 75aa6fb885
5 changed files with 13 additions and 7 deletions
+2 -2
View File
@@ -93,7 +93,7 @@ modelRegister('nginx', {
fetch: async () => { fetch: async () => {
const r = await apiFetch('/api/proxy/domains'); const r = await apiFetch('/api/proxy/domains');
if (!r.ok) throw new Error(r.error); if (!r.ok) throw new Error(r.error);
return r.data || []; return { domains: r.data || [] };
}, },
}); });
@@ -102,7 +102,7 @@ modelRegister('acme', {
fetch: async () => { fetch: async () => {
const r = await apiFetch('/api/certs/list'); const r = await apiFetch('/api/certs/list');
if (!r.ok) throw new Error(r.error); if (!r.ok) throw new Error(r.error);
return r.data || []; return { certs: r.data || [] };
}, },
}); });
+8 -2
View File
@@ -80,7 +80,7 @@ export function renderGuard(state, title, subtitle, data) {
*/ */
export function renderGuardMulti(title, subtitle, ...models) { export function renderGuardMulti(title, subtitle, ...models) {
const combined = collectLoadingModels(...models); const combined = collectLoadingModels(...models);
return renderGuard(combined, title, subtitle); return renderGuard(combined, title, subtitle, models.map(m => m.data));
} }
/** /**
@@ -90,7 +90,13 @@ export function renderGuardMulti(title, subtitle, ...models) {
*/ */
function isEmpty(data) { function isEmpty(data) {
if (data === null || data === undefined || data === '') return true; if (data === null || data === undefined || data === '') return true;
if (Array.isArray(data)) return data.length === 0; if (Array.isArray(data)) {
// Array of model data values (from renderGuardMulti) — empty only if all models have no data
if (data.length === 0) return true;
return data.every(d => d === null || d === undefined ||
(Array.isArray(d) && d.length === 0) ||
(typeof d === 'object' && Object.keys(d).length === 0));
}
if (typeof data === 'object') return Object.keys(data).length === 0; if (typeof data === 'object') return Object.keys(data).length === 0;
if (typeof data === 'number') return false; if (typeof data === 'number') return false;
return !data; return !data;
+1 -1
View File
@@ -58,7 +58,7 @@ export default definePage({
const guard = renderGuard(state.acme, 'Certificates', 'ACME certificate management', state.acme.data); const guard = renderGuard(state.acme, 'Certificates', 'ACME certificate management', state.acme.data);
if (guard) return guard; if (guard) return guard;
const rows = (state.acme.data || []).map(c => { const rows = (state.acme.data?.certs || []).map(c => {
const badge = certStatusBadge({ expired: c.expired, daysRemaining: c.days_remaining }); const badge = certStatusBadge({ expired: c.expired, daysRemaining: c.days_remaining });
return h('tr', { key: c.domain }, return h('tr', { key: c.domain },
+1 -1
View File
@@ -58,7 +58,7 @@ export default definePage({
const guard = renderGuardMulti('Proxy', 'Nginx reverse proxy', state.nginx, state.acme); const guard = renderGuardMulti('Proxy', 'Nginx reverse proxy', state.nginx, state.acme);
if (guard) return guard; if (guard) return guard;
const domains = state.nginx.data || []; const domains = state.nginx.data.domains || [];
const rows = domains.map(d => { const rows = domains.map(d => {
const certBadge = certStatusBadge({ const certBadge = certStatusBadge({
certStatus: d.cert_status, certStatus: d.cert_status,
+1 -1
View File
@@ -57,7 +57,7 @@ export default definePage({
}; };
}, },
render(state) { render(state) {
const guard = renderGuard(state.wireguard, 'WireGuard', null, state.wireguard.data?.peers); const guard = renderGuard(state.wireguard, 'WireGuard', 'Tunnel & peer management', state.wireguard.data);
if (guard) return guard; if (guard) return guard;
const st = state.wireguard.data?.status || {}; const st = state.wireguard.data?.status || {};