@@ -55,15 +55,23 @@ type QueryTableProps<Item> = {
55
55
emptyState : React . ReactElement
56
56
} & (
57
57
| {
58
- onSelect : ( selection : string ) => void
58
+ /**
59
+ * If present, the table will include a select column and make rows
60
+ * selectable one at a time.
61
+ */
62
+ onSingleSelect : ( selection : string ) => void
59
63
onMultiSelect ?: never
60
64
}
61
65
| {
62
- onSelect ?: never
66
+ onSingleSelect ?: never
67
+ /**
68
+ * If present, the table will include a select column and make rows
69
+ * selectable.
70
+ */
63
71
onMultiSelect : ( selections : string [ ] ) => void
64
72
}
65
73
| {
66
- onSelect ?: never
74
+ onSingleSelect ?: never
67
75
onMultiSelect ?: never
68
76
}
69
77
)
@@ -81,7 +89,7 @@ const makeQueryTable = <Item,>(
81
89
pagination = 'page' ,
82
90
pageSize = 10 ,
83
91
emptyState,
84
- onSelect ,
92
+ onSingleSelect ,
85
93
onMultiSelect,
86
94
} : QueryTableProps < Item > ) {
87
95
invariant (
@@ -92,9 +100,9 @@ const makeQueryTable = <Item,>(
92
100
const [ rowSelection , setRowSelection ] = React . useState ( { } )
93
101
useEffect ( ( ) => {
94
102
const selected = Object . keys ( rowSelection )
95
- onSelect ?.( selected [ 0 ] )
103
+ onSingleSelect ?.( selected [ 0 ] )
96
104
onMultiSelect ?.( selected )
97
- } , [ rowSelection , onSelect , onMultiSelect ] )
105
+ } , [ rowSelection , onSingleSelect , onMultiSelect ] )
98
106
99
107
const { currentPage, goToNextPage, goToPrevPage, hasPrev } = usePagination ( )
100
108
const tableHelper = useMemo ( ( ) => createTable ( ) . setRowType < Item > ( ) , [ ] )
@@ -123,7 +131,7 @@ const makeQueryTable = <Item,>(
123
131
)
124
132
} )
125
133
126
- if ( onSelect ) {
134
+ if ( onSingleSelect ) {
127
135
columns . unshift ( getSelectCol ( ) )
128
136
} else if ( onMultiSelect ) {
129
137
columns . unshift ( getMultiSelectCol ( ) )
@@ -134,7 +142,7 @@ const makeQueryTable = <Item,>(
134
142
}
135
143
136
144
return columns
137
- } , [ children , tableHelper , makeActions , onSelect , onMultiSelect ] )
145
+ } , [ children , tableHelper , makeActions , onSingleSelect , onMultiSelect ] )
138
146
139
147
const { data, isLoading } = useApiQuery (
140
148
query ,
@@ -155,7 +163,7 @@ const makeQueryTable = <Item,>(
155
163
rowSelection,
156
164
} ,
157
165
manualPagination : true ,
158
- enableRowSelection : ! ! onSelect ,
166
+ enableRowSelection : ! ! onSingleSelect ,
159
167
enableMultiRowSelection : ! ! onMultiSelect ,
160
168
onRowSelectionChange : setRowSelection ,
161
169
} )
0 commit comments