@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
|
@@ -64,9 +64,14 @@ function removeItemVersion1({ id, config, itemsStateAndParams }) {
|
|
|
64
64
|
itemsStateAndParams: newItemsStateAndParams,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
|
|
67
|
+
function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, paramsSettings) {
|
|
68
68
|
var _a;
|
|
69
|
+
const paramsTypeName = (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.type) || 'params';
|
|
70
|
+
const isActionParamsMode = paramsTypeName === 'actionParams';
|
|
69
71
|
let allowedParams = {};
|
|
72
|
+
const stateParamsConf = isActionParamsMode
|
|
73
|
+
? (0, shared_1.pickActionParamsFromParams)(stateAndParams.params, false)
|
|
74
|
+
: stateAndParams.params;
|
|
70
75
|
if ((0, shared_1.isItemWithTabs)(item)) {
|
|
71
76
|
let tab;
|
|
72
77
|
if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
|
|
@@ -76,14 +81,19 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
|
|
|
76
81
|
const tabId = (0, shared_1.resolveItemInnerId)({ item, itemsStateAndParams });
|
|
77
82
|
tab = item.data.tabs.find(({ id }) => id === tabId);
|
|
78
83
|
}
|
|
79
|
-
allowedParams = (0, pick_1.default)(
|
|
84
|
+
allowedParams = (0, pick_1.default)(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
|
|
80
85
|
}
|
|
81
86
|
else {
|
|
82
|
-
allowedParams = (0, pick_1.default)(
|
|
87
|
+
allowedParams = (0, pick_1.default)(stateParamsConf, Object.keys(item.defaults || {}));
|
|
83
88
|
}
|
|
84
|
-
if (Object.keys(allowedParams).length !== Object.keys(
|
|
89
|
+
if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
|
|
85
90
|
console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
|
|
86
91
|
}
|
|
92
|
+
if (isActionParamsMode) {
|
|
93
|
+
return (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.returnPrefix)
|
|
94
|
+
? (0, shared_1.transformParamsToActionParams)(allowedParams)
|
|
95
|
+
: allowedParams;
|
|
96
|
+
}
|
|
87
97
|
return allowedParams;
|
|
88
98
|
}
|
|
89
99
|
function changeStateAndParamsVersion1({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
|
|
@@ -244,6 +254,7 @@ class UpdateManager {
|
|
|
244
254
|
const currentMeta = (0, shared_1.getItemsStateAndParamsMeta)(itemsStateAndParams);
|
|
245
255
|
if ('params' in stateAndParams) {
|
|
246
256
|
const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
|
|
257
|
+
const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
|
|
247
258
|
const tabId = (0, shared_1.isItemWithTabs)(initiatorItem)
|
|
248
259
|
? newTabId || (0, shared_1.resolveItemInnerId)({ item: initiatorItem, itemsStateAndParams })
|
|
249
260
|
: undefined;
|
|
@@ -254,15 +265,16 @@ class UpdateManager {
|
|
|
254
265
|
if (isTabSwitched) {
|
|
255
266
|
commandUpdateParams = '$set';
|
|
256
267
|
}
|
|
257
|
-
|
|
268
|
+
const obj = {
|
|
258
269
|
$unset: unusedIds,
|
|
259
270
|
[initiatorId]: {
|
|
260
271
|
$auto: Object.assign({ params: {
|
|
261
|
-
[commandUpdateParams]: allowableParams,
|
|
272
|
+
[commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
|
|
262
273
|
} }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
|
|
263
274
|
},
|
|
264
275
|
[shared_1.META_KEY]: { $set: meta },
|
|
265
|
-
}
|
|
276
|
+
};
|
|
277
|
+
return (0, immutability_helper_1.default)(itemsStateAndParams, obj);
|
|
266
278
|
}
|
|
267
279
|
else if (hasState) {
|
|
268
280
|
let metaSpec = {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { META_KEY } from '../../constants';
|
|
2
|
-
import { formQueueData } from '../helpers';
|
|
1
|
+
import { ACTION_PARAM_PREFIX, META_KEY } from '../../constants';
|
|
2
|
+
import { formQueueData, hasActionParams, pickExceptActionParamsFromParams, transformParamsToActionParams, } from '../helpers';
|
|
3
3
|
const DEFAULT_CONTROL_ID = 'controlId';
|
|
4
4
|
const DEFAULT_WIDGET_ID = 'widgetId';
|
|
5
5
|
const DEFAULT_WIDGET_TAB_ID = 'widget_tabId';
|
|
@@ -11,6 +11,59 @@ const getMockedControlItem = ({ id = DEFAULT_CONTROL_ID, defaults, }) => ({
|
|
|
11
11
|
type: 'control',
|
|
12
12
|
namespace: NAMESPACE,
|
|
13
13
|
});
|
|
14
|
+
const stateAndParamsWithParamsOnly = {
|
|
15
|
+
params: {
|
|
16
|
+
paramName: 'param1',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const stateAndParamsWithStateOnly = {
|
|
20
|
+
state: {
|
|
21
|
+
tabId: 'tabId1',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const stateAndParamsWithActionParamsInParamsOnly = {
|
|
25
|
+
params: {
|
|
26
|
+
_ap_paramName: 'param1',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const stateAndParamsWithStateAndActionParamsInParams = {
|
|
30
|
+
state: {
|
|
31
|
+
tabId: 'tabId1',
|
|
32
|
+
},
|
|
33
|
+
params: {
|
|
34
|
+
_ap_paramName: 'param1',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const stateAndParamsWithParamsAndActionParamsInParams = {
|
|
38
|
+
params: {
|
|
39
|
+
paramName2: 'param2',
|
|
40
|
+
_ap_paramName: 'param1',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const paramsToTransform = {
|
|
44
|
+
in: {
|
|
45
|
+
param1: 'val 1',
|
|
46
|
+
param2: 'val 2',
|
|
47
|
+
},
|
|
48
|
+
out: {
|
|
49
|
+
[`${ACTION_PARAM_PREFIX}param1`]: 'val 1',
|
|
50
|
+
[`${ACTION_PARAM_PREFIX}param2`]: 'val 2',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const exeptActionParam1 = {
|
|
54
|
+
in: stateAndParamsWithParamsOnly.params,
|
|
55
|
+
out: stateAndParamsWithParamsOnly.params,
|
|
56
|
+
};
|
|
57
|
+
const exeptActionParam2 = {
|
|
58
|
+
in: stateAndParamsWithActionParamsInParamsOnly.params,
|
|
59
|
+
out: {},
|
|
60
|
+
};
|
|
61
|
+
const exeptActionParam3 = {
|
|
62
|
+
in: stateAndParamsWithParamsAndActionParamsInParams.params,
|
|
63
|
+
out: {
|
|
64
|
+
paramName2: 'param2',
|
|
65
|
+
},
|
|
66
|
+
};
|
|
14
67
|
const getMockedWidgetItem = ({ id = DEFAULT_WIDGET_ID, tabs }) => ({
|
|
15
68
|
id,
|
|
16
69
|
data: { tabs },
|
|
@@ -212,4 +265,28 @@ describe('modules.helpers', () => {
|
|
|
212
265
|
}));
|
|
213
266
|
});
|
|
214
267
|
});
|
|
268
|
+
describe('actionParams helpers', () => {
|
|
269
|
+
it('check hasActionParams', () => {
|
|
270
|
+
const empty = hasActionParams({});
|
|
271
|
+
expect(empty).toBeFalsy();
|
|
272
|
+
const withParamsOnly = hasActionParams(stateAndParamsWithParamsOnly);
|
|
273
|
+
expect(withParamsOnly).toBeFalsy();
|
|
274
|
+
const withStateOnly = hasActionParams(stateAndParamsWithStateOnly);
|
|
275
|
+
expect(withStateOnly).toBeFalsy();
|
|
276
|
+
const withAPinParams = hasActionParams(stateAndParamsWithActionParamsInParamsOnly);
|
|
277
|
+
expect(withAPinParams).toBeTruthy();
|
|
278
|
+
const withAPinParamsNState = hasActionParams(stateAndParamsWithStateAndActionParamsInParams);
|
|
279
|
+
expect(withAPinParamsNState).toBeTruthy();
|
|
280
|
+
const withParamsAndAPinParams = hasActionParams(stateAndParamsWithParamsAndActionParamsInParams);
|
|
281
|
+
expect(withParamsAndAPinParams).toBeTruthy();
|
|
282
|
+
});
|
|
283
|
+
it('check transformParamsToActionParams', () => {
|
|
284
|
+
expect(paramsToTransform.out).toEqual(transformParamsToActionParams(paramsToTransform.in));
|
|
285
|
+
});
|
|
286
|
+
it('check pickExceptActionParamsFromParams', () => {
|
|
287
|
+
expect(exeptActionParam1.out).toEqual(pickExceptActionParamsFromParams(exeptActionParam1.in));
|
|
288
|
+
expect(exeptActionParam2.out).toEqual(pickExceptActionParamsFromParams(exeptActionParam2.in));
|
|
289
|
+
expect(exeptActionParam3.out).toEqual(pickExceptActionParamsFromParams(exeptActionParam3.in));
|
|
290
|
+
});
|
|
291
|
+
});
|
|
215
292
|
});
|
|
@@ -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 {};
|
|
@@ -3,7 +3,8 @@ 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
|
|
6
|
+
import intersection from 'lodash/intersection';
|
|
7
|
+
import { META_KEY, CURRENT_VERSION, ACTION_PARAM_PREFIX } from '../constants';
|
|
7
8
|
function getNormalizedPlugins(plugins) {
|
|
8
9
|
return keyBy(plugins, 'type');
|
|
9
10
|
}
|
|
@@ -44,7 +45,7 @@ export function isItemWithTabs(item) {
|
|
|
44
45
|
var _a;
|
|
45
46
|
return Array.isArray((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.tabs);
|
|
46
47
|
}
|
|
47
|
-
//
|
|
48
|
+
// Array of parameters from widgets according to queue
|
|
48
49
|
export function formQueueData({ items, itemsStateAndParams, }) {
|
|
49
50
|
var _a;
|
|
50
51
|
const queue = ((_a = getItemsStateAndParamsMeta(itemsStateAndParams)) === null || _a === void 0 ? void 0 : _a.queue) || [];
|
|
@@ -69,10 +70,24 @@ export function formQueueData({ items, itemsStateAndParams, }) {
|
|
|
69
70
|
itemDefaultParams = item.defaults || {};
|
|
70
71
|
}
|
|
71
72
|
const itemQueueParams = get(itemsStateAndParams, [item.id, 'params'], {});
|
|
73
|
+
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
|
+
/**
|
|
84
|
+
* merging filtered params and filtered actionParams with prefixes
|
|
85
|
+
*/
|
|
86
|
+
const params = Object.assign(Object.assign({}, filteredParamsByDefaults), transformParamsToActionParams(filteredActionParamsByDefaults));
|
|
72
87
|
return {
|
|
73
88
|
id: item.id,
|
|
74
89
|
namespace: item.namespace,
|
|
75
|
-
params
|
|
90
|
+
params,
|
|
76
91
|
};
|
|
77
92
|
})
|
|
78
93
|
.filter(nonNullable);
|
|
@@ -114,10 +129,11 @@ export function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirs
|
|
|
114
129
|
.map(({ to }) => invertedMapIds[to]) });
|
|
115
130
|
}, {});
|
|
116
131
|
}
|
|
117
|
-
export function mergeParamsWithAliases({ aliases, namespace, params, }) {
|
|
132
|
+
export function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }) {
|
|
118
133
|
const aliasesByNamespace = get(aliases, [namespace], []);
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
const items = Object.assign(Object.assign({}, (params || {})), (actionParams || {}));
|
|
135
|
+
return Object.keys(items).reduce((matchedParams, paramKey) => {
|
|
136
|
+
const paramValue = items[paramKey];
|
|
121
137
|
const collectAliasesParamsKeys = aliasesByNamespace.reduce((collect, group) => {
|
|
122
138
|
return group.includes(paramKey) ? collect.concat(group) : collect;
|
|
123
139
|
}, [paramKey]);
|
|
@@ -155,3 +171,91 @@ export function deleteFromQueue(data) {
|
|
|
155
171
|
const meta = addToQueue(data);
|
|
156
172
|
return Object.assign(Object.assign({}, meta), { queue: meta.queue.slice(0, -1) });
|
|
157
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* public function for getting only actionParams from object (all fields with keys that contains prefix)
|
|
176
|
+
* @param params - object for pick fields
|
|
177
|
+
* @param returnWithPrefix - format of returning actionParams fields (with actionParams prefix or without them)
|
|
178
|
+
*
|
|
179
|
+
* ex1: pickActionParamsFromParams({City: 'NY', _ap_Year: '2023'}, true) returns {_ap_Year: '2023'}
|
|
180
|
+
* ex2: pickActionParamsFromParams({City: 'NY', _ap_Year: '2023'}) returns {Year: '2023'}
|
|
181
|
+
*/
|
|
182
|
+
export function pickActionParamsFromParams(params, returnWithPrefix) {
|
|
183
|
+
if (!params || isEmpty(params)) {
|
|
184
|
+
return {};
|
|
185
|
+
}
|
|
186
|
+
const actionParams = {};
|
|
187
|
+
for (const [key, val] of Object.entries(params)) {
|
|
188
|
+
// starts with actionParams prefix (from'_ap_')
|
|
189
|
+
if (key.startsWith(ACTION_PARAM_PREFIX)) {
|
|
190
|
+
const paramName = returnWithPrefix ? key : key.slice(ACTION_PARAM_PREFIX.length);
|
|
191
|
+
actionParams[paramName] = val;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return actionParams;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* public function for getting params from object without actionParams
|
|
198
|
+
* @param params
|
|
199
|
+
*/
|
|
200
|
+
export function pickExceptActionParamsFromParams(params) {
|
|
201
|
+
if (!params || isEmpty(params)) {
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
const onlyParams = {};
|
|
205
|
+
for (const [key, val] of Object.entries(params)) {
|
|
206
|
+
if (!key.startsWith(ACTION_PARAM_PREFIX)) {
|
|
207
|
+
onlyParams[key] = val;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return onlyParams;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* public function for transforming object to actionParams format
|
|
214
|
+
* @param params
|
|
215
|
+
*/
|
|
216
|
+
export function transformParamsToActionParams(params) {
|
|
217
|
+
if (!params || isEmpty(params)) {
|
|
218
|
+
return {};
|
|
219
|
+
}
|
|
220
|
+
const actionParams = {};
|
|
221
|
+
for (const [key, val] of Object.entries(params)) {
|
|
222
|
+
actionParams[`${ACTION_PARAM_PREFIX}${key}`] = val;
|
|
223
|
+
}
|
|
224
|
+
return actionParams;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* check if object contains actionParams
|
|
228
|
+
* @param conf
|
|
229
|
+
*/
|
|
230
|
+
export function hasActionParam(conf) {
|
|
231
|
+
return Object.keys(conf || {}).some((key) => key.startsWith(ACTION_PARAM_PREFIX));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* check if ItemStateAndParams object has actionParams in params or state field
|
|
235
|
+
* @param stateAndParams
|
|
236
|
+
*/
|
|
237
|
+
export function hasActionParams(stateAndParams) {
|
|
238
|
+
if (!stateAndParams || isEmpty(stateAndParams)) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
return hasActionParam(stateAndParams.params);
|
|
242
|
+
}
|
|
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,6 +1,8 @@
|
|
|
1
1
|
import groupBy from 'lodash/groupBy';
|
|
2
|
-
import
|
|
2
|
+
import intersection from 'lodash/intersection';
|
|
3
|
+
import omit from 'lodash/omit';
|
|
3
4
|
import { META_KEY } from '../constants';
|
|
5
|
+
import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, transformParamsToActionParams, isItemWithTabs, resolveItemInnerId, getDefaultsActionParamsToClear, } from './helpers';
|
|
4
6
|
export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
|
|
5
7
|
const { aliases, connections } = config;
|
|
6
8
|
const items = prerenderItems({ items: config.items, plugins });
|
|
@@ -8,7 +10,7 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
|
|
|
8
10
|
const queueData = isFirstVersion
|
|
9
11
|
? []
|
|
10
12
|
: formQueueData({ items, itemsStateAndParams });
|
|
11
|
-
//
|
|
13
|
+
// to consider other kind types in future (not only ignore)
|
|
12
14
|
const mapItemsIgnores = getMapItemsIgnores({
|
|
13
15
|
items,
|
|
14
16
|
ignores: connections.filter(({ kind }) => kind === 'ignore'),
|
|
@@ -18,35 +20,70 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
|
|
|
18
20
|
const groupByNamespace = groupBy(items, 'namespace');
|
|
19
21
|
const itemsWithDefaultsByNamespace = Object.keys(groupByNamespace).reduce((acc, namespace) => {
|
|
20
22
|
return Object.assign(Object.assign({}, acc), {
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
+
// there are defaults only in selectors by now, need to get them from item.data.tabs[].defaults for widgets
|
|
24
|
+
// but make a decision about there's order first
|
|
23
25
|
[namespace]: groupByNamespace[namespace].filter((item) => item.defaults) });
|
|
24
26
|
}, {});
|
|
25
27
|
return items.reduce((itemsParams, item) => {
|
|
26
|
-
var _a;
|
|
28
|
+
var _a, _b;
|
|
27
29
|
const { id, namespace } = item;
|
|
28
|
-
|
|
30
|
+
let defaultWidgetParams = {};
|
|
31
|
+
if (isItemWithTabs(item)) {
|
|
32
|
+
const currentWidgetTabId = resolveItemInnerId({ item, itemsStateAndParams });
|
|
33
|
+
const itemTabs = item.data.tabs;
|
|
34
|
+
defaultWidgetParams =
|
|
35
|
+
((_a = itemTabs.find((tabItem) => (tabItem === null || tabItem === void 0 ? void 0 : tabItem.id) === currentWidgetTabId)) === null || _a === void 0 ? void 0 : _a.params) || {};
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
defaultWidgetParams = item.defaults || {};
|
|
39
|
+
}
|
|
40
|
+
const getMergedParams = (params, actionParams) => mergeParamsWithAliases({ aliases, namespace, params: params || {}, actionParams });
|
|
29
41
|
const itemIgnores = mapItemsIgnores[id];
|
|
30
42
|
const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
|
|
31
43
|
let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
|
|
32
|
-
//
|
|
44
|
+
// default parameters to begin with
|
|
33
45
|
affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
|
|
34
46
|
return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
|
|
35
47
|
}, {}), getMergedParams(globalParams));
|
|
36
48
|
if (isFirstVersion) {
|
|
37
|
-
itemParams = Object.assign(itemParams, ((
|
|
49
|
+
itemParams = Object.assign(itemParams, ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _b === void 0 ? void 0 : _b.params) || {});
|
|
38
50
|
}
|
|
39
51
|
else {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
// params according to queue of its applying
|
|
53
|
+
let prevQueueDataWithActionParams = {};
|
|
54
|
+
let queueDataItems = {};
|
|
55
|
+
for (const data of Object.values(queueData)) {
|
|
43
56
|
if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
|
|
44
|
-
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
let actionParams;
|
|
60
|
+
let params = data.params;
|
|
61
|
+
const needAliasesForActionParams = data.id !== id && hasActionParam(data.params);
|
|
62
|
+
if (needAliasesForActionParams) {
|
|
63
|
+
actionParams = pickActionParamsFromParams(data.params);
|
|
64
|
+
params = pickExceptActionParamsFromParams(data.params);
|
|
65
|
+
}
|
|
66
|
+
const mergedParams = getMergedParams(params, actionParams);
|
|
67
|
+
const actionParamKeyToClear = intersection(Object.keys(transformParamsToActionParams(mergedParams)), Object.keys(prevQueueDataWithActionParams));
|
|
68
|
+
let queueDataRes = Object.assign({}, queueDataItems);
|
|
69
|
+
if (actionParamKeyToClear.length) {
|
|
70
|
+
queueDataRes = omit(queueDataItems, actionParamKeyToClear);
|
|
45
71
|
}
|
|
46
|
-
|
|
47
|
-
|
|
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);
|
|
83
|
+
}
|
|
84
|
+
itemParams = Object.assign(itemParams, queueDataItems);
|
|
48
85
|
}
|
|
49
|
-
return Object.assign(Object.assign({}, itemsParams), { [id]: itemParams });
|
|
86
|
+
return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
|
|
50
87
|
}, {});
|
|
51
88
|
}
|
|
52
89
|
export function getItemsState({ config, itemsStateAndParams, }) {
|