Skip to content

Conversation

@Qxisylolo
Copy link
Contributor

@Qxisylolo Qxisylolo commented Nov 27, 2025

Description

Issues Resolved

Screenshot

Testing the changes

Changelog

  • skip

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility for visualizations created with deprecated styling by automatically adapting legacy style data during retrieval and spec generation.
  • Tests
    • Added tests ensuring legacy style adaptation runs when older visualizations are fetched.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Qxisylolo <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Walkthrough

Added two exported utilities (adaptLegacyData, getColumnsByAxesMapping) for legacy visualization style adaptation and updated ExploreEmbeddable.fetch() to call adaptLegacyData and use adapted styles when building the visualization spec; tests updated to assert the adaptation call.

Changes

Cohort / File(s) Summary
Visualization utils (new exports)
src/plugins/explore/public/components/visualizations/visualization_builder_utils
Exported adaptLegacyData (adapts deprecated style structures including thresholdLines) and getColumnsByAxesMapping (returns numerical/categorical/date column groupings).
Embeddable implementation
src/plugins/explore/public/embeddable/explore_embeddable.tsx
Imported adaptLegacyData; in fetch flow call adaptLegacyData(type, styles, axesMapping) and prefer adapted styles when calling matchedRule.toSpec.
Embeddable tests
src/plugins/explore/public/embeddable/explore_embeddable.test.tsx
Mocked new utility exports and added test asserting adaptLegacyData is invoked when a saved visualization contains deprecated threshold styles.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ExploreEmbeddable
    participant Utils as visualization_builder_utils
    participant SpecGen as matchedRule.toSpec

    Client->>ExploreEmbeddable: fetch()
    ExploreEmbeddable->>ExploreEmbeddable: load saved visualization + styleOptions
    alt saved viz has legacy thresholdLines
        ExploreEmbeddable->>Utils: adaptLegacyData(type, styles, axesMapping)
        Utils-->>ExploreEmbeddable: adaptedStyles
        ExploreEmbeddable->>SpecGen: toSpec(..., styles = adaptedStyles)
    else no legacy styles
        ExploreEmbeddable->>SpecGen: toSpec(..., styles = styleOptions)
    end
    SpecGen-->>Client: visualization spec
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • visualization_builder_utils implementations for correctness of adaptation logic and edge cases
    • explore_embeddable.tsx fetch path: correct usage of axesMapping, preservation of existing behavior when adaptLegacyData returns nothing
    • Unit test (explore_embeddable.test.tsx) mocks and assertion that adaptation is invoked in both test and production paths

Poem

🐰 I nibble at old lines of style,

I stitch thresholds into a smile,
New specs hop out, tidy and spry,
Legacy cared for, we bounce high! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only template placeholders with no concrete details filled in; sections for Description, Issues Resolved, Screenshot, and Testing are empty, making it difficult to understand the actual changes and rationale. Fill in the Description section with details about what this change achieves, provide testing steps, and include any relevant issues resolved or screenshots.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title '[Explore Vis] adapt deprecated styles in embeddable' clearly and specifically summarizes the main change: adapting deprecated styles in the embeddable component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added distinguished-contributor Skip-Changelog PRs that are too trivial to warrant a changelog or release notes entry labels Nov 27, 2025
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.79%. Comparing base (96f160b) to head (b044fea).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10984      +/-   ##
==========================================
+ Coverage   60.77%   60.79%   +0.02%     
==========================================
  Files        4533     4531       -2     
  Lines      122256   122265       +9     
  Branches    20491    20502      +11     
==========================================
+ Hits        74298    74332      +34     
+ Misses      42719    42691      -28     
- Partials     5239     5242       +3     
Flag Coverage Δ
Linux_1 26.55% <ø> (-0.02%) ⬇️
Linux_2 38.92% <ø> (-0.01%) ⬇️
Linux_3 39.51% <ø> (+0.02%) ⬆️
Linux_4 ?
Windows_1 26.57% <ø> (-0.02%) ⬇️
Windows_2 38.90% <ø> (-0.01%) ⬇️
Windows_3 39.51% <ø> (+0.02%) ⬆️
Windows_4 33.74% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/plugins/explore/public/embeddable/explore_embeddable.test.tsx (2)

