Skip to content

Proof of concept: Take column logic out of QueryTable - #2110

Merged
david-crespo merged 8 commits into
mainfrom
shrink-query-table
Mar 29, 2024
Merged

david-crespo merged 8 commits into
mainfrom
shrink-query-table

Conversation

@david-crespo

@david-crespo david-crespo commented Mar 29, 2024 •

Copy link
Copy Markdown
Collaborator

Closes #2107
Supersedes #2109

In #2109 I had a big outstanding mystery:

Unsolved: why does unmount happen before the loader is complete? Page transition should only happen after loader is done.

To investigate, I tried to reproduce the #2107 problem on StackBlitz with a very minimal setup:

But it did not have the issue, so I had to go back to our code and ask myself what we're doing to cause it. The breakthrough came when I replaced the IP pools table with this and the problem went away.

<Link to={pb.ipPool({ pool: 'ip-pool-1' })}>ip-pool-1</Link>
<UtilizationCell pool="ip-pool-1" />

So most likely it was QueryTable causing the UtilizationCell to unmount and remount at a weird time. Then I remembered: QueryTable is full of shenanigans, it would totally do that. The culprit was my least favorite part of QueryTable:

const columns = useMemo(() => {
const colHelper = createColumnHelper<Item>()
const columns = React.Children.toArray(children).map((child) => {
const column = { ...(child as ReactElement<QueryTableColumnProps<Item>>).props }
// QueryTableColumnProps ensures `id` is passed in if and only if
// `accessor` is not a string
const id =
'id' in column
? column.id
: typeof column.accessor === 'string'
? column.accessor
: undefined // should never happen because id is required if accessor is a function
return colHelper.accessor(column.accessor, {
id: id!, // undefined not really possible, and helper doesn't allow it
header: typeof column.header === 'string' ? column.header : id,
cell: (info: any) => {
const Comp = column.cell || DefaultCell
return <Comp value={info.getValue()} />
},
})
})
if (onSingleSelect) {
columns.unshift(getSelectCol())
} else if (onMultiSelect) {
columns.unshift(getMultiSelectCol())
}
if (makeActions) {
columns.push(getActionsCol(makeActions))
}
return columns
}, [children, makeActions, onSingleSelect, onMultiSelect])

Turning QueryTable inside out and getting rid of all the any bits has been a long-term goal of mine, but it is pretty hard to untangle. What hadn't occurred to me until now is that we can pretty easily stop doing the columns part altogether, passing in a native React Table columns array as a prop instead of doing the <Column /> business.

So in this PR, I've introduced useQueryTable2, which is the same as useQueryTable but with the bad columns thing deleted.

I think we should convert all existing useQueryTable calls to useQueryTable2, then delete the original and rename useQueryTable2 back to useQueryTable. There are 21 useQueryTable calls (not including the IP pools one I changed here), and some will be pretty involved, so we probably don't want to do them all in one PR.

@vercel

vercel Bot commented Mar 29, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Mar 29, 2024 3:56pm

@david-crespo
david-crespo marked this pull request as ready for review March 29, 2024 13:40
@david-crespo

Copy link
Copy Markdown
Collaborator Author

The same test failed twice in a row in Safari, so that’s significant. Will take a look.

@david-crespo

Copy link
Copy Markdown
Collaborator Author

The test has now passed multiple times in a row in Safari in CI. Running it one more time to be sure. I wasn't able to repro the failure locally.

@charliepark charliepark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good sleuthing on this. No concerns I can come up with; stoked it's addressing the issue. We might extract some of the common columns from different tables into helper functions, though I also get it if the benefits there are minimal. Regardless, this is good.

@david-crespo

Copy link
Copy Markdown
Collaborator Author

Thanks for the quick review. Definitely with you on cleaner helper functions. I did a bit of that with defaultCell and makeLinkCell.

@david-crespo

Copy link
Copy Markdown
Collaborator Author

The test passed in Safari but now flaked in Firefox and in the same spot. Very interesting....

@david-crespo
david-crespo enabled auto-merge (squash) March 29, 2024 15:59
@david-crespo
david-crespo merged commit 156c082 into main Mar 29, 2024
@david-crespo
david-crespo deleted the shrink-query-table branch March 29, 2024 16:06

This branch was successfully deployed

1 active deployment
Preview — 8b677db4 Deployed Mar 29, 2024 by vercel[bot]
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.

Error on nav from IP pools to IP pool detail before utilization fetch completes

2 participants