mckinsey / vizro

Vizro is a toolkit for creating modular data visualization applications.
https://vizro.readthedocs.io/en/stable/
Apache License 2.0
2.49k stars 112 forks source link

No validation for Card.href can break page opening #285

Closed l0uden closed 4 months ago

l0uden commented 6 months ago

Description

If we create path="/page page" for any page it will be available in browser like /page-page. At the same time if we create Card.href="/page page" we'll get 404 during page opening.

Looks like to synchronise this values we should apply same validation for href and path

Expected behavior

No response

Which package?

vizro

Package version

0.1.8

Python version

3.9

OS

Mac OS

How to Reproduce

  1. Create one page with path="/page page"
  2. Create second page with Card.href="/page page"
  3. Run the dashboard and click Card on the second page.

Output

No response

Code of Conduct

antonymilne commented 6 months ago

Currently this is the expected behaviour, but I think you're right we should change the behaviour.

There's two different things here:

The case you give here is a special (but common) case where you use Card.href to refer to a page in the app and hence use a relative link. We handle this as:

href=get_relative_path(self.href) if self.href.startswith("/") else self.href

I think we should change this:

  1. put self.href through the same clean_path transformation that Page.path has in the case that it's a relative path. Hence writing Card.href = "/page page" would then work
  2. even better, make it so that you can just write Card.href = "page page" without the leading / and it would still work. This would mean we need a better check to see if the href is relative or absolute and to add the / back in the case that it's not absolute and it's missing

This way a user will be able to put the page title directly in the Card.href without thinking about it even if it's got weird characters, i.e. this should work:

Page(title = "something weird %*")
Card(href = "something weird %*")
antonymilne commented 4 months ago

After more thought we should not implement this feature for now. See #348 for explanation.