@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.
- package/CHANGELOG.md +15 -0
- package/build/cjs/shared/constants/common.d.ts +1 -0
- package/build/cjs/shared/constants/common.js +2 -1
- package/build/cjs/shared/modules/__tests__/helpers.test.js +77 -0
- package/build/cjs/shared/modules/helpers.d.ts +41 -2
- package/build/cjs/shared/modules/helpers.js +116 -6
- package/build/cjs/shared/modules/state-and-params.js +52 -15
- package/build/cjs/shared/units/__tests__/state-and-params.test.js +206 -0
- package/build/cjs/utils/update-manager.js +19 -7
- package/build/esm/shared/constants/common.d.ts +1 -0
- package/build/esm/shared/constants/common.js +1 -0
- package/build/esm/shared/modules/__tests__/helpers.test.js +79 -2
- package/build/esm/shared/modules/helpers.d.ts +41 -2
- package/build/esm/shared/modules/helpers.js +110 -6
- package/build/esm/shared/modules/state-and-params.js +52 -15
- package/build/esm/shared/units/__tests__/state-and-params.test.js +206 -0
- package/build/esm/utils/update-manager.js +20 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.4.0](https://github.com/gravity-ui/dashkit/compare/v5.3.0...v5.4.0) (2023-04-13)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add widget defaults ([#52](https://github.com/gravity-ui/dashkit/issues/52)) ([a6e512d](https://github.com/gravity-ui/dashkit/commit/a6e512d132e6c9f0fc93d63527f233656863831e))
|
|
9
|
+
* clear default actionParams ([#55](https://github.com/gravity-ui/dashkit/issues/55)) ([4184b82](https://github.com/gravity-ui/dashkit/commit/4184b828228c6faae21a9c9731fee544f7dd5362))
|
|
10
|
+
|
|
11
|
+
## [5.3.0](https://github.com/gravity-ui/dashkit/compare/v5.2.0...v5.3.0) (2023-04-06)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* add actionParams support ([#47](https://github.com/gravity-ui/dashkit/issues/47)) ([0c78ae2](https://github.com/gravity-ui/dashkit/commit/0c78ae2b96d9882ea27a7e7742d40728fadcfa84))
|
|
17
|
+
|
|
3
18
|
## [5.2.0](https://github.com/gravity-ui/dashkit/compare/v5.1.0...v5.2.0) (2023-03-27)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.META_KEY = exports.CURRENT_VERSION = void 0;
|
|
3
|
+
exports.ACTION_PARAM_PREFIX = exports.META_KEY = exports.CURRENT_VERSION = void 0;
|
|
4
4
|
exports.CURRENT_VERSION = 2;
|
|
5
5
|
exports.META_KEY = '__meta__';
|
|
6
|
+
exports.ACTION_PARAM_PREFIX = '_ap_';
|
|
@@ -13,6 +13,59 @@ const getMockedControlItem = ({ id = DEFAULT_CONTROL_ID, defaults, }) => ({
|
|
|
13
13
|
type: 'control',
|
|
14
14
|
namespace: NAMESPACE,
|
|
15
15
|
});
|
|
16
|
+
const stateAndParamsWithParamsOnly = {
|
|
17
|
+
params: {
|
|
18
|
+
paramName: 'param1',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const stateAndParamsWithStateOnly = {
|
|
22
|
+
state: {
|
|
23
|
+
tabId: 'tabId1',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const stateAndParamsWithActionParamsInParamsOnly = {
|
|
27
|
+
params: {
|
|
28
|
+
_ap_paramName: 'param1',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const stateAndParamsWithStateAndActionParamsInParams = {
|
|
32
|
+
state: {
|
|
33
|
+
tabId: 'tabId1',
|
|
34
|
+
},
|
|
35
|
+
params: {
|
|
36
|
+
_ap_paramName: 'param1',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
const stateAndParamsWithParamsAndActionParamsInParams = {
|
|
40
|
+
params: {
|
|
41
|
+
paramName2: 'param2',
|
|
42
|
+
_ap_paramName: 'param1',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const paramsToTransform = {
|
|
46
|
+
in: {
|
|
47
|
+
param1: 'val 1',
|
|
48
|
+
param2: 'val 2',
|
|
49
|
+
},
|
|
50
|
+
out: {
|
|
51
|
+
[`${constants_1.ACTION_PARAM_PREFIX}param1`]: 'val 1',
|
|
52
|
+
[`${constants_1.ACTION_PARAM_PREFIX}param2`]: 'val 2',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const exeptActionParam1 = {
|
|
56
|
+
in: stateAndParamsWithParamsOnly.params,
|
|
57
|
+
out: stateAndParamsWithParamsOnly.params,
|
|
58
|
+
};
|
|
59
|
+
const exeptActionParam2 = {
|
|
60
|
+
in: stateAndParamsWithActionParamsInParamsOnly.params,
|
|
61
|
+
out: {},
|
|
62
|
+
};
|
|
63
|
+
const exeptActionParam3 = {
|
|
64
|
+
in: stateAndParamsWithParamsAndActionParamsInParams.params,
|
|
65
|
+
out: {
|
|
66
|
+
paramName2: 'param2',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
16
69
|
const getMockedWidgetItem = ({ id = DEFAULT_WIDGET_ID, tabs }) => ({
|
|
17
70
|
id,
|
|
18
71
|
data: { tabs },
|
|
@@ -214,4 +267,28 @@ describe('modules.helpers', () => {
|
|
|
214
267
|
}));
|
|
215
268
|
});
|
|
216
269
|
});
|
|
270
|
+
describe('actionParams helpers', () => {
|
|
271
|
+
it('check hasActionParams', () => {
|
|
272
|
+
const empty = (0, helpers_1.hasActionParams)({});
|
|
273
|
+
expect(empty).toBeFalsy();
|
|
274
|
+
const withParamsOnly = (0, helpers_1.hasActionParams)(stateAndParamsWithParamsOnly);
|
|
275
|
+
expect(withParamsOnly).toBeFalsy();
|
|
276
|
+
const withStateOnly = (0, helpers_1.hasActionParams)(stateAndParamsWithStateOnly);
|
|
277
|
+
expect(withStateOnly).toBeFalsy();
|
|
278
|
+
const withAPinParams = (0, helpers_1.hasActionParams)(stateAndParamsWithActionParamsInParamsOnly);
|
|
279
|
+
expect(withAPinParams).toBeTruthy();
|
|
280
|
+
const withAPinParamsNState = (0, helpers_1.hasActionParams)(stateAndParamsWithStateAndActionParamsInParams);
|
|
281
|
+
expect(withAPinParamsNState).toBeTruthy();
|
|
282
|
+
const withParamsAndAPinParams = (0, helpers_1.hasActionParams)(stateAndParamsWithParamsAndActionParamsInParams);
|
|
283
|
+
expect(withParamsAndAPinParams).toBeTruthy();
|
|
284
|
+
});
|
|
285
|
+
it('check transformParamsToActionParams', () => {
|
|
286
|
+
expect(paramsToTransform.out).toEqual((0, helpers_1.transformParamsToActionParams)(paramsToTransform.in));
|
|
287
|
+
});
|
|
288
|
+
it('check pickExceptActionParamsFromParams', () => {
|
|
289
|
+
expect(exeptActionParam1.out).toEqual((0, helpers_1.pickExceptActionParamsFromParams)(exeptActionParam1.in));
|
|
290
|
+
expect(exeptActionParam2.out).toEqual((0, helpers_1.pickExceptActionParamsFromParams)(exeptActionParam2.in));
|
|
291
|
+
expect(exeptActionParam3.out).toEqual((0, helpers_1.pickExceptActionParamsFromParams)(exeptActionParam3.in));
|
|
292
|
+
});
|
|
293
|
+
});
|
|
217
294
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginBase, ConfigItem, ItemsStateAndParams, StateAndParamsMetaData, StringParams, ConfigConnection, ConfigAliases, ConfigItemWithTabs, Config } from '../types';
|
|
1
|
+
import { PluginBase, ConfigItem, ItemsStateAndParams, StateAndParamsMetaData, StringParams, ConfigConnection, ConfigAliases, ConfigItemWithTabs, Config, ItemStateAndParams } from '../types';
|
|
2
2
|
export declare function prerenderItems({ items, plugins, }: {
|
|
3
3
|
items: ConfigItem[];
|
|
4
4
|
plugins: PluginBase[];
|
|
@@ -25,10 +25,11 @@ export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams
|
|
|
25
25
|
itemsStateAndParams: ItemsStateAndParams;
|
|
26
26
|
isFirstVersion: boolean;
|
|
27
27
|
}): Record<string, string[]>;
|
|
28
|
-
export declare function mergeParamsWithAliases({ aliases, namespace, params, }: {
|
|
28
|
+
export declare function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }: {
|
|
29
29
|
aliases: ConfigAliases;
|
|
30
30
|
namespace: string;
|
|
31
31
|
params: StringParams;
|
|
32
|
+
actionParams?: StringParams;
|
|
32
33
|
}): StringParams;
|
|
33
34
|
export declare function getInitialItemsStateAndParamsMeta(): StateAndParamsMetaData;
|
|
34
35
|
interface ChangeQueueArg {
|
|
@@ -39,4 +40,42 @@ interface ChangeQueueArg {
|
|
|
39
40
|
}
|
|
40
41
|
export declare function addToQueue({ id, tabId, config, itemsStateAndParams, }: ChangeQueueArg): StateAndParamsMetaData;
|
|
41
42
|
export declare function deleteFromQueue(data: ChangeQueueArg): StateAndParamsMetaData;
|
|
43
|
+
/**
|
|
44
|
+
* public function for getting only actionParams from object (all fields with keys that contains prefix)
|
|
45
|
+
* @param params - object for pick fields
|
|
46
|
+
* @param returnWithPrefix - format of returning actionParams fields (with actionParams prefix or without them)
|
|
47
|
+
*
|
|
48
|
+
* ex1: pickActionParamsFromParams({City: 'NY', _ap_Year: '2023'}, true) returns {_ap_Year: '2023'}
|
|
49
|
+
* ex2: pickActionParamsFromParams({City: 'NY', _ap_Year: '2023'}) returns {Year: '2023'}
|
|
50
|
+
*/
|
|
51
|
+
export declare function pickActionParamsFromParams(params: ItemStateAndParams['params'], returnWithPrefix?: boolean): StringParams;
|
|
52
|
+
/**
|
|
53
|
+
* public function for getting params from object without actionParams
|
|
54
|
+
* @param params
|
|
55
|
+
*/
|
|
56
|
+
export declare function pickExceptActionParamsFromParams(params: ItemStateAndParams['params']): StringParams;
|
|
57
|
+
/**
|
|
58
|
+
* public function for transforming object to actionParams format
|
|
59
|
+
* @param params
|
|
60
|
+
*/
|
|
61
|
+
export declare function transformParamsToActionParams(params: ItemStateAndParams['params']): StringParams;
|
|
62
|
+
/**
|
|
63
|
+
* check if object contains actionParams
|
|
64
|
+
* @param conf
|
|
65
|
+
*/
|
|
66
|
+
export declare function hasActionParam(conf?: StringParams): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* check if ItemStateAndParams object has actionParams in params or state field
|
|
69
|
+
* @param stateAndParams
|
|
70
|
+
*/
|
|
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[];
|
|
42
81
|
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteFromQueue = exports.addToQueue = exports.getInitialItemsStateAndParamsMeta = exports.mergeParamsWithAliases = exports.getMapItemsIgnores = exports.resolveItemInnerId = exports.formQueueData = exports.isItemWithTabs = exports.getCurrentVersion = exports.getItemsStateAndParamsMeta = exports.prerenderItems = void 0;
|
|
3
|
+
exports.getDefaultsActionParamsToClear = 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"));
|
|
10
11
|
const constants_1 = require("../constants");
|
|
11
12
|
function getNormalizedPlugins(plugins) {
|
|
12
13
|
return (0, keyBy_1.default)(plugins, 'type');
|
|
@@ -52,7 +53,7 @@ function isItemWithTabs(item) {
|
|
|
52
53
|
return Array.isArray((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.tabs);
|
|
53
54
|
}
|
|
54
55
|
exports.isItemWithTabs = isItemWithTabs;
|
|
55
|
-
//
|
|
56
|
+
// Array of parameters from widgets according to queue
|
|
56
57
|
function formQueueData({ items, itemsStateAndParams, }) {
|
|
57
58
|
var _a;
|
|
58
59
|
const queue = ((_a = getItemsStateAndParamsMeta(itemsStateAndParams)) === null || _a === void 0 ? void 0 : _a.queue) || [];
|
|
@@ -77,10 +78,24 @@ function formQueueData({ items, itemsStateAndParams, }) {
|
|
|
77
78
|
itemDefaultParams = item.defaults || {};
|
|
78
79
|
}
|
|
79
80
|
const itemQueueParams = (0, get_1.default)(itemsStateAndParams, [item.id, 'params'], {});
|
|
81
|
+
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
|
+
/**
|
|
92
|
+
* merging filtered params and filtered actionParams with prefixes
|
|
93
|
+
*/
|
|
94
|
+
const params = Object.assign(Object.assign({}, filteredParamsByDefaults), transformParamsToActionParams(filteredActionParamsByDefaults));
|
|
80
95
|
return {
|
|
81
96
|
id: item.id,
|
|
82
97
|
namespace: item.namespace,
|
|
83
|
-
params
|
|
98
|
+
params,
|
|
84
99
|
};
|
|
85
100
|
})
|
|
86
101
|
.filter(nonNullable);
|
|
@@ -125,10 +140,11 @@ function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersio
|
|
|
125
140
|
}, {});
|
|
126
141
|
}
|
|
127
142
|
exports.getMapItemsIgnores = getMapItemsIgnores;
|
|
128
|
-
function mergeParamsWithAliases({ aliases, namespace, params, }) {
|
|
143
|
+
function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }) {
|
|
129
144
|
const aliasesByNamespace = (0, get_1.default)(aliases, [namespace], []);
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const items = Object.assign(Object.assign({}, (params || {})), (actionParams || {}));
|
|
146
|
+
return Object.keys(items).reduce((matchedParams, paramKey) => {
|
|
147
|
+
const paramValue = items[paramKey];
|
|
132
148
|
const collectAliasesParamsKeys = aliasesByNamespace.reduce((collect, group) => {
|
|
133
149
|
return group.includes(paramKey) ? collect.concat(group) : collect;
|
|
134
150
|
}, [paramKey]);
|
|
@@ -170,3 +186,97 @@ function deleteFromQueue(data) {
|
|
|
170
186
|
return Object.assign(Object.assign({}, meta), { queue: meta.queue.slice(0, -1) });
|
|
171
187
|
}
|
|
172
188
|
exports.deleteFromQueue = deleteFromQueue;
|
|
189
|
+
/**
|
|
190
|
+
* public function for getting only actionParams from object (all fields with keys that contains prefix)
|
|
191
|
+
* @param params - object for pick fields
|
|
192
|
+
* @param returnWithPrefix - format of returning actionParams fields (with actionParams prefix or without them)
|
|
193
|
+
*
|
|
194
|
+
* ex1: pickActionParamsFromParams({City: 'NY', _ap_Year: '2023'}, true) returns {_ap_Year: '2023'}
|
|
195
|
+
* ex2: pickActionParamsFromParams({City: 'NY', _ap_Year: '2023'}) returns {Year: '2023'}
|
|
196
|
+
*/
|
|
197
|
+
function pickActionParamsFromParams(params, returnWithPrefix) {
|
|
198
|
+
if (!params || (0, isEmpty_1.default)(params)) {
|
|
199
|
+
return {};
|
|
200
|
+
}
|
|
201
|
+
const actionParams = {};
|
|
202
|
+
for (const [key, val] of Object.entries(params)) {
|
|
203
|
+
// starts with actionParams prefix (from'_ap_')
|
|
204
|
+
if (key.startsWith(constants_1.ACTION_PARAM_PREFIX)) {
|
|
205
|
+
const paramName = returnWithPrefix ? key : key.slice(constants_1.ACTION_PARAM_PREFIX.length);
|
|
206
|
+
actionParams[paramName] = val;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return actionParams;
|
|
210
|
+
}
|
|
211
|
+
exports.pickActionParamsFromParams = pickActionParamsFromParams;
|
|
212
|
+
/**
|
|
213
|
+
* public function for getting params from object without actionParams
|
|
214
|
+
* @param params
|
|
215
|
+
*/
|
|
216
|
+
function pickExceptActionParamsFromParams(params) {
|
|
217
|
+
if (!params || (0, isEmpty_1.default)(params)) {
|
|
218
|
+
return {};
|
|
219
|
+
}
|
|
220
|
+
const onlyParams = {};
|
|
221
|
+
for (const [key, val] of Object.entries(params)) {
|
|
222
|
+
if (!key.startsWith(constants_1.ACTION_PARAM_PREFIX)) {
|
|
223
|
+
onlyParams[key] = val;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return onlyParams;
|
|
227
|
+
}
|
|
228
|
+
exports.pickExceptActionParamsFromParams = pickExceptActionParamsFromParams;
|
|
229
|
+
/**
|
|
230
|
+
* public function for transforming object to actionParams format
|
|
231
|
+
* @param params
|
|
232
|
+
*/
|
|
233
|
+
function transformParamsToActionParams(params) {
|
|
234
|
+
if (!params || (0, isEmpty_1.default)(params)) {
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
237
|
+
const actionParams = {};
|
|
238
|
+
for (const [key, val] of Object.entries(params)) {
|
|
239
|
+
actionParams[`${constants_1.ACTION_PARAM_PREFIX}${key}`] = val;
|
|
240
|
+
}
|
|
241
|
+
return actionParams;
|
|
242
|
+
}
|
|
243
|
+
exports.transformParamsToActionParams = transformParamsToActionParams;
|
|
244
|
+
/**
|
|
245
|
+
* check if object contains actionParams
|
|
246
|
+
* @param conf
|
|
247
|
+
*/
|
|
248
|
+
function hasActionParam(conf) {
|
|
249
|
+
return Object.keys(conf || {}).some((key) => key.startsWith(constants_1.ACTION_PARAM_PREFIX));
|
|
250
|
+
}
|
|
251
|
+
exports.hasActionParam = hasActionParam;
|
|
252
|
+
/**
|
|
253
|
+
* check if ItemStateAndParams object has actionParams in params or state field
|
|
254
|
+
* @param stateAndParams
|
|
255
|
+
*/
|
|
256
|
+
function hasActionParams(stateAndParams) {
|
|
257
|
+
if (!stateAndParams || (0, isEmpty_1.default)(stateAndParams)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return hasActionParam(stateAndParams.params);
|
|
261
|
+
}
|
|
262
|
+
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,10 @@ 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
|
|
6
|
+
const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
|
|
7
|
+
const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
7
8
|
const constants_1 = require("../constants");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
8
10
|
function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
|
|
9
11
|
const { aliases, connections } = config;
|
|
10
12
|
const items = (0, helpers_1.prerenderItems)({ items: config.items, plugins });
|
|
@@ -12,7 +14,7 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
|
|
|
12
14
|
const queueData = isFirstVersion
|
|
13
15
|
? []
|
|
14
16
|
: (0, helpers_1.formQueueData)({ items, itemsStateAndParams });
|
|
15
|
-
//
|
|
17
|
+
// to consider other kind types in future (not only ignore)
|
|
16
18
|
const mapItemsIgnores = (0, helpers_1.getMapItemsIgnores)({
|
|
17
19
|
items,
|
|
18
20
|
ignores: connections.filter(({ kind }) => kind === 'ignore'),
|
|
@@ -22,35 +24,70 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
|
|
|
22
24
|
const groupByNamespace = (0, groupBy_1.default)(items, 'namespace');
|
|
23
25
|
const itemsWithDefaultsByNamespace = Object.keys(groupByNamespace).reduce((acc, namespace) => {
|
|
24
26
|
return Object.assign(Object.assign({}, acc), {
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
+
// there are defaults only in selectors by now, need to get them from item.data.tabs[].defaults for widgets
|
|
28
|
+
// but make a decision about there's order first
|
|
27
29
|
[namespace]: groupByNamespace[namespace].filter((item) => item.defaults) });
|
|
28
30
|
}, {});
|
|
29
31
|
return items.reduce((itemsParams, item) => {
|
|
30
|
-
var _a;
|
|
32
|
+
var _a, _b;
|
|
31
33
|
const { id, namespace } = item;
|
|
32
|
-
|
|
34
|
+
let defaultWidgetParams = {};
|
|
35
|
+
if ((0, helpers_1.isItemWithTabs)(item)) {
|
|
36
|
+
const currentWidgetTabId = (0, helpers_1.resolveItemInnerId)({ item, itemsStateAndParams });
|
|
37
|
+
const itemTabs = item.data.tabs;
|
|
38
|
+
defaultWidgetParams =
|
|
39
|
+
((_a = itemTabs.find((tabItem) => (tabItem === null || tabItem === void 0 ? void 0 : tabItem.id) === currentWidgetTabId)) === null || _a === void 0 ? void 0 : _a.params) || {};
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
defaultWidgetParams = item.defaults || {};
|
|
43
|
+
}
|
|
44
|
+
const getMergedParams = (params, actionParams) => (0, helpers_1.mergeParamsWithAliases)({ aliases, namespace, params: params || {}, actionParams });
|
|
33
45
|
const itemIgnores = mapItemsIgnores[id];
|
|
34
46
|
const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
|
|
35
47
|
let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
|
|
36
|
-
//
|
|
48
|
+
// default parameters to begin with
|
|
37
49
|
affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
|
|
38
50
|
return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
|
|
39
51
|
}, {}), getMergedParams(globalParams));
|
|
40
52
|
if (isFirstVersion) {
|
|
41
|
-
itemParams = Object.assign(itemParams, ((
|
|
53
|
+
itemParams = Object.assign(itemParams, ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _b === void 0 ? void 0 : _b.params) || {});
|
|
42
54
|
}
|
|
43
55
|
else {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
// params according to queue of its applying
|
|
57
|
+
let prevQueueDataWithActionParams = {};
|
|
58
|
+
let queueDataItems = {};
|
|
59
|
+
for (const data of Object.values(queueData)) {
|
|
47
60
|
if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
|
|
48
|
-
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let actionParams;
|
|
64
|
+
let params = data.params;
|
|
65
|
+
const needAliasesForActionParams = data.id !== id && (0, helpers_1.hasActionParam)(data.params);
|
|
66
|
+
if (needAliasesForActionParams) {
|
|
67
|
+
actionParams = (0, helpers_1.pickActionParamsFromParams)(data.params);
|
|
68
|
+
params = (0, helpers_1.pickExceptActionParamsFromParams)(data.params);
|
|
69
|
+
}
|
|
70
|
+
const mergedParams = getMergedParams(params, actionParams);
|
|
71
|
+
const actionParamKeyToClear = (0, intersection_1.default)(Object.keys((0, helpers_1.transformParamsToActionParams)(mergedParams)), Object.keys(prevQueueDataWithActionParams));
|
|
72
|
+
let queueDataRes = Object.assign({}, queueDataItems);
|
|
73
|
+
if (actionParamKeyToClear.length) {
|
|
74
|
+
queueDataRes = (0, omit_1.default)(queueDataItems, actionParamKeyToClear);
|
|
49
75
|
}
|
|
50
|
-
|
|
51
|
-
|
|
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);
|
|
87
|
+
}
|
|
88
|
+
itemParams = Object.assign(itemParams, queueDataItems);
|
|
52
89
|
}
|
|
53
|
-
return Object.assign(Object.assign({}, itemsParams), { [id]: itemParams });
|
|
90
|
+
return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
|
|
54
91
|
}, {});
|
|
55
92
|
}
|
|
56
93
|
exports.getItemsParams = getItemsParams;
|
|
@@ -261,6 +261,155 @@ exports.stateAndParams3 = {
|
|
|
261
261
|
},
|
|
262
262
|
},
|
|
263
263
|
};
|
|
264
|
+
const stateAndParamsForAP1 = {
|
|
265
|
+
in: {
|
|
266
|
+
Q8: { params: { _ap_Country: 'Italy' } },
|
|
267
|
+
__meta__: { queue: [{ id: 'Q8', tabId: 'K0' }], version: 2 },
|
|
268
|
+
},
|
|
269
|
+
out: {
|
|
270
|
+
L5: {
|
|
271
|
+
params: { Country: 'Italy', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Italy' },
|
|
272
|
+
state: {},
|
|
273
|
+
},
|
|
274
|
+
Q8: {
|
|
275
|
+
params: {
|
|
276
|
+
Country: '',
|
|
277
|
+
Year: '',
|
|
278
|
+
_ap_Country: 'Italy',
|
|
279
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
280
|
+
},
|
|
281
|
+
state: {},
|
|
282
|
+
},
|
|
283
|
+
al: {
|
|
284
|
+
params: { Country: 'Italy', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Italy' },
|
|
285
|
+
state: {},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
const stateAndParamsForAP2 = {
|
|
290
|
+
in: {
|
|
291
|
+
L5: {
|
|
292
|
+
params: { 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium' },
|
|
293
|
+
},
|
|
294
|
+
Q8: {
|
|
295
|
+
params: { _ap_Country: 'Italy' },
|
|
296
|
+
},
|
|
297
|
+
__meta__: { queue: [{ id: 'Q8', tabId: 'K0' }, { id: 'L5' }], version: 2 },
|
|
298
|
+
},
|
|
299
|
+
out: {
|
|
300
|
+
L5: {
|
|
301
|
+
params: { Country: 'Belgium', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium' },
|
|
302
|
+
state: {},
|
|
303
|
+
},
|
|
304
|
+
Q8: {
|
|
305
|
+
params: {
|
|
306
|
+
Country: 'Belgium',
|
|
307
|
+
Year: '',
|
|
308
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
|
|
309
|
+
},
|
|
310
|
+
state: {},
|
|
311
|
+
},
|
|
312
|
+
al: {
|
|
313
|
+
params: { Country: 'Belgium', 'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium' },
|
|
314
|
+
state: {},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
const stateAndParamsForAP3 = {
|
|
319
|
+
in: {
|
|
320
|
+
Q8: { params: { _ap_Country: 'Italy' } },
|
|
321
|
+
L5: { params: { 'd079937f-6bc4-4133-9171-40092bb20d6f': '' } },
|
|
322
|
+
__meta__: { queue: [{ id: 'Q8', tabId: 'K0' }, { id: 'L5' }], version: 2 },
|
|
323
|
+
},
|
|
324
|
+
out: {
|
|
325
|
+
L5: {
|
|
326
|
+
params: {
|
|
327
|
+
Country: '',
|
|
328
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
329
|
+
},
|
|
330
|
+
state: {},
|
|
331
|
+
},
|
|
332
|
+
Q8: {
|
|
333
|
+
params: {
|
|
334
|
+
Country: '',
|
|
335
|
+
Year: '',
|
|
336
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
337
|
+
},
|
|
338
|
+
state: {},
|
|
339
|
+
},
|
|
340
|
+
al: {
|
|
341
|
+
params: {
|
|
342
|
+
Country: '',
|
|
343
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
344
|
+
},
|
|
345
|
+
state: {},
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
const stateAndParamsForAP4 = {
|
|
350
|
+
in: {
|
|
351
|
+
Q8: { params: { _ap_Country: '' } },
|
|
352
|
+
L5: { params: { 'd079937f-6bc4-4133-9171-40092bb20d6f': '' } },
|
|
353
|
+
__meta__: { queue: [{ id: 'L5' }, { id: 'Q8', tabId: 'K0' }], version: 2 },
|
|
354
|
+
},
|
|
355
|
+
out: {
|
|
356
|
+
L5: {
|
|
357
|
+
params: {
|
|
358
|
+
Country: '',
|
|
359
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
360
|
+
},
|
|
361
|
+
state: {},
|
|
362
|
+
},
|
|
363
|
+
Q8: {
|
|
364
|
+
params: {
|
|
365
|
+
Country: '',
|
|
366
|
+
Year: '',
|
|
367
|
+
_ap_Country: '',
|
|
368
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
369
|
+
},
|
|
370
|
+
state: {},
|
|
371
|
+
},
|
|
372
|
+
al: {
|
|
373
|
+
params: {
|
|
374
|
+
Country: '',
|
|
375
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': '',
|
|
376
|
+
},
|
|
377
|
+
state: {},
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
const stateAndParamsForAP5 = {
|
|
382
|
+
in: {
|
|
383
|
+
Q8: { params: {} },
|
|
384
|
+
L5: { params: {} },
|
|
385
|
+
__meta__: { queue: [], version: 2 },
|
|
386
|
+
},
|
|
387
|
+
out: {
|
|
388
|
+
L5: {
|
|
389
|
+
params: {
|
|
390
|
+
Country: ['Italy', 'France'],
|
|
391
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': ['Italy', 'France'],
|
|
392
|
+
},
|
|
393
|
+
state: {},
|
|
394
|
+
},
|
|
395
|
+
Q8: {
|
|
396
|
+
params: {
|
|
397
|
+
Country: ['Italy', 'France'],
|
|
398
|
+
Year: '',
|
|
399
|
+
_ap_Country: 'Belgium',
|
|
400
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': ['Italy', 'France'],
|
|
401
|
+
},
|
|
402
|
+
state: {},
|
|
403
|
+
},
|
|
404
|
+
al: {
|
|
405
|
+
params: {
|
|
406
|
+
Country: ['Italy', 'France'],
|
|
407
|
+
'd079937f-6bc4-4133-9171-40092bb20d6f': ['Italy', 'France'],
|
|
408
|
+
},
|
|
409
|
+
state: {},
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
};
|
|
264
413
|
const configs = configs_json_1.default.configs;
|
|
265
414
|
describe('getItemsStateAndParamsDL', () => {
|
|
266
415
|
describe('old version fallback', () => {
|
|
@@ -297,3 +446,60 @@ describe('getItemsStateAndParamsDL', () => {
|
|
|
297
446
|
});
|
|
298
447
|
});
|
|
299
448
|
});
|
|
449
|
+
describe('getItemsStateAndParams actionParams variants check', () => {
|
|
450
|
+
describe('action and params state 1', () => {
|
|
451
|
+
const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
452
|
+
defaultGlobalParams: {},
|
|
453
|
+
globalParams: {},
|
|
454
|
+
config: configs[2],
|
|
455
|
+
itemsStateAndParams: stateAndParamsForAP1.in,
|
|
456
|
+
});
|
|
457
|
+
it('return stateAndParamsForAP1.out', () => {
|
|
458
|
+
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP1.out, constants_1.META_KEY));
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
describe('action and params state 2', () => {
|
|
462
|
+
const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
463
|
+
defaultGlobalParams: {},
|
|
464
|
+
globalParams: {},
|
|
465
|
+
config: configs[2],
|
|
466
|
+
itemsStateAndParams: stateAndParamsForAP2.in,
|
|
467
|
+
});
|
|
468
|
+
it('return stateAndParamsForAP2.out', () => {
|
|
469
|
+
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP2.out, constants_1.META_KEY));
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
describe('action and params state 3', () => {
|
|
473
|
+
const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
474
|
+
defaultGlobalParams: {},
|
|
475
|
+
globalParams: {},
|
|
476
|
+
config: configs[2],
|
|
477
|
+
itemsStateAndParams: stateAndParamsForAP3.in,
|
|
478
|
+
});
|
|
479
|
+
it('return stateAndParamsForAP3.out', () => {
|
|
480
|
+
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP3.out, constants_1.META_KEY));
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
describe('action and params state 4', () => {
|
|
484
|
+
const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
485
|
+
defaultGlobalParams: {},
|
|
486
|
+
globalParams: {},
|
|
487
|
+
config: configs[2],
|
|
488
|
+
itemsStateAndParams: stateAndParamsForAP4.in,
|
|
489
|
+
});
|
|
490
|
+
it('return stateAndParamsForAP4.out', () => {
|
|
491
|
+
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP4.out, constants_1.META_KEY));
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
describe('action and params state 5', () => {
|
|
495
|
+
const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
|
|
496
|
+
defaultGlobalParams: {},
|
|
497
|
+
globalParams: {},
|
|
498
|
+
config: configs[3],
|
|
499
|
+
itemsStateAndParams: stateAndParamsForAP5.in,
|
|
500
|
+
});
|
|
501
|
+
it('return stateAndParamsForAP5.out', () => {
|
|
502
|
+
expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP5.out, constants_1.META_KEY));
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
});
|