@gravity-ui/dashkit 4.1.0 → 4.1.1-unstable-4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prepareItem = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
6
7
  const DashKitContext_1 = require("../context/DashKitContext");
7
8
  const prop_types_1 = tslib_1.__importDefault(require("prop-types"));
9
+ const shared_1 = require("../shared");
8
10
  function prepareItem(Component) {
9
11
  var _a;
10
12
  return _a = class PrepareItem extends react_1.default.Component {
@@ -27,12 +29,16 @@ function prepareItem(Component) {
27
29
  }
28
30
  render() {
29
31
  const { id, width, height, item, adjustWidgetLayout, layout } = this.props;
30
- const { itemsState, itemsParams, registerManager, settings, context, editMode } = this.context;
32
+ const { itemsState, itemsParams, itemsActionParams, registerManager, settings, context, editMode, } = this.context;
33
+ const actionParams = (0, shared_1.transformParamsToActionParams)(itemsActionParams[id]);
34
+ const resultParams = (0, isEmpty_1.default)(actionParams)
35
+ ? itemsParams[id]
36
+ : Object.assign(Object.assign({}, itemsParams[id]), actionParams);
31
37
  const { type, data, defaults, namespace } = item;
32
38
  const rendererProps = {
33
39
  data,
34
40
  editMode,
35
- params: itemsParams[id],
41
+ params: resultParams,
36
42
  state: itemsState[id],
37
43
  onStateAndParamsChange: this._onStateAndParamsChange,
38
44
  width,
@@ -100,6 +100,10 @@ function useMemoStateContext(props) {
100
100
  config: props.config,
101
101
  itemsStateAndParams: props.itemsStateAndParams,
102
102
  }), [props.config, props.itemsStateAndParams]);
103
+ const itemsActionParams = react_1.default.useMemo(() => (0, shared_1.getItemsActionParams)({
104
+ config: props.config,
105
+ itemsStateAndParams: props.itemsStateAndParams,
106
+ }), [props.config, props.itemsStateAndParams]);
103
107
  const getItemsMeta = react_1.default.useCallback((pluginsRefs) => {
104
108
  return pluginsRefs
105
109
  .map((ref) => {
@@ -134,6 +138,7 @@ function useMemoStateContext(props) {
134
138
  settings: props.settings,
135
139
  itemsState,
136
140
  itemsParams,
141
+ itemsActionParams,
137
142
  registerManager: props.registerManager,
138
143
  onItemStateAndParamsChange,
139
144
  removeItem: onItemRemove,
@@ -155,6 +160,7 @@ function useMemoStateContext(props) {
155
160
  props.settings,
156
161
  itemsState,
157
162
  itemsParams,
163
+ itemsActionParams,
158
164
  props.registerManager,
159
165
  onItemStateAndParamsChange,
160
166
  onItemRemove,
@@ -1,2 +1,3 @@
1
1
  export declare const CURRENT_VERSION = 2;
2
2
  export declare const META_KEY = "__meta__";
3
+ export declare const ACTION_PARAM_PREFIX = "_ap_";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.META_KEY = exports.CURRENT_VERSION = void 0;
3
+ exports.ACTION_PARAM_PREFIX = exports.META_KEY = exports.CURRENT_VERSION = void 0;
4
4
  exports.CURRENT_VERSION = 2;
5
5
  exports.META_KEY = '__meta__';
6
+ exports.ACTION_PARAM_PREFIX = '_ap_';
@@ -25,11 +25,17 @@ export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams
25
25
  itemsStateAndParams: ItemsStateAndParams;
26
26
  isFirstVersion: boolean;
27
27
  }): Record<string, string[]>;
28
- export declare function mergeParamsWithAliases({ aliases, namespace, params, }: {
28
+ export declare function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }: {
29
29
  aliases: ConfigAliases;
30
30
  namespace: string;
31
31
  params: StringParams;
32
+ actionParams?: StringParams;
32
33
  }): StringParams;
34
+ export declare function mergeParamsNamesWithPairAliases({ aliases, namespace, paramsNames, }: {
35
+ aliases: ConfigAliases;
36
+ namespace: string;
37
+ paramsNames: Array<string>;
38
+ }): Array<Array<string>>;
33
39
  export declare function getInitialItemsStateAndParamsMeta(): StateAndParamsMetaData;
34
40
  interface ChangeQueueArg {
35
41
  id: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.deleteFromQueue = exports.addToQueue = exports.getInitialItemsStateAndParamsMeta = exports.mergeParamsNamesWithPairAliases = exports.mergeParamsWithAliases = exports.getMapItemsIgnores = exports.resolveItemInnerId = exports.formQueueData = 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"));
@@ -125,10 +125,9 @@ function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersio
125
125
  }, {});
126
126
  }
127
127
  exports.getMapItemsIgnores = getMapItemsIgnores;
128
- function mergeParamsWithAliases({ aliases, namespace, params, }) {
129
- const aliasesByNamespace = (0, get_1.default)(aliases, [namespace], []);
130
- return Object.keys(params).reduce((matchedParams, paramKey) => {
131
- const paramValue = params[paramKey];
128
+ function mergeParamsItemsWithAliases(aliasesByNamespace, items) {
129
+ return Object.keys(items).reduce((matchedParams, paramKey) => {
130
+ const paramValue = items[paramKey];
132
131
  const collectAliasesParamsKeys = aliasesByNamespace.reduce((collect, group) => {
133
132
  return group.includes(paramKey) ? collect.concat(group) : collect;
134
133
  }, [paramKey]);
@@ -137,7 +136,24 @@ function mergeParamsWithAliases({ aliases, namespace, params, }) {
137
136
  }, {}));
138
137
  }, {});
139
138
  }
139
+ function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }) {
140
+ const aliasesByNamespace = (0, get_1.default)(aliases, [namespace], []);
141
+ let actionParamsWithAliases = {};
142
+ if (actionParams && Object.entries(actionParams).length) {
143
+ actionParamsWithAliases = mergeParamsItemsWithAliases(aliasesByNamespace, actionParams);
144
+ }
145
+ return mergeParamsItemsWithAliases(aliasesByNamespace, Object.assign(Object.assign({}, (params || {})), actionParamsWithAliases));
146
+ }
140
147
  exports.mergeParamsWithAliases = mergeParamsWithAliases;
148
+ function mergeParamsNamesWithPairAliases({ aliases, namespace, paramsNames, }) {
149
+ const aliasesByNamespace = (0, get_1.default)(aliases, [namespace], []);
150
+ const res = [];
151
+ paramsNames.forEach((paramName) => {
152
+ res.push(...aliasesByNamespace.filter((item) => item.includes(paramName)));
153
+ });
154
+ return res;
155
+ }
156
+ exports.mergeParamsNamesWithPairAliases = mergeParamsNamesWithPairAliases;
141
157
  function getInitialItemsStateAndParamsMeta() {
142
158
  return {
143
159
  queue: [],
@@ -1,4 +1,4 @@
1
- import { GlobalParams, Config, ItemsStateAndParams, PluginBase, StringParams, ItemState } from '../types';
1
+ import { GlobalParams, Config, ItemsStateAndParams, PluginBase, StringParams, ItemState, ItemStateAndParams } from '../types';
2
2
  export interface GetItemsParamsArg {
3
3
  defaultGlobalParams: GlobalParams;
4
4
  globalParams: GlobalParams;
@@ -8,9 +8,32 @@ export interface GetItemsParamsArg {
8
8
  }
9
9
  declare type GetItemsParamsReturn = Record<string, StringParams>;
10
10
  export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): GetItemsParamsReturn;
11
+ export declare function getItemsActionParams({ config, itemsStateAndParams, settings, }: {
12
+ config: Config;
13
+ itemsStateAndParams: ItemsStateAndParams;
14
+ settings?: {
15
+ returnPrefix: boolean;
16
+ };
17
+ }): GetItemsParamsReturn;
11
18
  export declare function getItemsState({ config, itemsStateAndParams, }: {
12
19
  config: Config;
13
20
  itemsStateAndParams: ItemsStateAndParams;
14
21
  }): Record<string, ItemState>;
15
22
  export declare function getItemsStateAndParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): ItemsStateAndParams;
23
+ export declare function pickActionParamsFromParams(params: ItemStateAndParams['params'], returnWithPrefix?: boolean): StringParams;
24
+ /**
25
+ * public function for getting params from object without actionParams
26
+ * @param params
27
+ */
28
+ export declare function pickExceptActionParamsFromParams(params: ItemStateAndParams['params']): StringParams;
29
+ /**
30
+ * public function for transforming object to actionParams format
31
+ * @param params
32
+ */
33
+ export declare function transformParamsToActionParams(params: ItemStateAndParams['params']): StringParams;
34
+ /**
35
+ * check if ItemStateAndParams object has actionParams in params or state field
36
+ * @param stateAndParams
37
+ */
38
+ export declare function hasActionParams(stateAndParams: ItemStateAndParams): {};
16
39
  export {};
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getItemsStateAndParams = exports.getItemsState = exports.getItemsParams = void 0;
3
+ exports.hasActionParams = exports.transformParamsToActionParams = exports.pickExceptActionParamsFromParams = exports.pickActionParamsFromParams = exports.getItemsStateAndParams = exports.getItemsState = exports.getItemsActionParams = exports.getItemsParams = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
6
- const helpers_1 = require("./helpers");
6
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
7
7
  const constants_1 = require("../constants");
8
+ const helpers_1 = require("./helpers");
8
9
  function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
9
10
  const { aliases, connections } = config;
11
+ const actionParams = getItemsActionParams({
12
+ config,
13
+ itemsStateAndParams,
14
+ }) || {};
10
15
  const items = (0, helpers_1.prerenderItems)({ items: config.items, plugins });
11
16
  const isFirstVersion = (0, helpers_1.getCurrentVersion)(itemsStateAndParams) === 1;
12
17
  const queueData = isFirstVersion
@@ -29,7 +34,21 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
29
34
  return items.reduce((itemsParams, item) => {
30
35
  var _a;
31
36
  const { id, namespace } = item;
32
- const getMergedParams = (params) => (0, helpers_1.mergeParamsWithAliases)({ aliases, namespace, params: params || {} });
37
+ let actions = {};
38
+ for (const [key, val] of Object.entries(actionParams)) {
39
+ if (!actions) {
40
+ actions = {};
41
+ }
42
+ if (key !== id) {
43
+ actions = Object.assign(Object.assign({}, actions), val);
44
+ }
45
+ }
46
+ const getMergedParams = (params, actions) => (0, helpers_1.mergeParamsWithAliases)({
47
+ aliases,
48
+ namespace,
49
+ params: params || {},
50
+ actionParams: actions,
51
+ });
33
52
  const itemIgnores = mapItemsIgnores[id];
34
53
  const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
35
54
  let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
@@ -47,13 +66,21 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
47
66
  if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
48
67
  return queueParams;
49
68
  }
50
- return Object.assign(Object.assign({}, queueParams), getMergedParams(data.params));
69
+ return Object.assign(Object.assign({}, queueParams), getMergedParams(data.params, actions));
51
70
  }, {}));
52
71
  }
53
72
  return Object.assign(Object.assign({}, itemsParams), { [id]: itemParams });
54
73
  }, {});
55
74
  }
56
75
  exports.getItemsParams = getItemsParams;
76
+ function getItemsActionParams({ config, itemsStateAndParams, settings, }) {
77
+ return config.items.reduce((acc, { id }) => {
78
+ var _a;
79
+ const params = (_a = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.params;
80
+ return Object.assign(Object.assign({}, acc), { [id]: pickActionParamsFromParams(params, Boolean(settings === null || settings === void 0 ? void 0 : settings.returnPrefix)) || {} });
81
+ }, {});
82
+ }
83
+ exports.getItemsActionParams = getItemsActionParams;
57
84
  function getItemsState({ config, itemsStateAndParams, }) {
58
85
  return config.items.reduce((acc, { id }) => {
59
86
  var _a;
@@ -72,6 +99,13 @@ function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams = {}, c
72
99
  });
73
100
  const state = getItemsState({ config, itemsStateAndParams });
74
101
  const uniqIds = new Set([...Object.keys(params), ...Object.keys(state)]);
102
+ const actionParams = getItemsActionParams({
103
+ config,
104
+ itemsStateAndParams,
105
+ settings: {
106
+ returnPrefix: true,
107
+ },
108
+ });
75
109
  const result = Array.from(uniqIds).reduce((acc, id) => {
76
110
  const data = {};
77
111
  if (id in params) {
@@ -80,6 +114,12 @@ function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams = {}, c
80
114
  if (id in state) {
81
115
  data.state = state[id];
82
116
  }
117
+ if (id in actionParams) {
118
+ if (!data.params) {
119
+ data.params = {};
120
+ }
121
+ data.params = Object.assign(Object.assign({}, data.params), actionParams[id]);
122
+ }
83
123
  return Object.assign(Object.assign({}, acc), { [id]: data });
84
124
  }, {});
85
125
  const version = (0, helpers_1.getCurrentVersion)(itemsStateAndParams);
@@ -92,3 +132,68 @@ function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams = {}, c
92
132
  return Object.assign(Object.assign({}, meta), result);
93
133
  }
94
134
  exports.getItemsStateAndParams = getItemsStateAndParams;
135
+ function pickActionParamsFromParams(params, returnWithPrefix) {
136
+ if (!params || (0, isEmpty_1.default)(params)) {
137
+ return {};
138
+ }
139
+ const actionParams = {};
140
+ for (const [key, val] of Object.entries(params)) {
141
+ // starts with actionParams prefix (from'_ap_')
142
+ if (key.indexOf(constants_1.ACTION_PARAM_PREFIX) === 0) {
143
+ const paramName = returnWithPrefix ? key : key.substr(constants_1.ACTION_PARAM_PREFIX.length);
144
+ actionParams[paramName] = val;
145
+ }
146
+ }
147
+ return actionParams;
148
+ }
149
+ exports.pickActionParamsFromParams = pickActionParamsFromParams;
150
+ /**
151
+ * public function for getting params from object without actionParams
152
+ * @param params
153
+ */
154
+ function pickExceptActionParamsFromParams(params) {
155
+ if (!params || (0, isEmpty_1.default)(params)) {
156
+ return {};
157
+ }
158
+ const onlyParams = {};
159
+ for (const [key, val] of Object.entries(params)) {
160
+ if (!key.includes(constants_1.ACTION_PARAM_PREFIX)) {
161
+ onlyParams[key] = val;
162
+ }
163
+ }
164
+ return onlyParams;
165
+ }
166
+ exports.pickExceptActionParamsFromParams = pickExceptActionParamsFromParams;
167
+ /**
168
+ * public function for transforming object to actionParams format
169
+ * @param params
170
+ */
171
+ function transformParamsToActionParams(params) {
172
+ if (!params || (0, isEmpty_1.default)(params)) {
173
+ return {};
174
+ }
175
+ const actionParams = {};
176
+ for (const [key, val] of Object.entries(params)) {
177
+ actionParams[`${constants_1.ACTION_PARAM_PREFIX}${key}`] = val;
178
+ }
179
+ return actionParams;
180
+ }
181
+ exports.transformParamsToActionParams = transformParamsToActionParams;
182
+ /**
183
+ * check if object contains actionParams
184
+ * @param conf
185
+ */
186
+ function hasActionParam(conf) {
187
+ return Boolean(Object.keys(conf || {}).find((key) => key.indexOf(constants_1.ACTION_PARAM_PREFIX) === 0));
188
+ }
189
+ /**
190
+ * check if ItemStateAndParams object has actionParams in params or state field
191
+ * @param stateAndParams
192
+ */
193
+ function hasActionParams(stateAndParams) {
194
+ if (!stateAndParams || (0, isEmpty_1.default)(stateAndParams)) {
195
+ return {};
196
+ }
197
+ return hasActionParam(stateAndParams.params) || hasActionParam(stateAndParams.state);
198
+ }
199
+ exports.hasActionParams = hasActionParams;
@@ -7,6 +7,7 @@ export interface PluginWidgetProps {
7
7
  editMode: boolean;
8
8
  params: StringParams;
9
9
  state: ItemState;
10
+ actionParams: StringParams;
10
11
  onStateAndParamsChange: (stateAndParams: ItemStateAndParams) => void;
11
12
  width: number;
12
13
  height: number;
@@ -6,6 +6,7 @@ const immutability_helper_1 = tslib_1.__importStar(require("immutability-helper"
6
6
  const hashids_1 = tslib_1.__importDefault(require("hashids"));
7
7
  const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
8
8
  const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
9
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
9
10
  const shared_1 = require("../shared");
10
11
  const constants_1 = require("../constants");
11
12
  (0, immutability_helper_1.extend)('$auto', (value, object) => (object ? (0, immutability_helper_1.default)(object, value) : (0, immutability_helper_1.default)({}, value)));
@@ -64,9 +65,14 @@ function removeItemVersion1({ id, config, itemsStateAndParams }) {
64
65
  itemsStateAndParams: newItemsStateAndParams,
65
66
  };
66
67
  }
67
- function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
68
+ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, paramsSettings) {
68
69
  var _a;
70
+ const paramsTypeName = (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.type) || 'params';
71
+ const isActionParamsMode = paramsTypeName === 'actionParams';
69
72
  let allowedParams = {};
73
+ const stateParamsConf = isActionParamsMode
74
+ ? (0, shared_1.pickActionParamsFromParams)(stateAndParams.params, false)
75
+ : stateAndParams.params;
70
76
  if ((0, shared_1.isItemWithTabs)(item)) {
71
77
  let tab;
72
78
  if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
@@ -76,14 +82,19 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
76
82
  const tabId = (0, shared_1.resolveItemInnerId)({ item, itemsStateAndParams });
77
83
  tab = item.data.tabs.find(({ id }) => id === tabId);
78
84
  }
79
- allowedParams = (0, pick_1.default)(stateAndParams.params, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
85
+ allowedParams = (0, pick_1.default)(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
80
86
  }
81
87
  else {
82
- allowedParams = (0, pick_1.default)(stateAndParams.params, Object.keys(item.defaults || {}));
88
+ allowedParams = (0, pick_1.default)(stateParamsConf, Object.keys(item.defaults || {}));
83
89
  }
84
- if (Object.keys(allowedParams).length !== Object.keys(stateAndParams.params || {}).length) {
90
+ if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
85
91
  console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
86
92
  }
93
+ if (isActionParamsMode) {
94
+ return (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.returnPrefix)
95
+ ? (0, shared_1.transformParamsToActionParams)(allowedParams)
96
+ : allowedParams;
97
+ }
87
98
  return allowedParams;
88
99
  }
89
100
  function changeStateAndParamsVersion1({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
@@ -203,7 +214,7 @@ class UpdateManager {
203
214
  });
204
215
  }
205
216
  static changeStateAndParams({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
206
- var _a, _b;
217
+ var _a, _b, _c, _d;
207
218
  if ((0, shared_1.getCurrentVersion)(itemsStateAndParams) === 1) {
208
219
  return changeStateAndParamsVersion1({
209
220
  id: initiatorId,
@@ -213,7 +224,7 @@ class UpdateManager {
213
224
  });
214
225
  }
215
226
  const hasState = 'state' in stateAndParams;
216
- const { items } = config;
227
+ const { items, aliases } = config;
217
228
  const itemsIds = items.map(({ id: itemId }) => itemId);
218
229
  const itemsStateAndParamsIds = Object.keys((0, omit_1.default)(itemsStateAndParams, [shared_1.META_KEY]));
219
230
  const unusedIds = itemsStateAndParamsIds.filter((id) => !itemsIds.includes(id));
@@ -221,27 +232,151 @@ class UpdateManager {
221
232
  const newTabId = (_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId;
222
233
  const isTabSwitched = (0, shared_1.isItemWithTabs)(initiatorItem) && Boolean(newTabId);
223
234
  const currentMeta = (0, shared_1.getItemsStateAndParamsMeta)(itemsStateAndParams);
224
- if ('params' in stateAndParams) {
235
+ const hasChangedActionParams = (0, shared_1.hasActionParams)(stateAndParams);
236
+ const actionParamsAll = (0, shared_1.getItemsActionParams)({
237
+ config,
238
+ itemsStateAndParams,
239
+ }) || {};
240
+ const notEmptyActionParams = {};
241
+ for (const [key, val] of Object.entries(actionParamsAll)) {
242
+ if (!(0, isEmpty_1.default)(val)) {
243
+ notEmptyActionParams[key] = val;
244
+ }
245
+ }
246
+ if (hasChangedActionParams) {
247
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
248
+ const actionParamsWithAliasesNames = {};
249
+ for (const [widgetIdKey, itemActionParams] of Object.entries(notEmptyActionParams)) {
250
+ const aliasesNames = (0, shared_1.mergeParamsNamesWithPairAliases)({
251
+ aliases,
252
+ namespace: initiatorItem.namespace,
253
+ paramsNames: Object.keys(itemActionParams),
254
+ });
255
+ actionParamsWithAliasesNames[widgetIdKey] = [];
256
+ // убрать все триггеры, которые есть в aliasesNames
257
+ if (aliasesNames.length) {
258
+ actionParamsWithAliasesNames[widgetIdKey] =
259
+ // @ts-ignore
260
+ actionParamsWithAliasesNames[widgetIdKey].concat(aliasesNames);
261
+ }
262
+ }
263
+ const tabId = (0, shared_1.isItemWithTabs)(initiatorItem)
264
+ ? newTabId || (0, shared_1.resolveItemInnerId)({ item: initiatorItem, itemsStateAndParams })
265
+ : undefined;
266
+ const meta = (0, shared_1.addToQueue)({ id: initiatorId, tabId, config, itemsStateAndParams });
267
+ const paramsFromStateAndParams = ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params) || {};
268
+ const newParams = !(0, isEmpty_1.default)(paramsFromStateAndParams) || !(0, isEmpty_1.default)(allowableActionParams)
269
+ ? { params: Object.assign(Object.assign({}, paramsFromStateAndParams), allowableActionParams) }
270
+ : {};
271
+ const obj = {
272
+ [initiatorId]: {
273
+ $set: Object.assign(Object.assign({}, newParams), (hasState ? { state: { $set: stateAndParams.state } } : {})),
274
+ },
275
+ [shared_1.META_KEY]: { $set: meta },
276
+ };
277
+ const res = (0, immutability_helper_1.default)(itemsStateAndParams, obj);
278
+ return res;
279
+ }
280
+ else if ('params' in stateAndParams) {
225
281
  const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
282
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
283
+ const actionParamsWithAliasesNames = {};
284
+ for (const [widgetIdKey, itemActionParams] of Object.entries(notEmptyActionParams)) {
285
+ const aliasesNames = (0, shared_1.mergeParamsNamesWithPairAliases)({
286
+ aliases,
287
+ namespace: initiatorItem.namespace,
288
+ paramsNames: Object.keys(itemActionParams),
289
+ });
290
+ actionParamsWithAliasesNames[widgetIdKey] = [];
291
+ // убрать все триггеры, которые есть в aliasesNames
292
+ if (aliasesNames.length) {
293
+ actionParamsWithAliasesNames[widgetIdKey] =
294
+ // @ts-ignore
295
+ actionParamsWithAliasesNames[widgetIdKey].concat(aliasesNames);
296
+ }
297
+ }
298
+ let actionParamsToClear = {};
299
+ const actionParamsToDelete = {};
300
+ Object.keys(allowableParams).forEach((paramName) => {
301
+ for (const [widgetIdKey, itemActionParams] of Object.entries(notEmptyActionParams)) {
302
+ for (const [paramKey, paramVal] of Object.entries(itemActionParams)) {
303
+ // paramKey: Year; Country
304
+ const actionParamInAliases = actionParamsWithAliasesNames[widgetIdKey].find((row) => row.includes(paramKey)) || [];
305
+ // @ts-ignore
306
+ const hasAllowableParamInAliases = actionParamInAliases.includes(paramName);
307
+ if (hasAllowableParamInAliases &&
308
+ notEmptyActionParams[widgetIdKey][paramKey]) {
309
+ // @ts-ignore
310
+ if (!actionParamsToDelete[widgetIdKey]) {
311
+ // @ts-ignore
312
+ actionParamsToDelete[widgetIdKey] = {};
313
+ }
314
+ // @ts-ignore
315
+ actionParamsToDelete[widgetIdKey] = Object.assign(Object.assign({}, actionParamsToDelete[widgetIdKey]), { [`${shared_1.ACTION_PARAM_PREFIX}${paramKey}`]: paramVal });
316
+ delete notEmptyActionParams[widgetIdKey][paramKey];
317
+ }
318
+ }
319
+ actionParamsToClear = {
320
+ [widgetIdKey]: notEmptyActionParams[widgetIdKey],
321
+ };
322
+ }
323
+ });
324
+ for (const [widgetIdKey, itemActionParams] of Object.entries(actionParamsToClear)) {
325
+ const itemActionParamsWithPrefix = (0, shared_1.transformParamsToActionParams)(itemActionParams);
326
+ let updatingParams = {};
327
+ // @ts-ignore
328
+ if (!(0, isEmpty_1.default)((_c = itemsStateAndParams[widgetIdKey]) === null || _c === void 0 ? void 0 : _c.params)) {
329
+ // @ts-ignore
330
+ updatingParams = Object.assign({}, itemsStateAndParams[widgetIdKey].params);
331
+ if (!(0, isEmpty_1.default)(actionParamsToDelete)) {
332
+ // @ts-ignore
333
+ Object.keys(actionParamsToDelete[widgetIdKey] || []).forEach((keyToDelete) => {
334
+ if (keyToDelete in updatingParams) {
335
+ // @ts-ignore
336
+ delete updatingParams[keyToDelete];
337
+ }
338
+ });
339
+ }
340
+ }
341
+ const newParamsWithClear = Object.assign(Object.assign({}, updatingParams), itemActionParamsWithPrefix);
342
+ actionParamsToClear[widgetIdKey] = {
343
+ $set: {
344
+ params: newParamsWithClear,
345
+ },
346
+ };
347
+ }
226
348
  const tabId = (0, shared_1.isItemWithTabs)(initiatorItem)
227
349
  ? newTabId || (0, shared_1.resolveItemInnerId)({ item: initiatorItem, itemsStateAndParams })
228
350
  : undefined;
229
351
  const meta = (0, shared_1.addToQueue)({ id: initiatorId, tabId, config, itemsStateAndParams });
230
- let commandUpdateParams = ((_b = itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params)
352
+ let commandUpdateParams = ((_d = itemsStateAndParams[initiatorId]) === null || _d === void 0 ? void 0 : _d.params)
231
353
  ? '$merge'
232
354
  : '$set';
233
355
  if (isTabSwitched) {
234
356
  commandUpdateParams = '$set';
235
357
  }
236
- return (0, immutability_helper_1.default)(itemsStateAndParams, {
237
- $unset: unusedIds,
238
- [initiatorId]: {
239
- $auto: Object.assign({ params: {
240
- [commandUpdateParams]: allowableParams,
241
- } }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
242
- },
243
- [shared_1.META_KEY]: { $set: meta },
244
- });
358
+ const actionParamsCommand = (0, shared_1.hasActionParams)(itemsStateAndParams[initiatorId])
359
+ ? '$merge'
360
+ : '$set';
361
+ let setObj = null;
362
+ if (commandUpdateParams === '$set' && actionParamsCommand === '$set') {
363
+ setObj = {
364
+ params: Object.assign(Object.assign({}, allowableParams), (hasChangedActionParams ? allowableActionParams : {})),
365
+ };
366
+ }
367
+ const obj = Object.assign(Object.assign({ $unset: unusedIds, [initiatorId]: {
368
+ $auto: Object.assign(Object.assign({}, (setObj
369
+ ? {
370
+ $set: setObj,
371
+ }
372
+ : {
373
+ params: {
374
+ [commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
375
+ },
376
+ })), (hasState ? { state: { $set: stateAndParams.state } } : {})),
377
+ } }, actionParamsToClear), { [shared_1.META_KEY]: { $set: meta } });
378
+ const res = (0, immutability_helper_1.default)(itemsStateAndParams, obj);
379
+ return res;
245
380
  }
246
381
  else if (hasState) {
247
382
  let metaSpec = {};
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
+ import isEmpty from 'lodash/isEmpty';
2
3
  import { DashKitContext } from '../context/DashKitContext';
3
4
  import PropTypes from 'prop-types';
5
+ import { transformParamsToActionParams } from '../shared';
4
6
  export function prepareItem(Component) {
5
7
  var _a;
6
8
  return _a = class PrepareItem extends React.Component {
@@ -23,12 +25,16 @@ export function prepareItem(Component) {
23
25
  }
24
26
  render() {
25
27
  const { id, width, height, item, adjustWidgetLayout, layout } = this.props;
26
- const { itemsState, itemsParams, registerManager, settings, context, editMode } = this.context;
28
+ const { itemsState, itemsParams, itemsActionParams, registerManager, settings, context, editMode, } = this.context;
29
+ const actionParams = transformParamsToActionParams(itemsActionParams[id]);
30
+ const resultParams = isEmpty(actionParams)
31
+ ? itemsParams[id]
32
+ : Object.assign(Object.assign({}, itemsParams[id]), actionParams);
27
33
  const { type, data, defaults, namespace } = item;
28
34
  const rendererProps = {
29
35
  data,
30
36
  editMode,
31
- params: itemsParams[id],
37
+ params: resultParams,
32
38
  state: itemsState[id],
33
39
  onStateAndParamsChange: this._onStateAndParamsChange,
34
40
  width,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { DashKitContext } from '../context/DashKitContext';
3
3
  import { UpdateManager } from '../utils';
4
- import { getItemsParams, getItemsState } from '../shared';
4
+ import { getItemsParams, getItemsState, getItemsActionParams } from '../shared';
5
5
  import isEqual from 'lodash/isEqual';
6
6
  function useMemoStateContext(props) {
7
7
  // так как мы не хотим хранить параметры виджета с активированной автовысотой в сторе и на сервере, актуальный
@@ -96,6 +96,10 @@ function useMemoStateContext(props) {
96
96
  config: props.config,
97
97
  itemsStateAndParams: props.itemsStateAndParams,
98
98
  }), [props.config, props.itemsStateAndParams]);
99
+ const itemsActionParams = React.useMemo(() => getItemsActionParams({
100
+ config: props.config,
101
+ itemsStateAndParams: props.itemsStateAndParams,
102
+ }), [props.config, props.itemsStateAndParams]);
99
103
  const getItemsMeta = React.useCallback((pluginsRefs) => {
100
104
  return pluginsRefs
101
105
  .map((ref) => {
@@ -130,6 +134,7 @@ function useMemoStateContext(props) {
130
134
  settings: props.settings,
131
135
  itemsState,
132
136
  itemsParams,
137
+ itemsActionParams,
133
138
  registerManager: props.registerManager,
134
139
  onItemStateAndParamsChange,
135
140
  removeItem: onItemRemove,
@@ -151,6 +156,7 @@ function useMemoStateContext(props) {
151
156
  props.settings,
152
157
  itemsState,
153
158
  itemsParams,
159
+ itemsActionParams,
154
160
  props.registerManager,
155
161
  onItemStateAndParamsChange,
156
162
  onItemRemove,
@@ -1,2 +1,3 @@
1
1
  export declare const CURRENT_VERSION = 2;
2
2
  export declare const META_KEY = "__meta__";
3
+ export declare const ACTION_PARAM_PREFIX = "_ap_";
@@ -1,2 +1,3 @@
1
1
  export const CURRENT_VERSION = 2;
2
2
  export const META_KEY = '__meta__';
3
+ export const ACTION_PARAM_PREFIX = '_ap_';
@@ -25,11 +25,17 @@ export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams
25
25
  itemsStateAndParams: ItemsStateAndParams;
26
26
  isFirstVersion: boolean;
27
27
  }): Record<string, string[]>;
28
- export declare function mergeParamsWithAliases({ aliases, namespace, params, }: {
28
+ export declare function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }: {
29
29
  aliases: ConfigAliases;
30
30
  namespace: string;
31
31
  params: StringParams;
32
+ actionParams?: StringParams;
32
33
  }): StringParams;
34
+ export declare function mergeParamsNamesWithPairAliases({ aliases, namespace, paramsNames, }: {
35
+ aliases: ConfigAliases;
36
+ namespace: string;
37
+ paramsNames: Array<string>;
38
+ }): Array<Array<string>>;
33
39
  export declare function getInitialItemsStateAndParamsMeta(): StateAndParamsMetaData;
34
40
  interface ChangeQueueArg {
35
41
  id: string;
@@ -114,10 +114,9 @@ export function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirs
114
114
  .map(({ to }) => invertedMapIds[to]) });
115
115
  }, {});
116
116
  }
117
- export function mergeParamsWithAliases({ aliases, namespace, params, }) {
118
- const aliasesByNamespace = get(aliases, [namespace], []);
119
- return Object.keys(params).reduce((matchedParams, paramKey) => {
120
- const paramValue = params[paramKey];
117
+ function mergeParamsItemsWithAliases(aliasesByNamespace, items) {
118
+ return Object.keys(items).reduce((matchedParams, paramKey) => {
119
+ const paramValue = items[paramKey];
121
120
  const collectAliasesParamsKeys = aliasesByNamespace.reduce((collect, group) => {
122
121
  return group.includes(paramKey) ? collect.concat(group) : collect;
123
122
  }, [paramKey]);
@@ -126,6 +125,22 @@ export function mergeParamsWithAliases({ aliases, namespace, params, }) {
126
125
  }, {}));
127
126
  }, {});
128
127
  }
128
+ export function mergeParamsWithAliases({ aliases, namespace, params, actionParams, }) {
129
+ const aliasesByNamespace = get(aliases, [namespace], []);
130
+ let actionParamsWithAliases = {};
131
+ if (actionParams && Object.entries(actionParams).length) {
132
+ actionParamsWithAliases = mergeParamsItemsWithAliases(aliasesByNamespace, actionParams);
133
+ }
134
+ return mergeParamsItemsWithAliases(aliasesByNamespace, Object.assign(Object.assign({}, (params || {})), actionParamsWithAliases));
135
+ }
136
+ export function mergeParamsNamesWithPairAliases({ aliases, namespace, paramsNames, }) {
137
+ const aliasesByNamespace = get(aliases, [namespace], []);
138
+ const res = [];
139
+ paramsNames.forEach((paramName) => {
140
+ res.push(...aliasesByNamespace.filter((item) => item.includes(paramName)));
141
+ });
142
+ return res;
143
+ }
129
144
  export function getInitialItemsStateAndParamsMeta() {
130
145
  return {
131
146
  queue: [],
@@ -1,4 +1,4 @@
1
- import { GlobalParams, Config, ItemsStateAndParams, PluginBase, StringParams, ItemState } from '../types';
1
+ import { GlobalParams, Config, ItemsStateAndParams, PluginBase, StringParams, ItemState, ItemStateAndParams } from '../types';
2
2
  export interface GetItemsParamsArg {
3
3
  defaultGlobalParams: GlobalParams;
4
4
  globalParams: GlobalParams;
@@ -8,9 +8,32 @@ export interface GetItemsParamsArg {
8
8
  }
9
9
  declare type GetItemsParamsReturn = Record<string, StringParams>;
10
10
  export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): GetItemsParamsReturn;
11
+ export declare function getItemsActionParams({ config, itemsStateAndParams, settings, }: {
12
+ config: Config;
13
+ itemsStateAndParams: ItemsStateAndParams;
14
+ settings?: {
15
+ returnPrefix: boolean;
16
+ };
17
+ }): GetItemsParamsReturn;
11
18
  export declare function getItemsState({ config, itemsStateAndParams, }: {
12
19
  config: Config;
13
20
  itemsStateAndParams: ItemsStateAndParams;
14
21
  }): Record<string, ItemState>;
15
22
  export declare function getItemsStateAndParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): ItemsStateAndParams;
23
+ export declare function pickActionParamsFromParams(params: ItemStateAndParams['params'], returnWithPrefix?: boolean): StringParams;
24
+ /**
25
+ * public function for getting params from object without actionParams
26
+ * @param params
27
+ */
28
+ export declare function pickExceptActionParamsFromParams(params: ItemStateAndParams['params']): StringParams;
29
+ /**
30
+ * public function for transforming object to actionParams format
31
+ * @param params
32
+ */
33
+ export declare function transformParamsToActionParams(params: ItemStateAndParams['params']): StringParams;
34
+ /**
35
+ * check if ItemStateAndParams object has actionParams in params or state field
36
+ * @param stateAndParams
37
+ */
38
+ export declare function hasActionParams(stateAndParams: ItemStateAndParams): {};
16
39
  export {};
@@ -1,8 +1,13 @@
1
1
  import groupBy from 'lodash/groupBy';
2
+ import isEmpty from 'lodash/isEmpty';
3
+ import { ACTION_PARAM_PREFIX, META_KEY } from '../constants';
2
4
  import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, } from './helpers';
3
- import { META_KEY } from '../constants';
4
5
  export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
5
6
  const { aliases, connections } = config;
7
+ const actionParams = getItemsActionParams({
8
+ config,
9
+ itemsStateAndParams,
10
+ }) || {};
6
11
  const items = prerenderItems({ items: config.items, plugins });
7
12
  const isFirstVersion = getCurrentVersion(itemsStateAndParams) === 1;
8
13
  const queueData = isFirstVersion
@@ -25,7 +30,21 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
25
30
  return items.reduce((itemsParams, item) => {
26
31
  var _a;
27
32
  const { id, namespace } = item;
28
- const getMergedParams = (params) => mergeParamsWithAliases({ aliases, namespace, params: params || {} });
33
+ let actions = {};
34
+ for (const [key, val] of Object.entries(actionParams)) {
35
+ if (!actions) {
36
+ actions = {};
37
+ }
38
+ if (key !== id) {
39
+ actions = Object.assign(Object.assign({}, actions), val);
40
+ }
41
+ }
42
+ const getMergedParams = (params, actions) => mergeParamsWithAliases({
43
+ aliases,
44
+ namespace,
45
+ params: params || {},
46
+ actionParams: actions,
47
+ });
29
48
  const itemIgnores = mapItemsIgnores[id];
30
49
  const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
31
50
  let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
@@ -43,12 +62,19 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
43
62
  if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
44
63
  return queueParams;
45
64
  }
46
- return Object.assign(Object.assign({}, queueParams), getMergedParams(data.params));
65
+ return Object.assign(Object.assign({}, queueParams), getMergedParams(data.params, actions));
47
66
  }, {}));
48
67
  }
49
68
  return Object.assign(Object.assign({}, itemsParams), { [id]: itemParams });
50
69
  }, {});
51
70
  }
71
+ export function getItemsActionParams({ config, itemsStateAndParams, settings, }) {
72
+ return config.items.reduce((acc, { id }) => {
73
+ var _a;
74
+ const params = (_a = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.params;
75
+ return Object.assign(Object.assign({}, acc), { [id]: pickActionParamsFromParams(params, Boolean(settings === null || settings === void 0 ? void 0 : settings.returnPrefix)) || {} });
76
+ }, {});
77
+ }
52
78
  export function getItemsState({ config, itemsStateAndParams, }) {
53
79
  return config.items.reduce((acc, { id }) => {
54
80
  var _a;
@@ -66,6 +92,13 @@ export function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams
66
92
  });
67
93
  const state = getItemsState({ config, itemsStateAndParams });
68
94
  const uniqIds = new Set([...Object.keys(params), ...Object.keys(state)]);
95
+ const actionParams = getItemsActionParams({
96
+ config,
97
+ itemsStateAndParams,
98
+ settings: {
99
+ returnPrefix: true,
100
+ },
101
+ });
69
102
  const result = Array.from(uniqIds).reduce((acc, id) => {
70
103
  const data = {};
71
104
  if (id in params) {
@@ -74,6 +107,12 @@ export function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams
74
107
  if (id in state) {
75
108
  data.state = state[id];
76
109
  }
110
+ if (id in actionParams) {
111
+ if (!data.params) {
112
+ data.params = {};
113
+ }
114
+ data.params = Object.assign(Object.assign({}, data.params), actionParams[id]);
115
+ }
77
116
  return Object.assign(Object.assign({}, acc), { [id]: data });
78
117
  }, {});
79
118
  const version = getCurrentVersion(itemsStateAndParams);
@@ -85,3 +124,64 @@ export function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams
85
124
  };
86
125
  return Object.assign(Object.assign({}, meta), result);
87
126
  }
127
+ export function pickActionParamsFromParams(params, returnWithPrefix) {
128
+ if (!params || isEmpty(params)) {
129
+ return {};
130
+ }
131
+ const actionParams = {};
132
+ for (const [key, val] of Object.entries(params)) {
133
+ // starts with actionParams prefix (from'_ap_')
134
+ if (key.indexOf(ACTION_PARAM_PREFIX) === 0) {
135
+ const paramName = returnWithPrefix ? key : key.substr(ACTION_PARAM_PREFIX.length);
136
+ actionParams[paramName] = val;
137
+ }
138
+ }
139
+ return actionParams;
140
+ }
141
+ /**
142
+ * public function for getting params from object without actionParams
143
+ * @param params
144
+ */
145
+ export function pickExceptActionParamsFromParams(params) {
146
+ if (!params || isEmpty(params)) {
147
+ return {};
148
+ }
149
+ const onlyParams = {};
150
+ for (const [key, val] of Object.entries(params)) {
151
+ if (!key.includes(ACTION_PARAM_PREFIX)) {
152
+ onlyParams[key] = val;
153
+ }
154
+ }
155
+ return onlyParams;
156
+ }
157
+ /**
158
+ * public function for transforming object to actionParams format
159
+ * @param params
160
+ */
161
+ export function transformParamsToActionParams(params) {
162
+ if (!params || isEmpty(params)) {
163
+ return {};
164
+ }
165
+ const actionParams = {};
166
+ for (const [key, val] of Object.entries(params)) {
167
+ actionParams[`${ACTION_PARAM_PREFIX}${key}`] = val;
168
+ }
169
+ return actionParams;
170
+ }
171
+ /**
172
+ * check if object contains actionParams
173
+ * @param conf
174
+ */
175
+ function hasActionParam(conf) {
176
+ return Boolean(Object.keys(conf || {}).find((key) => key.indexOf(ACTION_PARAM_PREFIX) === 0));
177
+ }
178
+ /**
179
+ * check if ItemStateAndParams object has actionParams in params or state field
180
+ * @param stateAndParams
181
+ */
182
+ export function hasActionParams(stateAndParams) {
183
+ if (!stateAndParams || isEmpty(stateAndParams)) {
184
+ return {};
185
+ }
186
+ return hasActionParam(stateAndParams.params) || hasActionParam(stateAndParams.state);
187
+ }
@@ -7,6 +7,7 @@ export interface PluginWidgetProps {
7
7
  editMode: boolean;
8
8
  params: StringParams;
9
9
  state: ItemState;
10
+ actionParams: StringParams;
10
11
  onStateAndParamsChange: (stateAndParams: ItemStateAndParams) => void;
11
12
  width: number;
12
13
  height: number;
@@ -2,7 +2,8 @@ import update, { extend } from 'immutability-helper';
2
2
  import Hashids from 'hashids';
3
3
  import omit from 'lodash/omit';
4
4
  import pick from 'lodash/pick';
5
- import { mergeParamsWithAliases, isItemWithTabs, getCurrentVersion, META_KEY, deleteFromQueue, addToQueue, getInitialItemsStateAndParamsMeta, resolveItemInnerId, getItemsStateAndParamsMeta, } from '../shared';
5
+ import isEmpty from 'lodash/isEmpty';
6
+ import { mergeParamsWithAliases, isItemWithTabs, getCurrentVersion, META_KEY, deleteFromQueue, addToQueue, getInitialItemsStateAndParamsMeta, resolveItemInnerId, getItemsStateAndParamsMeta, getItemsActionParams, mergeParamsNamesWithPairAliases, hasActionParams, pickActionParamsFromParams, transformParamsToActionParams, ACTION_PARAM_PREFIX, } from '../shared';
6
7
  import { DEFAULT_NAMESPACE } from '../constants';
7
8
  extend('$auto', (value, object) => (object ? update(object, value) : update({}, value)));
8
9
  function removeItemVersion1({ id, config, itemsStateAndParams }) {
@@ -60,9 +61,14 @@ function removeItemVersion1({ id, config, itemsStateAndParams }) {
60
61
  itemsStateAndParams: newItemsStateAndParams,
61
62
  };
62
63
  }
63
- function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
64
+ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, paramsSettings) {
64
65
  var _a;
66
+ const paramsTypeName = (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.type) || 'params';
67
+ const isActionParamsMode = paramsTypeName === 'actionParams';
65
68
  let allowedParams = {};
69
+ const stateParamsConf = isActionParamsMode
70
+ ? pickActionParamsFromParams(stateAndParams.params, false)
71
+ : stateAndParams.params;
66
72
  if (isItemWithTabs(item)) {
67
73
  let tab;
68
74
  if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
@@ -72,14 +78,19 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams) {
72
78
  const tabId = resolveItemInnerId({ item, itemsStateAndParams });
73
79
  tab = item.data.tabs.find(({ id }) => id === tabId);
74
80
  }
75
- allowedParams = pick(stateAndParams.params, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
81
+ allowedParams = pick(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
76
82
  }
77
83
  else {
78
- allowedParams = pick(stateAndParams.params, Object.keys(item.defaults || {}));
84
+ allowedParams = pick(stateParamsConf, Object.keys(item.defaults || {}));
79
85
  }
80
- if (Object.keys(allowedParams).length !== Object.keys(stateAndParams.params || {}).length) {
86
+ if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
81
87
  console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
82
88
  }
89
+ if (isActionParamsMode) {
90
+ return (paramsSettings === null || paramsSettings === void 0 ? void 0 : paramsSettings.returnPrefix)
91
+ ? transformParamsToActionParams(allowedParams)
92
+ : allowedParams;
93
+ }
83
94
  return allowedParams;
84
95
  }
85
96
  function changeStateAndParamsVersion1({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
@@ -199,7 +210,7 @@ export class UpdateManager {
199
210
  });
200
211
  }
201
212
  static changeStateAndParams({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
202
- var _a, _b;
213
+ var _a, _b, _c, _d;
203
214
  if (getCurrentVersion(itemsStateAndParams) === 1) {
204
215
  return changeStateAndParamsVersion1({
205
216
  id: initiatorId,
@@ -209,7 +220,7 @@ export class UpdateManager {
209
220
  });
210
221
  }
211
222
  const hasState = 'state' in stateAndParams;
212
- const { items } = config;
223
+ const { items, aliases } = config;
213
224
  const itemsIds = items.map(({ id: itemId }) => itemId);
214
225
  const itemsStateAndParamsIds = Object.keys(omit(itemsStateAndParams, [META_KEY]));
215
226
  const unusedIds = itemsStateAndParamsIds.filter((id) => !itemsIds.includes(id));
@@ -217,27 +228,151 @@ export class UpdateManager {
217
228
  const newTabId = (_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId;
218
229
  const isTabSwitched = isItemWithTabs(initiatorItem) && Boolean(newTabId);
219
230
  const currentMeta = getItemsStateAndParamsMeta(itemsStateAndParams);
220
- if ('params' in stateAndParams) {
231
+ const hasChangedActionParams = hasActionParams(stateAndParams);
232
+ const actionParamsAll = getItemsActionParams({
233
+ config,
234
+ itemsStateAndParams,
235
+ }) || {};
236
+ const notEmptyActionParams = {};
237
+ for (const [key, val] of Object.entries(actionParamsAll)) {
238
+ if (!isEmpty(val)) {
239
+ notEmptyActionParams[key] = val;
240
+ }
241
+ }
242
+ if (hasChangedActionParams) {
243
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
244
+ const actionParamsWithAliasesNames = {};
245
+ for (const [widgetIdKey, itemActionParams] of Object.entries(notEmptyActionParams)) {
246
+ const aliasesNames = mergeParamsNamesWithPairAliases({
247
+ aliases,
248
+ namespace: initiatorItem.namespace,
249
+ paramsNames: Object.keys(itemActionParams),
250
+ });
251
+ actionParamsWithAliasesNames[widgetIdKey] = [];
252
+ // убрать все триггеры, которые есть в aliasesNames
253
+ if (aliasesNames.length) {
254
+ actionParamsWithAliasesNames[widgetIdKey] =
255
+ // @ts-ignore
256
+ actionParamsWithAliasesNames[widgetIdKey].concat(aliasesNames);
257
+ }
258
+ }
259
+ const tabId = isItemWithTabs(initiatorItem)
260
+ ? newTabId || resolveItemInnerId({ item: initiatorItem, itemsStateAndParams })
261
+ : undefined;
262
+ const meta = addToQueue({ id: initiatorId, tabId, config, itemsStateAndParams });
263
+ const paramsFromStateAndParams = ((_b = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params) || {};
264
+ const newParams = !isEmpty(paramsFromStateAndParams) || !isEmpty(allowableActionParams)
265
+ ? { params: Object.assign(Object.assign({}, paramsFromStateAndParams), allowableActionParams) }
266
+ : {};
267
+ const obj = {
268
+ [initiatorId]: {
269
+ $set: Object.assign(Object.assign({}, newParams), (hasState ? { state: { $set: stateAndParams.state } } : {})),
270
+ },
271
+ [META_KEY]: { $set: meta },
272
+ };
273
+ const res = update(itemsStateAndParams, obj);
274
+ return res;
275
+ }
276
+ else if ('params' in stateAndParams) {
221
277
  const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
278
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
279
+ const actionParamsWithAliasesNames = {};
280
+ for (const [widgetIdKey, itemActionParams] of Object.entries(notEmptyActionParams)) {
281
+ const aliasesNames = mergeParamsNamesWithPairAliases({
282
+ aliases,
283
+ namespace: initiatorItem.namespace,
284
+ paramsNames: Object.keys(itemActionParams),
285
+ });
286
+ actionParamsWithAliasesNames[widgetIdKey] = [];
287
+ // убрать все триггеры, которые есть в aliasesNames
288
+ if (aliasesNames.length) {
289
+ actionParamsWithAliasesNames[widgetIdKey] =
290
+ // @ts-ignore
291
+ actionParamsWithAliasesNames[widgetIdKey].concat(aliasesNames);
292
+ }
293
+ }
294
+ let actionParamsToClear = {};
295
+ const actionParamsToDelete = {};
296
+ Object.keys(allowableParams).forEach((paramName) => {
297
+ for (const [widgetIdKey, itemActionParams] of Object.entries(notEmptyActionParams)) {
298
+ for (const [paramKey, paramVal] of Object.entries(itemActionParams)) {
299
+ // paramKey: Year; Country
300
+ const actionParamInAliases = actionParamsWithAliasesNames[widgetIdKey].find((row) => row.includes(paramKey)) || [];
301
+ // @ts-ignore
302
+ const hasAllowableParamInAliases = actionParamInAliases.includes(paramName);
303
+ if (hasAllowableParamInAliases &&
304
+ notEmptyActionParams[widgetIdKey][paramKey]) {
305
+ // @ts-ignore
306
+ if (!actionParamsToDelete[widgetIdKey]) {
307
+ // @ts-ignore
308
+ actionParamsToDelete[widgetIdKey] = {};
309
+ }
310
+ // @ts-ignore
311
+ actionParamsToDelete[widgetIdKey] = Object.assign(Object.assign({}, actionParamsToDelete[widgetIdKey]), { [`${ACTION_PARAM_PREFIX}${paramKey}`]: paramVal });
312
+ delete notEmptyActionParams[widgetIdKey][paramKey];
313
+ }
314
+ }
315
+ actionParamsToClear = {
316
+ [widgetIdKey]: notEmptyActionParams[widgetIdKey],
317
+ };
318
+ }
319
+ });
320
+ for (const [widgetIdKey, itemActionParams] of Object.entries(actionParamsToClear)) {
321
+ const itemActionParamsWithPrefix = transformParamsToActionParams(itemActionParams);
322
+ let updatingParams = {};
323
+ // @ts-ignore
324
+ if (!isEmpty((_c = itemsStateAndParams[widgetIdKey]) === null || _c === void 0 ? void 0 : _c.params)) {
325
+ // @ts-ignore
326
+ updatingParams = Object.assign({}, itemsStateAndParams[widgetIdKey].params);
327
+ if (!isEmpty(actionParamsToDelete)) {
328
+ // @ts-ignore
329
+ Object.keys(actionParamsToDelete[widgetIdKey] || []).forEach((keyToDelete) => {
330
+ if (keyToDelete in updatingParams) {
331
+ // @ts-ignore
332
+ delete updatingParams[keyToDelete];
333
+ }
334
+ });
335
+ }
336
+ }
337
+ const newParamsWithClear = Object.assign(Object.assign({}, updatingParams), itemActionParamsWithPrefix);
338
+ actionParamsToClear[widgetIdKey] = {
339
+ $set: {
340
+ params: newParamsWithClear,
341
+ },
342
+ };
343
+ }
222
344
  const tabId = isItemWithTabs(initiatorItem)
223
345
  ? newTabId || resolveItemInnerId({ item: initiatorItem, itemsStateAndParams })
224
346
  : undefined;
225
347
  const meta = addToQueue({ id: initiatorId, tabId, config, itemsStateAndParams });
226
- let commandUpdateParams = ((_b = itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params)
348
+ let commandUpdateParams = ((_d = itemsStateAndParams[initiatorId]) === null || _d === void 0 ? void 0 : _d.params)
227
349
  ? '$merge'
228
350
  : '$set';
229
351
  if (isTabSwitched) {
230
352
  commandUpdateParams = '$set';
231
353
  }
232
- return update(itemsStateAndParams, {
233
- $unset: unusedIds,
234
- [initiatorId]: {
235
- $auto: Object.assign({ params: {
236
- [commandUpdateParams]: allowableParams,
237
- } }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
238
- },
239
- [META_KEY]: { $set: meta },
240
- });
354
+ const actionParamsCommand = hasActionParams(itemsStateAndParams[initiatorId])
355
+ ? '$merge'
356
+ : '$set';
357
+ let setObj = null;
358
+ if (commandUpdateParams === '$set' && actionParamsCommand === '$set') {
359
+ setObj = {
360
+ params: Object.assign(Object.assign({}, allowableParams), (hasChangedActionParams ? allowableActionParams : {})),
361
+ };
362
+ }
363
+ const obj = Object.assign(Object.assign({ $unset: unusedIds, [initiatorId]: {
364
+ $auto: Object.assign(Object.assign({}, (setObj
365
+ ? {
366
+ $set: setObj,
367
+ }
368
+ : {
369
+ params: {
370
+ [commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
371
+ },
372
+ })), (hasState ? { state: { $set: stateAndParams.state } } : {})),
373
+ } }, actionParamsToClear), { [META_KEY]: { $set: meta } });
374
+ const res = update(itemsStateAndParams, obj);
375
+ return res;
241
376
  }
242
377
  else if (hasState) {
243
378
  let metaSpec = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "4.1.0",
3
+ "version": "4.1.1-unstable-4.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {