[Cloud Posture] Support pagination in benchmarks page#128486
[Cloud Posture] Support pagination in benchmarks page#128486ari-aviran merged 3 commits intoelastic:mainfrom
Conversation
orouz
left a comment
There was a problem hiding this comment.
looks good!
minor comments
| <CspPageTemplate pageHeader={PAGE_HEADER}> | ||
| <BenchmarkSearchField | ||
| isLoading={queryResult.isLoading} | ||
| isLoading={queryResult.isFetching} |
There was a problem hiding this comment.
why is this preferred over isLoading ?
There was a problem hiding this comment.
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.
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.
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.
| 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.
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.
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.
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.