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

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-7",
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,
@@ -105,7 +103,7 @@ const dateRange = ref({
105
103
 
106
104
  const pagination = ref({
107
105
  page: 1,
108
- perPage: 10,
106
+ perPage: props.tableOptions?.perPage || 10,
109
107
  totalItems: 0,
110
108
  totalPages: 0,
111
109
  })
@@ -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" />
@@ -516,6 +497,7 @@ loadAndRender()
516
497
  <div v-if="hasContent" class="mt-4">
517
498
  <TablePaginator
518
499
  v-model="pagination"
500
+ :page-options="tableOptions?.pageOptions"
519
501
  @update:model-value="loadAndRender()"
520
502
  />
521
503
  </div>
@@ -1,16 +1,26 @@
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 {
5
5
  dateSearch?: boolean | DateRangeProps;
6
6
  defaultSort?: string;
7
7
  defaultSortDirection?: string;
8
+ pageOptions?: {
9
+ label: string;
10
+ value: number;
11
+ }[];
12
+ perPage?: number;
8
13
  refreshTrigger: number;
9
14
  reloadTrigger?: number;
10
15
  search?: boolean;
11
16
  url: string;
12
17
  }
13
- export interface DynamicTableAPI {
18
+ export interface DynamicTableAPI<T = TableRowData> {
19
+ /**
20
+ * Clear the currently selected rows when bulk selections are enabled
21
+ * This method is called when refresh and reset methods are called.
22
+ * @returns void
23
+ */
14
24
  clearSelection: () => void;
15
25
  /**
16
26
  * Force refresh the table data with the current api params state
@@ -22,6 +32,10 @@ export interface DynamicTableAPI {
22
32
  * @returns void
23
33
  */
24
34
  reset: () => void;
35
+ /**
36
+ * The selected data records when bulk actions are enabled on the table
37
+ */
38
+ selectedData: ComputedRef<T[]>;
25
39
  }
26
40
  export interface TableActionItem<T = TableRowData> extends ActionItem {
27
41
  /**
@@ -49,7 +63,7 @@ export interface TableActionItem<T = TableRowData> extends ActionItem {
49
63
  */
50
64
  show?: boolean | ((rowData: T, rowIndex: number) => boolean);
51
65
  }
52
- export interface TableBulkActionItem extends ActionItem {
66
+ export interface TableBulkActionItem<T = TableRowData> extends ActionItem {
53
67
  /**
54
68
  * Whether or not the bulk action item is enabled. Disabled actions are
55
69
  * visible in the UI, but do not trigger click events.
@@ -58,11 +72,11 @@ export interface TableBulkActionItem extends ActionItem {
58
72
  /**
59
73
  * The callback method triggered by the action item buttons click event.
60
74
  * @param selected the array of selected rows by the primary key `id`
61
- * @param _ NOTE(spk): Holding for T[]
75
+ * @param selectedData the array of selected rows as the underlying data type T
62
76
  * @param tableAPI DynamicTableAPI
63
77
  * @returns void
64
78
  */
65
- onClick: (selected: number[], _: undefined, tableAPI: DynamicTableAPI) => void;
79
+ onClick: (selected: number[], selectedData: T[], tableAPI: DynamicTableAPI) => void;
66
80
  /**
67
81
  * Whether or not to visible show the action item in the UI. When all action items
68
82
  * on a table a hidden with show: false, bulk selections are disabled for the table.
@@ -83,11 +97,7 @@ export interface TableBulkActions<T = TableRowData> {
83
97
  /**
84
98
  * an array of TableActionItem definitions
85
99
  */
86
- actions: TableBulkActionItem[];
87
- /**
88
- * whether to persist the selections across pagination, searching, sorting, and filtering
89
- */
90
- persistent?: boolean;
100
+ actions: TableBulkActionItem<T>[];
91
101
  /**
92
102
  * a function that determines if the row can be selected for bulk actions
93
103
  */
@@ -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
  } & {