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