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

feat(dashboard): API to get a dashboard's charts #12978

Merged
merged 29 commits into from Feb 15, 2021

Conversation

suddjian
Copy link
Member

@suddjian suddjian commented Feb 5, 2021

SUMMARY

Adds a new API to get the chart definitions for a specific dashboard. This is going to support future efforts to turn Superset's frontend into a single page app by allowing removal of the Dashboard app's bootstrap data.

Alternative considered: Using GET dashboard/:id/related/slices, and iterating over the results to fetch all the slices from /charts/:id.

I rejected this approach because it would require changing the /related/slices endpoint (currently the endpoint returns the names of charts rather than ids, which is pretty useless for this purpose), and also because it would result in a large number of API requests. The chosen method of a single convenient API endpoint is much simpler.

Thanks to @pkdotson for pairing ❤️

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TEST PLAN

Wrote tests

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@suddjian suddjian changed the title feat(dashboard): API to provide a dashboard's charts feat(dashboard): API to get a dashboard's charts Feb 5, 2021
@suddjian suddjian changed the base branch from dashboard-bootstrap to master February 5, 2021 23:00
@suddjian
Copy link
Member Author

suddjian commented Feb 5, 2021

Requesting review from @dpgaspar to make sure I got the security related code and doc strings correct :)

edit: CI says there's something wrong with my doc string but I'm not sure how to fix it! 😖

@nytai
Copy link
Member

nytai commented Feb 5, 2021

@suddjian You can probably get some logs if you visit /swagger/v1 which the result of compiling these docstrings.

@codecov-io
Copy link

codecov-io commented Feb 5, 2021

Codecov Report

Merging #12978 (2d3b001) into master (2ce7982) will increase coverage by 13.67%.
The diff coverage is 36.99%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #12978       +/-   ##
===========================================
+ Coverage   53.06%   66.74%   +13.67%     
===========================================
  Files         489      491        +2     
  Lines       17314    28972    +11658     
  Branches     4482        0     -4482     
===========================================
+ Hits         9187    19336    +10149     
- Misses       8127     9636     +1509     
Flag Coverage Δ
cypress ?
python 66.74% <36.99%> (?)

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

Impacted Files Coverage Δ
superset/constants.py 100.00% <ø> (ø)
superset/examples/birth_names.py 73.19% <ø> (ø)
...43f2fdb_add_granularity_to_charts_where_missing.py 0.00% <0.00%> (ø)
...s/260bf0649a77_migrate_x_dateunit_in_time_range.py 0.00% <0.00%> (ø)
...ons/versions/41ce8799acc3_rename_pie_label_type.py 0.00% <0.00%> (ø)
superset/connectors/sqla/views.py 62.43% <4.34%> (ø)
superset/views/datasource.py 88.70% <16.66%> (ø)
superset/utils/core.py 87.63% <66.66%> (ø)
superset/charts/commands/exceptions.py 92.85% <77.77%> (ø)
superset/db_engine_specs/elasticsearch.py 89.74% <93.75%> (ø)
... and 958 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86807e4...2d3b001. Read the comment docs.

Copy link
Member

@amitmiran137 amitmiran137 left a comment

Choose a reason for hiding this comment

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

I think tests readability can be improved.
maybe structure them in an AAA (arrange act assert ) like :
https://github.com/apache/superset/blob/master/tests/dashboards/security/security_rbac_tests.py#L47:L64

and a bit cleanup by extracting to common reusable method can make tests fairly easy to understand

tests/dashboards/api_tests.py Outdated Show resolved Hide resolved
tests/dashboards/api_tests.py Outdated Show resolved Hide resolved
Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

Nicely done, the N+1 is tricky but we can avoid it. Using Slice.data is handy but we probably can start using marshmallow to the same effect, with the plus of using the schema on the OpenAPI spec,

superset/dashboards/dao.py Outdated Show resolved Hide resolved
superset/dashboards/dao.py Show resolved Hide resolved
tests/dashboards/api_tests.py Outdated Show resolved Hide resolved
tests/dashboards/api_tests.py Outdated Show resolved Hide resolved
tests/dashboards/api_tests.py Show resolved Hide resolved
tests/dashboards/api_tests.py Outdated Show resolved Hide resolved
@junlincc junlincc added the api:dashboard Related to the REST endpoints of the Dashboard label Feb 6, 2021
@junlincc
Copy link
Member

junlincc commented Feb 6, 2021

Congrats on the first step and thanks for the collaboration! @suddjian @pkdotson
seems to me that Multiline chart is not passing through the new API.

Screen Shot 2021-02-06 at 3 27 43 PM

@suddjian
Copy link
Member Author

suddjian commented Feb 7, 2021

Thanks for the QA @junlincc, but I don't think that error could possibly have anything to do with this PR. No existing functionality has been changed here.

@junlincc
Copy link
Member

junlincc commented Feb 7, 2021

got it, that's strange. i also checked on master and other branches which don't have this issue. please disregard if it's not related.

superset/dashboards/api.py Outdated Show resolved Hide resolved
Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

Looks really good!

)
if cx < half_dash_count:
chart = self.insert_chart(f"slice{cx}", [admin.id], 1, params="{}")
Copy link
Member

Choose a reason for hiding this comment

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

Non blocking. Having one or a bunch of dashboards with more then 1 chart could make a better GET test

@@ -216,6 +219,53 @@ def __init__(self) -> None:
self.include_route_methods = self.include_route_methods | {"thumbnail"}
super().__init__()

@expose("/<pk>/charts", methods=["GET"])
@protect()
@safe
Copy link
Member

Choose a reason for hiding this comment

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

Should additionally use has_dashboard access decorator to enforce access for the dashboard

Copy link
Member

Choose a reason for hiding this comment

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

right! good point @amitmiran137, we can use dashboard = self.datamodel.get(pk, self._base_filters)

@suddjian suddjian merged commit cc9103b into apache:master Feb 15, 2021
@suddjian suddjian deleted the dashboard-bootstrap branch February 15, 2021 19:42
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:dashboard Related to the REST endpoints of the Dashboard 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants