@webitel/ui-datalist 26.8.23 → 26.8.25

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": "@webitel/ui-datalist",
3
- "version": "26.8.23",
3
+ "version": "26.8.25",
4
4
  "description": "Toolkit for building data lists in webitel ui system",
5
5
  "scripts": {
6
6
  "build:types": "vue-tsc -b tsconfig.build.json",
@@ -260,6 +260,65 @@ describe('tableStoreBody', () => {
260
260
  });
261
261
  });
262
262
 
263
+ /*
264
+ An endpoint may answer with sibling data alongside `items` — e.g. per-page
265
+ totals for a footer row — which has no home on the store otherwise;
266
+ without this, a table needing it had to bolt a bespoke wrapper onto
267
+ `createTableStore` just to surface one extra reactive field.
268
+ */
269
+ describe('aggs', () => {
270
+ let useStore: ReturnType<typeof createTableStore>;
271
+
272
+ beforeEach(async () => {
273
+ getList.mockResolvedValue({
274
+ items: [],
275
+ next: false,
276
+ aggs: {
277
+ total: 3,
278
+ },
279
+ });
280
+
281
+ useStore = createTableStore('cases-aggs/datalist', {
282
+ apiModule: {
283
+ getList,
284
+ },
285
+ headers,
286
+ disablePersistence: true,
287
+ });
288
+
289
+ mountTab(useStore);
290
+ await flush();
291
+ });
292
+
293
+ it('picks up aggs from the getList response', () => {
294
+ const store = useStore();
295
+
296
+ expect(store.aggs).toEqual({
297
+ total: 3,
298
+ });
299
+ });
300
+
301
+ it('stays undefined when the response has none', async () => {
302
+ getList.mockResolvedValue({
303
+ items: [],
304
+ next: false,
305
+ });
306
+
307
+ const store = useStore();
308
+ await store.loadDataList();
309
+
310
+ expect(store.aggs).toBeUndefined();
311
+ });
312
+
313
+ it('drops on $reset', () => {
314
+ const store = useStore();
315
+
316
+ store.$reset();
317
+
318
+ expect(store.aggs).toBeUndefined();
319
+ });
320
+ });
321
+
263
322
  describe('filters persistence of a nested list', () => {
264
323
  it('keeps an added filter out of the route query, in sessionStorage instead', async () => {
265
324
  const useStore = createTableStore('cases-nested-filters/datalist', {
@@ -126,6 +126,12 @@ export const tableStoreBody = <Entity extends Identifiable>(
126
126
  const selected: Ref<Entity[]> = ref([]);
127
127
  const error = ref<unknown>(null);
128
128
  const isLoading = ref(false);
129
+ /**
130
+ * Sibling data an endpoint answers alongside the paginated `items` — e.g.
131
+ * per-page totals for a footer row. Not every `getList` response has one;
132
+ * absent, it stays `undefined` and callers that do not need it can ignore it.
133
+ */
134
+ const aggs = ref<unknown>(undefined);
129
135
 
130
136
  const updateSelected = (value: Entity[]) => {
131
137
  selected.value = value;
@@ -177,9 +183,14 @@ export const tableStoreBody = <Entity extends Identifiable>(
177
183
  const params = getLoadDataParams();
178
184
 
179
185
  try {
180
- const { items, next } = await apiModule.getList(params);
186
+ const {
187
+ items,
188
+ next,
189
+ aggs: responseAggs,
190
+ } = await apiModule.getList(params);
181
191
 
182
192
  dataList.value = items ?? [];
193
+ aggs.value = responseAggs;
183
194
 
184
195
  /**
185
196
  * @author: @Oleksandr Palonnyi
@@ -221,9 +232,14 @@ export const tableStoreBody = <Entity extends Identifiable>(
221
232
  const params = getLoadDataParams();
222
233
 
223
234
  try {
224
- const { items, next } = await apiModule.getList(params);
235
+ const {
236
+ items,
237
+ next,
238
+ aggs: responseAggs,
239
+ } = await apiModule.getList(params);
225
240
 
226
241
  dataList.value.push(...(items ?? []));
242
+ aggs.value = responseAggs;
227
243
  $patchPaginationStore({
228
244
  next,
229
245
  });
@@ -413,6 +429,7 @@ export const tableStoreBody = <Entity extends Identifiable>(
413
429
  selected.value = [];
414
430
  error.value = null;
415
431
  isLoading.value = false;
432
+ aggs.value = undefined;
416
433
  parentId.value = undefined;
417
434
 
418
435
  paginationStore.$reset();
@@ -433,6 +450,7 @@ export const tableStoreBody = <Entity extends Identifiable>(
433
450
  selected,
434
451
  error,
435
452
  isLoading,
453
+ aggs,
436
454
 
437
455
  page,
438
456
  size,
@@ -68,12 +68,14 @@ export interface LoadDataListOptions {
68
68
  withLoading?: boolean;
69
69
  }
70
70
 
71
- export interface TableStore<Entity> {
71
+ export interface TableStore<Entity, Aggs = unknown> {
72
72
  // tableStore
73
73
  dataList: Ref<Entity[]>;
74
74
  selected: Ref<Entity[]>;
75
75
  error: Ref<Error | null>;
76
76
  isLoading: Ref<boolean>;
77
+ /** Sibling data alongside `dataList` — e.g. per-page totals for a footer row. */
78
+ aggs: Ref<Aggs | undefined>;
77
79
 
78
80
  // paginationStore
79
81
  page: Ref<number>;