@servicetitan/table 22.1.0 → 22.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +24 -0
- package/dist/demo/index.d.ts +4 -0
- package/dist/demo/index.d.ts.map +1 -0
- package/dist/demo/index.js +4 -0
- package/dist/demo/index.js.map +1 -0
- package/dist/demo/master-detail/detail-table.d.ts +4 -0
- package/dist/demo/master-detail/detail-table.d.ts.map +1 -0
- package/dist/demo/master-detail/detail-table.js +28 -0
- package/dist/demo/master-detail/detail-table.js.map +1 -0
- package/dist/demo/master-detail/detail-table.store.d.ts +14 -0
- package/dist/demo/master-detail/detail-table.store.d.ts.map +1 -0
- package/dist/demo/master-detail/detail-table.store.js +104 -0
- package/dist/demo/master-detail/detail-table.store.js.map +1 -0
- package/dist/demo/master-detail/index.d.ts +2 -0
- package/dist/demo/master-detail/index.d.ts.map +1 -0
- package/dist/demo/master-detail/index.js +2 -0
- package/dist/demo/master-detail/index.js.map +1 -0
- package/dist/demo/master-detail/master-table.store.d.ts +14 -0
- package/dist/demo/master-detail/master-table.store.d.ts.map +1 -0
- package/dist/demo/master-detail/master-table.store.js +103 -0
- package/dist/demo/master-detail/master-table.store.js.map +1 -0
- package/dist/demo/master-detail/product-detail.d.ts +8 -0
- package/dist/demo/master-detail/product-detail.d.ts.map +1 -0
- package/dist/demo/master-detail/product-detail.js +2 -0
- package/dist/demo/master-detail/product-detail.js.map +1 -0
- package/dist/demo/master-detail/product-details.d.ts +3 -0
- package/dist/demo/master-detail/product-details.d.ts.map +1 -0
- package/dist/demo/master-detail/product-details.js +55 -0
- package/dist/demo/master-detail/product-details.js.map +1 -0
- package/dist/demo/master-detail/product.d.ts +26 -0
- package/dist/demo/master-detail/product.d.ts.map +1 -0
- package/dist/demo/master-detail/product.js +16 -0
- package/dist/demo/master-detail/product.js.map +1 -0
- package/dist/demo/master-detail/products.d.ts +3 -0
- package/dist/demo/master-detail/products.d.ts.map +1 -0
- package/dist/demo/master-detail/products.js +117 -0
- package/dist/demo/master-detail/products.js.map +1 -0
- package/dist/demo/master-detail/table-master-detail.d.ts +3 -0
- package/dist/demo/master-detail/table-master-detail.d.ts.map +1 -0
- package/dist/demo/master-detail/table-master-detail.js +24 -0
- package/dist/demo/master-detail/table-master-detail.js.map +1 -0
- package/dist/demo/overview/actions-cell.d.ts +5 -0
- package/dist/demo/overview/actions-cell.d.ts.map +1 -0
- package/dist/demo/overview/actions-cell.js +38 -0
- package/dist/demo/overview/actions-cell.js.map +1 -0
- package/dist/demo/overview/index.d.ts +2 -0
- package/dist/demo/overview/index.d.ts.map +1 -0
- package/dist/demo/overview/index.js +2 -0
- package/dist/demo/overview/index.js.map +1 -0
- package/dist/demo/overview/product.d.ts +27 -0
- package/dist/demo/overview/product.d.ts.map +1 -0
- package/dist/demo/overview/product.js +16 -0
- package/dist/demo/overview/product.js.map +1 -0
- package/dist/demo/overview/products.d.ts +3 -0
- package/dist/demo/overview/products.d.ts.map +1 -0
- package/dist/demo/overview/products.js +127 -0
- package/dist/demo/overview/products.js.map +1 -0
- package/dist/demo/overview/table.d.ts +6 -0
- package/dist/demo/overview/table.d.ts.map +1 -0
- package/dist/demo/overview/table.js +44 -0
- package/dist/demo/overview/table.js.map +1 -0
- package/dist/demo/overview/table.store.d.ts +15 -0
- package/dist/demo/overview/table.store.d.ts.map +1 -0
- package/dist/demo/overview/table.store.js +92 -0
- package/dist/demo/overview/table.store.js.map +1 -0
- package/dist/demo/state-caching/beverages.d.ts +3 -0
- package/dist/demo/state-caching/beverages.d.ts.map +1 -0
- package/dist/demo/state-caching/beverages.js +48 -0
- package/dist/demo/state-caching/beverages.js.map +1 -0
- package/dist/demo/state-caching/index.d.ts +2 -0
- package/dist/demo/state-caching/index.d.ts.map +1 -0
- package/dist/demo/state-caching/index.js +2 -0
- package/dist/demo/state-caching/index.js.map +1 -0
- package/dist/demo/state-caching/product.d.ts +6 -0
- package/dist/demo/state-caching/product.d.ts.map +1 -0
- package/dist/demo/state-caching/product.js +2 -0
- package/dist/demo/state-caching/product.js.map +1 -0
- package/dist/demo/state-caching/products.d.ts +3 -0
- package/dist/demo/state-caching/products.d.ts.map +1 -0
- package/dist/demo/state-caching/products.js +53 -0
- package/dist/demo/state-caching/products.js.map +1 -0
- package/dist/demo/state-caching/state-caching-table.d.ts +3 -0
- package/dist/demo/state-caching/state-caching-table.d.ts.map +1 -0
- package/dist/demo/state-caching/state-caching-table.js +14 -0
- package/dist/demo/state-caching/state-caching-table.js.map +1 -0
- package/dist/demo/state-caching/state-caching-table.store.d.ts +13 -0
- package/dist/demo/state-caching/state-caching-table.store.d.ts.map +1 -0
- package/dist/demo/state-caching/state-caching-table.store.js +70 -0
- package/dist/demo/state-caching/state-caching-table.store.js.map +1 -0
- package/dist/editable-cell/boolean-editable-cell.d.ts +3 -0
- package/dist/editable-cell/boolean-editable-cell.d.ts.map +1 -0
- package/dist/editable-cell/boolean-editable-cell.js +14 -0
- package/dist/editable-cell/boolean-editable-cell.js.map +1 -0
- package/dist/editable-cell/date-editable-cell.d.ts +3 -0
- package/dist/editable-cell/date-editable-cell.d.ts.map +1 -0
- package/dist/editable-cell/date-editable-cell.js +14 -0
- package/dist/editable-cell/date-editable-cell.js.map +1 -0
- package/dist/editable-cell/get-action-cell.d.ts +13 -0
- package/dist/editable-cell/get-action-cell.d.ts.map +1 -0
- package/dist/editable-cell/get-action-cell.js +18 -0
- package/dist/editable-cell/get-action-cell.js.map +1 -0
- package/dist/editable-cell/get-editable-cell.d.ts +13 -0
- package/dist/editable-cell/get-editable-cell.d.ts.map +1 -0
- package/dist/editable-cell/get-editable-cell.js +18 -0
- package/dist/editable-cell/get-editable-cell.js.map +1 -0
- package/dist/editable-cell/get-select-editable-cell.d.ts +10 -0
- package/dist/editable-cell/get-select-editable-cell.d.ts.map +1 -0
- package/dist/editable-cell/get-select-editable-cell.js +19 -0
- package/dist/editable-cell/get-select-editable-cell.js.map +1 -0
- package/dist/editable-cell/index.d.ts +8 -0
- package/dist/editable-cell/index.d.ts.map +1 -0
- package/dist/editable-cell/index.js +8 -0
- package/dist/editable-cell/index.js.map +1 -0
- package/dist/editable-cell/numeric-editable-cell.d.ts +3 -0
- package/dist/editable-cell/numeric-editable-cell.d.ts.map +1 -0
- package/dist/editable-cell/numeric-editable-cell.js +15 -0
- package/dist/editable-cell/numeric-editable-cell.js.map +1 -0
- package/dist/editable-cell/text-editable-cell.d.ts +9 -0
- package/dist/editable-cell/text-editable-cell.d.ts.map +1 -0
- package/dist/editable-cell/text-editable-cell.js +20 -0
- package/dist/editable-cell/text-editable-cell.js.map +1 -0
- package/dist/export/export.d.ts +10 -0
- package/dist/export/export.d.ts.map +1 -0
- package/dist/export/export.js +6 -0
- package/dist/export/export.js.map +1 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +2 -0
- package/dist/export/index.js.map +1 -0
- package/dist/filters/column-menu-filters.d.ts +5 -0
- package/dist/filters/column-menu-filters.d.ts.map +1 -0
- package/dist/filters/column-menu-filters.js +9 -0
- package/dist/filters/column-menu-filters.js.map +1 -0
- package/dist/filters/datetime-filter/datetime-filter.d.ts +3 -0
- package/dist/filters/datetime-filter/datetime-filter.d.ts.map +1 -0
- package/dist/filters/datetime-filter/datetime-filter.js +71 -0
- package/dist/filters/datetime-filter/datetime-filter.js.map +1 -0
- package/dist/filters/field-values-filter.d.ts +6 -0
- package/dist/filters/field-values-filter.d.ts.map +1 -0
- package/dist/filters/field-values-filter.js +155 -0
- package/dist/filters/field-values-filter.js.map +1 -0
- package/dist/filters/index.d.ts +9 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +9 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/filters/multiselect-filter.d.ts +5 -0
- package/dist/filters/multiselect-filter.d.ts.map +1 -0
- package/dist/filters/multiselect-filter.js +107 -0
- package/dist/filters/multiselect-filter.js.map +1 -0
- package/dist/filters/numeric-filter-extended/numeric-extended-operators.d.ts +6 -0
- package/dist/filters/numeric-filter-extended/numeric-extended-operators.d.ts.map +1 -0
- package/dist/filters/numeric-filter-extended/numeric-extended-operators.js +6 -0
- package/dist/filters/numeric-filter-extended/numeric-extended-operators.js.map +1 -0
- package/dist/filters/numeric-filter-extended/numeric-filter-extended.d.ts +3 -0
- package/dist/filters/numeric-filter-extended/numeric-filter-extended.d.ts.map +1 -0
- package/dist/filters/numeric-filter-extended/numeric-filter-extended.js +27 -0
- package/dist/filters/numeric-filter-extended/numeric-filter-extended.js.map +1 -0
- package/dist/filters/range-filter/range-filter.d.ts +6 -0
- package/dist/filters/range-filter/range-filter.d.ts.map +1 -0
- package/dist/filters/range-filter/range-filter.js +117 -0
- package/dist/filters/range-filter/range-filter.js.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/filter-cell-ext.d.ts +21 -0
- package/dist/filters/standard-filter-with-multiselect/filter-cell-ext.d.ts.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/filter-cell-ext.js +82 -0
- package/dist/filters/standard-filter-with-multiselect/filter-cell-ext.js.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/multiselect-operators.d.ts +6 -0
- package/dist/filters/standard-filter-with-multiselect/multiselect-operators.d.ts.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/multiselect-operators.js +6 -0
- package/dist/filters/standard-filter-with-multiselect/multiselect-operators.js.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/standard-filter-with-multiselect.d.ts +26 -0
- package/dist/filters/standard-filter-with-multiselect/standard-filter-with-multiselect.d.ts.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/standard-filter-with-multiselect.js +69 -0
- package/dist/filters/standard-filter-with-multiselect/standard-filter-with-multiselect.js.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/table-column-menu-filter-ext.d.ts +6 -0
- package/dist/filters/standard-filter-with-multiselect/table-column-menu-filter-ext.d.ts.map +1 -0
- package/dist/filters/standard-filter-with-multiselect/table-column-menu-filter-ext.js +30 -0
- package/dist/filters/standard-filter-with-multiselect/table-column-menu-filter-ext.js.map +1 -0
- package/dist/filters/time-filter/time-filter.d.ts +3 -0
- package/dist/filters/time-filter/time-filter.d.ts.map +1 -0
- package/dist/filters/time-filter/time-filter.js +71 -0
- package/dist/filters/time-filter/time-filter.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/select-cell/index.d.ts +2 -0
- package/dist/select-cell/index.d.ts.map +1 -0
- package/dist/select-cell/index.js +2 -0
- package/dist/select-cell/index.js.map +1 -0
- package/dist/select-cell/select-cell.d.ts +25 -0
- package/dist/select-cell/select-cell.d.ts.map +1 -0
- package/dist/select-cell/select-cell.js +35 -0
- package/dist/select-cell/select-cell.js.map +1 -0
- package/dist/table-state.d.ts +161 -0
- package/dist/table-state.d.ts.map +1 -0
- package/dist/table-state.js +1106 -0
- package/dist/table-state.js.map +1 -0
- package/dist/table.d.ts +40 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +231 -0
- package/dist/table.js.map +1 -0
- package/package.json +6 -6
- package/src/select-cell/select-cell.tsx +16 -44
@@ -0,0 +1,1106 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17
|
+
});
|
18
|
+
};
|
19
|
+
import { action, computed, observable, runInAction, makeObservable } from 'mobx';
|
20
|
+
import { fromPromise } from 'mobx-utils';
|
21
|
+
import { formStateToJS } from '@servicetitan/form';
|
22
|
+
export function isGroupItem(item, groups) {
|
23
|
+
const field = item.field;
|
24
|
+
return !!field && groups.some(g => g.field === field);
|
25
|
+
}
|
26
|
+
function addAggregatesToGroups(groups, aggregates) {
|
27
|
+
return groups.map(group => (Object.assign(Object.assign({}, group), { aggregates })));
|
28
|
+
}
|
29
|
+
export class TableState {
|
30
|
+
constructor({ dataSource = null, pageSize, isRowUnselectable = () => false, selectionLimit = Infinity, getFormState, parent, getDetailTableState, initialState, alwaysEditable = false, } = {}) {
|
31
|
+
Object.defineProperty(this, "innerDataSource", {
|
32
|
+
enumerable: true,
|
33
|
+
configurable: true,
|
34
|
+
writable: true,
|
35
|
+
value: void 0
|
36
|
+
});
|
37
|
+
Object.defineProperty(this, "parent", {
|
38
|
+
enumerable: true,
|
39
|
+
configurable: true,
|
40
|
+
writable: true,
|
41
|
+
value: void 0
|
42
|
+
});
|
43
|
+
Object.defineProperty(this, "getDetailTableState", {
|
44
|
+
enumerable: true,
|
45
|
+
configurable: true,
|
46
|
+
writable: true,
|
47
|
+
value: void 0
|
48
|
+
});
|
49
|
+
Object.defineProperty(this, "selectedIds", {
|
50
|
+
enumerable: true,
|
51
|
+
configurable: true,
|
52
|
+
writable: true,
|
53
|
+
value: new Set()
|
54
|
+
});
|
55
|
+
Object.defineProperty(this, "inEdit", {
|
56
|
+
enumerable: true,
|
57
|
+
configurable: true,
|
58
|
+
writable: true,
|
59
|
+
value: new Map()
|
60
|
+
});
|
61
|
+
Object.defineProperty(this, "expandedIds", {
|
62
|
+
enumerable: true,
|
63
|
+
configurable: true,
|
64
|
+
writable: true,
|
65
|
+
value: new Set()
|
66
|
+
});
|
67
|
+
Object.defineProperty(this, "collapsedGroups", {
|
68
|
+
enumerable: true,
|
69
|
+
configurable: true,
|
70
|
+
writable: true,
|
71
|
+
value: new Set()
|
72
|
+
});
|
73
|
+
Object.defineProperty(this, "isRowUnselectable", {
|
74
|
+
enumerable: true,
|
75
|
+
configurable: true,
|
76
|
+
writable: true,
|
77
|
+
value: void 0
|
78
|
+
}); // TODO: think about a better name
|
79
|
+
Object.defineProperty(this, "selectionLimit", {
|
80
|
+
enumerable: true,
|
81
|
+
configurable: true,
|
82
|
+
writable: true,
|
83
|
+
value: void 0
|
84
|
+
});
|
85
|
+
Object.defineProperty(this, "data", {
|
86
|
+
enumerable: true,
|
87
|
+
configurable: true,
|
88
|
+
writable: true,
|
89
|
+
value: []
|
90
|
+
});
|
91
|
+
Object.defineProperty(this, "totalCount", {
|
92
|
+
enumerable: true,
|
93
|
+
configurable: true,
|
94
|
+
writable: true,
|
95
|
+
value: 0
|
96
|
+
});
|
97
|
+
Object.defineProperty(this, "filteredCount", {
|
98
|
+
enumerable: true,
|
99
|
+
configurable: true,
|
100
|
+
writable: true,
|
101
|
+
value: 0
|
102
|
+
});
|
103
|
+
Object.defineProperty(this, "selectedCount", {
|
104
|
+
enumerable: true,
|
105
|
+
configurable: true,
|
106
|
+
writable: true,
|
107
|
+
value: 0
|
108
|
+
});
|
109
|
+
Object.defineProperty(this, "unselectableCount", {
|
110
|
+
enumerable: true,
|
111
|
+
configurable: true,
|
112
|
+
writable: true,
|
113
|
+
value: 0
|
114
|
+
});
|
115
|
+
Object.defineProperty(this, "sort", {
|
116
|
+
enumerable: true,
|
117
|
+
configurable: true,
|
118
|
+
writable: true,
|
119
|
+
value: []
|
120
|
+
});
|
121
|
+
Object.defineProperty(this, "filter", {
|
122
|
+
enumerable: true,
|
123
|
+
configurable: true,
|
124
|
+
writable: true,
|
125
|
+
value: void 0
|
126
|
+
});
|
127
|
+
Object.defineProperty(this, "aggregates", {
|
128
|
+
enumerable: true,
|
129
|
+
configurable: true,
|
130
|
+
writable: true,
|
131
|
+
value: []
|
132
|
+
});
|
133
|
+
Object.defineProperty(this, "innerGroup", {
|
134
|
+
enumerable: true,
|
135
|
+
configurable: true,
|
136
|
+
writable: true,
|
137
|
+
value: []
|
138
|
+
});
|
139
|
+
Object.defineProperty(this, "skip", {
|
140
|
+
enumerable: true,
|
141
|
+
configurable: true,
|
142
|
+
writable: true,
|
143
|
+
value: 0
|
144
|
+
});
|
145
|
+
Object.defineProperty(this, "pageSize", {
|
146
|
+
enumerable: true,
|
147
|
+
configurable: true,
|
148
|
+
writable: true,
|
149
|
+
value: void 0
|
150
|
+
});
|
151
|
+
Object.defineProperty(this, "tablePdfExport", {
|
152
|
+
enumerable: true,
|
153
|
+
configurable: true,
|
154
|
+
writable: true,
|
155
|
+
value: null
|
156
|
+
});
|
157
|
+
Object.defineProperty(this, "tableExcelExport", {
|
158
|
+
enumerable: true,
|
159
|
+
configurable: true,
|
160
|
+
writable: true,
|
161
|
+
value: null
|
162
|
+
});
|
163
|
+
Object.defineProperty(this, "alwaysEditable", {
|
164
|
+
enumerable: true,
|
165
|
+
configurable: true,
|
166
|
+
writable: true,
|
167
|
+
value: void 0
|
168
|
+
});
|
169
|
+
Object.defineProperty(this, "fetchInitialData", {
|
170
|
+
enumerable: true,
|
171
|
+
configurable: true,
|
172
|
+
writable: true,
|
173
|
+
value: () => __awaiter(this, void 0, void 0, function* () {
|
174
|
+
if (!this.dataSource) {
|
175
|
+
return;
|
176
|
+
}
|
177
|
+
const initial = (yield this.dataSource.getData({
|
178
|
+
skip: this.skip,
|
179
|
+
take: this.pageSize,
|
180
|
+
filter: this.filter,
|
181
|
+
sort: [...this.sort],
|
182
|
+
group: [...this.group],
|
183
|
+
}));
|
184
|
+
runInAction(() => {
|
185
|
+
this.totalCount = initial.total;
|
186
|
+
this.filteredCount = initial.total;
|
187
|
+
this.data = initial.data;
|
188
|
+
this.unselectableCount = this.originalData.filter(this.isRowUnselectable).length;
|
189
|
+
this.addPropertiesToRows(this.data);
|
190
|
+
});
|
191
|
+
})
|
192
|
+
});
|
193
|
+
Object.defineProperty(this, "handleFilterChange", {
|
194
|
+
enumerable: true,
|
195
|
+
configurable: true,
|
196
|
+
writable: true,
|
197
|
+
value: (ev) => {
|
198
|
+
this.fetchData({
|
199
|
+
newFilter: ev.filter,
|
200
|
+
});
|
201
|
+
}
|
202
|
+
});
|
203
|
+
Object.defineProperty(this, "handleGroupChange", {
|
204
|
+
enumerable: true,
|
205
|
+
configurable: true,
|
206
|
+
writable: true,
|
207
|
+
value: (ev) => {
|
208
|
+
this.collapsedGroups = new Set();
|
209
|
+
this.fetchData({
|
210
|
+
newGroup: ev.group,
|
211
|
+
});
|
212
|
+
}
|
213
|
+
});
|
214
|
+
Object.defineProperty(this, "handleExpandChange", {
|
215
|
+
enumerable: true,
|
216
|
+
configurable: true,
|
217
|
+
writable: true,
|
218
|
+
value: ({ dataItem, value }) => {
|
219
|
+
if (isGroupItem(dataItem, this.group)) {
|
220
|
+
const { materializedPath } = dataItem;
|
221
|
+
if (value) {
|
222
|
+
this.collapsedGroups.delete(materializedPath);
|
223
|
+
}
|
224
|
+
else {
|
225
|
+
this.collapsedGroups.add(materializedPath);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
else {
|
229
|
+
if (!this.dataSource) {
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
if (!this.dataSource.idSelector) {
|
233
|
+
throw 'missing idSelector in the data source';
|
234
|
+
}
|
235
|
+
const id = this.dataSource.idSelector(dataItem);
|
236
|
+
if (value) {
|
237
|
+
this.expandedIds.add(id);
|
238
|
+
}
|
239
|
+
else {
|
240
|
+
this.expandedIds.delete(id);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
this.data = this.data.slice();
|
244
|
+
}
|
245
|
+
});
|
246
|
+
Object.defineProperty(this, "handleSortChange", {
|
247
|
+
enumerable: true,
|
248
|
+
configurable: true,
|
249
|
+
writable: true,
|
250
|
+
value: (ev) => {
|
251
|
+
this.fetchData({
|
252
|
+
newSort: ev.sort,
|
253
|
+
});
|
254
|
+
}
|
255
|
+
});
|
256
|
+
Object.defineProperty(this, "handlePageChange", {
|
257
|
+
enumerable: true,
|
258
|
+
configurable: true,
|
259
|
+
writable: true,
|
260
|
+
value: (ev) => {
|
261
|
+
if (this.pageSize !== ev.page.take) {
|
262
|
+
this.pageSize = ev.page.take;
|
263
|
+
}
|
264
|
+
else if (this.skip === ev.page.skip) {
|
265
|
+
return;
|
266
|
+
}
|
267
|
+
this.fetchData({
|
268
|
+
newSkip: ev.page.skip,
|
269
|
+
});
|
270
|
+
}
|
271
|
+
});
|
272
|
+
/** Call without params if unchanged */
|
273
|
+
Object.defineProperty(this, "fetchData", {
|
274
|
+
enumerable: true,
|
275
|
+
configurable: true,
|
276
|
+
writable: true,
|
277
|
+
value: ({ newSkip, newSort, newFilter, newAggregates, newGroup, } = {}) => __awaiter(this, void 0, void 0, function* () {
|
278
|
+
const sort = newSort !== null && newSort !== void 0 ? newSort : [...this.sort];
|
279
|
+
const filter = newFilter === null ? undefined : newFilter !== null && newFilter !== void 0 ? newFilter : this.filter;
|
280
|
+
const aggregates = newAggregates !== null && newAggregates !== void 0 ? newAggregates : this.aggregates;
|
281
|
+
const group = addAggregatesToGroups(newGroup !== null && newGroup !== void 0 ? newGroup : this.group, aggregates);
|
282
|
+
const skip = newSort || newFilter !== undefined || newGroup
|
283
|
+
? 0
|
284
|
+
: newSkip !== undefined
|
285
|
+
? newSkip
|
286
|
+
: this.skip;
|
287
|
+
if (!this.dataSource) {
|
288
|
+
runInAction(() => {
|
289
|
+
this.sort = sort;
|
290
|
+
this.filter = filter;
|
291
|
+
this.aggregates = aggregates;
|
292
|
+
this.innerGroup = group;
|
293
|
+
});
|
294
|
+
return;
|
295
|
+
}
|
296
|
+
const newData = (yield this.dataSource.getData({
|
297
|
+
skip,
|
298
|
+
sort,
|
299
|
+
filter,
|
300
|
+
group: [...group],
|
301
|
+
take: this.pageSize,
|
302
|
+
}));
|
303
|
+
runInAction(() => {
|
304
|
+
if (!this.dataSource) {
|
305
|
+
return;
|
306
|
+
}
|
307
|
+
if (newFilter !== undefined) {
|
308
|
+
// When a new filter is applied, deselect items that don't match the filter
|
309
|
+
if (this.dataSource.getFilteredPersistentItems) {
|
310
|
+
// For persistent items, deselect everything in the persistent array that's been filtered out
|
311
|
+
if (newFilter !== null && this.dataSource.idSelector) {
|
312
|
+
let delta = 0;
|
313
|
+
const filteredData = this.dataSource.getFilteredPersistentItems(newFilter);
|
314
|
+
filteredData.forEach(dataItem => {
|
315
|
+
const id = this.dataSource.idSelector(dataItem);
|
316
|
+
if (this.selectedIds.delete(id)) {
|
317
|
+
delta += 1;
|
318
|
+
}
|
319
|
+
if (!this.alwaysEditable) {
|
320
|
+
this.inEdit.delete(id);
|
321
|
+
}
|
322
|
+
this.expandedIds.delete(id);
|
323
|
+
});
|
324
|
+
this.selectedCount -= delta;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
else {
|
328
|
+
// For non-peristent items, everything is deselected by default
|
329
|
+
this.selectedCount = 0;
|
330
|
+
}
|
331
|
+
}
|
332
|
+
this.data = newData.data;
|
333
|
+
this.filteredCount = newData.total;
|
334
|
+
this.sort = sort;
|
335
|
+
this.filter = filter;
|
336
|
+
this.aggregates = aggregates;
|
337
|
+
this.innerGroup = group;
|
338
|
+
this.skip = skip;
|
339
|
+
this.addPropertiesToRows(this.data);
|
340
|
+
});
|
341
|
+
})
|
342
|
+
});
|
343
|
+
Object.defineProperty(this, "isRowSelectable", {
|
344
|
+
enumerable: true,
|
345
|
+
configurable: true,
|
346
|
+
writable: true,
|
347
|
+
value: (row) => !this.isRowUnselectable(row) &&
|
348
|
+
(this.selectionLimit === Infinity ||
|
349
|
+
row.selected ||
|
350
|
+
this.selectedCount < this.selectionLimit)
|
351
|
+
});
|
352
|
+
Object.defineProperty(this, "setTablePdfExportRef", {
|
353
|
+
enumerable: true,
|
354
|
+
configurable: true,
|
355
|
+
writable: true,
|
356
|
+
value: (el) => (this.tablePdfExport = el)
|
357
|
+
});
|
358
|
+
Object.defineProperty(this, "setTableExcelExportRef", {
|
359
|
+
enumerable: true,
|
360
|
+
configurable: true,
|
361
|
+
writable: true,
|
362
|
+
value: (el) => (this.tableExcelExport = el)
|
363
|
+
});
|
364
|
+
Object.defineProperty(this, "exportPdf", {
|
365
|
+
enumerable: true,
|
366
|
+
configurable: true,
|
367
|
+
writable: true,
|
368
|
+
value: () => __awaiter(this, void 0, void 0, function* () {
|
369
|
+
if (this.dataSource && this.tablePdfExport) {
|
370
|
+
const { data } = yield this.dataSource.getData({}); // fetch all data
|
371
|
+
this.tablePdfExport.save(data);
|
372
|
+
}
|
373
|
+
})
|
374
|
+
});
|
375
|
+
Object.defineProperty(this, "exportExcel", {
|
376
|
+
enumerable: true,
|
377
|
+
configurable: true,
|
378
|
+
writable: true,
|
379
|
+
value: (data, columns) => __awaiter(this, void 0, void 0, function* () {
|
380
|
+
if (this.tableExcelExport) {
|
381
|
+
this.tableExcelExport.save(data !== null && data !== void 0 ? data : (yield this.filteredSortedUnpaginatedData()).data, columns);
|
382
|
+
}
|
383
|
+
})
|
384
|
+
});
|
385
|
+
Object.defineProperty(this, "filteredSortedUnpaginatedData", {
|
386
|
+
enumerable: true,
|
387
|
+
configurable: true,
|
388
|
+
writable: true,
|
389
|
+
value: () => {
|
390
|
+
if (!this.dataSource) {
|
391
|
+
throw 'missing dataSource';
|
392
|
+
}
|
393
|
+
return this.dataSource.getData({
|
394
|
+
filter: this.filter,
|
395
|
+
sort: [...this.sort],
|
396
|
+
group: [...this.group],
|
397
|
+
});
|
398
|
+
}
|
399
|
+
});
|
400
|
+
Object.defineProperty(this, "getRowsBetween", {
|
401
|
+
enumerable: true,
|
402
|
+
configurable: true,
|
403
|
+
writable: true,
|
404
|
+
value: (start, end) => {
|
405
|
+
var _a;
|
406
|
+
const idSelector = (_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.idSelector;
|
407
|
+
if (!idSelector) {
|
408
|
+
return [];
|
409
|
+
}
|
410
|
+
let from, to;
|
411
|
+
const startId = idSelector(start);
|
412
|
+
const endId = idSelector(end);
|
413
|
+
for (const [index, row] of this.originalData.entries()) {
|
414
|
+
const id = idSelector(row);
|
415
|
+
if (startId === id) {
|
416
|
+
from = index;
|
417
|
+
}
|
418
|
+
if (endId === id) {
|
419
|
+
to = index;
|
420
|
+
}
|
421
|
+
}
|
422
|
+
if (from === undefined || to === undefined) {
|
423
|
+
return [];
|
424
|
+
}
|
425
|
+
return this.originalData.slice(Math.min(from, to), Math.max(from, to) + 1);
|
426
|
+
}
|
427
|
+
});
|
428
|
+
makeObservable(this);
|
429
|
+
this.innerDataSource = dataSource;
|
430
|
+
this.pageSize = pageSize;
|
431
|
+
this.isRowUnselectable = isRowUnselectable;
|
432
|
+
this.selectionLimit = selectionLimit;
|
433
|
+
this.getFormState = getFormState;
|
434
|
+
this.parent = parent;
|
435
|
+
this.getDetailTableState = getDetailTableState;
|
436
|
+
if (initialState) {
|
437
|
+
this.importState(initialState);
|
438
|
+
}
|
439
|
+
this.alwaysEditable = alwaysEditable;
|
440
|
+
this.fetchInitialData();
|
441
|
+
if (this.alwaysEditable) {
|
442
|
+
this.editAll();
|
443
|
+
}
|
444
|
+
}
|
445
|
+
get dataSource() {
|
446
|
+
return this.innerDataSource;
|
447
|
+
}
|
448
|
+
traverse(items, itemCallback, groupCallback, materializedPath = '') {
|
449
|
+
if (!items) {
|
450
|
+
return;
|
451
|
+
}
|
452
|
+
for (const item of items) {
|
453
|
+
if (isGroupItem(item, this.group)) {
|
454
|
+
const groupMaterializedPath = materializedPath + `/${item.value}`;
|
455
|
+
if (groupCallback) {
|
456
|
+
groupCallback(item, groupMaterializedPath);
|
457
|
+
}
|
458
|
+
this.traverse(item.items, itemCallback, groupCallback, groupMaterializedPath);
|
459
|
+
}
|
460
|
+
else {
|
461
|
+
itemCallback(item);
|
462
|
+
}
|
463
|
+
}
|
464
|
+
}
|
465
|
+
get originalData() {
|
466
|
+
const result = [];
|
467
|
+
this.traverse(this.data, item => {
|
468
|
+
result.push(item);
|
469
|
+
});
|
470
|
+
return result;
|
471
|
+
}
|
472
|
+
get unselectedCount() {
|
473
|
+
return this.totalCount - this.selectedCount;
|
474
|
+
}
|
475
|
+
get selectableCount() {
|
476
|
+
return this.totalCount - this.unselectableCount;
|
477
|
+
}
|
478
|
+
get filteredUnselectableCount() {
|
479
|
+
return this.originalData.filter(this.isRowUnselectable).length;
|
480
|
+
}
|
481
|
+
get filteredSelectableCount() {
|
482
|
+
return this.originalData.length - this.filteredUnselectableCount;
|
483
|
+
}
|
484
|
+
get totalFilteredSelectableCountPromise() {
|
485
|
+
return fromPromise(new Promise((resolve, reject) => {
|
486
|
+
if (!this.dataSource) {
|
487
|
+
return reject();
|
488
|
+
}
|
489
|
+
this.dataSource
|
490
|
+
.getData({
|
491
|
+
filter: this.filter,
|
492
|
+
})
|
493
|
+
.then(filteredData => {
|
494
|
+
resolve(filteredData.data.filter(row => !this.isRowUnselectable(row))
|
495
|
+
.length);
|
496
|
+
})
|
497
|
+
.catch(reject);
|
498
|
+
}));
|
499
|
+
}
|
500
|
+
get totalFilteredSelectableCount() {
|
501
|
+
return this.totalFilteredSelectableCountPromise.value || 0;
|
502
|
+
}
|
503
|
+
get group() {
|
504
|
+
return addAggregatesToGroups(this.innerGroup, this.aggregates);
|
505
|
+
}
|
506
|
+
set group(value) {
|
507
|
+
this.innerGroup = value;
|
508
|
+
}
|
509
|
+
addToDataSource(row, select, index) {
|
510
|
+
return __awaiter(this, void 0, void 0, function* () {
|
511
|
+
if (!this.dataSource) {
|
512
|
+
return;
|
513
|
+
}
|
514
|
+
if (!this.dataSource.addData) {
|
515
|
+
throw 'missing addData in the data source';
|
516
|
+
}
|
517
|
+
yield this.dataSource.addData(row, index);
|
518
|
+
runInAction(() => {
|
519
|
+
this.totalCount += 1;
|
520
|
+
if (select) {
|
521
|
+
if (!this.dataSource.idSelector) {
|
522
|
+
throw 'missing idSelector in the data source';
|
523
|
+
}
|
524
|
+
this.selectedIds.add(this.dataSource.idSelector(row));
|
525
|
+
this.selectedCount += 1;
|
526
|
+
}
|
527
|
+
if (this.alwaysEditable) {
|
528
|
+
this.edit(row);
|
529
|
+
}
|
530
|
+
});
|
531
|
+
yield this.fetchData();
|
532
|
+
});
|
533
|
+
}
|
534
|
+
removeFromDataSource(id) {
|
535
|
+
return __awaiter(this, void 0, void 0, function* () {
|
536
|
+
if (!this.dataSource) {
|
537
|
+
return;
|
538
|
+
}
|
539
|
+
if (!this.dataSource.removeData) {
|
540
|
+
throw 'missing removeData in the data source';
|
541
|
+
}
|
542
|
+
const row = (yield this.dataSource.removeData(id));
|
543
|
+
if (!row) {
|
544
|
+
return;
|
545
|
+
}
|
546
|
+
runInAction(() => {
|
547
|
+
this.totalCount -= 1;
|
548
|
+
if (this.selectedIds.has(id)) {
|
549
|
+
this.selectedIds.delete(id);
|
550
|
+
this.selectedCount -= 1;
|
551
|
+
}
|
552
|
+
if (this.inEdit.has(id)) {
|
553
|
+
this.inEdit.delete(id);
|
554
|
+
}
|
555
|
+
if (this.expandedIds.has(id)) {
|
556
|
+
this.expandedIds.delete(id);
|
557
|
+
}
|
558
|
+
});
|
559
|
+
yield this.fetchData();
|
560
|
+
return row;
|
561
|
+
});
|
562
|
+
}
|
563
|
+
setRowsSelection(rows, value, { ignoreUnselectable = true, recursive = true } = {}) {
|
564
|
+
return __awaiter(this, void 0, void 0, function* () {
|
565
|
+
if (!this.dataSource) {
|
566
|
+
return;
|
567
|
+
}
|
568
|
+
if (!this.dataSource.idSelector) {
|
569
|
+
throw 'missing idSelector in the data source';
|
570
|
+
}
|
571
|
+
for (const row of rows) {
|
572
|
+
if (ignoreUnselectable && this.isRowUnselectable(row)) {
|
573
|
+
continue;
|
574
|
+
}
|
575
|
+
runInAction(() => {
|
576
|
+
if (!value) {
|
577
|
+
this.selectedIds.delete(this.dataSource.idSelector(row));
|
578
|
+
}
|
579
|
+
else if (this.selectedCount < this.selectionLimit) {
|
580
|
+
this.selectedIds.add(this.dataSource.idSelector(row));
|
581
|
+
}
|
582
|
+
});
|
583
|
+
// update children selection
|
584
|
+
if (recursive && this.getDetailTableState) {
|
585
|
+
const detail = this.getDetailTableState(row);
|
586
|
+
if (detail === null || detail === void 0 ? void 0 : detail.selectableCount) {
|
587
|
+
// eslint-disable-next-line no-await-in-loop
|
588
|
+
yield detail.setAllSelection(value);
|
589
|
+
}
|
590
|
+
}
|
591
|
+
}
|
592
|
+
// update parent selection
|
593
|
+
if (this.parent) {
|
594
|
+
if (this.isAllPageRowsSelected) {
|
595
|
+
yield this.parent.tableState.setRowsSelection([this.parent.row], true, {
|
596
|
+
recursive: false,
|
597
|
+
});
|
598
|
+
}
|
599
|
+
else {
|
600
|
+
yield this.parent.tableState.setRowsSelection([this.parent.row], false, {
|
601
|
+
recursive: false,
|
602
|
+
});
|
603
|
+
}
|
604
|
+
}
|
605
|
+
runInAction(() => {
|
606
|
+
this.selectedCount = this.selectedIds.size;
|
607
|
+
this.data = this.data.slice();
|
608
|
+
});
|
609
|
+
});
|
610
|
+
}
|
611
|
+
selectPage(options) {
|
612
|
+
return __awaiter(this, void 0, void 0, function* () {
|
613
|
+
yield this.setRowsSelection(this.originalData, true, options);
|
614
|
+
});
|
615
|
+
}
|
616
|
+
deselectPage(options) {
|
617
|
+
return __awaiter(this, void 0, void 0, function* () {
|
618
|
+
yield this.setRowsSelection(this.originalData, false, options);
|
619
|
+
});
|
620
|
+
}
|
621
|
+
setAllSelection(value, options) {
|
622
|
+
return __awaiter(this, void 0, void 0, function* () {
|
623
|
+
if (!this.dataSource) {
|
624
|
+
return;
|
625
|
+
}
|
626
|
+
const filteredData = yield this.dataSource.getData({
|
627
|
+
filter: this.filter,
|
628
|
+
});
|
629
|
+
yield this.setRowsSelection(filteredData.data, value, options);
|
630
|
+
});
|
631
|
+
}
|
632
|
+
selectAll(options) {
|
633
|
+
return __awaiter(this, void 0, void 0, function* () {
|
634
|
+
if (this.selectionLimit !== Infinity) {
|
635
|
+
throw "selectAll isn't supported for limited selection";
|
636
|
+
}
|
637
|
+
yield this.setAllSelection(true, options);
|
638
|
+
});
|
639
|
+
}
|
640
|
+
deselectAll(options) {
|
641
|
+
return __awaiter(this, void 0, void 0, function* () {
|
642
|
+
yield this.setAllSelection(false, options);
|
643
|
+
});
|
644
|
+
}
|
645
|
+
edit(row, field) {
|
646
|
+
if (!this.dataSource) {
|
647
|
+
return;
|
648
|
+
}
|
649
|
+
if (!this.dataSource.idSelector) {
|
650
|
+
throw 'missing idSelector in the data source';
|
651
|
+
}
|
652
|
+
if (!this.getFormState) {
|
653
|
+
throw 'missing getFormState';
|
654
|
+
}
|
655
|
+
this.inEdit.set(this.dataSource.idSelector(row), {
|
656
|
+
form: this.getFormState(row),
|
657
|
+
field,
|
658
|
+
});
|
659
|
+
this.data = this.data.slice();
|
660
|
+
}
|
661
|
+
saveEdit(row, beforeSave) {
|
662
|
+
return __awaiter(this, void 0, void 0, function* () {
|
663
|
+
if (!this.dataSource) {
|
664
|
+
return;
|
665
|
+
}
|
666
|
+
if (!this.dataSource.idSelector) {
|
667
|
+
throw 'missing idSelector in the data source';
|
668
|
+
}
|
669
|
+
if (!this.dataSource.updateData) {
|
670
|
+
throw 'missing updateData in the data source';
|
671
|
+
}
|
672
|
+
const id = this.dataSource.idSelector(row);
|
673
|
+
const editingForm = this.inEdit.get(id);
|
674
|
+
if (!editingForm) {
|
675
|
+
return;
|
676
|
+
}
|
677
|
+
const { form, field } = editingForm;
|
678
|
+
const changed = formStateToJS(form); // FIXME: incompatible types
|
679
|
+
if (beforeSave) {
|
680
|
+
yield beforeSave(changed, field);
|
681
|
+
}
|
682
|
+
yield this.dataSource.updateData(id, changed);
|
683
|
+
if (!this.alwaysEditable) {
|
684
|
+
runInAction(() => {
|
685
|
+
this.inEdit.delete(id);
|
686
|
+
});
|
687
|
+
}
|
688
|
+
yield this.fetchData();
|
689
|
+
});
|
690
|
+
}
|
691
|
+
cancelEdit(row) {
|
692
|
+
if (!this.dataSource) {
|
693
|
+
return;
|
694
|
+
}
|
695
|
+
if (!this.dataSource.idSelector) {
|
696
|
+
throw 'missing idSelector in the data source';
|
697
|
+
}
|
698
|
+
if (this.alwaysEditable) {
|
699
|
+
return;
|
700
|
+
}
|
701
|
+
this.inEdit.delete(this.dataSource.idSelector(row));
|
702
|
+
this.data = this.data.slice();
|
703
|
+
}
|
704
|
+
editAll() {
|
705
|
+
return __awaiter(this, void 0, void 0, function* () {
|
706
|
+
if (!this.dataSource) {
|
707
|
+
return;
|
708
|
+
}
|
709
|
+
if (!this.dataSource.idSelector) {
|
710
|
+
throw 'missing idSelector in the data source';
|
711
|
+
}
|
712
|
+
if (!this.getFormState) {
|
713
|
+
throw 'missing getFormState';
|
714
|
+
}
|
715
|
+
const rows = (yield this.dataSource.getData({
|
716
|
+
filter: this.filter,
|
717
|
+
})).data;
|
718
|
+
runInAction(() => {
|
719
|
+
this.inEdit = new Map(rows.map(row => [
|
720
|
+
this.dataSource.idSelector(row),
|
721
|
+
{ form: this.getFormState(row) },
|
722
|
+
]));
|
723
|
+
this.data = this.data.slice();
|
724
|
+
});
|
725
|
+
});
|
726
|
+
}
|
727
|
+
saveEditAll(beforeSave) {
|
728
|
+
return __awaiter(this, void 0, void 0, function* () {
|
729
|
+
if (!this.dataSource) {
|
730
|
+
return;
|
731
|
+
}
|
732
|
+
if (!this.dataSource.updateData) {
|
733
|
+
throw 'missing updateData in the data source';
|
734
|
+
}
|
735
|
+
const changes = Array.from(this.inEdit).map(([id, { form }]) => ({
|
736
|
+
id,
|
737
|
+
changed: formStateToJS(form), // FIXME: incompatible types
|
738
|
+
}));
|
739
|
+
if (beforeSave) {
|
740
|
+
yield beforeSave(changes.map(change => change.changed));
|
741
|
+
}
|
742
|
+
for (const { id, changed } of changes) {
|
743
|
+
// eslint-disable-next-line no-await-in-loop
|
744
|
+
yield this.dataSource.updateData(id, changed);
|
745
|
+
}
|
746
|
+
if (!this.alwaysEditable) {
|
747
|
+
runInAction(() => {
|
748
|
+
this.inEdit = new Map();
|
749
|
+
});
|
750
|
+
}
|
751
|
+
yield this.fetchData();
|
752
|
+
});
|
753
|
+
}
|
754
|
+
cancelEditAll() {
|
755
|
+
if (!this.dataSource) {
|
756
|
+
return;
|
757
|
+
}
|
758
|
+
if (this.alwaysEditable) {
|
759
|
+
return;
|
760
|
+
}
|
761
|
+
this.inEdit = new Map();
|
762
|
+
this.data = this.data.slice();
|
763
|
+
}
|
764
|
+
reset() {
|
765
|
+
this.totalCount = 0;
|
766
|
+
this.filteredCount = 0;
|
767
|
+
this.data = [];
|
768
|
+
this.selectedCount = 0;
|
769
|
+
this.selectedIds = new Set();
|
770
|
+
this.inEdit = new Map();
|
771
|
+
this.expandedIds = new Set();
|
772
|
+
this.collapsedGroups = new Set();
|
773
|
+
this.sort = [];
|
774
|
+
this.filter = undefined;
|
775
|
+
this.aggregates = [];
|
776
|
+
this.innerGroup = [];
|
777
|
+
}
|
778
|
+
setDataSource(dataSource, setDataSourceParams) {
|
779
|
+
return __awaiter(this, void 0, void 0, function* () {
|
780
|
+
this.innerDataSource = dataSource;
|
781
|
+
this.skip = 0;
|
782
|
+
const reset = typeof setDataSourceParams === 'boolean'
|
783
|
+
? setDataSourceParams
|
784
|
+
: setDataSourceParams === null || setDataSourceParams === void 0 ? void 0 : setDataSourceParams.reset;
|
785
|
+
const config = setDataSourceParams;
|
786
|
+
if (reset) {
|
787
|
+
this.reset();
|
788
|
+
}
|
789
|
+
if (config === null || config === void 0 ? void 0 : config.initialState) {
|
790
|
+
this.importState(config.initialState);
|
791
|
+
}
|
792
|
+
yield this.fetchInitialData();
|
793
|
+
if (this.alwaysEditable) {
|
794
|
+
yield this.editAll();
|
795
|
+
}
|
796
|
+
});
|
797
|
+
}
|
798
|
+
addPropertiesToRows(data) {
|
799
|
+
this.traverse(data, item => {
|
800
|
+
if (!this.dataSource) {
|
801
|
+
return;
|
802
|
+
}
|
803
|
+
if (!this.dataSource.idSelector) {
|
804
|
+
return;
|
805
|
+
}
|
806
|
+
if (!('selected' in item)) {
|
807
|
+
Object.defineProperty(item, 'selected', {
|
808
|
+
get: () => this.selectedIds.has(this.dataSource.idSelector(item)),
|
809
|
+
});
|
810
|
+
}
|
811
|
+
if (!('indeterminate' in item)) {
|
812
|
+
Object.defineProperty(item, 'indeterminate', {
|
813
|
+
get: () => {
|
814
|
+
var _a;
|
815
|
+
const detail = (_a = this.getDetailTableState) === null || _a === void 0 ? void 0 : _a.call(this, item);
|
816
|
+
if (!detail) {
|
817
|
+
return false;
|
818
|
+
}
|
819
|
+
return detail.isSomePageRowsSelected;
|
820
|
+
},
|
821
|
+
});
|
822
|
+
}
|
823
|
+
if (!('inEdit' in item)) {
|
824
|
+
Object.defineProperty(item, 'inEdit', {
|
825
|
+
get: () => this.inEdit.has(this.dataSource.idSelector(item)),
|
826
|
+
});
|
827
|
+
}
|
828
|
+
if (!('expanded' in item)) {
|
829
|
+
Object.defineProperty(item, 'expanded', {
|
830
|
+
get: () => this.expandedIds.has(this.dataSource.idSelector(item)),
|
831
|
+
});
|
832
|
+
}
|
833
|
+
}, (group, materializedPath) => {
|
834
|
+
if (!('materializedPath' in group)) {
|
835
|
+
Object.defineProperty(group, 'materializedPath', {
|
836
|
+
get: () => materializedPath,
|
837
|
+
});
|
838
|
+
}
|
839
|
+
if (!('expanded' in group)) {
|
840
|
+
Object.defineProperty(group, 'expanded', {
|
841
|
+
get: () => !this.collapsedGroups.has(group.materializedPath),
|
842
|
+
});
|
843
|
+
}
|
844
|
+
});
|
845
|
+
}
|
846
|
+
toggleRowSelection(row, options) {
|
847
|
+
return __awaiter(this, void 0, void 0, function* () {
|
848
|
+
if (!this.dataSource) {
|
849
|
+
return;
|
850
|
+
}
|
851
|
+
if (!this.dataSource.idSelector) {
|
852
|
+
throw 'missing idSelector in the data source';
|
853
|
+
}
|
854
|
+
yield this.setRowsSelection([row], !this.selectedIds.has(this.dataSource.idSelector(row)), options);
|
855
|
+
});
|
856
|
+
}
|
857
|
+
get isAllPageRowsSelected() {
|
858
|
+
return (this.originalData.some(row => row.selected) &&
|
859
|
+
this.originalData.every(row => this.isRowUnselectable(row) || row.selected));
|
860
|
+
}
|
861
|
+
get isSomePageRowsSelected() {
|
862
|
+
return this.originalData.some(row => row.selected) && !this.isAllPageRowsSelected;
|
863
|
+
}
|
864
|
+
get isAllRowsSelected() {
|
865
|
+
if (!this.selectedIds.size) {
|
866
|
+
return false;
|
867
|
+
}
|
868
|
+
return this.selectedIds.size === this.totalFilteredSelectableCount;
|
869
|
+
}
|
870
|
+
get isSomeRowsSelected() {
|
871
|
+
if (!this.selectedIds.size) {
|
872
|
+
return false;
|
873
|
+
}
|
874
|
+
return !this.isAllRowsSelected;
|
875
|
+
}
|
876
|
+
exportState() {
|
877
|
+
return {
|
878
|
+
skip: this.skip,
|
879
|
+
selectedIds: Array.from(this.selectedIds),
|
880
|
+
expandedIds: Array.from(this.expandedIds),
|
881
|
+
collapsedGroups: Array.from(this.collapsedGroups),
|
882
|
+
sort: this.sort,
|
883
|
+
filter: this.filter,
|
884
|
+
aggregates: this.aggregates,
|
885
|
+
group: this.innerGroup,
|
886
|
+
};
|
887
|
+
}
|
888
|
+
importState(data) {
|
889
|
+
this.skip = data.skip;
|
890
|
+
this.selectedIds = new Set(data.selectedIds);
|
891
|
+
this.expandedIds = new Set(data.expandedIds);
|
892
|
+
this.collapsedGroups = new Set(data.collapsedGroups);
|
893
|
+
this.sort = data.sort;
|
894
|
+
this.filter = data.filter;
|
895
|
+
this.aggregates = data.aggregates;
|
896
|
+
this.innerGroup = data.group;
|
897
|
+
}
|
898
|
+
}
|
899
|
+
__decorate([
|
900
|
+
observable,
|
901
|
+
__metadata("design:type", Object)
|
902
|
+
], TableState.prototype, "innerDataSource", void 0);
|
903
|
+
__decorate([
|
904
|
+
computed,
|
905
|
+
__metadata("design:type", Object),
|
906
|
+
__metadata("design:paramtypes", [])
|
907
|
+
], TableState.prototype, "dataSource", null);
|
908
|
+
__decorate([
|
909
|
+
computed,
|
910
|
+
__metadata("design:type", Object),
|
911
|
+
__metadata("design:paramtypes", [])
|
912
|
+
], TableState.prototype, "originalData", null);
|
913
|
+
__decorate([
|
914
|
+
observable,
|
915
|
+
__metadata("design:type", Object)
|
916
|
+
], TableState.prototype, "selectedIds", void 0);
|
917
|
+
__decorate([
|
918
|
+
observable,
|
919
|
+
__metadata("design:type", Object)
|
920
|
+
], TableState.prototype, "inEdit", void 0);
|
921
|
+
__decorate([
|
922
|
+
observable,
|
923
|
+
__metadata("design:type", Object)
|
924
|
+
], TableState.prototype, "expandedIds", void 0);
|
925
|
+
__decorate([
|
926
|
+
observable,
|
927
|
+
__metadata("design:type", Object)
|
928
|
+
], TableState.prototype, "collapsedGroups", void 0);
|
929
|
+
__decorate([
|
930
|
+
observable,
|
931
|
+
__metadata("design:type", Object)
|
932
|
+
], TableState.prototype, "data", void 0);
|
933
|
+
__decorate([
|
934
|
+
observable,
|
935
|
+
__metadata("design:type", Object)
|
936
|
+
], TableState.prototype, "totalCount", void 0);
|
937
|
+
__decorate([
|
938
|
+
observable,
|
939
|
+
__metadata("design:type", Object)
|
940
|
+
], TableState.prototype, "filteredCount", void 0);
|
941
|
+
__decorate([
|
942
|
+
observable,
|
943
|
+
__metadata("design:type", Object)
|
944
|
+
], TableState.prototype, "selectedCount", void 0);
|
945
|
+
__decorate([
|
946
|
+
observable,
|
947
|
+
__metadata("design:type", Object)
|
948
|
+
], TableState.prototype, "unselectableCount", void 0);
|
949
|
+
__decorate([
|
950
|
+
computed,
|
951
|
+
__metadata("design:type", Object),
|
952
|
+
__metadata("design:paramtypes", [])
|
953
|
+
], TableState.prototype, "unselectedCount", null);
|
954
|
+
__decorate([
|
955
|
+
computed,
|
956
|
+
__metadata("design:type", Object),
|
957
|
+
__metadata("design:paramtypes", [])
|
958
|
+
], TableState.prototype, "selectableCount", null);
|
959
|
+
__decorate([
|
960
|
+
computed,
|
961
|
+
__metadata("design:type", Object),
|
962
|
+
__metadata("design:paramtypes", [])
|
963
|
+
], TableState.prototype, "filteredUnselectableCount", null);
|
964
|
+
__decorate([
|
965
|
+
computed,
|
966
|
+
__metadata("design:type", Object),
|
967
|
+
__metadata("design:paramtypes", [])
|
968
|
+
], TableState.prototype, "filteredSelectableCount", null);
|
969
|
+
__decorate([
|
970
|
+
computed,
|
971
|
+
__metadata("design:type", Object),
|
972
|
+
__metadata("design:paramtypes", [])
|
973
|
+
], TableState.prototype, "totalFilteredSelectableCountPromise", null);
|
974
|
+
__decorate([
|
975
|
+
computed,
|
976
|
+
__metadata("design:type", Number),
|
977
|
+
__metadata("design:paramtypes", [])
|
978
|
+
], TableState.prototype, "totalFilteredSelectableCount", null);
|
979
|
+
__decorate([
|
980
|
+
observable,
|
981
|
+
__metadata("design:type", Array)
|
982
|
+
], TableState.prototype, "sort", void 0);
|
983
|
+
__decorate([
|
984
|
+
observable,
|
985
|
+
__metadata("design:type", Object)
|
986
|
+
], TableState.prototype, "filter", void 0);
|
987
|
+
__decorate([
|
988
|
+
observable,
|
989
|
+
__metadata("design:type", Array)
|
990
|
+
], TableState.prototype, "aggregates", void 0);
|
991
|
+
__decorate([
|
992
|
+
observable,
|
993
|
+
__metadata("design:type", Array)
|
994
|
+
], TableState.prototype, "innerGroup", void 0);
|
995
|
+
__decorate([
|
996
|
+
computed,
|
997
|
+
__metadata("design:type", Array),
|
998
|
+
__metadata("design:paramtypes", [Array])
|
999
|
+
], TableState.prototype, "group", null);
|
1000
|
+
__decorate([
|
1001
|
+
observable,
|
1002
|
+
__metadata("design:type", Object)
|
1003
|
+
], TableState.prototype, "skip", void 0);
|
1004
|
+
__decorate([
|
1005
|
+
observable,
|
1006
|
+
__metadata("design:type", Number)
|
1007
|
+
], TableState.prototype, "pageSize", void 0);
|
1008
|
+
__decorate([
|
1009
|
+
action,
|
1010
|
+
__metadata("design:type", Function),
|
1011
|
+
__metadata("design:paramtypes", [Array, Boolean, Object]),
|
1012
|
+
__metadata("design:returntype", Promise)
|
1013
|
+
], TableState.prototype, "setRowsSelection", null);
|
1014
|
+
__decorate([
|
1015
|
+
action,
|
1016
|
+
__metadata("design:type", Function),
|
1017
|
+
__metadata("design:paramtypes", [Object, Object]),
|
1018
|
+
__metadata("design:returntype", void 0)
|
1019
|
+
], TableState.prototype, "edit", null);
|
1020
|
+
__decorate([
|
1021
|
+
action,
|
1022
|
+
__metadata("design:type", Function),
|
1023
|
+
__metadata("design:paramtypes", [Object, Function]),
|
1024
|
+
__metadata("design:returntype", Promise)
|
1025
|
+
], TableState.prototype, "saveEdit", null);
|
1026
|
+
__decorate([
|
1027
|
+
action,
|
1028
|
+
__metadata("design:type", Function),
|
1029
|
+
__metadata("design:paramtypes", [Object]),
|
1030
|
+
__metadata("design:returntype", void 0)
|
1031
|
+
], TableState.prototype, "cancelEdit", null);
|
1032
|
+
__decorate([
|
1033
|
+
action,
|
1034
|
+
__metadata("design:type", Function),
|
1035
|
+
__metadata("design:paramtypes", []),
|
1036
|
+
__metadata("design:returntype", void 0)
|
1037
|
+
], TableState.prototype, "cancelEditAll", null);
|
1038
|
+
__decorate([
|
1039
|
+
action,
|
1040
|
+
__metadata("design:type", Function),
|
1041
|
+
__metadata("design:paramtypes", []),
|
1042
|
+
__metadata("design:returntype", void 0)
|
1043
|
+
], TableState.prototype, "reset", null);
|
1044
|
+
__decorate([
|
1045
|
+
action,
|
1046
|
+
__metadata("design:type", Function),
|
1047
|
+
__metadata("design:paramtypes", [Object, Object]),
|
1048
|
+
__metadata("design:returntype", Promise)
|
1049
|
+
], TableState.prototype, "setDataSource", null);
|
1050
|
+
__decorate([
|
1051
|
+
action,
|
1052
|
+
__metadata("design:type", Object)
|
1053
|
+
], TableState.prototype, "fetchInitialData", void 0);
|
1054
|
+
__decorate([
|
1055
|
+
action,
|
1056
|
+
__metadata("design:type", Object)
|
1057
|
+
], TableState.prototype, "handleFilterChange", void 0);
|
1058
|
+
__decorate([
|
1059
|
+
action,
|
1060
|
+
__metadata("design:type", Object)
|
1061
|
+
], TableState.prototype, "handleGroupChange", void 0);
|
1062
|
+
__decorate([
|
1063
|
+
action,
|
1064
|
+
__metadata("design:type", Object)
|
1065
|
+
], TableState.prototype, "handleExpandChange", void 0);
|
1066
|
+
__decorate([
|
1067
|
+
action,
|
1068
|
+
__metadata("design:type", Object)
|
1069
|
+
], TableState.prototype, "handleSortChange", void 0);
|
1070
|
+
__decorate([
|
1071
|
+
action,
|
1072
|
+
__metadata("design:type", Object)
|
1073
|
+
], TableState.prototype, "handlePageChange", void 0);
|
1074
|
+
__decorate([
|
1075
|
+
action,
|
1076
|
+
__metadata("design:type", Function),
|
1077
|
+
__metadata("design:paramtypes", [Object, Object]),
|
1078
|
+
__metadata("design:returntype", Promise)
|
1079
|
+
], TableState.prototype, "toggleRowSelection", null);
|
1080
|
+
__decorate([
|
1081
|
+
computed,
|
1082
|
+
__metadata("design:type", Object),
|
1083
|
+
__metadata("design:paramtypes", [])
|
1084
|
+
], TableState.prototype, "isAllPageRowsSelected", null);
|
1085
|
+
__decorate([
|
1086
|
+
computed,
|
1087
|
+
__metadata("design:type", Object),
|
1088
|
+
__metadata("design:paramtypes", [])
|
1089
|
+
], TableState.prototype, "isSomePageRowsSelected", null);
|
1090
|
+
__decorate([
|
1091
|
+
computed,
|
1092
|
+
__metadata("design:type", Object),
|
1093
|
+
__metadata("design:paramtypes", [])
|
1094
|
+
], TableState.prototype, "isAllRowsSelected", null);
|
1095
|
+
__decorate([
|
1096
|
+
computed,
|
1097
|
+
__metadata("design:type", Object),
|
1098
|
+
__metadata("design:paramtypes", [])
|
1099
|
+
], TableState.prototype, "isSomeRowsSelected", null);
|
1100
|
+
__decorate([
|
1101
|
+
action,
|
1102
|
+
__metadata("design:type", Function),
|
1103
|
+
__metadata("design:paramtypes", [Object]),
|
1104
|
+
__metadata("design:returntype", void 0)
|
1105
|
+
], TableState.prototype, "importState", null);
|
1106
|
+
//# sourceMappingURL=table-state.js.map
|