-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add single select, multi select to QueryTable #1065
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
const getRowId = useCallback((row) => row.id, []) | ||
const getRowId = useCallback((row) => row.name, []) |
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.
Can't believe I didn't think to do this before 😅
This is so elegant! It works great. I'm going to take a look at the e2e tests. I also noticed that if you're in single select mode and click the more menu, it also triggers the select. Ideally the click would not propagate up to the row. Probably an easy fix; I'll take a look. But if not it's probably fine for now because we won't use single-select with an actions button anyway. |
Got it in eddd9da. Just needed |
className={cn({ 'cursor-pointer': !!onMultiSelect })} | ||
> | ||
{firstCell.renderCell()} | ||
</UITable.Cell> |
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 is a little confusing because it puts the onClick
on there whether there's a select column or not. The behavior is right because onSingleSelect
and onMultiSelect
are undefined when they're supposed to be, but it's a little hard to tell from looking it. I think I'll make a followup commit on main.
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.
Did that in 68adee2. Also renamed onSelect
to onSingleSelect
in QueryTable
because I kept mixing up what was single and what was multi.
onClick={onSingleSelect} | ||
> | ||
<UITable.Cell | ||
onClick={onMultiSelect} |
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.
clever making the click target the whole cell
Single select
Only one row can be selected at any given time and the selection happens by clicking anywhere in the row. To invoke this mode all you have to do is pass
onSelect
to the query table.Multi-select
This is the checkbox selection behavior as we had before but now the whole check cell is a clickable area. To invoke this mode all you have to do is pass
onMultiSelect
to the query table.When I was working on #606 I never really felt like the API was right. We pass
makeActions
to the table because the table actually has to render the row actions menu but the table fundamentally didn't need to know about bulk actions. As I was poking at #1060 today I realized that the logic for what to do when something is selected in the table just needs to live outside the table itself. A callback likeonSelect
oronMultiSelect
is sort of perfect for this. I've updated it so thatonSelect
just returns the name of the row selected (if any) andonMultiSelect
returns a list of names.This work will unlock both #1060 and #424.
Followups