@gravity-ui/dashkit 5.2.0 → 5.4.0

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.
@@ -257,6 +257,155 @@ export const stateAndParams3 = {
257
257
  },
258
258
  },
259
259
  };
260
+ const stateAndParamsForAP1 = {
261
+ in: {
262
+ Q8: { params: { _ap_Country: 'Italy' } },
263
+ __meta__: { queue: [{ id: 'Q8', tabId: 'K0' }], version: 2 },
264
+ },
265
+ out: {
266
+ L5: {
267
+ params: { Country: 'Italy', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Italy' },
268
+ state: {},
269
+ },
270
+ Q8: {
271
+ params: {
272
+ Country: '',
273
+ Year: '',
274
+ _ap_Country: 'Italy',
275
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
276
+ },
277
+ state: {},
278
+ },
279
+ al: {
280
+ params: { Country: 'Italy', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Italy' },
281
+ state: {},
282
+ },
283
+ },
284
+ };
285
+ const stateAndParamsForAP2 = {
286
+ in: {
287
+ L5: {
288
+ params: { 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium' },
289
+ },
290
+ Q8: {
291
+ params: { _ap_Country: 'Italy' },
292
+ },
293
+ __meta__: { queue: [{ id: 'Q8', tabId: 'K0' }, { id: 'L5' }], version: 2 },
294
+ },
295
+ out: {
296
+ L5: {
297
+ params: { Country: 'Belgium', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium' },
298
+ state: {},
299
+ },
300
+ Q8: {
301
+ params: {
302
+ Country: 'Belgium',
303
+ Year: '',
304
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
305
+ },
306
+ state: {},
307
+ },
308
+ al: {
309
+ params: { Country: 'Belgium', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium' },
310
+ state: {},
311
+ },
312
+ },
313
+ };
314
+ const stateAndParamsForAP3 = {
315
+ in: {
316
+ Q8: { params: { _ap_Country: 'Italy' } },
317
+ L5: { params: { 'd079937f-6bc4-4133-9171-40092bb20d6f': '' } },
318
+ __meta__: { queue: [{ id: 'Q8', tabId: 'K0' }, { id: 'L5' }], version: 2 },
319
+ },
320
+ out: {
321
+ L5: {
322
+ params: {
323
+ Country: '',
324
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
325
+ },
326
+ state: {},
327
+ },
328
+ Q8: {
329
+ params: {
330
+ Country: '',
331
+ Year: '',
332
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
333
+ },
334
+ state: {},
335
+ },
336
+ al: {
337
+ params: {
338
+ Country: '',
339
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
340
+ },
341
+ state: {},
342
+ },
343
+ },
344
+ };
345
+ const stateAndParamsForAP4 = {
346
+ in: {
347
+ Q8: { params: { _ap_Country: '' } },
348
+ L5: { params: { 'd079937f-6bc4-4133-9171-40092bb20d6f': '' } },
349
+ __meta__: { queue: [{ id: 'L5' }, { id: 'Q8', tabId: 'K0' }], version: 2 },
350
+ },
351
+ out: {
352
+ L5: {
353
+ params: {
354
+ Country: '',
355
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
356
+ },
357
+ state: {},
358
+ },
359
+ Q8: {
360
+ params: {
361
+ Country: '',
362
+ Year: '',
363
+ _ap_Country: '',
364
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
365
+ },
366
+ state: {},
367
+ },
368
+ al: {
369
+ params: {
370
+ Country: '',
371
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': '',
372
+ },
373
+ state: {},
374
+ },
375
+ },
376
+ };
377
+ const stateAndParamsForAP5 = {
378
+ in: {
379
+ Q8: { params: {} },
380
+ L5: { params: {} },
381
+ __meta__: { queue: [], version: 2 },
382
+ },
383
+ out: {
384
+ L5: {
385
+ params: {
386
+ Country: ['Italy', 'France'],
387
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': ['Italy', 'France'],
388
+ },
389
+ state: {},
390
+ },
391
+ Q8: {
392
+ params: {
393
+ Country: ['Italy', 'France'],
394
+ Year: '',
395
+ _ap_Country: 'Belgium',
396
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': ['Italy', 'France'],
397
+ },
398
+ state: {},
399
+ },
400
+ al: {
401
+ params: {
402
+ Country: ['Italy', 'France'],
403
+ 'd079937f-6bc4-4133-9171-40092bb20d6f': ['Italy', 'France'],
404
+ },
405
+ state: {},
406
+ },
407
+ },
408
+ };
260
409
  const configs = mockConfigs.configs;
261
410
  describe('getItemsStateAndParamsDL', () => {
262
411
  describe('old version fallback', () => {
@@ -293,3 +442,60 @@ describe('getItemsStateAndParamsDL', () => {
293
442
  });
294
443
  });
295
444
  });
445
+ describe('getItemsStateAndParams actionParams variants check', () => {
446
+ describe('action and params state 1', () => {
447
+ const resultItemsStateAndParams = getItemsStateAndParamsDL({
448
+ defaultGlobalParams: {},
449
+ globalParams: {},
450
+ config: configs[2],
451
+ itemsStateAndParams: stateAndParamsForAP1.in,
452
+ });
453
+ it('return stateAndParamsForAP1.out', () => {
454
+ expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP1.out, META_KEY));
455
+ });
456
+ });
457
+ describe('action and params state 2', () => {
458
+ const resultItemsStateAndParams = getItemsStateAndParamsDL({
459
+ defaultGlobalParams: {},
460
+ globalParams: {},
461
+ config: configs[2],
462
+ itemsStateAndParams: stateAndParamsForAP2.in,
463
+ });
464
+ it('return stateAndParamsForAP2.out', () => {
465
+ expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP2.out, META_KEY));
466
+ });
467
+ });
468
+ describe('action and params state 3', () => {
469
+ const resultItemsStateAndParams = getItemsStateAndParamsDL({
470
+ defaultGlobalParams: {},
471
+ globalParams: {},
472
+ config: configs[2],
473
+ itemsStateAndParams: stateAndParamsForAP3.in,
474
+ });
475
+ it('return stateAndParamsForAP3.out', () => {
476
+ expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP3.out, META_KEY));
477
+ });
478
+ });
479
+ describe('action and params state 4', () => {
480
+ const resultItemsStateAndParams = getItemsStateAndParamsDL({
481
+ defaultGlobalParams: {},
482
+ globalParams: {},
483
+ config: configs[2],
484
+ itemsStateAndParams: stateAndParamsForAP4.in,
485
+ });
486
+ it('return stateAndParamsForAP4.out', () => {
487
+ expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP4.out, META_KEY));
488
+ });
489
+ });
490
+ describe('action and params state 5', () => {
491
+ const resultItemsStateAndParams = getItemsStateAndParamsDL({
492
+ defaultGlobalParams: {},
493
+ globalParams: {},
494
+ config: configs[3],
495
+ itemsStateAndParams: stateAndParamsForAP5.in,
496
+ });
497
+ it('return stateAndParamsForAP5.out', () => {
498
+ expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP5.out, META_KEY));
499
+ });
500
+ });
501
+ });
@@ -1,7 +1,7 @@
1
1
  import update, { extend } from 'immutability-helper';
