@webitel/ui-datalist 26.12.6 → 26.12.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": "@webitel/ui-datalist",
3
- "version": "26.12.6",
3
+ "version": "26.12.7",
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",
@@ -146,6 +146,86 @@ describe('tableHeadersStoreBody', () => {
146
146
  });
147
147
  });
148
148
 
149
+ it('marks a resized column as resized', () => {
150
+ const store = createStore();
151
+
152
+ store.columnResize({
153
+ columnName: 'name',
154
+ columnWidth: '100px',
155
+ });
156
+
157
+ expect(store.headers.value[0]).toMatchObject({
158
+ width: '100px',
159
+ resized: true,
160
+ });
161
+ expect(store.headers.value[1].resized).toBeUndefined();
162
+ });
163
+
164
+ describe('column widths persistence', () => {
165
+ const resizedWidthsKey = `${id}/resizedColumnWidths`;
166
+ const legacyWidthsKey = `${id}/columnWidths`;
167
+
168
+ it('saves resized widths only, not default ones from header definitions', async () => {
169
+ const store = createStore();
170
+ store.headers.value[1].width = '300px'; // default width
171
+ await runWithRouter(() => store.setupPersistence());
172
+
173
+ store.columnResize({
174
+ columnName: 'name',
175
+ columnWidth: '100px',
176
+ });
177
+ await flushWrites();
178
+
179
+ expect(JSON.parse(localStorage.getItem(resizedWidthsKey) ?? '')).toEqual({
180
+ name: '100px',
181
+ });
182
+ });
183
+
184
+ it('restores saved widths as resized', async () => {
185
+ localStorage.setItem(
186
+ resizedWidthsKey,
187
+ JSON.stringify({
188
+ name: '100px',
189
+ }),
190
+ );
191
+
192
+ const store = await setUpStore();
193
+
194
+ expect(store.headers.value[0]).toMatchObject({
195
+ width: '100px',
196
+ resized: true,
197
+ });
198
+ expect(store.headers.value[1].resized).toBeUndefined();
199
+ });
200
+
201
+ it('restores legacy widths as plain widths, overridden by resized ones', async () => {
202
+ localStorage.setItem(
203
+ legacyWidthsKey,
204
+ JSON.stringify({
205
+ name: '50px',
206
+ subject: '60px',
207
+ }),
208
+ );
209
+ localStorage.setItem(
210
+ resizedWidthsKey,
211
+ JSON.stringify({
212
+ name: '100px',
213
+ }),
214
+ );
215
+
216
+ const store = await setUpStore();
217
+
218
+ expect(store.headers.value[0]).toMatchObject({
219
+ width: '100px',
220
+ resized: true,
221
+ });
222
+ expect(store.headers.value[1]).toMatchObject({
223
+ width: '60px',
224
+ resized: false,
225
+ });
226
+ });
227
+ });
228
+
149
229
  describe('persistence', () => {
150
230
  it('restores shown fields from the route query', async () => {
151
231
  await router.push({
@@ -81,6 +81,16 @@ export const tableHeadersStoreBody = ({
81
81
  }, {});
82
82
  });
83
83
 
84
+ // [Claude] widths of columns resized by the user only, default widths from header definitions are not included
85
+ const resizedColumnWidths = computed(() => {
86
+ return headers.value.reduce<Record<string, string>>((acc, header) => {
87
+ if (header.resized && header.width) {
88
+ acc[header.field] = header.width;
89
+ }
90
+ return acc;
91
+ }, {});
92
+ });
93
+
84
94
  const $reset = () => {
85
95
  headers.value = allowedHeaders;
86
96
  };
@@ -294,29 +304,58 @@ export const tableHeadersStoreBody = ({
294
304
  }),
295
305
  });
296
306
 
307
+ /*
308
+ * [Claude] stored under a new name: legacy "columnWidths" mixes resized widths with default ones,
309
+ * so it can't tell which columns were resized. It's still restored, but as plain (min) widths
310
+ */
311
+ const legacyColumnWidthsName = 'columnWidths';
312
+
313
+ const restoreWidths = async (
314
+ restore: (name: string) => Promise<unknown>,
315
+ name: string,
316
+ {
317
+ resized,
318
+ }: {
319
+ resized: boolean;
320
+ },
321
+ ) => {
322
+ const value = (await restore(name)) as string;
323
+ if (!value) return;
324
+
325
+ const parsedWidths = JSON.parse(value);
326
+ headers.value = headers.value.map((header) =>
327
+ parsedWidths[header.field]
328
+ ? {
329
+ ...header,
330
+ width: parsedWidths[header.field],
331
+ resized,
332
+ }
333
+ : header,
334
+ );
335
+ };
336
+
297
337
  const columnWidthsStorage = usePersistedStorage({
298
- name: 'columnWidths',
299
- value: columnWidths,
338
+ name: 'resizedColumnWidths',
339
+ value: resizedColumnWidths,
300
340
  storages: [
301
341
  PersistedStorageType.LocalStorage,
302
342
  ],
303
343
  storagePath: id,
304
344
  onStore: (save, { name }) => {
305
- const value = JSON.stringify(columnWidths.value);
345
+ const value = JSON.stringify(resizedColumnWidths.value);
306
346
  return save({
307
347
  name,
308
348
  value,
309
349
  });
310
350
  },
311
351
  onRestore: async (restore, name) => {
312
- const value = (await restore(name)) as string;
313
- if (value) {
314
- const parsedWidths = JSON.parse(value);
315
- headers.value = headers.value.map((header) => ({
316
- ...header,
317
- width: parsedWidths[header.field] || header.width,
318
- }));
319
- }
352
+ // [Claude] sequentially, so resized widths override legacy ones
353
+ await restoreWidths(restore, legacyColumnWidthsName, {
354
+ resized: false,
355
+ });
356
+ await restoreWidths(restore, name, {
357
+ resized: true,
358
+ });
320
359
  },
321
360
  });
322
361
 
@@ -355,6 +394,7 @@ export const tableHeadersStoreBody = ({
355
394
 
356
395
  if (column) {
357
396
  column.width = columnWidth;
397
+ column.resized = true;
358
398
  }
359
399
  };
360
400