Skip to content

chore: support multiple key:value search query params #12690

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

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Mar 20, 2024

GitHub does this in their label search. Including this for an upcoming feature where the csv format is a bit unwieldy.

supporting: #10661

Previously we enforced each key to only be used once, I changed this to be decided in the parse function, later in the process. This works better because the parser has more context.

What this does

It allows syntax like this to search for 2 ids:

id:cfd1898c-f903-47fc-a896-dacf18ed0bef id:2b2d5add-8615-4d4a-8ba2-7e907ceb60f2

Screenshot from 2024-03-20 16-27-14

The old error is still there for params that do not support it.

Screenshot from 2024-03-20 11-44-09

Future work

We have things like name:<workspace_name>. It would be nice to allow this syntax there too. Currently we get this error:

Screenshot from 2024-03-20 12-06-54

Comment on lines +209 to +214
if err != nil {
p.Errors = append(p.Errors, codersdk.ValidationError{
Field: queryParam,
Detail: fmt.Sprintf("Query param %q must be a valid string: %s", queryParam, err.Error()),
})
}
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 should never throw an error in practice, but it felt weird ignoring the error.

Comment on lines -166 to -176
for k := range searchValues {
if len(searchValues[k]) > 1 {
return nil, []codersdk.ValidationError{
{
Field: "q",
Detail: fmt.Sprintf("Query parameter %q provided more than once, found %d times", k, len(searchValues[k])),
},
}
}
}

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 is now enforced by the parser function. So the parser can decide on a query param basis if more than 1 value is allowed.

All default behavior remains as the underlying parsers require 1 value.

Emyrk added 3 commits March 20, 2024 16:04
GitHub does this in their label search. Including this for an upcoming
feature where the csv format is a bit unwieldy.
@Emyrk Emyrk force-pushed the stevenmasley/multiple_searchs branch from 061909b to 3fe88c4 Compare March 20, 2024 21:04
Copy link
Member Author

Emyrk commented Mar 20, 2024

@Emyrk Emyrk merged commit b4492ff into main Mar 21, 2024
@Emyrk Emyrk deleted the stevenmasley/multiple_searchs branch March 21, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants