Upgrade plugin system: lifecycle hooks, dependency checks, enabled gating
Local Build and Deploy / deploy (push) Failing after 48s
Local Build and Deploy / deploy (push) Failing after 48s
- PluginDefinition: add license, homepage, dependencies, onEnable, onDisable - store.ts: call onEnable/onDisable hooks on toggle, fix circular dependency - admin-nav.ts: async allEnabledHubs/allEnabledNavGroups filters by enabled state - layout.tsx: pass filtered nav groups to sidebar - client.tsx: show Disabled/Missing deps badges, dim disabled plugins - API: return dependency info, lifecycle hooks on PATCH - Radio depends on API, Events depends on Notifications
This commit is contained in:
1 parent
d56c48a0b3
commit
127d5dcfa6
9 files changed
+197
-78
No files matched your search
+54
-27
@@ -18,6 +18,7 @@ import {
|
||||
Wrench,
|
||||
} from "lucide-react";
|
||||
import { pluginRegistry } from "@/lib/plugins";
|
||||
import { getAllPluginStates } from "@/lib/plugins/store";
|
||||
import "@/lib/plugins/loader";
|
||||
|
||||
export interface AdminHubTab {
|
||||
@@ -346,25 +347,33 @@ export const ADMIN_HUBS: AdminHubDefinition[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export function allHubs(): AdminHubDefinition[] {
|
||||
const pluginHubs: AdminHubDefinition[] = pluginRegistry.getHubs().map((h) => ({
|
||||
id: h.id,
|
||||
titleKey: h.titleKey,
|
||||
subtitleKey: h.subtitleKey,
|
||||
icon: h.icon,
|
||||
prefixes: h.prefixes,
|
||||
tabs: h.tabs.map((t) => ({
|
||||
href: t.href,
|
||||
labelKey: t.labelKey,
|
||||
match: t.match,
|
||||
group: t.group,
|
||||
})),
|
||||
}));
|
||||
export function allHubs(enabled?: Record<string, boolean>): AdminHubDefinition[] {
|
||||
const allReg = pluginRegistry.getHubs();
|
||||
const pluginHubs: AdminHubDefinition[] = [];
|
||||
for (const h of allReg) {
|
||||
const hubPlugin = pluginRegistry
|
||||
.getAll()
|
||||
.find((p) => (p.hubs ?? []).some((ph) => ph.id === h.id));
|
||||
if (hubPlugin && enabled && enabled[hubPlugin.id] === false) continue;
|
||||
pluginHubs.push({
|
||||
id: h.id,
|
||||
titleKey: h.titleKey,
|
||||
subtitleKey: h.subtitleKey,
|
||||
icon: h.icon,
|
||||
prefixes: h.prefixes,
|
||||
tabs: h.tabs.map((t) => ({
|
||||
href: t.href,
|
||||
labelKey: t.labelKey,
|
||||
match: t.match,
|
||||
group: t.group,
|
||||
})),
|
||||
});
|
||||
}
|
||||
return [...ADMIN_HUBS, ...pluginHubs];
|
||||
}
|
||||
|
||||
export function findAdminHub(pathname: string): AdminHubDefinition | null {
|
||||
const hubs = allHubs();
|
||||
export function findAdminHub(pathname: string, enabled?: Record<string, boolean>): AdminHubDefinition | null {
|
||||
const hubs = allHubs(enabled);
|
||||
return (
|
||||
hubs.find((hub) =>
|
||||
hub.prefixes.some((p) => pathname === p || pathname.startsWith(`${p}/`)),
|
||||
@@ -372,17 +381,25 @@ export function findAdminHub(pathname: string): AdminHubDefinition | null {
|
||||
);
|
||||
}
|
||||
|
||||
export function allNavGroups(): AdminNavGroup[] {
|
||||
const pluginGroups: AdminNavGroup[] = pluginRegistry.getNavGroups().map((g) => ({
|
||||
labelKey: g.labelKey,
|
||||
icon: g.icon,
|
||||
items: g.items.map((item) => ({
|
||||
href: item.href,
|
||||
labelKey: item.labelKey,
|
||||
icon: item.icon,
|
||||
matchPrefixes: item.matchPrefixes,
|
||||
})),
|
||||
}));
|
||||
export function allNavGroups(enabled?: Record<string, boolean>): AdminNavGroup[] {
|
||||
const allReg = pluginRegistry.getNavGroups();
|
||||
const pluginGroups: AdminNavGroup[] = [];
|
||||
for (const g of allReg) {
|
||||
const groupPlugin = pluginRegistry
|
||||
.getAll()
|
||||
.find((p) => (p.navGroups ?? []).some((pg) => pg.labelKey === g.labelKey));
|
||||
if (groupPlugin && enabled && enabled[groupPlugin.id] === false) continue;
|
||||
pluginGroups.push({
|
||||
labelKey: g.labelKey,
|
||||
icon: g.icon,
|
||||
items: g.items.map((item) => ({
|
||||
href: item.href,
|
||||
labelKey: item.labelKey,
|
||||
icon: item.icon,
|
||||
matchPrefixes: item.matchPrefixes,
|
||||
})),
|
||||
});
|
||||
}
|
||||
if (pluginGroups.length === 0) return ADMIN_NAV_GROUPS;
|
||||
return [
|
||||
...ADMIN_NAV_GROUPS,
|
||||
@@ -394,6 +411,16 @@ export function allNavGroups(): AdminNavGroup[] {
|
||||
];
|
||||
}
|
||||
|
||||
export async function allEnabledHubs(): Promise<AdminHubDefinition[]> {
|
||||
const states = await getAllPluginStates();
|
||||
return allHubs(states.enabled);
|
||||
}
|
||||
|
||||
export async function allEnabledNavGroups(): Promise<AdminNavGroup[]> {
|
||||
const states = await getAllPluginStates();
|
||||
return allNavGroups(states.enabled);
|
||||
}
|
||||
|
||||
function hubPrefixes(id: string): string[] {
|
||||
return ADMIN_HUBS.find((h) => h.id === id)?.prefixes ?? [];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user