@dataloop-ai/components 0.20.165 → 0.20.166

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.20.165",
3
+ "version": "0.20.166",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -51,14 +51,18 @@ export function useTableRowSelection(
51
51
  )
52
52
  )
53
53
 
54
- const someRowsSelected = computed(
55
- () =>
56
- allRowsSelected.value !== true &&
57
- computedRows.value.some(
58
- (row) => selectedKeys.value[getRowKey.value(row)] === true
59
- )
60
- )
61
-
54
+ const someRowsSelected = computed(() => {
55
+ if (allRowsSelected.value === true) return false
56
+ const stack = computedRows.value.slice()
57
+ while (stack.length) {
58
+ const row = stack.pop()
59
+ if (selectedKeys.value[getRowKey.value(row)] === true) return true
60
+ if (row.children && row.children.length) {
61
+ stack.push(...row.children)
62
+ }
63
+ }
64
+ return false
65
+ })
62
66
  const rowsSelectedNumber = computed(() => props.selected.length)
63
67
 
64
68
  function isRowSelected(key: string) {
@@ -22,6 +22,7 @@ export type DlTableProps = {
22
22
 
23
23
  export type DlTableRow = {
24
24
  [key: string]: any
25
+ children?: DlTableRow[]
25
26
  }
26
27
 
27
28
  export type DlTableFilter = string | Record<string, any>
@@ -513,7 +513,12 @@ export default defineComponent({
513
513
  props.rowKey
514
514
  )
515
515
 
516
- updateSelection(childrenKeys, childrenCollection, adding, event)
516
+ selectedData.value = updateSelection(
517
+ childrenKeys,
518
+ childrenCollection,
519
+ adding,
520
+ event
521
+ )
517
522
  }
518
523
  const headerSelectedValue = computed(() => {
519
524
  if (selectedData.value.length === tableRows.value.length)
@@ -538,16 +543,7 @@ export default defineComponent({
538
543
  updateSelected(value ? tableRows.value : [])
539
544
  }
540
545
  const updateSelected = (payload: DlTableRow[]) => {
541
- const hasSelection = selectedData.value.length > 0
542
- selectedData.value = payload
543
-
544
- if (payload.length > 0) {
545
- selectAllRows(true)
546
- } else if (payload.length === 0 && hasSelection) {
547
- selectAllRows(false)
548
- } else {
549
- emitSelectedItems(payload)
550
- }
546
+ selectedData.value = selectAllRows(!allRowsSelected.value)
551
547
  }
552
548
  const emitSelectedItems = (payload: DlTableRow[]) => {
553
549
  emit('selected-items', payload)
@@ -182,6 +182,7 @@ export function useTreeTableRowSelection(
182
182
  selectedItemsNested.value = selectedItems
183
183
 
184
184
  emit('selected-items', selectedItems)
185
+ return selectedItems
185
186
  }
186
187
 
187
188
  function isIncludedInSelectedNestedItems(
@@ -257,12 +258,13 @@ export function useTreeTableRowSelection(
257
258
  if (select) {
258
259
  const allRows = getAllRows(computedRows.value)
259
260
  const allKeys = allRows.map(getRowKey.value)
260
- updateSelection(allKeys, allRows, true)
261
+ return updateSelection(allKeys, allRows, true)
261
262
  } else {
262
263
  clearSelection()
263
264
  selectedItemsNested.value = []
264
265
  emit('selected-items', [])
265
266
  }
267
+ return []
266
268
  }
267
269
 
268
270
  return {
@@ -110,7 +110,7 @@
110
110
  :loading="loading"
111
111
  :rows="tableRows"
112
112
  :resizable="resizable"
113
- row-key="name"
113
+ row-key="id"
114
114
  color="dl-color-secondary"
115
115
  title="Table Title"
116
116
  :virtual-scroll="vScroll"
@@ -560,7 +560,15 @@ const columns2 = [
560
560
  hint: 'test hint'
561
561
  }
562
562
  ]
563
-
563
+ function markAllSelectable(list: DlTableRow[]): DlTableRow[] {
564
+ return list.map((r) => ({
565
+ ...r,
566
+ isSelectable: true,
567
+ ...(Array.isArray(r.children) && r.children.length
568
+ ? { children: markAllSelectable(r.children) }
569
+ : {})
570
+ }))
571
+ }
564
572
  export default defineComponent({
565
573
  components: {
566
574
  DlSwitch,
@@ -583,7 +591,7 @@ export default defineComponent({
583
591
  const denseState = ref([])
584
592
  const virtualScroll = ref([])
585
593
  const resizableState = ref([])
586
- const tableRows = ref(rows)
594
+ const tableRows = ref(markAllSelectable(rows))
587
595
  const tableRowsVS = ref(cloneDeep(rows))
588
596
  const draggable = ref('both')
589
597
  const tableColumns = ref(columns)