2
2
  import omit from 'lodash/omit';
3
3
  import pick from 'lodash/pick';
4
- import { mergeParamsWithAliases, isItemWithTabs, getCurrentVersion, META_KEY, deleteFromQueue, addToQueue, getInitialItemsStateAndParamsMeta, resolveItemInnerId, getItemsStateAndParamsMeta, } from '../shared';
4
+ import { mergeParamsWithAliases, isItemWithTabs, getCurrentVersion, META_KEY, deleteFromQueue, addToQueue, getInitialItemsStateAndParamsMeta, resolveItemInnerId, getItemsStateAndParamsMeta, pickActionParamsFromParams, transformParamsToActionParams, } from '../shared';
5
5
  import { DEFAULT_NAMESPACE } from '../constants';
6
6
  import { getNewId } from './get-new-id';
7
7
  extend('$auto', (value, object) => (object ? update(object, value) : update({}, value)));
@@ -60,9 +60,14 @@ function removeItemVersion1({ id, config, itemsStateAndParams }) {
60
60
  itemsStateAndParams: newItemsStateAndParams,
61
61
  };
62
62
  }
63
- function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
63
+ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, paramsSettings) {
64
64
  var _a;
65
+ const paramsTypeName = (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.type) || 'params';
66
+ const isActionParamsMode = paramsTypeName === 'actionParams';
65
67
  let allowedParams = {};
68
+ const stateParamsConf = isActionParamsMode
69
+ ? pickActionParamsFromParams(stateAndParams.params, false)
70
+ : stateAndParams.params;
66
71
  if (isItemWithTabs(item)) {
67
72
  let tab;
68
73
  if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
@@ -72,14 +77,19 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
72
77
  const tabId = resolveItemInnerId({ item, itemsStateAndParams });
73
78
  tab = item.data.tabs.find(({ id }) => id === tabId);
74
79
  }
75
- allowedParams = pick(stateAndParams.params, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
80
+ allowedParams = pick(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
76
81
  }
77
82
  else {
78
- allowedParams = pick(stateAndParams.params, Object.keys(item.defaults || {}));
83
+ allowedParams = pick(stateParamsConf, Object.keys(item.defaults || {}));
79
84
  }
80
- if (Object.keys(allowedParams).length !== Object.keys(stateAndParams.params || {}).length) {
85
+ if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
81
86
  console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
82
87
  }
88
+ if (isActionParamsMode) {
89
+ return (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.returnPrefix)
90
+ ? transformParamsToActionParams(allowedParams)
91
+ : allowedParams;
92
+ }
83
93
  return allowedParams;
84
94
  }
85
95
  function changeStateAndParamsVersion1({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
@@ -240,6 +250,7 @@ export class UpdateManager {
240
250
  const currentMeta = getItemsStateAndParamsMeta(itemsStateAndParams);
241
251
  if ('params' in stateAndParams) {
242
252
  const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
253
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
243
254
  const tabId = isItemWithTabs(initiatorItem)
244
255
  ? newTabId || resolveItemInnerId({ item: initiatorItem, itemsStateAndParams })
245
256
  : undefined;
@@ -250,15 +261,16 @@ export class UpdateManager {
250
261
  if (isTabSwitched) {
251
262
  commandUpdateParams = '$set';
252
263
  }
253
- return update(itemsStateAndParams, {
264
+ const obj = {
254
265
  $unset: unusedIds,
255
266
  [initiatorId]: {
256
267
  $auto: Object.assign({ params: {
257
- [commandUpdateParams]: allowableParams,
268
+ [commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
258
269
  } }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
259
270
  },
260
271
  [META_KEY]: { $set: meta },
261
- });
272
+ };
273
+ return update(itemsStateAndParams, obj);
262
274
  }
263
275
  else if (hasState) {
264
276
  let metaSpec = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "5.2.0",
3
+ "version": "5.4.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {