redash icon indicating copy to clipboard operation
redash copied to clipboard

Provide stable URL for referencing dashboards

Open eradman opened this issue 2 years ago • 11 comments

What type of PR is this?

  • [x] Feature

Description

Dashboards may be referenced if their ID is known (/dashboards/{dashboard_id}-{slug}), but there was no easy method of linking one dashboard to another by name.

The route /dashboard/{slug} already exists, but was useless because the exact slug ID had to be supplied (slug, slug_1, slug_2, ...). This change improves this routes by finding the best match.

This enables dashboar

How is this tested?

  • [x] Unit tests (pytest, jest)
  • [x] Manually

Create several dashboards with the same name, archive the first and test redirects using /dashboard/{slug}

Example Use Case

redash-markdown-links

eradman avatar Sep 29 '23 12:09 eradman

Codecov Report

Merging #6490 (136adbf) into master (4a36abc) will increase coverage by 0.00%. Report is 1 commits behind head on master. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #6490   +/-   ##
=======================================
  Coverage   61.08%   61.08%           
=======================================
  Files         158      158           
  Lines       12878    12879    +1     
  Branches     1753     1753           
=======================================
+ Hits         7866     7867    +1     
  Misses       4766     4766           
  Partials      246      246           
Files Coverage Δ
redash/models/__init__.py 92.26% <100.00%> (+<0.01%) :arrow_up:

codecov[bot] avatar Sep 29 '23 12:09 codecov[bot]

Cool, this looks useful. :smile:

@getredash/maintainers Anyone up for reviewing this? It's fairly simple Python backend code.

justinclift avatar Sep 30 '23 06:09 justinclift

I see, so I took a route that exists but was supposed to be deprecated.

Slugs are named sequentially, in the order they were created, so it is difficult to reference them by exact name

redash=# select slug from dashboards order by slug;
...
 extension-analytics
 extension-analytics_1
 extension-analytics_2

This makes the legacy /dashboard/ route is useless because you cannot guess the exact slug name. Should we remove the legacy route and add a new one?

/dashboards/find/{slug}

eradman avatar Sep 30 '23 12:09 eradman

@eradman but why do you want to load them by slug and not id?

arikfr avatar Sep 30 '23 14:09 arikfr

For context, my general workflow is this:

  1. create a dashboard on a dev environtment
  2. export the dashboard (add json defenition + sql files to git)
  3. publish dashboard to S3
  4. user installs dashboard from HTTP location

If there is a single instance of Redash then the dashboard ID can be hard coded, but this is never the case in the evironments I work in since I don't have access to our customer sites.

I don't even have access to the Redash instances that my colleges are using, so there is no case where a hard-coded ID would work.

eradman avatar Sep 30 '23 23:09 eradman

Interesting. That sounds like a pretty reasonable scenario @eradman. :smile:

justinclift avatar Oct 01 '23 07:10 justinclift

@arikfr do you think it would be better to add a new route (redirect) to find a dashboard by name, or is it okay to repurpose the legacy route/dashboard/{slug}?

eradman avatar Oct 03 '23 17:10 eradman

It's probably better to add a more explicit route, just to make things less confusing. Also, maybe we add the option to set the slug via the API (along with the lookup by slug) so things are more predictable and stable?

arikfr avatar Oct 05 '23 16:10 arikfr

Dashboard slugs are strange because the exact name is not determanistic:

def generate_slug(ctx):
    slug = utils.slugify(ctx.current_parameters["name"])
    tries = 1
    while Dashboard.query.filter(Dashboard.slug == slug).first() is not None:
        slug = utils.slugify(ctx.current_parameters["name"]) + "_" + str(tries)
        tries += 1
    return slug

Some ideas

  1. Allow the user to define a custom slug
  2. Add a redirect-route for searching by dashboard name
  3. Erase slug when a dashboard is archived and make the slug unique

eradman avatar Oct 06 '23 15:10 eradman

I'd find the dashboards-by-slug stuff useful. I'd be in favor of making slugs unique period - I don't think we should delete them when archived, since if someone archives dashboard 1, then creates an identically-slugged dashboard 2, and unarchives dashboard 1, we'd have a conflict. I can't really think of a use case where you'd want two identically-named dashboards.

That way, we can also provide the stable URL for referencing dashboards, as well, which is more useful than by ID imo.

guidopetri avatar Oct 28 '23 23:10 guidopetri

#4932 seems like an issue that wants a similar outcome, but for queries.

guidopetri avatar Oct 29 '23 02:10 guidopetri

Closing because this change is too narrow: we need a generic way of linking to dashboards and queries, and visualizations by name.

eradman avatar Mar 01 '24 17:03 eradman