انتقل إلى المحتوى
تجربة مجانية 14 يومًا، بلا بطاقة9 لغات176 نوع عمل · 50 تطبيقًا
AR· 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