Filter dashboard widgets by View
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from govoplan_core.core.access import CAPABILITY_AUTH_PERMISSION_EVALUATOR, CAPABILITY_AUTH_PRINCIPAL_RESOLVER
|
||||
from govoplan_core.core.modules import DocumentationTopic, FrontendModule, FrontendRoute, ModuleManifest, NavItem
|
||||
from govoplan_core.core.views import ViewSurface
|
||||
|
||||
|
||||
manifest = ModuleManifest(
|
||||
@@ -16,6 +17,15 @@ manifest = ModuleManifest(
|
||||
package_name="@govoplan/dashboard-webui",
|
||||
routes=(FrontendRoute(path="/dashboard", component="DashboardPage", order=10),),
|
||||
nav_items=(NavItem(path="/dashboard", label="Dashboard", icon="dashboard", order=10),),
|
||||
view_surfaces=(
|
||||
ViewSurface(
|
||||
id="dashboard.widget.installed-modules",
|
||||
module_id="dashboard",
|
||||
kind="section",
|
||||
label="Installed modules widget",
|
||||
order=10,
|
||||
),
|
||||
),
|
||||
),
|
||||
documentation=(
|
||||
DocumentationTopic(
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
dashboardWidgetsForModules,
|
||||
hasAnyScope,
|
||||
hasScope,
|
||||
useEffectiveView,
|
||||
usePlatformModules,
|
||||
type ApiSettings,
|
||||
type AuthInfo,
|
||||
@@ -23,7 +24,14 @@ type DashboardLayout = {
|
||||
|
||||
export default function DashboardPage({ settings, auth }: { settings: ApiSettings; auth: AuthInfo }) {
|
||||
const modules = usePlatformModules();
|
||||
const widgets = useMemo(() => dashboardWidgetsForModules(modules).filter((widget) => canUseWidget(auth, widget)), [auth, modules]);
|
||||
const effectiveView = useEffectiveView();
|
||||
const widgets = useMemo(
|
||||
() =>
|
||||
dashboardWidgetsForModules(modules, effectiveView).filter((widget) =>
|
||||
canUseWidget(auth, widget)
|
||||
),
|
||||
[auth, effectiveView, modules]
|
||||
);
|
||||
const widgetSignature = widgets.map((widget) => widget.id).join("|");
|
||||
const storageKey = `govoplan.dashboard.layout:${auth.active_tenant?.id ?? auth.tenant.id}:${auth.user.id}`;
|
||||
const [layout, setLayout] = useState<DashboardLayout>(() => defaultLayout(widgets));
|
||||
|
||||
@@ -10,6 +10,7 @@ const dashboardWidgets: DashboardWidgetsUiCapability = {
|
||||
widgets: [
|
||||
{
|
||||
id: "dashboard.installed-modules",
|
||||
surfaceId: "dashboard.widget.installed-modules",
|
||||
title: "Installed modules",
|
||||
description: "Enabled WebUI modules in this browser session.",
|
||||
moduleId: "dashboard",
|
||||
@@ -33,6 +34,15 @@ export const dashboardModule: PlatformWebModule = {
|
||||
dependencies: ["access"],
|
||||
optionalDependencies: ["ops", "campaigns", "files", "mail", "tasks", "notifications", "reporting"],
|
||||
translations,
|
||||
viewSurfaces: [
|
||||
{
|
||||
id: "dashboard.widget.installed-modules",
|
||||
moduleId: "dashboard",
|
||||
kind: "section",
|
||||
label: "Installed modules widget",
|
||||
order: 10
|
||||
}
|
||||
],
|
||||
navItems: [{ to: "/dashboard", label: "i18n:govoplan-dashboard.dashboard.3f8b4df2", iconName: "dashboard", order: 10 }],
|
||||
routes: [
|
||||
{ path: "/dashboard", order: 10, render: ({ settings, auth }) => createElement(DashboardPage, { settings, auth }) }
|
||||
@@ -43,4 +53,3 @@ export const dashboardModule: PlatformWebModule = {
|
||||
};
|
||||
|
||||
export default dashboardModule;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user