Skip to content
Back to skills

Adding Dashboard V2 Panel Types

ASecurity

Guides adding or changing a panel type in dashboards v2 (`products/dashboards_v2/frontend/panels/`): the PanelSpec, definePanel, config schema, tile slots (Component, Loading, HeaderExtra, Footer), menuActions, allowedCustomizations and lazy loading, with the markdown type as the worked example. Use when creating a new kind of tile content for a dashboards v2 host, changing a panel type's config, or reviewing a diff under `frontend/panels/`. Not for v1 dashboard widgets (`manage-dashboard-wid...

  • 41,325 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmenttypescriptgoreactawsfrontendperformance

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add PostHog/posthog --skill adding-dashboard-v2-panel-types --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Adding Dashboard V2 Panel Types?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Adding Dashboard V2 Panel Types
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/posthog-adding-dashboard-v2-panel-types/badge)](https://www.skillsdirectory.com/skills/posthog-adding-dashboard-v2-panel-types)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: adding-dashboard-v2-panel-types
description: >
  Guides adding or changing a panel type in dashboards v2 (`products/dashboards_v2/frontend/panels/`):
  the PanelSpec, definePanel, config schema, tile slots (Component, Loading, HeaderExtra, Footer),
  menuActions, allowedCustomizations and lazy loading, with the markdown type as the worked example.
  Use when creating a new kind of tile content for a dashboards v2 host, changing a panel type's config,
  or reviewing a diff under `frontend/panels/`. Not for v1 dashboard widgets (`manage-dashboard-widgets`).
---

# Adding a dashboards v2 panel type

A panel type is the content a tile shows, such as a chart or markdown.
The tile owns the frame: title, description, menu, dragging, resizing and the error boundary.
Read `products/dashboards_v2/.agents/primitives.md`, `.agents/performance.md` and `.agents/filters.md` first.

## Decide before you build

A panel type is the most expensive way to add content, so check the cheaper ones first ("Which to build for new content" in `primitives.md`).
Then answer each question, because each answer becomes part of the type's contract:

- **What does the document save?** The `type` and every config field are saved forever. Keep config to what a person or a dashboard written as code sets, and work everything else out at render.
- **Where does data come from?** The dashboard never fetches. A type that loads data takes the loader from the host through a factory, as `createChartPanel({ runQuery })` does, and supports `sampleData`.
- **How do filters and the time range apply?** Read them from `FiltersContext`. Decide which kinds the type ignores, and say so to the host. See `filters.md`.
- **What does it cost on a 200-tile dashboard?** It mounts only when in view, may mount late after a filter changed, and must not run work per tile on load. See `performance.md`.
- **What does it look like in each state?** Loading before it mounts, empty, error, sample data, and a broken config. The tile shows the broken config message, and the type supplies the rest.
- **What does it look like in a snapshot?** Images and printed pages render it without interaction. Use `showOnInteractiveOnly` when it means nothing there.
- **What can a person do to it?** Menu entries, refresh, duplicate, move, background color. Each is off unless the type turns it on.
- **How big is it?** `size` gives the default and the minimum; `sizeFor` when the size depends on config.

Give the type its own folder, `frontend/panels/<type>/`:

- `<type>Spec.ts` holds the config schema, the `PanelSpec` and the `definePanel` call.
- Each component has its own file, such as `<Type>Panel.tsx`.

The layout functions, `validateDashboard` and tools that write dashboards as code load the spec file, sometimes outside the browser.
So the spec file loads its components with `React.lazy` and never imports one directly.
`panelDefinition.tsx` depends only on React, so keep it that way: UI such as messages and error reporting goes in `PanelView` or the tile.

## Rules

- Define `config` as a `z.strictObject`, and take its TypeScript type from the schema with `z.infer`. `definePanel` checks every saved config against the schema before any part of the type gets it, so the parts never cast `config` and never type it as `unknown`.
- Give the spec its config type and its literal type name: `PanelSpec<MarkdownConfig, 'markdown'>`.
- The `type` and every config field are saved in dashboard documents. Renaming one breaks saved dashboards, so it needs a migration, not a rename.
- A panel type fills only its slots: `Component`, `Loading`, `HeaderExtra`, `Footer` and `menuActions`. Do not draw a title or add an error boundary in a panel.
- Give the type a `Loading` shaped like its content when it has one. Off-screen tiles and suspended tiles show it, so a tile looks like itself before it mounts.
- A type that shows data takes a `sampleData` option in its factory, as `createChartPanel` does. The host sets it while it has no real data, and the type then draws made-up data in `Component` and runs no queries. Mark it as sample data and keep its made-up numbers out of tooltips.
- Components read only the small contexts they need, such as `FiltersContext` and `PanelHostContext`, and never the dashboard state. A component that changes the dashboard's filters reads `FilterControlsContext`, and one that changes the time range calls `useTimeFilter()`.
- `showOnInteractiveOnly(panel)` returning true leaves the tile out of snapshots, such as images and printed pages.
- `refreshable(panel)` returning true adds Refresh to the tile's menu, which reruns only that tile's queries.
- `movable(panel)` returning false stops a person dragging, resizing, moving or removing the tile. Left out, every tile is movable.
- `duplicable(panel)` returning false takes Duplicate off the tile's menu. Left out, every tile can be duplicated.
- `keepMounted(panel)` returning true keeps the panel mounted after it scrolls out of view. Use it only for a panel that holds state a person would lose, because the panel then stays in memory.
- To show a product's own component rather than add a type, use `/adding-dashboard-v2-custom-content`.
- `allowedCustomizations` lists the tile customizations the type allows, such as `['backgroundColor']`. The values a person picks are saved on the tile's `panel.appearance`.
- `menuActions(actions, context)` returns the tile's menu. Append entries to `actions` with a stable `key`, and change the config with `context.setConfig`, which saves one undo step.
- Add the type to `DEFAULT_PANELS` only when every host should get it. Otherwise a host passes the type in its own list.
- A pure function in the spec, such as `sizeFor`, gets a unit test.

## Example: markdown

`frontend/panels/markdown/markdownSpec.ts`:

```ts
export const markdownConfigSchema = z.strictObject({ text: z.string() })

export type MarkdownConfig = z.infer<typeof markdownConfigSchema>

export const markdownSpec: PanelSpec<MarkdownConfig, 'markdown'> = {
  type: 'markdown',
  size: { w: 8, h: 8, minW: 3, minH: 4 },
  configSchema: markdownConfigSchema,
  allowedCustomizations: ['backgroundColor'],
}

const MarkdownPanel = lazy(() => import('./MarkdownPanel').then((module) => ({ default: module.MarkdownPanel })))

export const markdownPanel = definePanel({
  ...markdownSpec,
  addTileOptions: [
    { label: 'Text', create: () => ({ type: 'markdown', config: { text: 'Write notes in **Markdown**.' } }) },
  ],
  Component: MarkdownPanel,
})
```

`MarkdownPanel` gets `panel: ContentPanel<MarkdownConfig>`, so `panel.config.text` is a checked string.
A host passes the type in its list, such as `panels={[createChartPanel({ runQuery }), markdownPanel]}`.

The chart type is a factory instead, `createChartPanel`, because a host adds its own kinds of chart and its query runner.
Follow it only when a host must configure the type.

## Before you report done

- `pnpm --filter=@posthog/frontend typescript:check` and the dashboards v2 Jest tests pass.
- The new type renders on the `/dashboard-v2` kitchen sink: its content, its loading state, and the "not valid" message for a broken config.
- Its tile can still be moved, resized and removed when the panel throws.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.