70-81: Align adaptLegacyData mock shape with the production implementation

The mock currently returns { useThresholdColor: true }, while fetch expects adaptLegacyData to return a config object and then reads its styles property. In tests this yields styles === undefined, so we always fall back to styleOptions and never exercise the adapted-style path, which can hide regressions.

Consider making the mock return a config-like object with a styles field so the adapted styles are actually used:

-  adaptLegacyData: jest.fn().mockReturnValue({ useThresholdColor: true }),
+  adaptLegacyData: jest.fn().mockImplementation((config) => ({
+    ...config,
+    styles: {
+      ...(config?.styles ?? {}),
+      useThresholdColor: true,
+    },
+  })),

This keeps the test behavior closer to production and lets you verify that migrated styles are wired through correctly.


517-542: Strengthen the “adapt deprecated styles” test to validate arguments and effects

This test currently only asserts that adaptLegacyData is called. It would still pass if fetch called it with incorrect arguments or then ignored its result.

To make the test more robust, consider additionally asserting:

  • The arguments, e.g. type, styles and axesMapping:
expect(adaptLegacyDataSpy).toHaveBeenCalledWith(
  expect.objectContaining({
    type: 'line',
    styles: expect.anything(),
    axesMapping: { x: 'field1', y: 'field2' },
  })
);
  • Optionally, that matchedRule.toSpec is invoked with the adapted styles (e.g. by checking the corresponding argument).

This would give stronger coverage of the legacy-style adaptation flow.

src/plugins/explore/public/embeddable/explore_embeddable.tsx (1)

48-51: Persist effective (adapted) styles into searchProps to avoid divergence

The integration of adaptLegacyData here looks correct, and using styles || styleOptions keeps behavior unchanged when no migration is needed. However, searchProps.styleOptions remains set to the original visualization.params, so consumers of searchProps may still see the legacy config (e.g., with thresholdLines) while the rendered spec uses the migrated thresholdOptions.

If you want the embeddable state and rendered visualization to stay in sync, consider writing back the effective styles:

const styleOptions = visualization.params;

const styles = adaptLegacyData({
  type: selectedChartType,
  styles: styleOptions,
  axesMapping: visualization.axesMapping,
})?.styles;

const effectiveStyles = styles || styleOptions;
this.searchProps.styleOptions = effectiveStyles;

const spec = matchedRule.toSpec(
  visualizationData.transformedData,
  numericalColumns,
  categoricalColumns,
  dateColumns,
  effectiveStyles,
  selectedChartType,
  axesMapping
);

This keeps the internal state consistent with the migrated configuration while preserving your current fallback behavior.

Also applies to: 408-419

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a47de88 and 7fe4442.

📒 Files selected for processing (2)
  • src/plugins/explore/public/embeddable/explore_embeddable.test.tsx (2 hunks)
  • src/plugins/explore/public/embeddable/explore_embeddable.tsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/plugins/explore/public/embeddable/explore_embeddable.tsx (1)
src/plugins/explore/public/components/visualizations/visualization_builder_utils.ts (1)
  • adaptLegacyData (85-184)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: Run cypress tests (osd:ciGroup17Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup13Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup10Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup15Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup15)
  • GitHub Check: Run cypress tests (osd:ciGroup16Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup12Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup14)
  • GitHub Check: Run cypress tests (osd:ciGroup10Slow)
  • GitHub Check: Run cypress tests (osd:ciGroup13)
  • GitHub Check: Run cypress tests (osd:ciGroup12)
  • GitHub Check: Run functional tests on Windows (ciGroup12)
  • GitHub Check: Run functional tests on Windows (ciGroup11)
  • GitHub Check: Run functional tests on Windows (ciGroup4)
  • GitHub Check: Run functional tests on Windows (ciGroup3)

ruanyl
ruanyl previously approved these changes Nov 27, 2025
this.searchProps.searchContext = searchContext;
const styleOptions = visualization.params;

const styles = adaptLegacyData({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we need to update searchProps.styleOptions as well?

Copy link
Contributor Author

@Qxisylolo Qxisylolo Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only table needs searchProps.styleOptions when rendering embeddable currently which doesn't need to adapt legacy data. but I will include this as table will use value mapping in the future and we may need to migrate some data. thanks!

Signed-off-by: Qxisylolo <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fe4442 and b044fea.

📒 Files selected for processing (1)
  • src/plugins/explore/public/embeddable/explore_embeddable.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (67)
  • GitHub Check: Run functional tests on Windows (ciGroup9)
  • GitHub Check: Run functional tests on Windows (ciGroup7)
  • GitHub Check: Run cypress tests (osd:ciGroup17Explore)
  • GitHub Check: Run functional tests on Windows (ciGroup13)
  • GitHub Check: Run functional tests on Linux (ciGroup13)
  • GitHub Check: Run functional tests on Windows (ciGroup8)
  • GitHub Check: Run functional tests on Windows (ciGroup6)
  • GitHub Check: Run functional tests on Windows (ciGroup4)
  • GitHub Check: Run cypress tests (osd:ciGroup14Explore)
  • GitHub Check: Run functional tests on Windows (ciGroup12)
  • GitHub Check: Run cypress tests (osd:ciGroup16Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup13Explore)
  • GitHub Check: Run functional tests on Windows (ciGroup11)
  • GitHub Check: Run functional tests on Windows (ciGroup10)
  • GitHub Check: Run functional tests on Windows (ciGroup5)
  • GitHub Check: Run functional tests on Windows (ciGroup2)
  • GitHub Check: Run cypress tests (osd:ciGroup15Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup12Explore)
  • GitHub Check: Run cypress tests (osd:ciGroup15)
  • GitHub Check: Run cypress tests (osd:ciGroup10Explore)
  • GitHub Check: Run functional tests on Linux (ciGroup12)
  • GitHub Check: Run functional tests on Linux (ciGroup8)
  • GitHub Check: Run functional tests on Linux (ciGroup6)
  • GitHub Check: Run functional tests on Windows (ciGroup3)
  • GitHub Check: Run functional tests on Linux (ciGroup11)
  • GitHub Check: Run functional tests on Linux (ciGroup5)
  • GitHub Check: Run functional tests on Linux (ciGroup9)
  • GitHub Check: Run functional tests on Linux (ciGroup7)
  • GitHub Check: Run functional tests on Windows (ciGroup1)
  • GitHub Check: Run functional tests on Linux (ciGroup10)
  • GitHub Check: Run cypress tests (osd:ciGroup14)
  • GitHub Check: Run cypress tests (osd:ciGroup10Fast)
  • GitHub Check: Run cypress tests (osd:ciGroup11)
  • GitHub Check: Run cypress tests (osd:ciGroup12)
  • GitHub Check: Run functional tests on Linux (ciGroup3)
  • GitHub Check: Run functional tests on Linux (ciGroup4)
  • GitHub Check: Run cypress tests (osd:ciGroup6)
  • GitHub Check: Run cypress tests (osd:ciGroup13)
  • GitHub Check: Run cypress tests (osd:ciGroup4)
  • GitHub Check: Run cypress tests (osd:ciGroup3)
  • GitHub Check: Run cypress tests (osd:ciGroup2)
  • GitHub Check: Run cypress tests (osd:ciGroup7)
  • GitHub Check: Run cypress tests (osd:ciGroup10Slow)
  • GitHub Check: Run cypress tests (osd:ciGroup8)
  • GitHub Check: Run functional tests on Linux (ciGroup2)
  • GitHub Check: Run cypress tests (osd:ciGroup1)
  • GitHub Check: Run cypress tests (osd:ciGroup9)
  • GitHub Check: Run cypress tests (osd:ciGroup5)
  • GitHub Check: Run functional tests on Linux (ciGroup1)
  • GitHub Check: Build min release artifacts on macOS ARM64
  • GitHub Check: Build min release artifacts on Windows x64
  • GitHub Check: Build min release artifacts on Linux ARM64
  • GitHub Check: Build min release artifacts on macOS x64
  • GitHub Check: Build and Verify on Windows (ciGroup3)
  • GitHub Check: Build min release artifacts on Linux x64
  • GitHub Check: Build and Verify on Linux (ciGroup1)
  • GitHub Check: Build and Verify on Windows (ciGroup4)
  • GitHub Check: Build and Verify on Linux (ciGroup2)
  • GitHub Check: Build and Verify on Windows (ciGroup2)
  • GitHub Check: Build and Verify on Linux (ciGroup4)
  • GitHub Check: Build and Verify on Linux (ciGroup3)
  • GitHub Check: Build and Verify on Windows (ciGroup1)
  • GitHub Check: Run plugin functional tests on Linux
  • GitHub Check: Run plugin functional tests on Windows
  • GitHub Check: Lint and validate
  • GitHub Check: lighthouse
  • GitHub Check: bundle-analyzer
🔇 Additional comments (1)
src/plugins/explore/public/embeddable/explore_embeddable.tsx (1)

48-51: Importing adaptLegacyData alongside convertStringsToMappings looks consistent

The new import cleanly reflects the added usage in fetch() and keeps related visualization utilities co-located; no issues here.

Comment on lines +408 to +415
const styles = adaptLegacyData({
type: selectedChartType,
styles: styleOptions,
axesMapping: visualization.axesMapping,
})?.styles;

this.searchProps.styleOptions = styles;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Preserve original style options when legacy adaptation yields no result

Right now you compute:

  • const styleOptions = visualization.params;
  • const styles = adaptLegacyData(... )?.styles;
  • this.searchProps.styleOptions = styles;
  • toSpec(..., styles || styleOptions, ...)

If adaptLegacyData returns undefined (e.g., non-legacy or unsupported configs), styles is undefined, so:

  • toSpec still sees the correct fallback via styles || styleOptions,
  • but this.searchProps.styleOptions becomes undefined, losing the original params that were previously always available to the embeddable.

To keep behavior consistent and still prefer adapted styles, you can fold the fallback into a single variable and use it both for searchProps and toSpec:

-          const styleOptions = visualization.params;
-
-          const styles = adaptLegacyData({
-            type: selectedChartType,
-            styles: styleOptions,
-            axesMapping: visualization.axesMapping,
-          })?.styles;
-
-          this.searchProps.styleOptions = styles;
+          const styleOptions = visualization.params;
+
+          const adaptedStyles =
+            adaptLegacyData({
+              type: selectedChartType,
+              styles: styleOptions,
+              axesMapping: visualization.axesMapping,
+            })?.styles ?? styleOptions;
+
+          this.searchProps.styleOptions = adaptedStyles;
@@
-            dateColumns,
-            styles || styleOptions,
+            dateColumns,
+            adaptedStyles,

This keeps searchProps.styleOptions always populated (original or adapted) and aligns it with what is actually sent into toSpec.

Also applies to: 421-421

🤖 Prompt for AI Agents
In src/plugins/explore/public/embeddable/explore_embeddable.tsx around lines
408-415 (also apply at 421), adaptLegacyData may return undefined causing styles
to be undefined and this.searchProps.styleOptions to lose the original
visualization.params; create a single fallback variable (e.g., const
resolvedStyles = adaptLegacyData(...)?.styles || styleOptions) and use
resolvedStyles both to set this.searchProps.styleOptions and to pass into toSpec
so searchProps always retains the original params when adaptation yields no
result while still preferring adapted styles when present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

distinguished-contributor Skip-Changelog PRs that are too trivial to warrant a changelog or release notes entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants