@gravity-ui/dashkit 6.8.0 → 6.10.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.
Files changed (29) hide show
  1. package/README.md +1 -1
  2. package/build/cjs/components/OverlayControls/OverlayControls.d.ts +5 -3
  3. package/build/cjs/shared/modules/__tests__/helpers.test.js +212 -2
  4. package/build/cjs/shared/modules/helpers.d.ts +14 -5
  5. package/build/cjs/shared/modules/helpers.js +89 -19
  6. package/build/cjs/shared/modules/state-and-params.d.ts +2 -2
  7. package/build/cjs/shared/modules/state-and-params.js +73 -42
  8. package/build/cjs/shared/modules/uniq-id.js +3 -0
  9. package/build/cjs/shared/types/config.d.ts +13 -0
  10. package/build/cjs/shared/types/state-and-params.d.ts +4 -2
  11. package/build/cjs/typings/plugin.d.ts +4 -4
  12. package/build/cjs/utils/__tests__/update-manager.test.js +193 -5
  13. package/build/cjs/utils/update-manager.d.ts +2 -2
  14. package/build/cjs/utils/update-manager.js +71 -4
  15. package/build/esm/components/OverlayControls/OverlayControls.d.ts +5 -3
  16. package/build/esm/components/OverlayControls/OverlayControls.js +2 -2
  17. package/build/esm/shared/modules/__tests__/helpers.test.js +213 -3
  18. package/build/esm/shared/modules/helpers.d.ts +14 -5
  19. package/build/esm/shared/modules/helpers.js +87 -19
  20. package/build/esm/shared/modules/state-and-params.d.ts +2 -2
  21. package/build/esm/shared/modules/state-and-params.js +74 -43
  22. package/build/esm/shared/modules/uniq-id.js +4 -1
  23. package/build/esm/shared/types/config.d.ts +13 -0
  24. package/build/esm/shared/types/state-and-params.d.ts +4 -2
  25. package/build/esm/typings/plugin.d.ts +4 -4
  26. package/build/esm/utils/__tests__/update-manager.test.js +193 -5
  27. package/build/esm/utils/update-manager.d.ts +2 -2
  28. package/build/esm/utils/update-manager.js +72 -5
  29. package/package.json +1 -1
@@ -1,6 +1,9 @@
1
1
  import { ACTION_PARAM_PREFIX, META_KEY } from '../../constants';
2
- import { formQueueData, hasActionParams, pickExceptActionParamsFromParams, transformParamsToActionParams, } from '../helpers';
2
+ import { addGroupToQueue, addToQueue, formQueueData, hasActionParams, pickExceptActionParamsFromParams, transformParamsToActionParams, } from '../helpers';
3
3
  const DEFAULT_CONTROL_ID = 'controlId';
4
+ const DEFAULT_CONTROL_ID_2 = 'controlId2';
5
+ const DEFAULT_GROUP_ITEM_ID = 'groupItemId';
6
+ const DEFAULT_GROUP_ITEM_ID_2 = 'groupItemId2';
4
7
  const DEFAULT_WIDGET_ID = 'widgetId';
5
8
  const DEFAULT_WIDGET_TAB_ID = 'widget_tabId';
6
9
  const NAMESPACE = 'default';
@@ -11,6 +14,25 @@ const getMockedControlItem = ({ id = DEFAULT_CONTROL_ID, defaults, }) => ({
11
14
  type: 'control',
12
15
  namespace: NAMESPACE,
13
16
  });
17
+ const getMockedGroupControlItem = ({ id = DEFAULT_CONTROL_ID, groupItemId = DEFAULT_GROUP_ITEM_ID, groupItemId2 = DEFAULT_GROUP_ITEM_ID_2, defaults, }) => ({
18
+ id,
19
+ data: {
20
+ group: [
21
+ { id: groupItemId, namespace: NAMESPACE, defaults },
22
+ { id: groupItemId2, namespace: NAMESPACE, defaults },
23
+ ],
24
+ },
25
+ type: 'group-control',
26
+ namespace: NAMESPACE,
27
+ });
28
+ const getMockedConfig = ({ items }) => ({
29
+ items,
30
+ salt: '0.9021043992843898',
31
+ counter: 124,
32
+ layout: [],
33
+ aliases: {},
34
+ connections: [],
35
+ });
14
36
  const stateAndParamsWithParamsOnly = {
15
37
  params: {
16
38
  paramName: 'param1',
@@ -119,6 +141,58 @@ describe('modules.helpers', () => {
119
141
  },
120
142
  ]).toEqual(formQueueData({ items: [controlItem5], itemsStateAndParams }));
121
143
  });
144
+ it('return correct queue data for control: group control', () => {
145
+ const itemsStateAndParams = {
146
+ [DEFAULT_CONTROL_ID]: {
147
+ params: {
148
+ [DEFAULT_GROUP_ITEM_ID]: {
149
+ scale: 'd',
150
+ view: 'normal',
151
+ },
152
+ },
153
+ },
154
+ [META_KEY]: {
155
+ queue: [{ id: DEFAULT_CONTROL_ID, groupItemId: DEFAULT_GROUP_ITEM_ID }],
156
+ version: 2,
157
+ },
158
+ };
159
+ const controlItem1 = getMockedGroupControlItem({
160
+ id: 'control-1',
161
+ groupItemId: 'group-control-1',
162
+ });
163
+ expect([]).toEqual(formQueueData({ items: [controlItem1], itemsStateAndParams }));
164
+ const controlItem2 = getMockedGroupControlItem({ defaults: { number: 'one', size: 's' } });
165
+ expect([
166
+ {
167
+ id: DEFAULT_GROUP_ITEM_ID,
168
+ namespace: NAMESPACE,
169
+ params: {},
170
+ },
171
+ ]).toEqual(formQueueData({ items: [controlItem2], itemsStateAndParams }));
172
+ const controlItem4 = getMockedGroupControlItem({ defaults: { scale: 'm', size: 's' } });
173
+ expect([
174
+ {
175
+ id: DEFAULT_GROUP_ITEM_ID,
176
+ namespace: NAMESPACE,
177
+ params: {
178
+ scale: 'd',
179
+ },
180
+ },
181
+ ]).toEqual(formQueueData({ items: [controlItem4], itemsStateAndParams }));
182
+ const controlItem5 = getMockedGroupControlItem({
183
+ defaults: { scale: 'm', size: 's', view: 'contrast' },
184
+ });
185
+ expect([
186
+ {
187
+ id: DEFAULT_GROUP_ITEM_ID,
188
+ namespace: NAMESPACE,
189
+ params: {
190
+ scale: 'd',
191
+ view: 'normal',
192
+ },
193
+ },
194
+ ]).toEqual(formQueueData({ items: [controlItem5], itemsStateAndParams }));
195
+ });
122
196
  it('return correct queue data for widget: common', () => {
123
197
  const itemsStateAndParams = {
124
198
  [DEFAULT_WIDGET_ID]: {
@@ -230,10 +304,18 @@ describe('modules.helpers', () => {
230
304
  view: 'normal',
231
305
  },
232
306
  },
307
+ [DEFAULT_CONTROL_ID_2]: {
308
+ params: {
309
+ [DEFAULT_GROUP_ITEM_ID]: {
310
+ size: 'm',
311
+ },
312
+ },
313
+ },
233
314
  [META_KEY]: {
234
315
  queue: [
235
316
  { id: DEFAULT_CONTROL_ID },
236
317
  { id: DEFAULT_WIDGET_ID, tabId: DEFAULT_WIDGET_TAB_ID },
318
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID },
237
319
  ],
238
320
  version: 2,
239
321
  },
@@ -248,19 +330,41 @@ describe('modules.helpers', () => {
248
330
  });
249
331
  const control1 = getMockedControlItem({ id: 'control-1' });
250
332
  const control2 = getMockedControlItem({ defaults: { scale: 'm', view: 'contrast' } });
333
+ const groupControl1 = getMockedGroupControlItem({ id: 'group-control-1' });
334
+ const groupControl2 = getMockedGroupControlItem({
335
+ id: DEFAULT_CONTROL_ID_2,
336
+ defaults: { size: 'xl', view: 'normal' },
337
+ });
251
338
  expect([
252
339
  {
253
340
  id: DEFAULT_CONTROL_ID,
254
341
  namespace: NAMESPACE,
255
- params: { scale: 'd' },
342
+ params: {
343
+ scale: 'd',
344
+ },
256
345
  },
257
346
  {
258
347
  id: DEFAULT_WIDGET_ID,
259
348
  namespace: NAMESPACE,
260
349
  params: { view: 'normal' },
261
350
  },
351
+ {
352
+ id: DEFAULT_GROUP_ITEM_ID,
353
+ namespace: NAMESPACE,
354
+ params: {
355
+ size: 'm',
356
+ },
357
+ },
262
358
  ]).toEqual(formQueueData({
263
- items: [widgetItem2, widgetItem3, control1, widgetItem1, control2],
359
+ items: [
360
+ widgetItem2,
361
+ widgetItem3,
362
+ control1,
363
+ widgetItem1,
364
+ control2,
365
+ groupControl1,
366
+ groupControl2,
367
+ ],
264
368
  itemsStateAndParams,
265
369
  }));
266
370
  });
@@ -289,4 +393,110 @@ describe('modules.helpers', () => {
289
393
  expect(exeptActionParam3.out).toEqual(pickExceptActionParamsFromParams(exeptActionParam3.in));
290
394
  });
291
395
  });
396
+ describe('queue helpers', () => {
397
+ it('add common control to the end of queue', () => {
398
+ const itemsStateAndParams = {
399
+ [META_KEY]: {
400
+ queue: [
401
+ { id: DEFAULT_CONTROL_ID },
402
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID },
403
+ ],
404
+ version: 2,
405
+ },
406
+ };
407
+ const config = getMockedConfig({
408
+ items: [
409
+ getMockedControlItem({}),
410
+ getMockedGroupControlItem({ id: DEFAULT_CONTROL_ID_2 }),
411
+ ],
412
+ });
413
+ expect({
414
+ queue: [
415
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID },
416
+ { id: DEFAULT_CONTROL_ID },
417
+ ],
418
+ version: 2,
419
+ }).toEqual(addToQueue({ id: DEFAULT_CONTROL_ID, config, itemsStateAndParams }));
420
+ });
421
+ it('remove unused items from queue after adding new group item: remove common items and group items', () => {
422
+ const itemsStateAndParams = {
423
+ [META_KEY]: {
424
+ queue: [
425
+ { id: 'control1' },
426
+ { id: 'control2', tabId: 'tab' },
427
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID_2 },
428
+ { id: DEFAULT_CONTROL_ID },
429
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: 'group-item-1' },
430
+ ],
431
+ version: 2,
432
+ },
433
+ };
434
+ const config = getMockedConfig({
435
+ items: [
436
+ getMockedControlItem({}),
437
+ getMockedGroupControlItem({ id: DEFAULT_CONTROL_ID_2 }),
438
+ ],
439
+ });
440
+ expect({
441
+ queue: [
442
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID_2 },
443
+ { id: DEFAULT_CONTROL_ID },
444
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID },
445
+ ],
446
+ version: 2,
447
+ }).toEqual(addGroupToQueue({
448
+ id: DEFAULT_CONTROL_ID_2,
449
+ groupItemIds: [DEFAULT_GROUP_ITEM_ID],
450
+ config,
451
+ itemsStateAndParams,
452
+ }));
453
+ });
454
+ it('remove unused items from queue after adding new item: remove common items and item with group', () => {
455
+ const itemsStateAndParams = {
456
+ [META_KEY]: {
457
+ queue: [
458
+ { id: 'control1' },
459
+ { id: 'control2', tabId: 'a3' },
460
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID_2 },
461
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID },
462
+ ],
463
+ version: 2,
464
+ },
465
+ };
466
+ const config = getMockedConfig({
467
+ items: [getMockedControlItem({})],
468
+ });
469
+ expect({
470
+ queue: [{ id: DEFAULT_CONTROL_ID }],
471
+ version: 2,
472
+ }).toEqual(addToQueue({
473
+ id: DEFAULT_CONTROL_ID,
474
+ config,
475
+ itemsStateAndParams,
476
+ }));
477
+ });
478
+ it('add group control to queue', () => {
479
+ const itemsStateAndParams = {
480
+ [META_KEY]: {
481
+ queue: [{ id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID_2 }],
482
+ version: 2,
483
+ },
484
+ };
485
+ const config = getMockedConfig({
486
+ items: [getMockedGroupControlItem({})],
487
+ });
488
+ expect({
489
+ queue: [
490
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID },
491
+ { id: DEFAULT_CONTROL_ID_2, groupItemId: DEFAULT_GROUP_ITEM_ID_2 },
492
+ ],
493
+ version: 2,
494
+ }).toEqual(addGroupToQueue({
495
+ id: DEFAULT_CONTROL_ID_2,
496
+ groupItemIds: [DEFAULT_GROUP_ITEM_ID, DEFAULT_GROUP_ITEM_ID_2],
497
+ config,
498
+ itemsStateAndParams,
499
+ }));
500
+ });
501
+ });
292
502
  });
