@xy-planning-network/trees 0.11.6-dev-5 → 0.11.6-dev-6

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": "@xy-planning-network/trees",
3
- "version": "0.11.6-dev-5",
3
+ "version": "0.11.6-dev-6",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": "github:xy-planning-network/trees",
@@ -45,9 +45,7 @@ const loadAndRender = (): void => {
45
45
  q: query.value,
46
46
  }
47
47
 
48
- if (!selectionsPersisted.value) {
49
- clearSelections()
50
- }
48
+ clearSelections()
51
49
 
52
50
  BaseAPI.get<TrailsRespPaged<unknown>>(
53
51
  props.tableOptions.url,
@@ -140,10 +138,6 @@ const hasContent = computed((): boolean => {
140
138
  return rows.value.length ? true : false
141
139
  })
142
140
 
143
- const selectionsPersisted = computed(() => {
144
- return props.tableBulkActions.persistent ?? false
145
- })
146
-
147
141
  const clearSelections = () => {
148
142
  selected.value = []
149
143
  }
@@ -153,6 +147,12 @@ const selected = defineModel<number[]>("selected", {
153
147
  default: [],
154
148
  })
155
149
 
150
+ const selectedData = computed((): TableRowData[] => {
151
+ return tableData.value.filter((data) => {
152
+ return selected.value.includes(data?.id)
153
+ })
154
+ })
155
+
156
156
  const selectedOnPage = computed(() => {
157
157
  return selected.value.filter((id) => {
158
158
  return selectable.value.includes(id)
@@ -171,7 +171,7 @@ const bulkActions = computed(() => {
171
171
  onClick: () =>
172
172
  action.onClick.apply(undefined, [
173
173
  selected.value,
174
- undefined,
174
+ selectedData.value,
175
175
  publicMethods,
176
176
  ]),
177
177
  }
@@ -216,21 +216,6 @@ const bulkSelectIndeterminate = computed(
216
216
  const bulkSelectOnChange = (e: Event) => {
217
217
  const isChecked = (e.target as HTMLInputElement).checked
218
218
 
219
- // append all records on current page to existing selection
220
- if (selectionsPersisted.value && isChecked) {
221
- selected.value = [...selected.value, ...selectable.value.map((id) => id)]
222
- return
223
- }
224
-
225
- // remove all records on current page from existing selection
226
- if (selectionsPersisted.value && !isChecked) {
227
- selected.value = selected.value.filter((id) => {
228
- return !selectable.value.includes(id)
229
- })
230
-
231
- return
232
- }
233
-
234
219
  // set all records on current page to selection
235
220
  if (isChecked) {
236
221
  selected.value = selectable.value.map((id) => id)
@@ -242,6 +227,7 @@ const bulkSelectOnChange = (e: Event) => {
242
227
 
243
228
  const publicMethods: DynamicTableAPI = {
244
229
  clearSelection: clearSelections,
230
+ selectedData: selectedData,
245
231
  refresh: loadAndRender,
246
232
  reset: reloadTable,
247
233
  }
@@ -435,11 +421,6 @@ loadAndRender()
435
421
  <span class="font-medium">{{ selectedOnPage.length }}</span>
436
422
  of
437
423
  <span class="font-medium">{{ selectable.length }}</span>
438
- <span v-if="selectionsPersisted">
439
- /
440
- <span class="font-medium">{{ selected.length }}</span>
441
- total
442
- </span>
443
424
  </div>
444
425
 
445
426
  <TableActionButtons :actions="bulkActions" />
@@ -1,4 +1,4 @@
1
- import { VNodeChild } from "vue";
1
+ import { VNodeChild, type ComputedRef } from "vue";
2
2
  import { ActionItem } from "../composables/nav";
3
3
  import { DateRangeProps } from "./date";
4
4
  export interface DynamicTableOptions {
@@ -10,7 +10,12 @@ export interface DynamicTableOptions {
10
10
  search?: boolean;
11
11
  url: string;
12
12
  }
13
- export interface DynamicTableAPI {
13
+ export interface DynamicTableAPI<T = TableRowData> {
14
+ /**
15
+ * Clear the currently selected rows when bulk selections are enabled
16
+ * This method is called when refresh and reset methods are called.
17
+ * @returns void
18
+ */
14
19
  clearSelection: () => void;
15
20
  /**
16
21
  * Force refresh the table data with the current api params state
@@ -22,6 +27,10 @@ export interface DynamicTableAPI {
22
27
  * @returns void
23
28
  */
24
29
  reset: () => void;
30
+ /**
31
+ * The selected data records when bulk actions are enabled on the table
32
+ */
33
+ selectedData: ComputedRef<T[]>;
25
34
  }
26
35
  export interface TableActionItem<T = TableRowData> extends ActionItem {
27
36
  /**
@@ -49,7 +58,7 @@ export interface TableActionItem<T = TableRowData> extends ActionItem {
49
58
  */
50
59
  show?: boolean | ((rowData: T, rowIndex: number) => boolean);
51
60
  }
52
- export interface TableBulkActionItem extends ActionItem {
61
+ export interface TableBulkActionItem<T = TableRowData> extends ActionItem {
53
62
  /**
54
63
  * Whether or not the bulk action item is enabled. Disabled actions are
55
64
  * visible in the UI, but do not trigger click events.
@@ -58,11 +67,11 @@ export interface TableBulkActionItem extends ActionItem {
58
67
  /**
59
68
  * The callback method triggered by the action item buttons click event.
60
69
  * @param selected the array of selected rows by the primary key `id`
61
- * @param _ NOTE(spk): Holding for T[]
70
+ * @param selectedData the array of selected rows as the underlying data type T
62
71
  * @param tableAPI DynamicTableAPI
63
72
  * @returns void
64
73
  */
65
- onClick: (selected: number[], _: undefined, tableAPI: DynamicTableAPI) => void;
74
+ onClick: (selected: number[], selectedData: T[], tableAPI: DynamicTableAPI) => void;
66
75
  /**
67
76
  * Whether or not to visible show the action item in the UI. When all action items
68
77
  * on a table a hidden with show: false, bulk selections are disabled for the table.
@@ -83,11 +92,7 @@ export interface TableBulkActions<T = TableRowData> {
83
92
  /**
84
93
  * an array of TableActionItem definitions
85
94
  */
86
- actions: TableBulkActionItem[];
87
- /**
88
- * whether to persist the selections across pagination, searching, sorting, and filtering
89
- */
90
- persistent?: boolean;
95
+ actions: TableBulkActionItem<T>[];
91
96
  /**
92
97
  * a function that determines if the row can be selected for bulk actions
93
98
  */
@@ -1,4 +1,4 @@
1
- import type { DynamicTableOptions, TableActions, TableBulkActions, TableColumns } from "../../composables/table";
1
+ import type { DynamicTableOptions, TableActions, TableBulkActions, TableColumns, TableRowData } from "../../composables/table";
2
2
  type __VLS_Props = {
3
3
  tableActions?: TableActions<any>;
4
4
  tableBulkActions?: TableBulkActions<any>;
@@ -12,6 +12,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
12
12
  clearSelection: () => void;
13
13
  refresh: () => void;
14
14
  reset: () => void;
15
+ selectedData: import("vue").ComputedRef<TableRowData[]>;
15
16
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
17
  "update:selected": (value: number[]) => any;
17
18
  } & {