@gravity-ui/dashkit 6.7.0 → 6.7.2
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/build/cjs/shared/modules/helpers.d.ts +0 -9
- package/build/cjs/shared/modules/helpers.js +2 -32
- package/build/cjs/shared/modules/state-and-params.js +3 -21
- package/build/cjs/shared/units/__tests__/state-and-params.test.js +218 -0
- package/build/esm/shared/modules/helpers.d.ts +0 -9
- package/build/esm/shared/modules/helpers.js +1 -30
- package/build/esm/shared/modules/state-and-params.js +4 -22
- package/build/esm/shared/units/__tests__/state-and-params.test.js +218 -0
- package/package.json +1 -1
|
@@ -69,13 +69,4 @@ export declare function hasActionParam(conf?: StringParams): boolean;
|
|
|
69
69
|
* @param stateAndParams
|
|
70
70
|
*/
|
|
71
71
|
export declare function hasActionParams(stateAndParams: ItemStateAndParams): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
|
|
74
|
-
* @param defaultWidgetParams
|
|
75
|
-
* @param queueWidgetParams
|
|
76
|
-
*/
|
|
77
|
-
export declare function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }: {
|
|
78
|
-
defaultWidgetParams: StringParams;
|
|
79
|
-
queueWidgetParams: StringParams;
|
|
80
|
-
}): string[];
|
|
81
72
|
export {};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.hasActionParams = exports.hasActionParam = exports.transformParamsToActionParams = exports.pickExceptActionParamsFromParams = exports.pickActionParamsFromParams = exports.deleteFromQueue = exports.addToQueue = exports.getInitialItemsStateAndParamsMeta = exports.mergeParamsWithAliases = exports.getMapItemsIgnores = exports.resolveItemInnerId = exports.formQueueData = exports.isItemWithTabs = exports.getCurrentVersion = exports.getItemsStateAndParamsMeta = exports.prerenderItems = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const keyBy_1 = tslib_1.__importDefault(require("lodash/keyBy"));
|
|
6
6
|
const get_1 = tslib_1.__importDefault(require("lodash/get"));
|
|
7
7
|
const invert_1 = tslib_1.__importDefault(require("lodash/invert"));
|
|
8
8
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
9
9
|
const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
|
10
|
-
const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
|
|
11
10
|
const constants_1 = require("../constants");
|
|
12
11
|
function getNormalizedPlugins(plugins) {
|
|
13
12
|
return (0, keyBy_1.default)(plugins, 'type');
|
|
@@ -79,19 +78,10 @@ function formQueueData({ items, itemsStateAndParams, }) {
|
|
|
79
78
|
}
|
|
80
79
|
const itemQueueParams = (0, get_1.default)(itemsStateAndParams, [item.id, 'params'], {});
|
|
81
80
|
const filteredParamsByDefaults = (0, pick_1.default)(itemQueueParams, Object.keys(itemDefaultParams));
|
|
82
|
-
/**
|
|
83
|
-
* filtering actionParams without prefixes by defaults params
|
|
84
|
-
* ex.:
|
|
85
|
-
* itemDefaultParams contains 'Country' in defaults
|
|
86
|
-
* and we receive '_ap_Country' and '_ap_City' in itemQueueParams
|
|
87
|
-
* we need to ignore '_ap_City' param because we don't have actionParam without prefix ('City') in defaults
|
|
88
|
-
*/
|
|
89
|
-
const actionParams = pickActionParamsFromParams(itemQueueParams, false) || {};
|
|
90
|
-
const filteredActionParamsByDefaults = (0, pick_1.default)(actionParams, Object.keys(itemDefaultParams));
|
|
91
81
|
/**
|
|
92
82
|
* merging filtered params and filtered actionParams with prefixes
|
|
93
83
|
*/
|
|
94
|
-
const params = Object.assign(Object.assign({}, filteredParamsByDefaults),
|
|
84
|
+
const params = Object.assign(Object.assign({}, filteredParamsByDefaults), (pickActionParamsFromParams(itemQueueParams, true) || {}));
|
|
95
85
|
return {
|
|
96
86
|
id: item.id,
|
|
97
87
|
namespace: item.namespace,
|
|
@@ -260,23 +250,3 @@ function hasActionParams(stateAndParams) {
|
|
|
260
250
|
return hasActionParam(stateAndParams.params);
|
|
261
251
|
}
|
|
262
252
|
exports.hasActionParams = hasActionParams;
|
|
263
|
-
/**
|
|
264
|
-
* Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
|
|
265
|
-
* @param defaultWidgetParams
|
|
266
|
-
* @param queueWidgetParams
|
|
267
|
-
*/
|
|
268
|
-
function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }) {
|
|
269
|
-
const widgetDefaultsWithActionParams = hasActionParam(defaultWidgetParams)
|
|
270
|
-
? pickActionParamsFromParams(defaultWidgetParams)
|
|
271
|
-
: null;
|
|
272
|
-
if (!widgetDefaultsWithActionParams) {
|
|
273
|
-
return [];
|
|
274
|
-
}
|
|
275
|
-
// clear default actionParams if some param with the same name without prefix affected on current widget
|
|
276
|
-
// ex.: queueWidgetParams contain {Year: 1970} and default actionParams contain {_ap_Year: 2000}
|
|
277
|
-
const actionParamKeyToClear = (0, intersection_1.default)(Object.keys(queueWidgetParams), Object.keys(widgetDefaultsWithActionParams));
|
|
278
|
-
return actionParamKeyToClear.length
|
|
279
|
-
? actionParamKeyToClear.map((key) => `${constants_1.ACTION_PARAM_PREFIX}${key}`)
|
|
280
|
-
: [];
|
|
281
|
-
}
|
|
282
|
-
exports.getDefaultsActionParamsToClear = getDefaultsActionParamsToClear;
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getItemsStateAndParams = exports.getItemsState = exports.getItemsParams = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
|
|
6
|
-
const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
|
|
7
|
-
const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
8
6
|
const constants_1 = require("../constants");
|
|
9
7
|
const helpers_1 = require("./helpers");
|
|
10
8
|
function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
|
|
@@ -54,8 +52,7 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
|
|
|
54
52
|
}
|
|
55
53
|
else {
|
|
56
54
|
// params according to queue of its applying
|
|
57
|
-
let
|
|
58
|
-
let queueDataItems = {};
|
|
55
|
+
let queueDataItemsParams = {};
|
|
59
56
|
for (const data of Object.values(queueData)) {
|
|
60
57
|
if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
|
|
61
58
|
continue;
|
|
@@ -68,24 +65,9 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
|
|
|
68
65
|
params = (0, helpers_1.pickExceptActionParamsFromParams)(data.params);
|
|
69
66
|
}
|
|
70
67
|
const mergedParams = getMergedParams(params, actionParams);
|
|
71
|
-
|
|
72
|
-
let queueDataRes = Object.assign({}, queueDataItems);
|
|
73
|
-
if (actionParamKeyToClear.length) {
|
|
74
|
-
queueDataRes = (0, omit_1.default)(queueDataItems, actionParamKeyToClear);
|
|
75
|
-
}
|
|
76
|
-
queueDataItems = Object.assign(Object.assign({}, queueDataRes), mergedParams);
|
|
77
|
-
prevQueueDataWithActionParams = (0, helpers_1.hasActionParam)(queueDataItems)
|
|
78
|
-
? (0, helpers_1.pickActionParamsFromParams)(data.params, true)
|
|
79
|
-
: {};
|
|
80
|
-
}
|
|
81
|
-
const clearActionParams = (0, helpers_1.getDefaultsActionParamsToClear)({
|
|
82
|
-
defaultWidgetParams,
|
|
83
|
-
queueWidgetParams: queueDataItems,
|
|
84
|
-
});
|
|
85
|
-
if (clearActionParams.length) {
|
|
86
|
-
defaultWidgetParams = (0, omit_1.default)(defaultWidgetParams, clearActionParams);
|
|
68
|
+
queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
|
|
87
69
|
}
|
|
88
|
-
itemParams = Object.assign(itemParams,
|
|
70
|
+
itemParams = Object.assign(itemParams, queueDataItemsParams);
|
|
89
71
|
}
|
|
90
72
|
return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
|
|
91
73
|
}, {});
|
|
@@ -306,6 +306,7 @@ const stateAndParamsForAP2 = {
|
|
|
306
306
|
Country: 'Belgium',
|
|
307
307
|
Year: '',
|
|
308
308
|
'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
|
|
309
|
+
_ap_Country: 'Italy',
|
|
309
310
|
},
|
|
310
311
|
state: {},
|
|
311
312
|
},
|
|
@@ -334,6 +335,7 @@ const stateAndParamsForAP3 = {
|
|
|
334
335
|
Country: '',
|
|
335
336
|
Year: '',
|
|
336
337
|
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
338
|
+
_ap_Country: 'Italy',
|
|
337
339
|
},
|
|
338
340
|
state: {},
|
|
339
341
|
},
|
|
@@ -410,6 +412,64 @@ const stateAndParamsForAP5 = {
|
|
|
410
412
|
},
|
|
411
413
|
},
|
|
412
414
|
};
|
|
415
|
+
const stateAndParamsForAP6 = {
|
|
416
|
+
in: {
|
|
417
|
+
Q8: {
|
|
418
|
+
params: {
|
|
419
|
+
_ap_Year: '2021',
|
|
420
|
+
_ap_Country: 'Russia',
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
L5: {
|
|
424
|
+
params: {
|
|
425
|
+
_ap_Country: 'Russia',
|
|
426
|
+
_ap_Name: 'Alex',
|
|
427
|
+
_ap_Price: '1000',
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
__meta__: {
|
|
431
|
+
queue: [
|
|
432
|
+
{ id: 'Q8', tabId: 'K0' },
|
|
433
|
+
{ id: 'L5', tabId: 'K1' },
|
|
434
|
+
],
|
|
435
|
+
version: 2,
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
out: {
|
|
439
|
+
L5: {
|
|
440
|
+
params: {
|
|
441
|
+
Name: '',
|
|
442
|
+
Price: '',
|
|
443
|
+
Year: '2021',
|
|
444
|
+
Country: 'Russia',
|
|
445
|
+
_ap_Country: 'Russia',
|
|
446
|
+
_ap_Name: 'Alex',
|
|
447
|
+
_ap_Price: '1000',
|
|
448
|
+
},
|
|
449
|
+
state: {},
|
|
450
|
+
},
|
|
451
|
+
Q8: {
|
|
452
|
+
params: {
|
|
453
|
+
Year: '',
|
|
454
|
+
Country: 'Russia',
|
|
455
|
+
Name: 'Alex',
|
|
456
|
+
Price: '1000',
|
|
457
|
+
_ap_Year: '2021',
|
|
458
|
+
_ap_Country: 'Russia',
|
|
459
|
+
},
|
|
460
|
+
state: {},
|
|
461
|
+
},
|
|
462
|
+
al: {
|
|
463
|
+
params: {
|
|
464
|
+
Country: 'Russia',
|
|
465
|
+
Name: 'Alex',
|
|
466
|
+
Price: '1000',
|
|
467
|
+
Year: '2021',
|
|
468
|
+
},
|
|
469
|
+
state: {},
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
};
|
|
413
473
|
const configs = configs_json_1.default.configs;
|
|
414
474
|
describe('getItemsStateAndParamsDL', () => {
|
|
415
475
|
describe('old version fallback', () => {
|
|
@@ -502,4 +562,162 @@ describe('getItemsStateAndParams actionParams variants check', () => {
|
|
|
502
562
|
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP5.out, constants_1.META_KEY));
|
|
503
563
|
});
|
|
504
564
|
});
|
|
565
|
+
describe('action and params state 6', () => {
|
|
566
|
+
const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
567
|
+
defaultGlobalParams: {},
|
|
568
|
+
globalParams: {},
|
|
569
|
+
config: configs[4],
|
|
570
|
+
itemsStateAndParams: stateAndParamsForAP6.in,
|
|
571
|
+
});
|
|
572
|
+
it('return stateAndParamsForAP6.out', () => {
|
|
573
|
+
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP6.out, constants_1.META_KEY));
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
const config = {
|
|
578
|
+
id: '7kw',
|
|
579
|
+
items: [
|
|
580
|
+
{
|
|
581
|
+
id: 'nvp',
|
|
582
|
+
data: {
|
|
583
|
+
tabs: [
|
|
584
|
+
{
|
|
585
|
+
id: 'rkq',
|
|
586
|
+
title: 'test',
|
|
587
|
+
params: {},
|
|
588
|
+
chartId: 'some-chart',
|
|
589
|
+
isDefault: true,
|
|
590
|
+
autoHeight: false,
|
|
591
|
+
description: '',
|
|
592
|
+
enableActionParams: true,
|
|
593
|
+
},
|
|
594
|
+
],
|
|
595
|
+
hideTitle: true,
|
|
596
|
+
},
|
|
597
|
+
type: 'widget',
|
|
598
|
+
layout: {
|
|
599
|
+
h: 12,
|
|
600
|
+
w: 12,
|
|
601
|
+
},
|
|
602
|
+
namespace: 'default',
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
id: 'Q9K',
|
|
606
|
+
data: {
|
|
607
|
+
title: 'Year',
|
|
608
|
+
source: {},
|
|
609
|
+
},
|
|
610
|
+
type: 'control',
|
|
611
|
+
layout: {
|
|
612
|
+
h: 2,
|
|
613
|
+
w: 8,
|
|
614
|
+
},
|
|
615
|
+
defaults: {
|
|
616
|
+
year_some_id: '',
|
|
617
|
+
},
|
|
618
|
+
namespace: 'default',
|
|
619
|
+
},
|
|
620
|
+
],
|
|
621
|
+
title: 'test',
|
|
622
|
+
layout: [
|
|
623
|
+
{
|
|
624
|
+
h: 12,
|
|
625
|
+
i: 'nvp',
|
|
626
|
+
w: 12,
|
|
627
|
+
x: 0,
|
|
628
|
+
y: 0,
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
h: 2,
|
|
632
|
+
i: 'Q9K',
|
|
633
|
+
w: 8,
|
|
634
|
+
x: 12,
|
|
635
|
+
y: 0,
|
|
636
|
+
},
|
|
637
|
+
],
|
|
638
|
+
aliases: {},
|
|
639
|
+
connections: [],
|
|
640
|
+
salt: '123',
|
|
641
|
+
counter: 1,
|
|
642
|
+
};
|
|
643
|
+
const itemsStateAndParamsActionParamTest1 = {
|
|
644
|
+
nvp: {
|
|
645
|
+
params: {
|
|
646
|
+
_ap_year_some_id: ['2022'],
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
__meta__: {
|
|
650
|
+
queue: [
|
|
651
|
+
{
|
|
652
|
+
id: 'nvp',
|
|
653
|
+
tabId: 'rkq',
|
|
654
|
+
},
|
|
655
|
+
],
|
|
656
|
+
version: 2,
|
|
657
|
+
},
|
|
658
|
+
};
|
|
659
|
+
const stateAndParamsActionParamsRes1 = {
|
|
660
|
+
Q9K: {
|
|
661
|
+
params: {
|
|
662
|
+
year_some_id: ['2022'],
|
|
663
|
+
},
|
|
664
|
+
state: {},
|
|
665
|
+
},
|
|
666
|
+
nvp: {
|
|
667
|
+
params: {
|
|
668
|
+
_ap_year_some_id: ['2022'],
|
|
669
|
+
year_some_id: '',
|
|
670
|
+
},
|
|
671
|
+
state: {},
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
const itemsStateAndParamsActionParamTest2 = {
|
|
675
|
+
nvp: {
|
|
676
|
+
params: {
|
|
677
|
+
_ap_another: ['2022'],
|
|
678
|
+
},
|
|
679
|
+
},
|
|
680
|
+
__meta__: {
|
|
681
|
+
queue: [
|
|
682
|
+
{
|
|
683
|
+
id: 'nvp',
|
|
684
|
+
tabId: 'rkq',
|
|
685
|
+
},
|
|
686
|
+
],
|
|
687
|
+
version: 2,
|
|
688
|
+
},
|
|
689
|
+
};
|
|
690
|
+
const stateAndParamsActionParamsRes2 = {
|
|
691
|
+
Q9K: {
|
|
692
|
+
params: {
|
|
693
|
+
another: ['2022'],
|
|
694
|
+
year_some_id: '',
|
|
695
|
+
},
|
|
696
|
+
state: {},
|
|
697
|
+
},
|
|
698
|
+
nvp: {
|
|
699
|
+
params: {
|
|
700
|
+
_ap_another: ['2022'],
|
|
701
|
+
year_some_id: '',
|
|
702
|
+
},
|
|
703
|
+
state: {},
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
describe('state and params with actionParams', () => {
|
|
707
|
+
it('check state', () => {
|
|
708
|
+
const res1 = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
709
|
+
defaultGlobalParams: {},
|
|
710
|
+
globalParams: {},
|
|
711
|
+
config,
|
|
712
|
+
itemsStateAndParams: itemsStateAndParamsActionParamTest1,
|
|
713
|
+
});
|
|
714
|
+
expect(res1).toEqual(stateAndParamsActionParamsRes1);
|
|
715
|
+
const res2 = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
716
|
+
defaultGlobalParams: {},
|
|
717
|
+
globalParams: {},
|
|
718
|
+
config,
|
|
719
|
+
itemsStateAndParams: itemsStateAndParamsActionParamTest2,
|
|
720
|
+
});
|
|
721
|
+
expect(res2).toEqual(stateAndParamsActionParamsRes2);
|
|
722
|
+
});
|
|
505
723
|
});
|
|
@@ -69,13 +69,4 @@ export declare function hasActionParam(conf?: StringParams): boolean;
|
|
|
69
69
|
* @param stateAndParams
|
|
70
70
|
*/
|
|
71
71
|
export declare function hasActionParams(stateAndParams: ItemStateAndParams): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
|
|
74
|
-
* @param defaultWidgetParams
|
|
75
|
-
* @param queueWidgetParams
|
|
76
|
-
*/
|
|
77
|
-
export declare function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }: {
|
|
78
|
-
defaultWidgetParams: StringParams;
|
|
79
|
-
queueWidgetParams: StringParams;
|
|
80
|
-
}): string[];
|
|
81
72
|
export {};
|
|
@@ -3,7 +3,6 @@ import get from 'lodash/get';
|
|
|
3
3
|
import invert from 'lodash/invert';
|
|
4
4
|
import isEmpty from 'lodash/isEmpty';
|
|
5
5
|
import pick from 'lodash/pick';
|
|
6
|
-
import intersection from 'lodash/intersection';
|
|
7
6
|
import { META_KEY, CURRENT_VERSION, ACTION_PARAM_PREFIX } from '../constants';
|
|
8
7
|
function getNormalizedPlugins(plugins) {
|
|
9
8
|
return keyBy(plugins, 'type');
|
|
@@ -71,19 +70,10 @@ export function formQueueData({ items, itemsStateAndParams, }) {
|
|
|
71
70
|
}
|
|
72
71
|
const itemQueueParams = get(itemsStateAndParams, [item.id, 'params'], {});
|
|
73
72
|
const filteredParamsByDefaults = pick(itemQueueParams, Object.keys(itemDefaultParams));
|
|
74
|
-
/**
|
|
75
|
-
* filtering actionParams without prefixes by defaults params
|
|
76
|
-
* ex.:
|
|
77
|
-
* itemDefaultParams contains 'Country' in defaults
|
|
78
|
-
* and we receive '_ap_Country' and '_ap_City' in itemQueueParams
|
|
79
|
-
* we need to ignore '_ap_City' param because we don't have actionParam without prefix ('City') in defaults
|
|
80
|
-
*/
|
|
81
|
-
const actionParams = pickActionParamsFromParams(itemQueueParams, false) || {};
|
|
82
|
-
const filteredActionParamsByDefaults = pick(actionParams, Object.keys(itemDefaultParams));
|
|
83
73
|
/**
|
|
84
74
|
* merging filtered params and filtered actionParams with prefixes
|
|
85
75
|
*/
|
|
86
|
-
const params = Object.assign(Object.assign({}, filteredParamsByDefaults),
|
|
76
|
+
const params = Object.assign(Object.assign({}, filteredParamsByDefaults), (pickActionParamsFromParams(itemQueueParams, true) || {}));
|
|
87
77
|
return {
|
|
88
78
|
id: item.id,
|
|
89
79
|
namespace: item.namespace,
|
|
@@ -240,22 +230,3 @@ export function hasActionParams(stateAndParams) {
|
|
|
240
230
|
}
|
|
241
231
|
return hasActionParam(stateAndParams.params);
|
|
242
232
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
|
|
245
|
-
* @param defaultWidgetParams
|
|
246
|
-
* @param queueWidgetParams
|
|
247
|
-
*/
|
|
248
|
-
export function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }) {
|
|
249
|
-
const widgetDefaultsWithActionParams = hasActionParam(defaultWidgetParams)
|
|
250
|
-
? pickActionParamsFromParams(defaultWidgetParams)
|
|
251
|
-
: null;
|
|
252
|
-
if (!widgetDefaultsWithActionParams) {
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
// clear default actionParams if some param with the same name without prefix affected on current widget
|
|
256
|
-
// ex.: queueWidgetParams contain {Year: 1970} and default actionParams contain {_ap_Year: 2000}
|
|
257
|
-
const actionParamKeyToClear = intersection(Object.keys(queueWidgetParams), Object.keys(widgetDefaultsWithActionParams));
|
|
258
|
-
return actionParamKeyToClear.length
|
|
259
|
-
? actionParamKeyToClear.map((key) => `${ACTION_PARAM_PREFIX}${key}`)
|
|
260
|
-
: [];
|
|
261
|
-
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import groupBy from 'lodash/groupBy';
|
|
2
|
-
import intersection from 'lodash/intersection';
|
|
3
|
-
import omit from 'lodash/omit';
|
|
4
2
|
import { META_KEY } from '../constants';
|
|
5
|
-
import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams,
|
|
3
|
+
import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, isItemWithTabs, resolveItemInnerId, } from './helpers';
|
|
6
4
|
export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
|
|
7
5
|
const { aliases, connections } = config;
|
|
8
6
|
const items = prerenderItems({ items: config.items, plugins });
|
|
@@ -50,8 +48,7 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
|
|
|
50
48
|
}
|
|
51
49
|
else {
|
|
52
50
|
// params according to queue of its applying
|
|
53
|
-
let
|
|
54
|
-
let queueDataItems = {};
|
|
51
|
+
let queueDataItemsParams = {};
|
|
55
52
|
for (const data of Object.values(queueData)) {
|
|
56
53
|
if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
|
|
57
54
|
continue;
|
|
@@ -64,24 +61,9 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
|
|
|
64
61
|
params = pickExceptActionParamsFromParams(data.params);
|
|
65
62
|
}
|
|
66
63
|
const mergedParams = getMergedParams(params, actionParams);
|
|
67
|
-
|
|
68
|
-
let queueDataRes = Object.assign({}, queueDataItems);
|
|
69
|
-
if (actionParamKeyToClear.length) {
|
|
70
|
-
queueDataRes = omit(queueDataItems, actionParamKeyToClear);
|
|
71
|
-
}
|
|
72
|
-
queueDataItems = Object.assign(Object.assign({}, queueDataRes), mergedParams);
|
|
73
|
-
prevQueueDataWithActionParams = hasActionParam(queueDataItems)
|
|
74
|
-
? pickActionParamsFromParams(data.params, true)
|
|
75
|
-
: {};
|
|
76
|
-
}
|
|
77
|
-
const clearActionParams = getDefaultsActionParamsToClear({
|
|
78
|
-
defaultWidgetParams,
|
|
79
|
-
queueWidgetParams: queueDataItems,
|
|
80
|
-
});
|
|
81
|
-
if (clearActionParams.length) {
|
|
82
|
-
defaultWidgetParams = omit(defaultWidgetParams, clearActionParams);
|
|
64
|
+
queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
|
|
83
65
|
}
|
|
84
|
-
itemParams = Object.assign(itemParams,
|
|
66
|
+
itemParams = Object.assign(itemParams, queueDataItemsParams);
|
|
85
67
|
}
|
|
86
68
|
return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
|
|
87
69
|
}, {});
|
|
@@ -302,6 +302,7 @@ const stateAndParamsForAP2 = {
|
|
|
302
302
|
Country: 'Belgium',
|
|
303
303
|
Year: '',
|
|
304
304
|
'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
|
|
305
|
+
_ap_Country: 'Italy',
|
|
305
306
|
},
|
|
306
307
|
state: {},
|
|
307
308
|
},
|
|
@@ -330,6 +331,7 @@ const stateAndParamsForAP3 = {
|
|
|
330
331
|
Country: '',
|
|
331
332
|
Year: '',
|
|
332
333
|
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
334
|
+
_ap_Country: 'Italy',
|
|
333
335
|
},
|
|
334
336
|
state: {},
|
|
335
337
|
},
|
|
@@ -406,6 +408,64 @@ const stateAndParamsForAP5 = {
|
|
|
406
408
|
},
|
|
407
409
|
},
|
|
408
410
|
};
|
|
411
|
+
const stateAndParamsForAP6 = {
|
|
412
|
+
in: {
|
|
413
|
+
Q8: {
|
|
414
|
+
params: {
|
|
415
|
+
_ap_Year: '2021',
|
|
416
|
+
_ap_Country: 'Russia',
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
L5: {
|
|
420
|
+
params: {
|
|
421
|
+
_ap_Country: 'Russia',
|
|
422
|
+
_ap_Name: 'Alex',
|
|
423
|
+
_ap_Price: '1000',
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
__meta__: {
|
|
427
|
+
queue: [
|
|
428
|
+
{ id: 'Q8', tabId: 'K0' },
|
|
429
|
+
{ id: 'L5', tabId: 'K1' },
|
|
430
|
+
],
|
|
431
|
+
version: 2,
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
out: {
|
|
435
|
+
L5: {
|
|
436
|
+
params: {
|
|
437
|
+
Name: '',
|
|
438
|
+
Price: '',
|
|
439
|
+
Year: '2021',
|
|
440
|
+
Country: 'Russia',
|
|
441
|
+
_ap_Country: 'Russia',
|
|
442
|
+
_ap_Name: 'Alex',
|
|
443
|
+
_ap_Price: '1000',
|
|
444
|
+
},
|
|
445
|
+
state: {},
|
|
446
|
+
},
|
|
447
|
+
Q8: {
|
|
448
|
+
params: {
|
|
449
|
+
Year: '',
|
|
450
|
+
Country: 'Russia',
|
|
451
|
+
Name: 'Alex',
|
|
452
|
+
Price: '1000',
|
|
453
|
+
_ap_Year: '2021',
|
|
454
|
+
_ap_Country: 'Russia',
|
|
455
|
+
},
|
|
456
|
+
state: {},
|
|
457
|
+
},
|
|
458
|
+
al: {
|
|
459
|
+
params: {
|
|
460
|
+
Country: 'Russia',
|
|
461
|
+
Name: 'Alex',
|
|
462
|
+
Price: '1000',
|
|
463
|
+
Year: '2021',
|
|
464
|
+
},
|
|
465
|
+
state: {},
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
};
|
|
409
469
|
const configs = mockConfigs.configs;
|
|
410
470
|
describe('getItemsStateAndParamsDL', () => {
|
|
411
471
|
describe('old version fallback', () => {
|
|
@@ -498,4 +558,162 @@ describe('getItemsStateAndParams actionParams variants check', () => {
|
|
|
498
558
|
expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP5.out, META_KEY));
|
|
499
559
|
});
|
|
500
560
|
});
|
|
561
|
+
describe('action and params state 6', () => {
|
|
562
|
+
const resultItemsStateAndParams = getItemsStateAndParamsDL({
|
|
563
|
+
defaultGlobalParams: {},
|
|
564
|
+
globalParams: {},
|
|
565
|
+
config: configs[4],
|
|
566
|
+
itemsStateAndParams: stateAndParamsForAP6.in,
|
|
567
|
+
});
|
|
568
|
+
it('return stateAndParamsForAP6.out', () => {
|
|
569
|
+
expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP6.out, META_KEY));
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
const config = {
|
|
574
|
+
id: '7kw',
|
|
575
|
+
items: [
|
|
576
|
+
{
|
|
577
|
+
id: 'nvp',
|
|
578
|
+
data: {
|
|
579
|
+
tabs: [
|
|
580
|
+
{
|
|
581
|
+
id: 'rkq',
|
|
582
|
+
title: 'test',
|
|
583
|
+
params: {},
|
|
584
|
+
chartId: 'some-chart',
|
|
585
|
+
isDefault: true,
|
|
586
|
+
autoHeight: false,
|
|
587
|
+
description: '',
|
|
588
|
+
enableActionParams: true,
|
|
589
|
+
},
|
|
590
|
+
],
|
|
591
|
+
hideTitle: true,
|
|
592
|
+
},
|
|
593
|
+
type: 'widget',
|
|
594
|
+
layout: {
|
|
595
|
+
h: 12,
|
|
596
|
+
w: 12,
|
|
597
|
+
},
|
|
598
|
+
namespace: 'default',
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
id: 'Q9K',
|
|
602
|
+
data: {
|
|
603
|
+
title: 'Year',
|
|
604
|
+
source: {},
|
|
605
|
+
},
|
|
606
|
+
type: 'control',
|
|
607
|
+
layout: {
|
|
608
|
+
h: 2,
|
|
609
|
+
w: 8,
|
|
610
|
+
},
|
|
611
|
+
defaults: {
|
|
612
|
+
year_some_id: '',
|
|
613
|
+
},
|
|
614
|
+
namespace: 'default',
|
|
615
|
+
},
|
|
616
|
+
],
|
|
617
|
+
title: 'test',
|
|
618
|
+
layout: [
|
|
619
|
+
{
|
|
620
|
+
h: 12,
|
|
621
|
+
i: 'nvp',
|
|
622
|
+
w: 12,
|
|
623
|
+
x: 0,
|
|
624
|
+
y: 0,
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
h: 2,
|
|
628
|
+
i: 'Q9K',
|
|
629
|
+
w: 8,
|
|
630
|
+
x: 12,
|
|
631
|
+
y: 0,
|
|
632
|
+
},
|
|
633
|
+
],
|
|
634
|
+
aliases: {},
|
|
635
|
+
connections: [],
|
|
636
|
+
salt: '123',
|
|
637
|
+
counter: 1,
|
|
638
|
+
};
|
|
639
|
+
const itemsStateAndParamsActionParamTest1 = {
|
|
640
|
+
nvp: {
|
|
641
|
+
params: {
|
|
642
|
+
_ap_year_some_id: ['2022'],
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
__meta__: {
|
|
646
|
+
queue: [
|
|
647
|
+
{
|
|
648
|
+
id: 'nvp',
|
|
649
|
+
tabId: 'rkq',
|
|
650
|
+
},
|
|
651
|
+
],
|
|
652
|
+
version: 2,
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
const stateAndParamsActionParamsRes1 = {
|
|
656
|
+
Q9K: {
|
|
657
|
+
params: {
|
|
658
|
+
year_some_id: ['2022'],
|
|
659
|
+
},
|
|
660
|
+
state: {},
|
|
661
|
+
},
|
|
662
|
+
nvp: {
|
|
663
|
+
params: {
|
|
664
|
+
_ap_year_some_id: ['2022'],
|
|
665
|
+
year_some_id: '',
|
|
666
|
+
},
|
|
667
|
+
state: {},
|
|
668
|
+
},
|
|
669
|
+
};
|
|
670
|
+
const itemsStateAndParamsActionParamTest2 = {
|
|
671
|
+
nvp: {
|
|
672
|
+
params: {
|
|
673
|
+
_ap_another: ['2022'],
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
__meta__: {
|
|
677
|
+
queue: [
|
|
678
|
+
{
|
|
679
|
+
id: 'nvp',
|
|
680
|
+
tabId: 'rkq',
|
|
681
|
+
},
|
|
682
|
+
],
|
|
683
|
+
version: 2,
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
const stateAndParamsActionParamsRes2 = {
|
|
687
|
+
Q9K: {
|
|
688
|
+
params: {
|
|
689
|
+
another: ['2022'],
|
|
690
|
+
year_some_id: '',
|
|
691
|
+
},
|
|
692
|
+
state: {},
|
|
693
|
+
},
|
|
694
|
+
nvp: {
|
|
695
|
+
params: {
|
|
696
|
+
_ap_another: ['2022'],
|
|
697
|
+
year_some_id: '',
|
|
698
|
+
},
|
|
699
|
+
state: {},
|
|
700
|
+
},
|
|
701
|
+
};
|
|
702
|
+
describe('state and params with actionParams', () => {
|
|
703
|
+
it('check state', () => {
|
|
704
|
+
const res1 = getItemsStateAndParamsDL({
|
|
705
|
+
defaultGlobalParams: {},
|
|
706
|
+
globalParams: {},
|
|
707
|
+
config,
|
|
708
|
+
itemsStateAndParams: itemsStateAndParamsActionParamTest1,
|
|
709
|
+
});
|
|
710
|
+
expect(res1).toEqual(stateAndParamsActionParamsRes1);
|
|
711
|
+
const res2 = getItemsStateAndParamsDL({
|
|
712
|
+
defaultGlobalParams: {},
|
|
713
|
+
globalParams: {},
|
|
714
|
+
config,
|
|
715
|
+
itemsStateAndParams: itemsStateAndParamsActionParamTest2,
|
|
716
|
+
});
|
|
717
|
+
expect(res2).toEqual(stateAndParamsActionParamsRes2);
|
|
718
|
+
});
|
|
501
719
|
});
|