跳到正文
14 天免费试用,无需银行卡9 种语言176 种业务类型 · 50 个应用
ZH· USD
试用在线演示免费试用

此页面暂无简体中文版本,现以英文显示。

Widget kinds, HTML sanitising and the dashboard filter

The four data kinds, tones and links, which HTML survives, and how the dashboard.widgets filter hides widgets per user.

  • about 7 min
KindShape
statitems[{ label, value, hint?, tone?, href? }], up to 8
listitems[{ title, subtitle?, meta?, tone?, href? }], up to 20, plus empty?
texttext
htmlhtml — sanitised: only b i strong em u s p br ul ol li code span small a[href] survive

Every kind accepts href + linkLabel for the card header link. tone is good, warn or bad. Return null to render nothing.

A stat widget with tones
import { defineWidget } from "@/lib/plugins/sdk";

export const summary = defineWidget(async (ctx) => ({
  kind: "stat",
  href: "/admin/site-visits",
  linkLabel: "Open",
  items: [
    { label: "Planned", value: 4, href: "/admin/site-visits?status=PLANNED" },
    { label: "Today", value: 1, tone: "warn" },
    { label: "Done this month", value: 12, tone: "good", hint: "12 of 15" },
  ],
}));

Hiding widgets per user

The dashboard.widgets filter receives the widget ids (catalogue order) with { userId, may } and may remove ids to hide widgets for that user. Adding ids is not supported yet — the page resolves the layout before the filter runs.

Hide this plugin's cards from people without invoice rights
filters: {
  "dashboard.widgets": async (ids, ctx) => (ctx.may("invoices.view") ? ids : ids.filter((id) => !id.startsWith("plugin:site-visits:"))),
},

Written from: docs/PLUGIN-DEVELOPER-GUIDE.md, src/lib/plugins/types.ts, src/lib/plugins/widget-html.ts, src/lib/plugins/filters.ts, src/lib/plugins/sdk.ts