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