@gravity-ui/dashkit 6.6.0 → 6.6.1-beta-v.shangin.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.
@@ -38,6 +38,14 @@ interface OverlayControlsProps extends OverlayControlsDefaultProps {
38
38
  items?: OverlayControlItem[];
39
39
  overlayControls?: Record<string, OverlayControlItem[]>;
40
40
  }
41
+ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults' | 'namespace'> & {
42
+ timestamp: number;
43
+ layout: {
44
+ w: number;
45
+ h: number;
46
+ };
47
+ };
48
+ export type PreparedCopyItemOptions = PreparedCopyItemOptionsArg;
41
49
  type DashKitCtx = React.Context<{
42
50
  context: Record<string, any>;
43
51
  registerManager: RegisterManager;
@@ -1,3 +1,3 @@
1
1
  export * from './DashKit';
2
- export type { OverlayControlItem } from './OverlayControls/OverlayControls';
2
+ export type { OverlayControlItem, PreparedCopyItemOptions } from './OverlayControls/OverlayControls';
3
3
  export * from './ActionPanel/ActionPanel';
@@ -69,13 +69,4 @@ export declare function hasActionParam(conf?: StringParams): boolean;
69
69
  * @param stateAndParams
70
70
  */
71
71
  export declare function hasActionParams(stateAndParams: ItemStateAndParams): boolean;
72
- /**
73
- * Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
74
- * @param defaultWidgetParams
75
- * @param queueWidgetParams
76
- */
77
- export declare function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }: {
78
- defaultWidgetParams: StringParams;
79
- queueWidgetParams: StringParams;
80
- }): string[];
81
72
  export {};
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultsActionParamsToClear = 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.addToQueue = exports.getInitialItemsStateAndParamsMeta = 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"));
7
7
  const invert_1 = tslib_1.__importDefault(require("lodash/invert"));
8
8
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
9
9
  const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
10
- const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
11
10
  const constants_1 = require("../constants");
12
11
  function getNormalizedPlugins(plugins) {
13
12
  return (0, keyBy_1.default)(plugins, 'type');
@@ -260,23 +259,3 @@ function hasActionParams(stateAndParams) {
260
259
  return hasActionParam(stateAndParams.params);
261
260
  }
262
261
  exports.hasActionParams = hasActionParams;
263
- /**
264
- * Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
265
- * @param defaultWidgetParams
266
- * @param queueWidgetParams
267
- */
268
- function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }) {
269
- const widgetDefaultsWithActionParams = hasActionParam(defaultWidgetParams)
270
- ? pickActionParamsFromParams(defaultWidgetParams)
271
- : null;
272
- if (!widgetDefaultsWithActionParams) {
273
- return [];
274
- }
275
- // clear default actionParams if some param with the same name without prefix affected on current widget
276
- // ex.: queueWidgetParams contain {Year: 1970} and default actionParams contain {_ap_Year: 2000}
277
- const actionParamKeyToClear = (0, intersection_1.default)(Object.keys(queueWidgetParams), Object.keys(widgetDefaultsWithActionParams));
278
- return actionParamKeyToClear.length
279
- ? actionParamKeyToClear.map((key) => `${constants_1.ACTION_PARAM_PREFIX}${key}`)
280
- : [];
281
- }
282
- exports.getDefaultsActionParamsToClear = getDefaultsActionParamsToClear;
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getItemsStateAndParams = exports.getItemsState = exports.getItemsParams = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
6
- const intersection_1 = tslib_1.__importDefault(require("lodash/intersection"));
7
- const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
8
6
  const constants_1 = require("../constants");
9
7
  const helpers_1 = require("./helpers");
10
8
  function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
@@ -54,8 +52,7 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
54
52
  }
55
53
  else {
56
54
  // params according to queue of its applying
57
- let prevQueueDataWithActionParams = {};
58
- let queueDataItems = {};
55
+ let queueDataItemsParams = {};
59
56
  for (const data of Object.values(queueData)) {
60
57
  if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
61
58
  continue;
@@ -68,24 +65,9 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
68
65
  params = (0, helpers_1.pickExceptActionParamsFromParams)(data.params);
69
66
  }
70
67
  const mergedParams = getMergedParams(params, actionParams);
71
- const actionParamKeyToClear = (0, intersection_1.default)(Object.keys((0, helpers_1.transformParamsToActionParams)(mergedParams)), Object.keys(prevQueueDataWithActionParams));
72
- let queueDataRes = Object.assign({}, queueDataItems);
73
- if (actionParamKeyToClear.length) {
74
- queueDataRes = (0, omit_1.default)(queueDataItems, actionParamKeyToClear);
75
- }
76
- queueDataItems = Object.assign(Object.assign({}, queueDataRes), mergedParams);
77
- prevQueueDataWithActionParams = (0, helpers_1.hasActionParam)(queueDataItems)
78
- ? (0, helpers_1.pickActionParamsFromParams)(data.params, true)
79
- : {};
80
- }
81
- const clearActionParams = (0, helpers_1.getDefaultsActionParamsToClear)({
82
- defaultWidgetParams,
83
- queueWidgetParams: queueDataItems,
84
- });
85
- if (clearActionParams.length) {
86
- defaultWidgetParams = (0, omit_1.default)(defaultWidgetParams, clearActionParams);
68
+ queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
87
69
  }
88
- itemParams = Object.assign(itemParams, queueDataItems);
70
+ itemParams = Object.assign(itemParams, queueDataItemsParams);
89
71
  }
90
72
  return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
91
73
  }, {});
@@ -306,6 +306,7 @@ const stateAndParamsForAP2 = {
306
306
  Country: 'Belgium',
307
307
  Year: '',
308
308
  'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
309
+ _ap_Country: 'Italy',
309
310
  },
310
311
  state: {},
311
312
  },
@@ -334,6 +335,7 @@ const stateAndParamsForAP3 = {
334
335
  Country: '',
335
336
  Year: '',
336
337
  'd079937f-6bc4-4133-9171-40092bb20d6f': '',
338
+ _ap_Country: 'Italy',
337
339
  },
338
340
  state: {},
339
341
  },
@@ -410,6 +412,64 @@ const stateAndParamsForAP5 = {
410
412
  },
411
413
  },
412
414
  };
415
+ const stateAndParamsForAP6 = {
416
+ in: {
417
+ Q8: {
418
+ params: {
419
+ _ap_Year: '2021',
420
+ _ap_Country: 'Russia',
421
+ },
422
+ },
423
+ L5: {
424
+ params: {
425
+ _ap_Country: 'Russia',
426
+ _ap_Name: 'Alex',
427
+ _ap_Price: '1000',
428
+ },
429
+ },
430
+ __meta__: {
431
+ queue: [
432
+ { id: 'Q8', tabId: 'K0' },
433
+ { id: 'L5', tabId: 'K1' },
434
+ ],
435
+ version: 2,
436
+ },
437
+ },
438
+ out: {
439
+ L5: {
440
+ params: {
441
+ Name: '',
442
+ Price: '',
443
+ Year: '2021',
444
+ Country: 'Russia',
445
+ _ap_Country: 'Russia',
446
+ _ap_Name: 'Alex',
447
+ _ap_Price: '1000',
448
+ },
449
+ state: {},
450
+ },
451
+ Q8: {
452
+ params: {
453
+ Year: '',
454
+ Country: 'Russia',
455
+ Name: 'Alex',
456
+ Price: '1000',
457
+ _ap_Year: '2021',
458
+ _ap_Country: 'Russia',
459
+ },
460
+ state: {},
461
+ },
462
+ al: {
463
+ params: {
464
+ Country: 'Russia',
465
+ Name: 'Alex',
466
+ Price: '1000',
467
+ Year: '2021',
468
+ },
469
+ state: {},
470
+ },
471
+ },
472
+ };
413
473
  const configs = configs_json_1.default.configs;
414
474
  describe('getItemsStateAndParamsDL', () => {
415
475
  describe('old version fallback', () => {
@@ -502,4 +562,15 @@ describe('getItemsStateAndParams actionParams variants check', () => {
502
562
  expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP5.out, constants_1.META_KEY));
503
563
  });
504
564
  });
565
+ describe('action and params state 6', () => {
566
+ const resultItemsStateAndParams = (0, datalens_1.getItemsStateAndParamsDL)({
567
+ defaultGlobalParams: {},
568
+ globalParams: {},
569
+ config: configs[4],
570
+ itemsStateAndParams: stateAndParamsForAP6.in,
571
+ });
572
+ it('return stateAndParamsForAP6.out', () => {
573
+ expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP6.out, constants_1.META_KEY));
574
+ });
575
+ });
505
576
  });
@@ -39,6 +39,14 @@ interface OverlayControlsProps extends OverlayControlsDefaultProps {
39
39
  items?: OverlayControlItem[];
40
40
  overlayControls?: Record<string, OverlayControlItem[]>;
41
41
  }
42
+ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults' | 'namespace'> & {
43
+ timestamp: number;
44
+ layout: {
45
+ w: number;
46
+ h: number;
47
+ };
48
+ };
49
+ export type PreparedCopyItemOptions = PreparedCopyItemOptionsArg;
42
50
  type DashKitCtx = React.Context<{
43
51
  context: Record<string, any>;
44
52
  registerManager: RegisterManager;
@@ -1,3 +1,3 @@
1
1
  export * from './DashKit';
2
- export type { OverlayControlItem } from './OverlayControls/OverlayControls';
2
+ export type { OverlayControlItem, PreparedCopyItemOptions } from './OverlayControls/OverlayControls';
3
3
  export * from './ActionPanel/ActionPanel';
@@ -69,13 +69,4 @@ export declare function hasActionParam(conf?: StringParams): boolean;
69
69
  * @param stateAndParams
70
70
  */
71
71
  export declare function hasActionParams(stateAndParams: ItemStateAndParams): boolean;
72
- /**
73
- * Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
74
- * @param defaultWidgetParams
75
- * @param queueWidgetParams
76
- */
77
- export declare function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }: {
78
- defaultWidgetParams: StringParams;
79
- queueWidgetParams: StringParams;
80
- }): string[];
81
72
  export {};
@@ -3,7 +3,6 @@ import get from 'lodash/get';
3
3
  import invert from 'lodash/invert';
4
4
  import isEmpty from 'lodash/isEmpty';
5
5
  import pick from 'lodash/pick';
6
- import intersection from 'lodash/intersection';
7
6
  import { META_KEY, CURRENT_VERSION, ACTION_PARAM_PREFIX } from '../constants';
8
7
  function getNormalizedPlugins(plugins) {
9
8
  return keyBy(plugins, 'type');
@@ -240,22 +239,3 @@ export function hasActionParams(stateAndParams) {
240
239
  }
241
240
  return hasActionParam(stateAndParams.params);
242
241
  }
243
- /**
244
- * Collect array of actionParams keys with prefix (_ap_) that must be cleared from widget defaults
245
- * @param defaultWidgetParams
246
- * @param queueWidgetParams
247
- */
248
- export function getDefaultsActionParamsToClear({ defaultWidgetParams, queueWidgetParams, }) {
249
- const widgetDefaultsWithActionParams = hasActionParam(defaultWidgetParams)
250
- ? pickActionParamsFromParams(defaultWidgetParams)
251
- : null;
252
- if (!widgetDefaultsWithActionParams) {
253
- return [];
254
- }
255
- // clear default actionParams if some param with the same name without prefix affected on current widget
256
- // ex.: queueWidgetParams contain {Year: 1970} and default actionParams contain {_ap_Year: 2000}
257
- const actionParamKeyToClear = intersection(Object.keys(queueWidgetParams), Object.keys(widgetDefaultsWithActionParams));
258
- return actionParamKeyToClear.length
259
- ? actionParamKeyToClear.map((key) => `${ACTION_PARAM_PREFIX}${key}`)
260
- : [];
261
- }
@@ -1,8 +1,6 @@
1
1
  import groupBy from 'lodash/groupBy';
2
- import intersection from 'lodash/intersection';
3
- import omit from 'lodash/omit';
4
2
  import { META_KEY } from '../constants';
5
- import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, transformParamsToActionParams, isItemWithTabs, resolveItemInnerId, getDefaultsActionParamsToClear, } from './helpers';
3
+ import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, isItemWithTabs, resolveItemInnerId, } from './helpers';
6
4
  export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
7
5
  const { aliases, connections } = config;
8
6
  const items = prerenderItems({ items: config.items, plugins });
@@ -50,8 +48,7 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
50
48
  }
51
49
  else {
52
50
  // params according to queue of its applying
53
- let prevQueueDataWithActionParams = {};
54
- let queueDataItems = {};
51
+ let queueDataItemsParams = {};
55
52
  for (const data of Object.values(queueData)) {
56
53
  if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
57
54
  continue;
@@ -64,24 +61,9 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
64
61
  params = pickExceptActionParamsFromParams(data.params);
65
62
  }
66
63
  const mergedParams = getMergedParams(params, actionParams);
67
- const actionParamKeyToClear = intersection(Object.keys(transformParamsToActionParams(mergedParams)), Object.keys(prevQueueDataWithActionParams));
68
- let queueDataRes = Object.assign({}, queueDataItems);
69
- if (actionParamKeyToClear.length) {
70
- queueDataRes = omit(queueDataItems, actionParamKeyToClear);
71
- }
72
- queueDataItems = Object.assign(Object.assign({}, queueDataRes), mergedParams);
73
- prevQueueDataWithActionParams = hasActionParam(queueDataItems)
74
- ? pickActionParamsFromParams(data.params, true)
75
- : {};
76
- }
77
- const clearActionParams = getDefaultsActionParamsToClear({
78
- defaultWidgetParams,
79
- queueWidgetParams: queueDataItems,
80
- });
81
- if (clearActionParams.length) {
82
- defaultWidgetParams = omit(defaultWidgetParams, clearActionParams);
64
+ queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
83
65
  }
84
- itemParams = Object.assign(itemParams, queueDataItems);
66
+ itemParams = Object.assign(itemParams, queueDataItemsParams);
85
67
  }
86
68
  return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
87
69
  }, {});
@@ -302,6 +302,7 @@ const stateAndParamsForAP2 = {
302
302
  Country: 'Belgium',
303
303
  Year: '',
304
304
  'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
305
+ _ap_Country: 'Italy',
305
306
  },
306
307
  state: {},
307
308
  },
@@ -330,6 +331,7 @@ const stateAndParamsForAP3 = {
330
331
  Country: '',
331
332
  Year: '',
332
333
  'd079937f-6bc4-4133-9171-40092bb20d6f': '',
334
+ _ap_Country: 'Italy',
333
335
  },
334
336
  state: {},
335
337
  },
@@ -406,6 +408,64 @@ const stateAndParamsForAP5 = {
406
408
  },
407
409
  },
408
410
  };
411
+ const stateAndParamsForAP6 = {
412
+ in: {
413
+ Q8: {
414
+ params: {
415
+ _ap_Year: '2021',
416
+ _ap_Country: 'Russia',
417
+ },
418
+ },
419
+ L5: {
420
+ params: {
421
+ _ap_Country: 'Russia',
422
+ _ap_Name: 'Alex',
423
+ _ap_Price: '1000',
424
+ },
425
+ },
426
+ __meta__: {
427
+ queue: [
428
+ { id: 'Q8', tabId: 'K0' },
429
+ { id: 'L5', tabId: 'K1' },
430
+ ],
431
+ version: 2,
432
+ },
433
+ },
434
+ out: {
435
+ L5: {
436
+ params: {
437
+ Name: '',
438
+ Price: '',
439
+ Year: '2021',
440
+ Country: 'Russia',
441
+ _ap_Country: 'Russia',
442
+ _ap_Name: 'Alex',
443
+ _ap_Price: '1000',
444
+ },
445
+ state: {},
446
+ },
447
+ Q8: {
448
+ params: {
449
+ Year: '',
450
+ Country: 'Russia',
451
+ Name: 'Alex',
452
+ Price: '1000',
453
+ _ap_Year: '2021',
454
+ _ap_Country: 'Russia',
455
+ },
456
+ state: {},
457
+ },
458
+ al: {
459
+ params: {
460
+ Country: 'Russia',
461
+ Name: 'Alex',
462
+ Price: '1000',
463
+ Year: '2021',
464
+ },
465
+ state: {},
466
+ },
467
+ },
468
+ };
409
469
  const configs = mockConfigs.configs;
410
470
  describe('getItemsStateAndParamsDL', () => {
411
471
  describe('old version fallback', () => {
@@ -498,4 +558,15 @@ describe('getItemsStateAndParams actionParams variants check', () => {
498
558
  expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP5.out, META_KEY));
499
559
  });
500
560
  });
561
+ describe('action and params state 6', () => {
562
+ const resultItemsStateAndParams = getItemsStateAndParamsDL({
563
+ defaultGlobalParams: {},
564
+ globalParams: {},
565
+ config: configs[4],
566
+ itemsStateAndParams: stateAndParamsForAP6.in,
567
+ });
568
+ it('return stateAndParamsForAP6.out', () => {
569
+ expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP6.out, META_KEY));
570
+ });
571
+ });
501
572
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "6.6.0",
3
+ "version": "6.6.1-beta-v.shangin.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {