[FEATURE] Add usePanelAnnotationsWithData hook for panel-level annotations#206
Draft
nicolastakashi wants to merge 1 commit into
Draft
[FEATURE] Add usePanelAnnotationsWithData hook for panel-level annotations#206nicolastakashi wants to merge 1 commit into
nicolastakashi wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ownannotations.definitionsthrough the existinguseAnnotationsruntime 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
AnnotationSpecWithDataand theAnnotationProviderstore, so no fetching logic is duplicated.Dependency
This is stacked on perses/spec#61, which adds
PanelSpec.Annotations(and thePanelAnnotationstype) to the data model. It will not compile until that lands and@perses-dev/specis bumped here.Testing
I built the spec branch locally, linked it in, and ran
tsc --noEmitondashboards: it passes clean.usePanelAnnotationsWithData.test.tsxcovers 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'sjest.config.tsfails 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:
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?