@@ -1,11 +1,12 @@
1
- import { PluginBase, ConfigItem, ItemsStateAndParams, StateAndParamsMetaData, StringParams, ConfigConnection, ConfigAliases, ConfigItemWithTabs, Config, ItemStateAndParams } from '../types';
1
+ import { Config, ConfigAliases, ConfigConnection, ConfigItem, ConfigItemGroup, ConfigItemWithGroup, ConfigItemWithTabs, ItemStateAndParams, ItemsStateAndParams, PluginBase, StateAndParamsMetaData, StringParams } from '../types';
2
2
  export declare function prerenderItems({ items, plugins, }: {
3
3
  items: ConfigItem[];
4
4
  plugins: PluginBase[];
5
5
  }): ConfigItem[];
6
6
  export declare function getItemsStateAndParamsMeta(itemsStateAndParams: ItemsStateAndParams): StateAndParamsMetaData | undefined;
7
7
  export declare function getCurrentVersion(itemsStateAndParams: ItemsStateAndParams): number;
8
- export declare function isItemWithTabs(item: Pick<ConfigItem, 'data'>): item is Pick<ConfigItemWithTabs, 'data'>;
8
+ export declare function isItemWithTabs(item: Pick<ConfigItem, 'data'> | ConfigItemGroup): item is Pick<ConfigItemWithTabs, 'data'>;
9
+ export declare function isItemWithGroup(item: Pick<ConfigItem, 'data'>): item is Pick<ConfigItemWithGroup, 'data'>;
9
10
  export type FormedQueueData = {
10
11
  id: string;
11
12
  namespace: string;
@@ -16,11 +17,11 @@ export declare function formQueueData({ items, itemsStateAndParams, }: {
16
17
  itemsStateAndParams: ItemsStateAndParams;
17
18
  }): FormedQueueData[];
18
19
  export declare function resolveItemInnerId({ item, itemsStateAndParams, }: {
19
- item: ConfigItem;
20
+ item: Pick<ConfigItemWithTabs, 'data' | 'id'>;
20
21
  itemsStateAndParams: ItemsStateAndParams;
21
22
  }): string;
22
23
  export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersion, }: {
23
- items: ConfigItem[];
24
+ items: (ConfigItem | ConfigItemGroup)[];
24
25
  ignores: ConfigConnection[];
25
26
  itemsStateAndParams: ItemsStateAndParams;
26
27
  isFirstVersion: boolean;
@@ -35,10 +36,18 @@ export declare function getInitialItemsStateAndParamsMeta(): StateAndParamsMetaD
35
36
  interface ChangeQueueArg {
36
37
  id: string;
37
38
  tabId?: string;
39
+ groupItemId?: string;
40
+ config: Config;
41
+ itemsStateAndParams: ItemsStateAndParams;
42
+ }
43
+ interface ChangeQueueGroupArg {
44
+ id: string;
45
+ groupItemIds: string[];
38
46
  config: Config;
39
47
  itemsStateAndParams: ItemsStateAndParams;
40
48
  }
41
49
  export declare function addToQueue({ id, tabId, config, itemsStateAndParams, }: ChangeQueueArg): StateAndParamsMetaData;
50
+ export declare function addGroupToQueue({ id, groupItemIds, config, itemsStateAndParams, }: ChangeQueueGroupArg): StateAndParamsMetaData;
42
51
  export declare function deleteFromQueue(data: ChangeQueueArg): StateAndParamsMetaData;
43
52
  /**
44
53
  * public function for getting only actionParams from object (all fields with keys that contains prefix)
@@ -63,7 +72,7 @@ export declare function transformParamsToActionParams(params: ItemStateAndParams
63
72
  * check if object contains actionParams
64
73
  * @param conf
65
74
  */
66
- export declare function hasActionParam(conf?: StringParams): boolean;
75
+ export declare function hasActionParam(conf?: StringParams | Record<string, StringParams>): boolean;
67
76
  /**
68
77
  * check if ItemStateAndParams object has actionParams in params or state field
69
78
  * @param stateAndParams
@@ -3,7 +3,7 @@ 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 { META_KEY, CURRENT_VERSION, ACTION_PARAM_PREFIX } from '../constants';
6
+ import { ACTION_PARAM_PREFIX, CURRENT_VERSION, META_KEY } from '../constants';
7
7
  function getNormalizedPlugins(plugins) {
8
8
  return keyBy(plugins, 'type');
9
9
  }
@@ -37,30 +37,54 @@ export function getCurrentVersion(itemsStateAndParams) {
37
37
  }
38
38
  return meta.version;
39
39
  }
40
- function nonNullable(value) {
41
- return value !== null && value !== undefined;
40
+ function isConfigData(item) {
41
+ return 'data' in item && 'type' in item;
42
42
  }
43
43
  export function isItemWithTabs(item) {
44
44
  var _a;
45
- return Array.isArray((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.tabs);
45
+ return isConfigData(item) && Array.isArray((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.tabs);
46
+ }
47
+ export function isItemWithGroup(item) {
48
+ var _a;
49
+ return Array.isArray((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.group);
46
50
  }
47
51
  // Array of parameters from widgets according to queue
48
52
  export function formQueueData({ items, itemsStateAndParams, }) {
49
53
  var _a;
50
54
  const queue = ((_a = getItemsStateAndParamsMeta(itemsStateAndParams)) === null || _a === void 0 ? void 0 : _a.queue) || [];
51
55
  const keyById = keyBy(items, 'id');
52
- return queue
53
- .map((queueItem) => {
56
+ return queue.reduce((queueArray, queueItem) => {
54
57
  var _a;
55
- const { id: queueId, tabId } = queueItem;
58
+ const { id: queueId, tabId, groupItemId } = queueItem;
56
59
  const item = keyById[queueId];
57
- if (!item) {
58
- return null;
60
+ const isGroup = isItemWithGroup(item);
61
+ if (!item || (isGroup && !groupItemId)) {
62
+ return queueArray;
63
+ }
64
+ if (isGroup && groupItemId) {
65
+ const itemQueueParams = get(itemsStateAndParams, [item.id, 'params'], {});
66
+ const groupItem = item.data.group.find(({ id }) => id === groupItemId);
67
+ if (!groupItem) {
68
+ return queueArray;
69
+ }
70
+ const groupItemQueueParams = itemQueueParams[groupItemId];
71
+ const filteredParamsByDefaults = pick(groupItemQueueParams, Object.keys(groupItem.defaults || {}));
72
+ /**
73
+ * merging filtered params and filtered actionParams with prefixes
74
+ */
75
+ const params = Object.assign(Object.assign({}, filteredParamsByDefaults), (pickActionParamsFromParams(groupItemQueueParams, true) || {}));
76
+ queueArray.push({
77
+ id: groupItem.id,
78
+ namespace: groupItem.namespace,
79
+ params,
80
+ });
81
+ return queueArray;
59
82
  }
83
+ const itemQueueParams = get(itemsStateAndParams, [item.id, 'params'], {});
60
84
  let itemDefaultParams;
61
85
  if (isItemWithTabs(item)) {
62
86
  if (!tabId || resolveItemInnerId({ item, itemsStateAndParams }) !== tabId) {
63
- return null;
87
+ return queueArray;
64
88
  }
65
89
  itemDefaultParams =
66
90
  ((_a = item.data.tabs.find((tabData) => tabData.id === tabId)) === null || _a === void 0 ? void 0 : _a.params) || {};
@@ -68,19 +92,18 @@ export function formQueueData({ items, itemsStateAndParams, }) {
68
92
  else {
69
93
  itemDefaultParams = item.defaults || {};
70
94
  }
71
- const itemQueueParams = get(itemsStateAndParams, [item.id, 'params'], {});
72
95
  const filteredParamsByDefaults = pick(itemQueueParams, Object.keys(itemDefaultParams));
73
96
  /**
74
97
  * merging filtered params and filtered actionParams with prefixes
75
98
  */
76
99
  const params = Object.assign(Object.assign({}, filteredParamsByDefaults), (pickActionParamsFromParams(itemQueueParams, true) || {}));
77
- return {
100
+ queueArray.push({
78
101
  id: item.id,
79
102
  namespace: item.namespace,
80
103
  params,
81
- };
82
- })
83
- .filter(nonNullable);
104
+ });
105
+ return queueArray;
106
+ }, []);
84
107
  }
85
108
  export function resolveItemInnerId({ item, itemsStateAndParams, }) {
86
109
  var _a, _b;
@@ -138,6 +161,17 @@ export function getInitialItemsStateAndParamsMeta() {
138
161
  version: CURRENT_VERSION,
139
162
  };
140
163
  }
164
+ function getActualItemsIds(items) {
165
+ return items.reduce((ids, item) => {
166
+ if (isItemWithGroup(item)) {
167
+ item.data.group.forEach((groupItem) => {
168
+ ids.push(groupItem.id);
169
+ });
170
+ }
171
+ ids.push(item.id);
172
+ return ids;
173
+ }, []);
174
+ }
141
175
  export function addToQueue({ id, tabId, config, itemsStateAndParams, }) {
142
176
  const queueItem = { id };
143
177
  if (tabId) {
@@ -147,16 +181,45 @@ export function addToQueue({ id, tabId, config, itemsStateAndParams, }) {
147
181
  if (!meta) {
148
182
  return { queue: [queueItem], version: CURRENT_VERSION };
149
183
  }
150
- const { items } = config;
151
- const actualIds = items.map((item) => item.id);
184
+ const actualIds = getActualItemsIds(config.items);
152
185
  const metaQueue = meta.queue || [];
186
+ const notCurrent = (item) => {
187
+ if (item.groupItemId) {
188
+ return actualIds.includes(item.groupItemId);
189
+ }
190
+ return item.id !== id;
191
+ };
153
192
  return {
154
193
  queue: metaQueue
155
- .filter((item) => actualIds.includes(item.id) && item.id !== id)
194
+ .filter((item) => actualIds.includes(item.id) && notCurrent(item))
156
195
  .concat(queueItem),
157
196
  version: meta.version || CURRENT_VERSION,
158
197
  };
159
198
  }
199
+ export function addGroupToQueue({ id, groupItemIds, config, itemsStateAndParams, }) {
200
+ const queueItems = groupItemIds.map((groupItemId) => ({
201
+ id,
202
+ groupItemId,
203
+ }));
204
+ const meta = getItemsStateAndParamsMeta(itemsStateAndParams);
205
+ if (!meta) {
206
+ return { queue: queueItems, version: CURRENT_VERSION };
207
+ }
208
+ const actualIds = getActualItemsIds(config.items);
209
+ const metaQueue = meta.queue || [];
210
+ const notCurrent = (item) => {
211
+ if (item.groupItemId) {
212
+ return actualIds.includes(item.groupItemId) && !groupItemIds.includes(item.groupItemId);
213
+ }
214
+ return true;
215
+ };
216
+ return {
217
+ queue: metaQueue
218
+ .filter((item) => actualIds.includes(item.id) && notCurrent(item))
219
+ .concat(queueItems),
220
+ version: meta.version || CURRENT_VERSION,
221
+ };
222
+ }
160
223
  export function deleteFromQueue(data) {
161
224
  const meta = addToQueue(data);
162
225
  return Object.assign(Object.assign({}, meta), { queue: meta.queue.slice(0, -1) });
@@ -218,7 +281,12 @@ export function transformParamsToActionParams(params) {
218
281
  * @param conf
219
282
  */
220
283
  export function hasActionParam(conf) {
221
- return Object.keys(conf || {}).some((key) => key.startsWith(ACTION_PARAM_PREFIX));
284
+ return Object.keys(conf || {}).some((key) => {
285
+ if (conf && typeof conf[key] === 'object' && !Array.isArray(conf[key])) {
286
+ return Object.keys(conf[key]).some((subkey) => subkey.startsWith(ACTION_PARAM_PREFIX));
287
+ }
288
+ return key.startsWith(ACTION_PARAM_PREFIX);
289
+ });
222
290
  }
223
291
  /**
224
292
  * check if ItemStateAndParams object has actionParams in params or state field
@@ -1,4 +1,4 @@
1
- import { GlobalParams, Config, ItemsStateAndParams, PluginBase, StringParams, ItemState } from '../types';
1
+ import { Config, GlobalParams, ItemState, ItemsStateAndParams, PluginBase, StringParams } from '../types';
2
2
  export interface GetItemsParamsArg {
3
3
  defaultGlobalParams: GlobalParams;
4
4
  globalParams: GlobalParams;
@@ -6,7 +6,7 @@ export interface GetItemsParamsArg {
6
6
  itemsStateAndParams: ItemsStateAndParams;
7
7
  plugins: PluginBase[];
8
8
  }
9
- type GetItemsParamsReturn = Record<string, StringParams>;
9
+ type GetItemsParamsReturn = Record<string, StringParams | Record<string, StringParams>>;
10
10
  export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): GetItemsParamsReturn;
11
11
  export declare function getItemsState({ config, itemsStateAndParams, }: {
12
12
  config: Config;
@@ -1,21 +1,75 @@
1
1
  import groupBy from 'lodash/groupBy';
2
2
  import { META_KEY } from '../constants';
3
- import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, isItemWithTabs, resolveItemInnerId, } from './helpers';
3
+ import { formQueueData, getCurrentVersion, getMapItemsIgnores, hasActionParam, isItemWithGroup, isItemWithTabs, mergeParamsWithAliases, pickActionParamsFromParams, pickExceptActionParamsFromParams, prerenderItems, resolveItemInnerId, } from './helpers';
4
+ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDefaultsByNamespace, getMergedParams, defaultGlobalParams, globalParams, isFirstVersion, queueData, }) {
5
+ var _a, _b;
6
+ const { id, namespace } = item;
7
+ let defaultWidgetParams = {};
8
+ if (isItemWithTabs(item)) {
9
+ const currentWidgetTabId = resolveItemInnerId({ item, itemsStateAndParams });
10
+ const itemTabs = item.data.tabs;
11
+ defaultWidgetParams =
12
+ ((_a = itemTabs.find((tabItem) => (tabItem === null || tabItem === void 0 ? void 0 : tabItem.id) === currentWidgetTabId)) === null || _a === void 0 ? void 0 : _a.params) || {};
13
+ }
14
+ else {
15
+ defaultWidgetParams = item.defaults || {};
16
+ }
17
+ const itemIgnores = mapItemsIgnores[id];
18
+ const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
19
+ let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
20
+ // default parameters to begin with
21
+ affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
22
+ return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
23
+ }, {}), getMergedParams(globalParams));
24
+ if (isFirstVersion) {
25
+ itemParams = Object.assign(itemParams, ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _b === void 0 ? void 0 : _b.params) || {});
26
+ }
27
+ else {
28
+ // params according to queue of its applying
29
+ let queueDataItemsParams = {};
30
+ for (const data of queueData) {
31
+ if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
32
+ continue;
33
+ }
34
+ let actionParams;
35
+ let params = data.params;
36
+ const needAliasesForActionParams = data.id !== id && hasActionParam(data.params);
37
+ if (needAliasesForActionParams) {
38
+ actionParams = pickActionParamsFromParams(data.params);
39
+ params = pickExceptActionParamsFromParams(data.params);
40
+ }
41
+ const mergedParams = getMergedParams(params, actionParams);
42
+ queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
43
+ }
44
+ itemParams = Object.assign(itemParams, queueDataItemsParams);
45
+ }
46
+ return Object.assign(Object.assign({}, defaultWidgetParams), itemParams);
47
+ }
4
48
  export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
5
49
  const { aliases, connections } = config;
6
50
  const items = prerenderItems({ items: config.items, plugins });
7
51
  const isFirstVersion = getCurrentVersion(itemsStateAndParams) === 1;
52
+ const allItems = items.reduce((paramsItems, item) => {
53
+ if (isItemWithGroup(item)) {
54
+ item.data.group.forEach((groupItem) => {
55
+ paramsItems.push(groupItem);
56
+ });
57
+ return paramsItems;
58
+ }
59
+ paramsItems.push(item);
60
+ return paramsItems;
61
+ }, []);
8
62
  const queueData = isFirstVersion
9
63
  ? []
10
64
  : formQueueData({ items, itemsStateAndParams });
11
65
  // to consider other kind types in future (not only ignore)
12
66
  const mapItemsIgnores = getMapItemsIgnores({
13
- items,
67
+ items: allItems,
14
68
  ignores: connections.filter(({ kind }) => kind === 'ignore'),
15
69
  itemsStateAndParams,
16
70
  isFirstVersion,
17
71
  });
18
- const groupByNamespace = groupBy(items, 'namespace');
72
+ const groupByNamespace = groupBy(allItems, 'namespace');
19
73
  const itemsWithDefaultsByNamespace = Object.keys(groupByNamespace).reduce((acc, namespace) => {
20
74
  return Object.assign(Object.assign({}, acc), {
21
75
  // there are defaults only in selectors by now, need to get them from item.data.tabs[].defaults for widgets
@@ -23,49 +77,26 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
23
77
  [namespace]: groupByNamespace[namespace].filter((item) => item.defaults) });
24
78
  }, {});
25
79
  return items.reduce((itemsParams, item) => {
26
- var _a, _b;
27
80
  const { id, namespace } = item;
28
- let defaultWidgetParams = {};
29
- if (isItemWithTabs(item)) {
30
- const currentWidgetTabId = resolveItemInnerId({ item, itemsStateAndParams });
31
- const itemTabs = item.data.tabs;
32
- defaultWidgetParams =
33
- ((_a = itemTabs.find((tabItem) => (tabItem === null || tabItem === void 0 ? void 0 : tabItem.id) === currentWidgetTabId)) === null || _a === void 0 ? void 0 : _a.params) || {};
34
- }
35
- else {
36
- defaultWidgetParams = item.defaults || {};
37
- }
38
81
  const getMergedParams = (params, actionParams) => mergeParamsWithAliases({ aliases, namespace, params: params || {}, actionParams });
39
- const itemIgnores = mapItemsIgnores[id];
40
- const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
41
- let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
42
- // default parameters to begin with
43
- affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
44
- return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
45
- }, {}), getMergedParams(globalParams));
46
- if (isFirstVersion) {
47
- itemParams = Object.assign(itemParams, ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _b === void 0 ? void 0 : _b.params) || {});
48
- }
49
- else {
50
- // params according to queue of its applying
51
- let queueDataItemsParams = {};
52
- for (const data of Object.values(queueData)) {
53
- if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
54
- continue;
55
- }
56
- let actionParams;
57
- let params = data.params;
58
- const needAliasesForActionParams = data.id !== id && hasActionParam(data.params);
59
- if (needAliasesForActionParams) {
60
- actionParams = pickActionParamsFromParams(data.params);
61
- params = pickExceptActionParamsFromParams(data.params);
62
- }
63
- const mergedParams = getMergedParams(params, actionParams);
64
- queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
65
- }
66
- itemParams = Object.assign(itemParams, queueDataItemsParams);
82
+ const paramsOptions = {
83
+ itemsStateAndParams,
84
+ mapItemsIgnores,
85
+ itemsWithDefaultsByNamespace,
86
+ getMergedParams,
87
+ defaultGlobalParams,
88
+ globalParams,
89
+ isFirstVersion,
90
+ queueData,
91
+ };
92
+ if (isItemWithGroup(item)) {
93
+ const groupParams = item.data.group.reduce((groupItemParams, groupItem) => {
94
+ groupItemParams[groupItem.id] = getItemParams(Object.assign({ item: groupItem }, paramsOptions));
95
+ return groupItemParams;
96
+ }, {});
97
+ return Object.assign(Object.assign({}, itemsParams), { [id]: groupParams });
67
98
  }
68
- return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
99
+ return Object.assign(Object.assign({}, itemsParams), { [id]: getItemParams(Object.assign({ item }, paramsOptions)) });
69
100
  }, {});
70
101
  }
71
102
  export function getItemsState({ config, itemsStateAndParams, }) {