Skip to content

fix(SceneDataTransformer): preserve undefined annotations when source has none - #1623

Draft
sidsri14 wants to merge 1 commit into
grafana:mainfrom
sidsri14:fix/scenedatatransformer-preserve-undefined-annotations
Draft

fix(SceneDataTransformer): preserve undefined annotations when source has none#1623
sidsri14 wants to merge 1 commit into
grafana:mainfrom
sidsri14:fix/scenedatatransformer-preserve-undefined-annotations

Conversation

@sidsri14

Copy link
Copy Markdown

Summary

Fixes #1612.

SceneDataTransformer.transform() was previously always returning annotations: [] even when the input data.annotations was undefined and no annotations were created.

In consumers like Grafana's TimeSeriesPanel and CandlestickPanel, components guard on presence of data.annotations (e.g. {data.annotations && <ExemplarsPlugin ... />}). Promoting undefined to [] caused ExemplarsPlugin (and its EventsCanvas with uPlot draw hook) to mount on every panel with a transformation, resulting in unnecessary React re-renders on pan/zoom/cursor redraws.

Changes

  • In packages/scenes/src/querying/SceneDataTransformer.ts:
    Set annotations: annotations.length > 0 || data.annotations !== undefined ? annotations : undefined.
    This preserves undefined when no annotations existed on the source data and none were produced by transformations, while correctly retaining [] if a transformer explicitly reduced existing annotations to empty.
  • In packages/scenes/src/querying/SceneDataTransformer.test.ts:
    Added a unit test verifying that data.annotations remains undefined when transforming source data without annotations.

Verification

  • yarn workspace @grafana/scenes test packages/scenes/src/querying/SceneDataTransformer.test.ts --watchAll=false passed 100% (20 passed, 1 skipped).
  • yarn turbo typecheck --filter=@grafana/scenes passed with 0 errors.

… has none

SceneDataTransformer.transform() was unconditionally setting `annotations` to `[]` even when source data had `annotations: undefined`.

Consumers such as Grafana's TimeSeriesPanel and CandlestickPanel guard on presence of `data.annotations` (e.g. `{data.annotations && <ExemplarsPlugin ... />}`). Promoting `undefined` to `[]` caused ExemplarsPlugin and its EventsCanvas uPlot draw hook to be mounted on every panel with a transformation, resulting in unnecessary state updates and render cycles on pan, zoom, and cursor redraws.

This updates SceneDataTransformer to preserve `undefined` when `annotations.length === 0` and `data.annotations === undefined`.
@github-actions

Copy link
Copy Markdown
Contributor

Signed commits report

1 of 1 commit between main and fix/scenedatatransformer-preserve-undefined-annotations could not be fully verified:

Commit Author Reason Message
c42aefd1 sid sri unsigned fix(SceneDataTransformer): preserve undefined annotations when source has none

This repository requires all commits to be signed. See GitHub docs on commit signature verification.

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.

SceneDataTransformer promotes annotations: undefined to []

1 participant