-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cloud Posture] Support pagination in benchmarks page #128486
Conversation
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.
looks good!
minor comments
@@ -129,7 +138,7 @@ export const Benchmarks = () => { | |||
return ( | |||
<CspPageTemplate pageHeader={PAGE_HEADER}> | |||
<BenchmarkSearchField | |||
isLoading={queryResult.isLoading} | |||
isLoading={queryResult.isFetching} |
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.
why is this preferred over isLoading
?
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.
When sorting the data, react-query
dispatches an additional query, but isLoading
remains false (it only applies to initial loading of data), and we do want the table and search field to present the loading state
// @ts-ignore - EUI types currently do not support sorting by nested fields | ||
sort: { field: query.sortField, direction: query.sortOrder }, |
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.
1 - can you clarify what error do we get here? i don't recall having to do this in other tables.
2 - prefer @ts-expect-error
(optionally add TS[number]) so it's clear what error the author wants to ignore.
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.
This only applies when sorting based on a nested field, as the type for sort.field
is keyof T
(where T
is the data object for the table), and keyof
only applies to top-level fields.
? // Asserting since type inference does not support sorting of nested fields | ||
(sort.field as UseCspBenchmarkIntegrationsProps['sortField']) | ||
: current.sortField, | ||
sortOrder: sort?.direction ? sort.direction : current.sortOrder, |
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.
sortOrder: sort?.direction ? sort.direction : current.sortOrder, | |
sortOrder: sort?.direction || current.sortOrder, |
const query: BenchmarksQuerySchema = { | ||
benchmark_name: name, | ||
per_page: perPage, | ||
page, | ||
sort_field: sortField, | ||
sort_order: sortOrder, | ||
}; | ||
|
||
return useQuery( | ||
[QUERY_KEY, { name, perPage, page, sortField, sortOrder }], |
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 think it makes sense to make the queryKey
take the full query. as in:
[QUERY_KEY, { query }]
* - package_policy.package.title | ||
* - package_policy.package.version | ||
*/ | ||
sort_field: schema.oneOf( |
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 think we support every field in PackagePolicy
(as we don't own it anyway)
and maybe we should just take what's currently applicable by the UI. as in - just the column headers.
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.
Yes we technically support every field in that object type, but better be explicit in the docs and schema. Regarding using only what's in the UI - IMO its better to leave the API more flexible for the future
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
Summary
Adds sorting to the benchmarks table in the Cloud Security Posture application.
Checklist
Delete any items that are not applicable to this PR.