-
Notifications
You must be signed in to change notification settings - Fork 15
refactor: new useQueryTable with legit types, returns the query data
#2567
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
I discovered a bug on 2024-11-20-instance-polling-bug.mp4 |
5efc71e to
e9d7db3
Compare
d019a8a to
fa28e3c
Compare
fa28e3c to
9406444
Compare
| { | ||
| // this helper can only be used with endpoints that return ResultsPage | ||
| [K in keyof A]: Result<A[K]> extends ResultsPage<unknown> ? K : never | ||
| }[keyof A], |
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.
| /> | ||
| ) | ||
|
|
||
| const snapshotList = (project: string) => getListQFn('snapshotList', { query: { project } }) |
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.
We can now share the query options between the prefetch in the loader and the query table, and we don't have to specify PAGE_SIZE manually here to make sure it matches the query inside QueryTable.
app/table/QueryTable2.tsx
Outdated
| // require ID only so we can use it in getRowId | ||
| export function useQueryTable<TItem extends { id: string }>({ | ||
| optionsFn, | ||
| pageSize = PAGE_SIZE, |
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.
There's something off that I need to figure out about the fact that PAGE_SIZE has a default both here and in getListQueryOptionsFn. It means you can manually override the page size in the loader prefetch call and a) it won't apply to the QueryTable, and b) the only way you find out about the mismatch is that the prefetch check in QueryTable fails. It's not the worst (it's more or less what we have now) but it doesn't feel right — it doesn't feel like it's taking advantage of the query options sharing.
I feel like ideally you would not have to specify page size on useQueryTable at all; instead, you would set it on the query options object shared by the loader and the query table. It's easy to build the page size into the options object — the only real obstacle is that inside useQueryTable we need the pageSize for UI reasons (whether to enable the next button), so if we build pageSize into the query options, we need to be able to pull it back out of there. There is a meta key on query options that we could put pageSize on.
|
Figured out #2567 (comment) in 8cab460. This video shows how the page size for a given page, both loader and The error on hot reload when I change the value is an 2024-11-21-page-size-demo.mp4 |
97a67e3 to
1a5fbda
Compare
| return getApiQueryOptions(api)(method, newParams, { | ||
| ...options, | ||
| // identity function so current page sticks around while next loads | ||
| placeholderData: (x) => x, |
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 just remembered the problem with this, which made me reluctant to do it everywhere, though doing it in just a few random tables (what we currently do) is probably even worse. When we don't do the blank flash, we don't scroll to top when the next page loads.
2024-11-21-pag-no-scroll.mp4
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.
GOT EM
2024-11-21-fix-table-scroll-to-top.mp4
|
Loading spinner. We're in business. 2024-11-21-table-loading-spinner.mp4 |
532bb80 to
31ddca8
Compare
oxidecomputer/console@6fe6936...653b572 * [653b5725](oxidecomputer/console@653b5725) oxidecomputer/console#2577 * [175d75b7](oxidecomputer/console@175d75b7) oxidecomputer/console#2575 * [3e40ff71](oxidecomputer/console@3e40ff71) oxidecomputer/console#2571 * [034ca87e](oxidecomputer/console@034ca87e) oxidecomputer/console#2567 * [4b4d7fb9](oxidecomputer/console@4b4d7fb9) oxidecomputer/console#2574 * [e116e404](oxidecomputer/console@e116e404) bump web console to latest dogfood version * [67033a32](oxidecomputer/console@67033a32) oxidecomputer/console#2566 * [c4258804](oxidecomputer/console@c4258804) oxidecomputer/console#2568 * [0f922b2e](oxidecomputer/console@0f922b2e) cleanup: move getUseApiQueries down in the file to reduce diff noise elsewhere * [cf7802a7](oxidecomputer/console@cf7802a7) oxidecomputer/console#2565
oxidecomputer/console@6fe6936...059c551 * [059c5514](oxidecomputer/console@059c5514) oxidecomputer/console#2487 * [25106d32](oxidecomputer/console@25106d32) oxidecomputer/console#2581 * [653b5725](oxidecomputer/console@653b5725) oxidecomputer/console#2577 * [175d75b7](oxidecomputer/console@175d75b7) oxidecomputer/console#2575 * [3e40ff71](oxidecomputer/console@3e40ff71) oxidecomputer/console#2571 * [034ca87e](oxidecomputer/console@034ca87e) oxidecomputer/console#2567 * [4b4d7fb9](oxidecomputer/console@4b4d7fb9) oxidecomputer/console#2574 * [e116e404](oxidecomputer/console@e116e404) bump web console to latest dogfood version * [67033a32](oxidecomputer/console@67033a32) oxidecomputer/console#2566 * [c4258804](oxidecomputer/console@c4258804) oxidecomputer/console#2568 * [0f922b2e](oxidecomputer/console@0f922b2e) cleanup: move getUseApiQueries down in the file to reduce diff noise elsewhere * [cf7802a7](oxidecomputer/console@cf7802a7) oxidecomputer/console#2565
oxidecomputer/console@6fe6936...059c551 * [059c5514](oxidecomputer/console@059c5514) oxidecomputer/console#2487 * [25106d32](oxidecomputer/console@25106d32) oxidecomputer/console#2581 * [653b5725](oxidecomputer/console@653b5725) oxidecomputer/console#2577 * [175d75b7](oxidecomputer/console@175d75b7) oxidecomputer/console#2575 * [3e40ff71](oxidecomputer/console@3e40ff71) oxidecomputer/console#2571 * [034ca87e](oxidecomputer/console@034ca87e) oxidecomputer/console#2567 * [4b4d7fb9](oxidecomputer/console@4b4d7fb9) oxidecomputer/console#2574 * [e116e404](oxidecomputer/console@e116e404) bump web console to latest dogfood version * [67033a32](oxidecomputer/console@67033a32) oxidecomputer/console#2566 * [c4258804](oxidecomputer/console@c4258804) oxidecomputer/console#2568 * [0f922b2e](oxidecomputer/console@0f922b2e) cleanup: move getUseApiQueries down in the file to reduce diff noise elsewhere * [cf7802a7](oxidecomputer/console@cf7802a7) oxidecomputer/console#2565

This is built on top of the
queryOptionswork in #2566. The types inQueryTablehave always bothered me, as does returning a component instead of an element, but I could never figure out how to fix it.console/app/table/QueryTable.tsx
Lines 65 to 77 in 0f922b2
This change:
anyTData extends { items: TItem[] })useApiQuerycall where we painstaking ensure the params match (see below), we don't have to do that anymoreconsole/app/pages/ProjectsPage.tsx
Lines 64 to 67 in 0f922b2
The new file is 80 lines instead of 120 and strictly better across the board. There are only 20
useQueryTablecalls in the app. It would be pretty quick to convert them all. We could do that here or merge this and convert in batches.