-
Notifications
You must be signed in to change notification settings - Fork 166
feat: small improvements to search #6736
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import type { CompoundQueryResult } from "@rilldata/web-common/features/compound-query-result"; | ||
| import { | ||
| createInExpression, | ||
| createLikeExpression, | ||
|
|
@@ -13,7 +14,7 @@ export function useDimensionSearch( | |
| timeStart?: string, | ||
| timeEnd?: string, | ||
| enabled?: boolean, | ||
| ) { | ||
| ): CompoundQueryResult<string[]> { | ||
| const addNull = searchText.length !== 0 && "null".includes(searchText); | ||
|
|
||
| const queries = metricsViewNames.map((mvName) => | ||
|
|
@@ -37,15 +38,31 @@ export function useDimensionSearch( | |
| ); | ||
|
|
||
| return derived(queries, ($queries) => { | ||
| const someQueryFetching = $queries.some((q) => q.isFetching); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically we should use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm my understanding was
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if for whatever reason there a refetch the data would go from blank to showing values without a spinner. So I think it is fine to use |
||
| if (someQueryFetching) { | ||
| return { | ||
| data: undefined, | ||
| error: undefined, | ||
| isFetching: true, | ||
| }; | ||
| } | ||
| const errors = $queries.filter((q) => q.isError).map((q) => q.error); | ||
| if (errors.length > 0) { | ||
| return { | ||
| data: undefined, | ||
| // TODO: merge multiple errors | ||
| error: errors[0]?.response?.data.message, | ||
| isFetching: false, | ||
| }; | ||
| } | ||
|
|
||
| const items = $queries.flatMap((query) => query.data?.data || []); | ||
| const values = items.map((item) => item[dimensionName] as string); | ||
| const seen = new Set(); | ||
| return values.filter((value) => { | ||
| if (seen.has(value)) { | ||
| return false; | ||
| } | ||
| seen.add(value); | ||
| return true; | ||
| }); | ||
| const dedupedValues = new Set(values); | ||
| return { | ||
| data: [...dedupedValues], | ||
| error: undefined, | ||
| isFetching: false, | ||
| }; | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little worried about divergence between our menu components. For example, all other
SearchableMenuContentwould also benefit from the loading & error states you've added here. I wonder if we could add the requisite functionality toSearchableMenuComponent(e.g. make it pluggable?). I'll leave it up to you.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya I wanted to wait for the design to stabilise before refactoring this too much. The end goal would be a common component with hooks for dimension filter.