@gravity-ui/dashkit 8.1.0-beta.8 → 8.2.0-beta.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 CHANGED
@@ -29,6 +29,7 @@ interface DashKitProps {
29
29
  editMode: boolean;
30
30
  onItemEdit: ({id}: {id: string}) => void;
31
31
  onChange: (data: {config: Config; itemsStateAndParams: ItemsStateAndParams}) => void;
32
+ onDrop: (dropProps: ItemDropProps) => void;
32
33
  defaultGlobalParams: GlobalParams;
33
34
  globalParams: GlobalParams;
34
35
  itemsStateAndParams: ItemsStateAndParams;
@@ -36,6 +37,8 @@ interface DashKitProps {
36
37
  context: ContextProps;
37
38
  overlayControls?: Record<string, OverlayControlItem[]>;
38
39
  noOverlay?: boolean;
40
+ focusable?: boolean;
41
+ draggableHandleClassName?: string;
39
42
  }
40
43
  ```
41
44
 
@@ -43,6 +46,7 @@ interface DashKitProps {
43
46
  - **editMode**: Whether edit mode is enabled.
44
47
  - **onItemEdit**: Called when you click to edit a widget.
45
48
  - **onChange**: Called when config or [itemsStateAndParams](#temsStateAndParams) are changed.
49
+ - **onDrop**: Called when item dropped from ActionPanel using (#DashKitDnDWrapper)
46
50
  - **defaultGlobalParams**, **globalParams**: [Parameters](#Params) that affect all widgets. In DataLens, `defaultGlobalParams` are global parameters set in the dashboard settings. `globalParams` are globals parameters that can be set in the url.
47
51
  - **itemsStateAndParams**: [itemsStateAndParams](#temsStateAndParams).
48
52
  - **settings**: DashKit settings.
@@ -208,6 +212,23 @@ const config: DashKitProps['config'] = {
208
212
  Add a new item to the config:
209
213
 
210
214
  ```ts
215
+ const newLayout = updateLayout: [
216
+ {
217
+ h: 6,
218
+ i: 'Ea',
219
+ w: 12,
220
+ x: 0,
221
+ y: 6,
222
+ },
223
+ {
224
+ h: 4,
225
+ i: 'Dk',
226
+ w: 8,
227
+ x: 0,
228
+ y: 12,
229
+ },
230
+ ];
231
+
211
232
  const newConfig = DashKit.setItem({
212
233
  item: {
213
234
  data: {
@@ -215,8 +236,19 @@ const newConfig = DashKit.setItem({
215
236
  },
216
237
  namespace: 'default',
217
238
  type: 'text',
239
+ // Optional. If new item needed to be inserted in current layout with predefined dimensions
240
+ layout: { // Current item inseterted before 'Ea'
241
+ h: 6,
242
+ w: 12,
243
+ x: 0,
244
+ y: 2,
245
+ },,
218
246
  },
219
247
  config: config,
248
+ options: {
249
+ // Optional. New layout values for existing items when new element is dropped from ActionPanel
250
+ updateLayout: newLayout,
251
+ },
220
252
  });
221
253
  ```
222
254
 
@@ -314,6 +346,69 @@ type MenuItem = {
314
346
  DashKit.setSettings({menu: [] as Array<MenuItem>});
315
347
  ```
316
348
 
349
+ ### Draggable items from ActionPanel
350
+
351
+ #### DashKitDnDWrapper
352
+
353
+ ```ts
354
+ interface DashKitDnDWrapperProps {
355
+ dragImageSrc?: string;
356
+ onDragStart?: (dragProps: ItemDragProps) => void;
357
+ onDragEnd?: () => void;
358
+ }
359
+ ```
360
+
361
+ - **dragImageSrc**: Drag image preview, by default used transparent 1px png base64
362
+ - **onDragStart**: Callback called when element is dragged from ActionPanel
363
+ - **onDragEnd**: Callback called when element dropped or drag canceled
364
+
365
+ ```ts
366
+ type ItemDragProps = {
367
+ type: string; // Plugin type
368
+ layout?: { // Optional. Layout item size for preview and init
369
+ w?: number;
370
+ h?: number;
371
+ };
372
+ extra?: any; // Custom user context
373
+ };
374
+ ```
375
+
376
+ ```ts
377
+ type ItemDropProps = {
378
+ commit: () => void; // Callback should be called after all config operations are made
379
+ dragProps: ItemDragProps; // Item drag props
380
+ itemLayout: ConfigLayout; // Calculated item layout dimensions
381
+ newLayout: ConfigLayout[]; // New layout after element is dropped
382
+ };
383
+ ```
384
+
385
+
386
+ #### Example:
387
+
388
+ ```jsx
389
+ const menuItems = [
390
+ {
391
+ id: 'chart',
392
+ icon: <Icon data={ChartColumn} />,
393
+ title: 'Chart',
394
+ qa: 'chart',
395
+ dragProps: { // ItemDragProps
396
+ type: 'custom', // Registered plugin type
397
+ },
398
+ }
399
+ ]
400
+
401
+ const onDrop = (dropProps: ItemDropProps) => {
402
+ // ... add element to your config
403
+ dropProps.commit();
404
+ }
405
+
406
+ <DashKitDnDWrapper>
407
+ <DashKit editMode={true} config={config} onChange={onChange} onDrop={onDrop} />
408
+ <ActionPanel items={menuItems} />
409
+ </DashKitDnDWrapper>
410
+ ```
411
+
317
412
  ### CSS API
318
413
 
319
414
  | Name | Description |
@@ -55,7 +55,7 @@ function useMemoStateContext(props) {
55
55
  }
56
56
  else {
57
57
  if (temporaryLayout) {
58
- setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.filter(({ i }) => i !== id) }));
58
+ setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.data.filter(({ i }) => i !== id) }));
59
59
  }
60
60
  onChange(utils_1.UpdateManager.removeItem({
61
61
  id,
@@ -5,9 +5,10 @@ export interface GetItemsParamsArg {
5
5
  config: Config;
6
6
  itemsStateAndParams: ItemsStateAndParams;
7
7
  plugins: PluginBase[];
8
+ useStateAsInitial?: boolean;
8
9
  }
9
10
  type GetItemsParamsReturn = Record<string, StringParams | Record<string, StringParams>>;
10
- export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): GetItemsParamsReturn;
11
+ export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, useStateAsInitial, }: GetItemsParamsArg): GetItemsParamsReturn;
11
12
  export declare function getItemsState({ config, itemsStateAndParams, }: {
12
13
  config: Config;
13
14
  itemsStateAndParams: ItemsStateAndParams;
@@ -5,7 +5,18 @@ 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, }) {
8
+ const getParamsFromStateAndParams = ({ itemsStateAndParams, parentItemId, item, }) => {
9
+ const widgetId = parentItemId || item.id;
10
+ if (!(widgetId in itemsStateAndParams)) {
11
+ return {};
12
+ }
13
+ const stateAndParams = itemsStateAndParams;
14
+ const itemParams = parentItemId
15
+ ? Object.assign({}, stateAndParams[widgetId].params[item.id])
16
+ : Object.assign({}, stateAndParams[widgetId].params);
17
+ return itemParams;
18
+ };
19
+ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDefaultsByNamespace, getMergedParams, defaultGlobalParams, globalParams, isFirstVersion, queueData, parentItemId, useStateAsInitial, }) {
9
20
  var _a, _b;
10
21
  const { id, namespace } = item;
11
22
  let defaultWidgetParams = {};
@@ -24,7 +35,9 @@ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDe
24
35
  // default parameters to begin with
25
36
  affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
26
37
  return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
27
- }, {}), getMergedParams(globalParams));
38
+ }, {}), getMergedParams(globalParams), useStateAsInitial
39
+ ? getParamsFromStateAndParams({ parentItemId, item, itemsStateAndParams })
40
+ : {});
28
41
  if (isFirstVersion) {
29
42
  itemParams = Object.assign(itemParams, ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _b === void 0 ? void 0 : _b.params) || {});
30
43
  }
@@ -49,7 +62,7 @@ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDe
49
62
  }
50
63
  return Object.assign(Object.assign({}, defaultWidgetParams), itemParams);
51
64
  }
52
- function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
65
+ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, useStateAsInitial, }) {
53
66
  const { aliases, connections } = config;
54
67
  const items = (0, helpers_1.prerenderItems)({ items: config.items, plugins });
55
68
  const isFirstVersion = (0, helpers_1.getCurrentVersion)(itemsStateAndParams) === 1;
@@ -92,10 +105,11 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
92
105
  globalParams,
93
106
  isFirstVersion,
94
107
  queueData,
108
+ useStateAsInitial,
95
109
  };
96
110
  if ((0, helpers_1.isItemWithGroup)(item)) {
97
111
  const groupParams = item.data.group.reduce((groupItemParams, groupItem) => {
98
- groupItemParams[groupItem.id] = getItemParams(Object.assign({ item: groupItem }, paramsOptions));
112
+ groupItemParams[groupItem.id] = getItemParams(Object.assign({ item: groupItem, parentItemId: item.id }, paramsOptions));
99
113
  return groupItemParams;
100
114
  }, {});
101
115
  return Object.assign(Object.assign({}, itemsParams), { [id]: groupParams });
@@ -1,4 +1,4 @@
1
- import type { Config, ConfigItem, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
1
+ import type { Config, ConfigItem, ConfigItemGroup, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
2
  import type { AddConfigItem, SetItemOptions, SetNewItemOptions, WidgetLayout } from '../typings';
3
3
  import { RegisterManagerPluginLayout } from './register-manager';
4
4
  interface RemoveItemArg {
@@ -13,6 +13,13 @@ interface ChangeStateAndParamsArg {
13
13
  stateAndParams: ItemStateAndParams;
14
14
  options?: ItemStateAndParamsChangeOptions;
15
15
  }
16
+ export declare const getChangedParams: ({ initiatorItem, stateAndParams, itemsStateAndParams, }: {
17
+ initiatorItem: ConfigItem | ConfigItemGroup;
18
+ stateAndParams: ItemStateAndParams;
19
+ itemsStateAndParams: ItemsStateAndParams;
20
+ }) => {
21
+ [x: string]: string | string[];
22
+ };
16
23
  export declare class UpdateManager {
17
24
  static addItem({ item, namespace, layout, config, options, }: {
18
25
  item: AddConfigItem;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UpdateManager = void 0;
3
+ exports.UpdateManager = exports.getChangedParams = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const immutability_helper_1 = tslib_1.__importStar(require("immutability-helper"));
6
6
  const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
@@ -78,6 +78,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
78
78
  : allowedParams;
79
79
  }
80
80
  const stateParamsConf = stateAndParams.params;
81
+ // check if structure is StringParams or Record<string, StringParams>
82
+ // if it's Record<string, StringParams>, then this is a group application of params
83
+ // and checking for comparison of allowedParams and stateParamsConf is not necessary
84
+ const isGroupParamsApply = typeof (stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]) === 'object' &&
85
+ !Array.isArray(stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]);
81
86
  if ((0, shared_1.isItemWithTabs)(item)) {
82
87
  let tab;
83
88
  if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
@@ -90,14 +95,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
90
95
  allowedParams = (0, pick_1.default)(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
91
96
  }
92
97
  else {
93
- // check if structure is StringParams or Record<string, StringParams>
94
- const paramsConf = typeof (stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]) === 'object' &&
95
- !Array.isArray(stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id])
96
- ? stateParamsConf[item.id]
97
- : stateParamsConf;
98
+ const paramsConf = isGroupParamsApply ? stateParamsConf[item.id] : stateParamsConf;
98
99
  allowedParams = (0, pick_1.default)(paramsConf, Object.keys(item.defaults || {}));
99
100
  }
100
- if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
101
+ if (!isGroupParamsApply &&
102
+ Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
101
103
  console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
102
104
  }
103
105
  return allowedParams;
@@ -180,6 +182,12 @@ function getNewItemData({ item, config, counter: argsCounter, salt, options }) {
180
182
  }
181
183
  return { data, counter, excludeIds };
182
184
  }
185
+ const getChangedParams = ({ initiatorItem, stateAndParams, itemsStateAndParams, }) => {
186
+ const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
187
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
188
+ return Object.assign(Object.assign({}, allowableParams), allowableActionParams);
189
+ };
190
+ exports.getChangedParams = getChangedParams;
183
191
  function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStateAndParams, stateAndParams, config, unusedIds, }) {
184
192
  var _a;
185
193
  const meta = (0, shared_1.addGroupToQueue)({
@@ -192,9 +200,12 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
192
200
  const currentItemParams = (_a = itemsStateAndParams[initiatorId]) === null || _a === void 0 ? void 0 : _a.params;
193
201
  for (const groupItem of initiatorItem.data.group) {
194
202
  if (groupItemIds.includes(groupItem.id)) {
195
- const allowableParams = getAllowableChangedParams(groupItem, stateAndParams, itemsStateAndParams);
196
- const allowableActionParams = getAllowableChangedParams(groupItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
197
- updatedItems[groupItem.id] = Object.assign(Object.assign({}, allowableParams), allowableActionParams);
203
+ const changedParams = (0, exports.getChangedParams)({
204
+ initiatorItem: groupItem,
205
+ stateAndParams,
206
+ itemsStateAndParams,
207
+ });
208
+ updatedItems[groupItem.id] = changedParams;
198
209
  continue;
199
210
  }
200
211
  if (currentItemParams && currentItemParams[groupItem.id]) {
@@ -354,8 +365,11 @@ class UpdateManager {
354
365
  });
355
366
  }
356
367
  if ('params' in stateAndParams) {
357
- const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
358
- const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
368
+ const changedParams = (0, exports.getChangedParams)({
369
+ initiatorItem,
370
+ stateAndParams,
371
+ itemsStateAndParams,
372
+ });
359
373
  const tabId = (0, shared_1.isItemWithTabs)(initiatorItem)
360
374
  ? newTabId || (0, shared_1.resolveItemInnerId)({ item: initiatorItem, itemsStateAndParams })
361
375
  : undefined;
@@ -370,7 +384,7 @@ class UpdateManager {
370
384
  $unset: unusedIds,
371
385
  [initiatorId]: {
372
386
  $auto: Object.assign({ params: {
373
- [commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
387
+ [commandUpdateParams]: changedParams,
374
388
  } }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
375
389
  },
376
390
  [shared_1.META_KEY]: { $set: meta },
@@ -51,7 +51,7 @@ function useMemoStateContext(props) {
51
51
  }
52
52
  else {
53
53
  if (temporaryLayout) {
54
- setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.filter(({ i }) => i !== id) }));
54
+ setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.data.filter(({ i }) => i !== id) }));
55
55
  }
56
56
  onChange(UpdateManager.removeItem({
57
57
  id,
@@ -5,9 +5,10 @@ export interface GetItemsParamsArg {
5
5
  config: Config;
6
6
  itemsStateAndParams: ItemsStateAndParams;
7
7
  plugins: PluginBase[];
8
+ useStateAsInitial?: boolean;
8
9
  }
9
10
  type GetItemsParamsReturn = Record<string, StringParams | Record<string, StringParams>>;
10
- export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): GetItemsParamsReturn;
11
+ export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, useStateAsInitial, }: GetItemsParamsArg): GetItemsParamsReturn;
11
12
  export declare function getItemsState({ config, itemsStateAndParams, }: {
12
13
  config: Config;
13
14
  itemsStateAndParams: ItemsStateAndParams;
@@ -1,7 +1,18 @@
1
1
  import groupBy from 'lodash/groupBy';
2
2
  import { META_KEY } from '../constants';
3
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, }) {
4
+ const getParamsFromStateAndParams = ({ itemsStateAndParams, parentItemId, item, }) => {
5
+ const widgetId = parentItemId || item.id;
6
+ if (!(widgetId in itemsStateAndParams)) {
7
+ return {};
8
+ }
9
+ const stateAndParams = itemsStateAndParams;
10
+ const itemParams = parentItemId
11
+ ? Object.assign({}, stateAndParams[widgetId].params[item.id])
12
+ : Object.assign({}, stateAndParams[widgetId].params);
13
+ return itemParams;
14
+ };
15
+ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDefaultsByNamespace, getMergedParams, defaultGlobalParams, globalParams, isFirstVersion, queueData, parentItemId, useStateAsInitial, }) {
5
16
  var _a, _b;
6
17
  const { id, namespace } = item;
7
18
  let defaultWidgetParams = {};
@@ -20,7 +31,9 @@ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDe
20
31
  // default parameters to begin with
21
32
  affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
22
33
  return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
23
- }, {}), getMergedParams(globalParams));
34
+ }, {}), getMergedParams(globalParams), useStateAsInitial
35
+ ? getParamsFromStateAndParams({ parentItemId, item, itemsStateAndParams })
36
+ : {});
24
37
  if (isFirstVersion) {
25
38
  itemParams = Object.assign(itemParams, ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _b === void 0 ? void 0 : _b.params) || {});
26
39
  }
@@ -45,7 +58,7 @@ function getItemParams({ item, itemsStateAndParams, mapItemsIgnores, itemsWithDe
45
58
  }
46
59
  return Object.assign(Object.assign({}, defaultWidgetParams), itemParams);
47
60
  }
48
- export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
61
+ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, useStateAsInitial, }) {
49
62
  const { aliases, connections } = config;
50
63
  const items = prerenderItems({ items: config.items, plugins });
51
64
  const isFirstVersion = getCurrentVersion(itemsStateAndParams) === 1;
@@ -88,10 +101,11 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
88
101
  globalParams,
89
102
  isFirstVersion,
90
103
  queueData,
104
+ useStateAsInitial,
91
105
  };
92
106
  if (isItemWithGroup(item)) {
93
107
  const groupParams = item.data.group.reduce((groupItemParams, groupItem) => {
94
- groupItemParams[groupItem.id] = getItemParams(Object.assign({ item: groupItem }, paramsOptions));
108
+ groupItemParams[groupItem.id] = getItemParams(Object.assign({ item: groupItem, parentItemId: item.id }, paramsOptions));
95
109
  return groupItemParams;
96
110
  }, {});
97
111
  return Object.assign(Object.assign({}, itemsParams), { [id]: groupParams });
@@ -1,4 +1,4 @@
1
- import type { Config, ConfigItem, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
1
+ import type { Config, ConfigItem, ConfigItemGroup, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
2
  import type { AddConfigItem, SetItemOptions, SetNewItemOptions, WidgetLayout } from '../typings';
3
3
  import { RegisterManagerPluginLayout } from './register-manager';
4
4
  interface RemoveItemArg {
@@ -13,6 +13,13 @@ interface ChangeStateAndParamsArg {
13
13
  stateAndParams: ItemStateAndParams;
14
14
  options?: ItemStateAndParamsChangeOptions;
15
15
  }
16
+ export declare const getChangedParams: ({ initiatorItem, stateAndParams, itemsStateAndParams, }: {
17
+ initiatorItem: ConfigItem | ConfigItemGroup;
18
+ stateAndParams: ItemStateAndParams;
19
+ itemsStateAndParams: ItemsStateAndParams;
20
+ }) => {
21
+ [x: string]: string | string[];
22
+ };
16
23
  export declare class UpdateManager {
17
24
  static addItem({ item, namespace, layout, config, options, }: {
18
25
  item: AddConfigItem;
@@ -74,6 +74,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
74
74
  : allowedParams;
75
75
  }
76
76
  const stateParamsConf = stateAndParams.params;
77
+ // check if structure is StringParams or Record<string, StringParams>
78
+ // if it's Record<string, StringParams>, then this is a group application of params
79
+ // and checking for comparison of allowedParams and stateParamsConf is not necessary
80
+ const isGroupParamsApply = typeof (stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]) === 'object' &&
81
+ !Array.isArray(stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]);
77
82
  if (isItemWithTabs(item)) {
78
83
  let tab;
79
84
  if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
@@ -86,14 +91,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
86
91
  allowedParams = pick(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
87
92
  }
88
93
  else {
89
- // check if structure is StringParams or Record<string, StringParams>
90
- const paramsConf = typeof (stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]) === 'object' &&
91
- !Array.isArray(stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id])
92
- ? stateParamsConf[item.id]
93
- : stateParamsConf;
94
+ const paramsConf = isGroupParamsApply ? stateParamsConf[item.id] : stateParamsConf;
94
95
  allowedParams = pick(paramsConf, Object.keys(item.defaults || {}));
95
96
  }
96
- if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
97
+ if (!isGroupParamsApply &&
98
+ Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
97
99
  console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
98
100
  }
99
101
  return allowedParams;
@@ -176,6 +178,11 @@ function getNewItemData({ item, config, counter: argsCounter, salt, options }) {
176
178
  }
177
179
  return { data, counter, excludeIds };
178
180
  }
181
+ export const getChangedParams = ({ initiatorItem, stateAndParams, itemsStateAndParams, }) => {
182
+ const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
183
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
184
+ return Object.assign(Object.assign({}, allowableParams), allowableActionParams);
185
+ };
179
186
  function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStateAndParams, stateAndParams, config, unusedIds, }) {
180
187
  var _a;
181
188
  const meta = addGroupToQueue({
@@ -188,9 +195,12 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
188
195
  const currentItemParams = (_a = itemsStateAndParams[initiatorId]) === null || _a === void 0 ? void 0 : _a.params;
189
196
  for (const groupItem of initiatorItem.data.group) {
190
197
  if (groupItemIds.includes(groupItem.id)) {
191
- const allowableParams = getAllowableChangedParams(groupItem, stateAndParams, itemsStateAndParams);
192
- const allowableActionParams = getAllowableChangedParams(groupItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
193
- updatedItems[groupItem.id] = Object.assign(Object.assign({}, allowableParams), allowableActionParams);
198
+ const changedParams = getChangedParams({
199
+ initiatorItem: groupItem,
200
+ stateAndParams,
201
+ itemsStateAndParams,
202
+ });
203
+ updatedItems[groupItem.id] = changedParams;
194
204
  continue;
195
205
  }
196
206
  if (currentItemParams && currentItemParams[groupItem.id]) {
@@ -350,8 +360,11 @@ export class UpdateManager {
350
360
  });
351
361
  }
352
362
  if ('params' in stateAndParams) {
353
- const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
354
- const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
363
+ const changedParams = getChangedParams({
364
+ initiatorItem,
365
+ stateAndParams,
366
+ itemsStateAndParams,
367
+ });
355
368
  const tabId = isItemWithTabs(initiatorItem)
356
369
  ? newTabId || resolveItemInnerId({ item: initiatorItem, itemsStateAndParams })
357
370
  : undefined;
@@ -366,7 +379,7 @@ export class UpdateManager {
366
379
  $unset: unusedIds,
367
380
  [initiatorId]: {
368
381
  $auto: Object.assign({ params: {
369
- [commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
382
+ [commandUpdateParams]: changedParams,
370
383
  } }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
371
384
  },
372
385
  [META_KEY]: { $set: meta },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.1.0-beta.8",
3
+ "version": "8.2.0-beta.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {