@gravity-ui/dashkit 6.7.2 → 6.9.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/README.md +57 -0
- package/build/cjs/components/ActionPanel/ActionPanel.css +48 -6
- package/build/cjs/components/ActionPanel/ActionPanel.d.ts +3 -1
- package/build/cjs/components/ActionPanel/ActionPanel.js +12 -1
- package/build/cjs/components/GridItem/GridItem.css +22 -7
- 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 +2 -2
- 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 +4 -4
- package/build/cjs/utils/__tests__/update-manager.test.js +193 -5
- package/build/cjs/utils/update-manager.d.ts +2 -2
- package/build/cjs/utils/update-manager.js +71 -4
- package/build/esm/components/ActionPanel/ActionPanel.css +48 -6
- package/build/esm/components/ActionPanel/ActionPanel.d.ts +3 -1
- package/build/esm/components/ActionPanel/ActionPanel.js +12 -1
- package/build/esm/components/GridItem/GridItem.css +22 -7
- 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 +87 -19
- package/build/esm/shared/modules/state-and-params.d.ts +2 -2
- 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 +4 -4
- package/build/esm/utils/__tests__/update-manager.test.js +193 -5
- package/build/esm/utils/update-manager.d.ts +2 -2
- package/build/esm/utils/update-manager.js +72 -5
- package/package.json +3 -2
|
@@ -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 keyBy_1 = tslib_1.__importDefault(require("lodash/keyBy"));
|
|
6
6
|
const get_1 = tslib_1.__importDefault(require("lodash/get"));
|
|
@@ -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
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GlobalParams,
|
|
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;
|
|
@@ -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));
|
|
@@ -6,6 +6,12 @@ export interface ConfigLayout {
|
|
|
6
6
|
x: number;
|
|
7
7
|
y: number;
|
|
8
8
|
}
|
|
9
|
+
export type ConfigItemGroup = {
|
|
10
|
+
id: string;
|
|
11
|
+
defaults?: StringParams;
|
|
12
|
+
namespace: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
9
15
|
export interface ConfigItemData {
|
|
10
16
|
_editActive?: boolean;
|
|
11
17
|
tabs?: {
|
|
@@ -14,11 +20,15 @@ export interface ConfigItemData {
|
|
|
14
20
|
params?: StringParams;
|
|
15
21
|
[key: string]: unknown;
|
|
16
22
|
}[];
|
|
23
|
+
group?: ConfigItemGroup[];
|
|
17
24
|
[key: string]: unknown;
|
|
18
25
|
}
|
|
19
26
|
export interface ConfigItemDataWithTabs extends Omit<ConfigItemData, 'tabs'> {
|
|
20
27
|
tabs: NonNullable<ConfigItemData['tabs']>;
|
|
21
28
|
}
|
|
29
|
+
export interface ConfigItemDataWithGroup extends Omit<ConfigItemData, 'group'> {
|
|
30
|
+
group: NonNullable<ConfigItemData['group']>;
|
|
31
|
+
}
|
|
22
32
|
export interface ConfigItem {
|
|
23
33
|
id: string;
|
|
24
34
|
data: ConfigItemData;
|
|
@@ -31,6 +41,9 @@ export interface ConfigItem {
|
|
|
31
41
|
export interface ConfigItemWithTabs extends Omit<ConfigItem, 'data'> {
|
|
32
42
|
data: ConfigItemDataWithTabs;
|
|
33
43
|
}
|
|
44
|
+
export interface ConfigItemWithGroup extends Omit<ConfigItem, 'data'> {
|
|
45
|
+
data: ConfigItemDataWithGroup;
|
|
46
|
+
}
|
|
34
47
|
export interface ConfigAliases {
|
|
35
48
|
[namespace: string]: string[][];
|
|
36
49
|
}
|
|
@@ -6,6 +6,7 @@ export interface ItemState {
|
|
|
6
6
|
export interface QueueItem {
|
|
7
7
|
id: string;
|
|
8
8
|
tabId?: string;
|
|
9
|
+
groupItemId?: string;
|
|
9
10
|
}
|
|
10
11
|
export type StateAndParamsMetaData = {
|
|
11
12
|
queue: QueueItem[];
|
|
@@ -15,11 +16,12 @@ export type StateAndParamsMeta = {
|
|
|
15
16
|
[META_KEY]: StateAndParamsMetaData;
|
|
16
17
|
};
|
|
17
18
|
export type ItemStateAndParams = {
|
|
18
|
-
params?: StringParams
|
|
19
|
+
params?: StringParams | Record<string, StringParams>;
|
|
19
20
|
state?: ItemState;
|
|
20
21
|
};
|
|
21
22
|
export type ItemStateAndParamsChangeOptions = {
|
|
22
|
-
action
|
|
23
|
+
action?: 'setParams' | 'removeItem';
|
|
24
|
+
groupItemIds?: string[];
|
|
23
25
|
};
|
|
24
26
|
export type ItemsStateAndParamsBase = Record<string, ItemStateAndParams>;
|
|
25
27
|
export type ItemsStateAndParams = ItemsStateAndParamsBase | StateAndParamsMeta;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ContextProps, SettingsProps, WidgetLayout } from './common';
|
|
3
|
-
import {
|
|
3
|
+
import { ConfigItem, ItemState, ItemStateAndParams, ItemStateAndParamsChangeOptions, PluginBase, StringParams } from '../shared';
|
|
4
4
|
import type { ReactGridLayoutProps } from 'react-grid-layout';
|
|
5
|
-
export interface PluginWidgetProps {
|
|
5
|
+
export interface PluginWidgetProps<T = StringParams> {
|
|
6
6
|
id: string;
|
|
7
7
|
editMode: boolean;
|
|
8
|
-
params:
|
|
8
|
+
params: T;
|
|
9
9
|
state: ItemState;
|
|
10
10
|
onStateAndParamsChange: (stateAndParams: ItemStateAndParams, options?: ItemStateAndParamsChangeOptions) => void;
|
|
11
11
|
width: number;
|
|
@@ -33,7 +33,7 @@ export interface PluginDefaultLayout {
|
|
|
33
33
|
minH?: number;
|
|
34
34
|
maxH?: number;
|
|
35
35
|
}
|
|
36
|
-
export interface Plugin<P extends PluginWidgetProps = any> extends PluginBase {
|
|
36
|
+
export interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {
|
|
37
37
|
defaultLayout?: PluginDefaultLayout;
|
|
38
38
|
renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
|
|
39
39
|
}
|