openxiangda 1.0.216 → 1.0.217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -197,8 +197,11 @@ export function AdminList<Row>(props: AdminListProps<Row>) {
197
197
  preserveSelectionAcrossPages = true,
198
198
  rowActions = [],
199
199
  rowKey,
200
+ rowSelectable,
201
+ rowSelectionReason,
200
202
  searchFields = [],
201
203
  selectable = true,
204
+ selectedRowKeys: controlledSelectedKeys,
202
205
  style,
203
206
  toolbar,
204
207
  } = props
@@ -287,6 +290,46 @@ export function AdminList<Row>(props: AdminListProps<Row>) {
287
290
  [messageApi, onSelectionChange],
288
291
  )
289
292
 
293
+ useEffect(() => {
294
+ if (!controlledSelectedKeys) return
295
+ const nextKeys = [...controlledSelectedKeys]
296
+ const nextKeySet = new Set(nextKeys)
297
+ for (const key of selectedRowsRef.current.keys()) {
298
+ if (!nextKeySet.has(key)) selectedRowsRef.current.delete(key)
299
+ }
300
+ for (const row of rows) {
301
+ const key = getRowKey(rowKey, row)
302
+ if (nextKeySet.has(key)) selectedRowsRef.current.set(key, row)
303
+ }
304
+ selectedKeysRef.current = nextKeys
305
+ setSelectedKeys(nextKeys)
306
+ }, [controlledSelectedKeys, rowKey, rows])
307
+
308
+ useEffect(() => {
309
+ if (!rowSelectable || !selectedKeysRef.current.length || !rows.length) {
310
+ return
311
+ }
312
+ const disabledKeys = new Set(
313
+ rows
314
+ .filter((row) => !rowSelectable(row))
315
+ .map((row) => getRowKey(rowKey, row)),
316
+ )
317
+ if (!disabledKeys.size) return
318
+ const nextKeys = selectedKeysRef.current.filter(
319
+ (key) => !disabledKeys.has(key),
320
+ )
321
+ if (nextKeys.length === selectedKeysRef.current.length) return
322
+ for (const key of disabledKeys) selectedRowsRef.current.delete(key)
323
+ selectedKeysRef.current = nextKeys
324
+ setSelectedKeys(nextKeys)
325
+ onSelectionChange?.({
326
+ rowKeys: nextKeys,
327
+ rows: nextKeys
328
+ .map((key) => selectedRowsRef.current.get(key))
329
+ .filter(Boolean) as Row[],
330
+ })
331
+ }, [onSelectionChange, rowKey, rowSelectable, rows])
332
+
290
333
  useEffect(() => {
291
334
  let active = true
292
335
  setReady(false)
@@ -1425,6 +1468,10 @@ export function AdminList<Row>(props: AdminListProps<Row>) {
1425
1468
  preserveSelectedRowKeys:
1426
1469
  preserveSelectionAcrossPages,
1427
1470
  selectedRowKeys: selectedKeys,
1471
+ getCheckboxProps: (row: Row) => ({
1472
+ disabled: rowSelectable ? !rowSelectable(row) : false,
1473
+ title: rowSelectionReason?.(row),
1474
+ }),
1428
1475
  onChange: handleSelectionChange,
1429
1476
  }
1430
1477
  : undefined
@@ -236,6 +236,9 @@ export interface AdminListProps<Row> {
236
236
  fixedFilters?: Record<string, unknown>
237
237
  lockedPreference?: AdminListLockedPreference
238
238
  selectable?: boolean
239
+ selectedRowKeys?: Key[]
240
+ rowSelectable?: (row: Row) => boolean
241
+ rowSelectionReason?: (row: Row) => string | undefined
239
242
  preserveSelectionAcrossPages?: boolean
240
243
  exportable?: boolean
241
244
  fileName?: string