1
+ import { useRef , useEffect , useMemo , Fragment } from 'react'
1
2
import { Checkbox } from '@Common/Checkbox'
2
3
import { DEFAULT_BASE_PAGE_SIZE } from '@Common/Constants'
3
4
import ErrorScreenManager from '@Common/ErrorScreenManager'
4
- import { useAsync , showError , CHECKBOX_VALUE , GenericFilterEmptyState , GenericEmptyState } from '@Common/index'
5
+ import {
6
+ useAsync ,
7
+ showError ,
8
+ CHECKBOX_VALUE ,
9
+ GenericFilterEmptyState ,
10
+ GenericEmptyState ,
11
+ useEffectAfterMount ,
12
+ } from '@Common/index'
5
13
import { Pagination } from '@Common/Pagination'
6
14
import { SortableTableHeaderCell } from '@Common/SortableTableHeaderCell'
7
- import { useRef , useEffect , useMemo , Fragment } from 'react'
15
+
8
16
import { BulkSelection } from '../BulkSelection'
9
17
import BulkSelectionActionWidget from './BulkSelectionActionWidget'
10
18
import { SEARCH_SORT_CHANGE_DEBOUNCE_TIME , BULK_ACTION_GUTTER_LABEL , EVENT_TARGET } from './constants'
@@ -56,14 +64,6 @@ const InternalTable = ({
56
64
isFilterApplied,
57
65
} = filterData ?? { }
58
66
59
- useEffect ( ( ) => {
60
- rowsContainerRef . current . scrollTo ( {
61
- top : 0 ,
62
- left : 0 ,
63
- behavior : 'smooth' ,
64
- } )
65
- } , [ offset ] )
66
-
67
67
const isBulkSelectionConfigured = ! ! bulkSelectionConfig
68
68
69
69
const {
@@ -161,11 +161,21 @@ const InternalTable = ({
161
161
return paginatedRows
162
162
} , [ paginationVariant , offset , pageSize , filteredRows ] )
163
163
164
- const { activeRowIndex } = useTableWithKeyboardShortcuts (
164
+ const { activeRowIndex, setActiveRowIndex } = useTableWithKeyboardShortcuts (
165
165
{ bulkSelectionConfig, bulkSelectionReturnValue, handleToggleBulkSelectionOnRow } ,
166
166
visibleRows ,
167
167
)
168
168
169
+ useEffectAfterMount ( ( ) => {
170
+ rowsContainerRef . current . scrollTo ( {
171
+ top : 0 ,
172
+ left : 0 ,
173
+ behavior : 'smooth' ,
174
+ } )
175
+
176
+ setActiveRowIndex ( 0 )
177
+ } , [ offset ] )
178
+
169
179
useEffect ( ( ) => {
170
180
setIdentifiers ?.(
171
181
visibleRows . reduce ( ( acc , row ) => {
@@ -187,7 +197,7 @@ const InternalTable = ({
187
197
return
188
198
}
189
199
190
- node . scrollIntoView ( { behavior : 'instant ' , block : 'nearest' } )
200
+ node . scrollIntoView ( { behavior : 'smooth ' , block : 'nearest' } )
191
201
}
192
202
193
203
const showPagination =
@@ -238,15 +248,18 @@ const InternalTable = ({
238
248
return visibleRows . map ( ( row , visibleRowIndex ) => {
239
249
const rowIndex = rowToIndexMap ?. get ( row )
240
250
const isRowActive = activeRowIndex === visibleRowIndex
251
+ const isRowBulkSelected = ! ! bulkSelectionState [ row . id ] || isBulkSelectionApplied
241
252
242
253
return (
243
254
< div
244
255
ref = { scrollIntoViewActiveRowRefCallback }
245
- className = { `dc__grid px-20 ${
256
+ className = { `dc__grid px-20 form__checkbox-parent ${
246
257
showSeparatorBetweenRows ? 'dc__border-bottom-n1' : ''
247
258
} fs-13 fw-4 lh-20 cn-9 generic-table__row dc__gap-16 ${
248
- isRowActive ? 'generic-table__row--active' : ''
249
- } ${ RowActionsOnHoverComponent ? 'dc__position-rel dc__opacity-hover dc__opacity-hover--parent' : '' } `}
259
+ isRowActive ? 'generic-table__row--active form__checkbox-parent--active' : ''
260
+ } ${ RowActionsOnHoverComponent ? 'dc__position-rel dc__opacity-hover dc__opacity-hover--parent' : '' } ${
261
+ isRowBulkSelected ? 'generic-table__row--bulk-selected' : ''
262
+ } `}
250
263
style = { {
251
264
gridTemplateColumns,
252
265
} }
@@ -257,7 +270,7 @@ const InternalTable = ({
257
270
if ( field === BULK_ACTION_GUTTER_LABEL ) {
258
271
return (
259
272
< Checkbox
260
- isChecked = { ! ! bulkSelectionState [ row . id ] || isBulkSelectionApplied }
273
+ isChecked = { isRowBulkSelected }
261
274
onChange = { ( ) => handleToggleBulkSelectionOnRow ( row ) }
262
275
rootClassName = "mb-0"
263
276
value = { CHECKBOX_VALUE . CHECKED }
@@ -271,8 +284,9 @@ const InternalTable = ({
271
284
field = { field }
272
285
value = { row . data [ field ] }
273
286
signals = { EVENT_TARGET as SignalsType }
274
- data = { row . data }
287
+ row = { row }
275
288
filterData = { filterData }
289
+ isRowActive = { isRowActive }
276
290
{ ...additionalProps }
277
291
/>
278
292
)
@@ -306,8 +320,8 @@ const InternalTable = ({
306
320
307
321
return (
308
322
< div className = "generic-table flexbox-col dc__overflow-hidden flex-grow-1" >
309
- < div className = "flexbox-col flex-grow-1 w-100 dc__overflow-auto" >
310
- < div className = "bg__primary dc__min-width-fit-content px-20 dc__border-bottom-n1" ref = { parentRef } >
323
+ < div className = "flexbox-col flex-grow-1 w-100 dc__overflow-auto" ref = { parentRef } >
324
+ < div className = "bg__primary dc__min-width-fit-content px-20 dc__border-bottom-n1" >
311
325
{ loading && ! visibleColumns . length ? (
312
326
< div className = "flexbox py-12 dc__gap-16" >
313
327
{ Array ( 3 )
@@ -334,10 +348,10 @@ const InternalTable = ({
334
348
< SortableTableHeaderCell
335
349
key = { label }
336
350
title = { label }
337
- isSortable = { isSortable }
351
+ isSortable = { ! ! isSortable }
338
352
sortOrder = { sortOrder }
339
- isSorted = { sortBy === label }
340
- triggerSorting = { getTriggerSortingHandler ( label ) }
353
+ isSorted = { sortBy === field }
354
+ triggerSorting = { getTriggerSortingHandler ( field ) }
341
355
showTippyOnTruncate = { showTippyOnTruncate }
342
356
disabled = { areFilteredRowsLoading }
343
357
{ ...( isResizable
0 commit comments