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

Enhancement Suggestion: Remove default query parameters automatically #137

Closed
garronej opened this issue Dec 7, 2023 · 2 comments
Closed

Comments

@garronej
Copy link
Contributor

garronej commented Dec 7, 2023

Hello!

Firstly, I want to reiterate the expression of my gratitude for the excellent work on Type-route. It's been a vital part of our project in Onyxia, significantly enhancing our development experience.

I have a suggestion for an enhancement that we've been missing for a while now.

Here's an example to illustrate my point:

export const routeDefs = {
    "dataExplorer": defineRoute(
        {
            "source": param.query.optional.string,
            "rowsPerPage": param.query.optional.number.default(25),
            "page": param.query.optional.number.default(1)
        },
        () => `/data-explorer`
    )
};

Currently, when navigating to subsequent pages in a dataset, our approach is to call:

routes[route.name]({
    ...route.params,
    page: route.params.page + 1
}).replace()

This results in URLs such as:

https://an-onyxia-instance.net/data-explorer?source="..."&rowsPerPage=25&page=2

The issue here is the inclusion of rowsPerPage=25, which is the default value. Ideally, we would prefer such default parameters to be omitted from the URL to maintain simplicity and brevity.

If Type-route could automatically exclude parameters from the URL when they match their default values, it would be really nice. For example, turning long URLs like:

https://datalab.sspcloud.fr/data-explorer?source=https%3A%2F%2Fshell.duckdb.org%2Fdata%2Ftpch%2F0_01%2Fparquet%2Flineitem.parquet&rowsPerPage=25&page=1&selectedRow=4&columnWidths=%7B%7D&columnVisibility=%7B%7D

Into more concise versions:

https://datalab.sspcloud.fr/data-explorer?source=https%3A%2F%2Fshell.duckdb.org%2Fdata%2Ftpch%2F0_01%2Fparquet%2Flineitem.parquet&selectedRow=4

Your consideration of this suggestion is greatly appreciated. Thank you for your continued efforts in making Type-route a remarkable tool for developers.

Best regards,

@bradenhs
Copy link
Contributor

bradenhs commented Dec 7, 2023

I love this idea! In fact, I've encountered the exact same problem and have wanted to do something about it. However, I'm in the midst of building a nascent startup and don't have time to commit in the near future. I'd be happy to review a PR though!

@bradenhs
Copy link
Contributor

bradenhs commented Dec 9, 2023

Just released https://github.com/zilch/type-route/releases/tag/1.1.0. Thanks again for the contribution @garronej!

@bradenhs bradenhs closed this as completed Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants