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

fix(dashboard): Get dashboard by slug #13352

Merged
merged 8 commits into from
Mar 5, 2021
Merged

Conversation

suddjian
Copy link
Member

SUMMARY

Need get dashboard by slug. Can't get dashboard by slug. Override default FAB endpoint to get dashboard by slug.

Also add field datasources, two birds one stone.

TEST PLAN

Tests to be written.

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

query, None
)
dashboard = query.one_or_none()
if not dashboard:
Copy link
Member Author

Choose a reason for hiding this comment

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

this if doesn't trigger when I enter a bogus slug or id and I'm not sure why yet

@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #13352 (b9d92ea) into master (0b114fc) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13352      +/-   ##
==========================================
+ Coverage   77.21%   77.23%   +0.02%     
==========================================
  Files         872      872              
  Lines       45140    45189      +49     
  Branches     5435     5435              
==========================================
+ Hits        34854    34901      +47     
- Misses      10163    10165       +2     
  Partials      123      123              
Flag Coverage Δ
cypress 58.53% <ø> (ø)
javascript 62.33% <ø> (ø)
python 80.88% <100.00%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
superset/dashboards/api.py 87.98% <100.00%> (+0.58%) ⬆️
superset/dashboards/dao.py 95.57% <100.00%> (+0.33%) ⬆️
superset/dashboards/schemas.py 99.12% <100.00%> (+0.27%) ⬆️
superset/models/dashboard.py 76.99% <100.00%> (+0.21%) ⬆️
superset/db_engine_specs/presto.py 88.03% <0.00%> (-0.43%) ⬇️

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 0b114fc...b9d92ea. Read the comment docs.

@amitmiran137 amitmiran137 self-assigned this Feb 26, 2021
@dpgaspar
Copy link
Member

dpgaspar commented Feb 26, 2021

@suddjian sorry I may have mislead you on a conversation. You can get a dashboard by slug by using the get list endpoint /api/v1/dasboard/ with a query rison parameter:

{
  "filters": [
    {
      "col": "slug",
      "opr": "eq",
      "value": "births"
    }
  ]
}

You can also create a new filter and add it to the list of filters, that filters by id or slug
Theres already a couple in place: https://github.com/apache/superset/blob/master/superset/dashboards/api.py#L184

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.

Evaluate if we really need the override

@suddjian
Copy link
Member Author

@dpgaspar Using the list endpoint isn't ideal as it isn't a very RESTful approach and also doesn't return all the dashboard fields we need. Do you think it would be too much work to get this endpoint working?

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.

Looking good, just a couple of comments

superset/dashboards/dao.py Outdated Show resolved Hide resolved
superset/models/dashboard.py Show resolved Hide resolved
@@ -361,15 +364,16 @@ def export_dashboards( # pylint: disable=too-many-locals
@classmethod
def get(cls, id_or_slug: str) -> Dashboard:
session = db.session()
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated, but seems strange that this is creating a new session here

Copy link
Member Author

Choose a reason for hiding this comment

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

It does. I didn't feel entirely comfortable removing it though. Not sure why it was put there.

tests/dashboards/api_tests.py Show resolved Hide resolved
superset/dashboards/schemas.py Outdated Show resolved Hide resolved
superset/dashboards/dao.py Outdated Show resolved Hide resolved
superset/dashboards/api.py Show resolved Hide resolved
@suddjian
Copy link
Member Author

suddjian commented Mar 4, 2021

Comments addressed

401:
$ref: '#/components/responses/401'
404:
$ref: '#/components/responses/404'
Copy link
Member

Choose a reason for hiding this comment

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

can return 500 also from the @safe decorator

@suddjian suddjian merged commit 491fbd1 into master Mar 5, 2021
@amitmiran137 amitmiran137 deleted the get-dashboard-by-slug branch March 29, 2021 18:17
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
* refactor out id_or_slug filter logic

* fix(dashboard): accept slug in place of id in url

* remove unnecessary show fields

* fixes and tests

* linting

* linter compliance

* change requests

* names
@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
🏷️ 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.

4 participants