Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(1/n) refactor legend components to use items prop #42417

Merged
merged 6 commits into from
May 14, 2024

Conversation

EmmadUsmani
Copy link
Contributor

@EmmadUsmani EmmadUsmani commented May 8, 2024

Precursor to #41988 and #41986

Description

Refactoring the legend component to take a single items prop that is an array of objects with a key, name, and color, instead of taking two separate arrays of labels and colors.

This will make it easier to implement toggling via the legend, because we can later add additional properties to the item object, like a boolean that describes whether the series is visible or not.

In general it will make the legend easier to work with, for example when we need to add a legend item for the "other" bar in that project it'll be easier to just add one object where the name and color are coupled.

How to verify

  1. Create any chart with a legend (e.g. orders count by month, product category)
  2. Confirm the legend still works and behaves like normal.

Demo

Screenshot 2024-05-10 at 8 17 04 AM

Checklist

  • Tests have been added/updated to cover changes in this PR

Covered by existing tests like 12439-click-on-legend-breaks-ui.cy.spec.js

@metabase-bot metabase-bot bot added the .Team/DashViz Dashboard and Viz team label May 8, 2024
Copy link
Contributor Author

EmmadUsmani commented May 8, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @EmmadUsmani and the rest of your teammates on Graphite Graphite

@EmmadUsmani EmmadUsmani marked this pull request as ready for review May 8, 2024 19:01
@EmmadUsmani EmmadUsmani added the no-backport Do not backport this PR to any branch label May 8, 2024
@metabase-bot metabase-bot bot added the visual Run Percy visual testing label May 8, 2024
Copy link

github-actions bot commented May 8, 2024

Codenotify: Notifying subscribers in CODENOTIFY files for diff 9d968d9...19522f5.

Notify File(s)
@alxnddr frontend/src/metabase/visualizations/components/legend/Legend.jsx
frontend/src/metabase/visualizations/components/legend/LegendItem.jsx
frontend/src/metabase/visualizations/components/legend/LegendLayout.jsx
frontend/src/metabase/visualizations/echarts/cartesian/model/legend.ts
frontend/src/metabase/visualizations/echarts/cartesian/model/legend.unit.spec.ts
frontend/src/metabase/visualizations/echarts/cartesian/model/types.ts
frontend/src/metabase/visualizations/visualizations/CartesianChart/CartesianChart.tsx
frontend/src/metabase/visualizations/visualizations/RowChart/RowChart.tsx
frontend/src/metabase/visualizations/visualizations/RowChart/utils/legend.ts

Copy link

replay-io bot commented May 8, 2024

Status Complete ↗︎
Commit 19522f5
Results
⚠️ 2 Flaky
2506 Passed

@EmmadUsmani EmmadUsmani requested review from a team and alxnddr May 10, 2024 15:18
Copy link
Contributor

@JesseSDevaney JesseSDevaney left a comment

Choose a reason for hiding this comment

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

This is working for dynamic visualizations for me, but it might be breaking static-viz?

image

I saw that there were some static-viz related type errors - maybe it is related to those?

@EmmadUsmani EmmadUsmani force-pushed the refactor_legend_components_to_use_items_prop branch from 90164f3 to 5defa89 Compare May 13, 2024 17:19
@EmmadUsmani
Copy link
Contributor Author

@JesseSDevaney Good catch! I've fixed the type errors, could you check if those dashcards still error in static viz?

Copy link
Contributor

@JesseSDevaney JesseSDevaney left a comment

Choose a reason for hiding this comment

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

LGTM! ❤️

image

We still need to fix those legend unit tests to account for the new dataKey attribute included in legendItems, but I will still approve because that is simple.

@EmmadUsmani EmmadUsmani enabled auto-merge (squash) May 14, 2024 00:55
@EmmadUsmani EmmadUsmani changed the title refactor legend components to use items prop (1/n) refactor legend components to use items prop May 14, 2024
@EmmadUsmani EmmadUsmani merged commit 0902226 into master May 14, 2024
112 of 113 checks passed
@EmmadUsmani EmmadUsmani deleted the refactor_legend_components_to_use_items_prop branch May 14, 2024 01:36
Copy link

@EmmadUsmani Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/DashViz Dashboard and Viz team visual Run Percy visual testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants