Skip to content

[FEATURE] Add usePanelAnnotationsWithData hook for panel-level annotations#206

Draft
nicolastakashi wants to merge 1 commit into
perses:mainfrom
nicolastakashi:draft/panel-level-annotations-consumer
Draft

[FEATURE] Add usePanelAnnotationsWithData hook for panel-level annotations#206
nicolastakashi wants to merge 1 commit into
perses:mainfrom
nicolastakashi:draft/panel-level-annotations-consumer

Conversation

@nicolastakashi

Copy link
Copy Markdown
Contributor

What this does

This adds usePanelAnnotationsWithData, a panel-scoped consumer hook in @perses-dev/dashboards, so a panel can control which annotations it shows.

The hook returns the dashboard-level annotations from the store, unless the panel turns them off with annotations.enabled === false (a nil or true value keeps them on, matching the default-on behavior in the two-level design). It also resolves the panel's own annotations.definitions through the existing useAnnotations runtime hook and merges the two sets. The merge is a plain concatenation, so by default a panel shows every dashboard annotation plus its own local ones. It does not dedup yet (see open questions).

It reuses AnnotationSpecWithData and the AnnotationProvider store, so no fetching logic is duplicated.

Dependency

This is stacked on perses/spec#61, which adds PanelSpec.Annotations (and the PanelAnnotations type) to the data model. It will not compile until that lands and @perses-dev/spec is bumped here.

Testing

I built the spec branch locally, linked it in, and ran tsc --noEmit on dashboards: it passes clean.

usePanelAnnotationsWithData.test.tsx covers the four cases: no annotations block (dashboard annotations show), toggle off (they are suppressed), toggle on with local definitions (both merge), and toggle off with local definitions (only the local ones show). The test typechecks. I could not run jest locally because the repo's jest.config.ts fails to load under Node 24, which affects every test in the repo, not this one.

Open questions

Carried over from perses/spec#61 and the design thread in perses/perses#3001:

  1. Name collisions. The merge does not dedup, and the store keys annotation state by display.name, so a panel-local definition sharing a name with a dashboard annotation could collide. Do you want name-uniqueness validation, last-wins, or namespacing?
  2. Toggle granularity. Right now it is one boolean for all dashboard annotations on the panel. The alternative is per-annotation opt-out by name.

…tions

Add a panel-scoped consumer hook in @perses-dev/dashboards. It returns the
dashboard-level annotations from the store unless the panel toggle disables them
(annotations.enabled === false; a nil or true value keeps them on), and merges in
the panel-local definitions resolved through the existing useAnnotations runtime
hook. The merge is a plain concatenation of both sets.

Reuses AnnotationSpecWithData and the AnnotationProvider store; no fetching logic
is duplicated. Includes unit tests for the toggle and merge behavior.

Depends on the panel-level annotations data model in perses/spec#61.

Signed-off-by: Nicolas Takashi <nicolas.takashi@dash0.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant