@gravity-ui/dashkit 6.6.1-beta-v.shangin.0 → 6.6.1-beta-v.marginy.1

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.
@@ -69,4 +69,13 @@ 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[];
72
81
  export {};
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasActionParams = exports.hasActionParam = exports.transformParamsToActionParams = exports.pickExceptActionParamsFromParams = exports.pickActionParamsFromParams = exports.deleteFromQueue = exports.addToQueue = exports.getInitialItemsStateAndParamsMeta = exports.mergeParamsWithAliases = exports.getMapItemsIgnores = exports.resolveItemInnerId = exports.formQueueData = exports.isItemWithTabs = exports.getCurrentVersion = exports.getItemsStateAndParamsMeta = exports.prerenderItems = void 0;
3
+ exports.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;
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"));
10
11
  const constants_1 = require("../constants");
11
12
  function getNormalizedPlugins(plugins) {
12
13
  return (0, keyBy_1.default)(plugins, 'type');
@@ -259,3 +260,23 @@ function hasActionParams(stateAndParams) {
259
260
  return hasActionParam(stateAndParams.params);
260
261
  }
261
262
  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,6 +3,8 @@ 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"));
6
8
  const constants_1 = require("../constants");
7
9
  const helpers_1 = require("./helpers");
8
10
  function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
@@ -52,7 +54,8 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
52
54
  }
53
55
  else {
54
56
  // params according to queue of its applying
55
- let queueDataItemsParams = {};
57
+ let prevQueueDataWithActionParams = {};
58
+ let queueDataItems = {};
56
59
  for (const data of Object.values(queueData)) {
57
60
  if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
58
61
  continue;
@@ -65,9 +68,24 @@ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, i
65
68
  params = (0, helpers_1.pickExceptActionParamsFromParams)(data.params);
66
69
  }
67
70
  const mergedParams = getMergedParams(params, actionParams);
68
- queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
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);
69
87
  }
70
- itemParams = Object.assign(itemParams, queueDataItemsParams);
88
+ itemParams = Object.assign(itemParams, queueDataItems);
71
89
  }
72
90
  return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
73
91
  }, {});
@@ -306,7 +306,6 @@ const stateAndParamsForAP2 = {
306
306
  Country: 'Belgium',
307
307
  Year: '',
308
308
  'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
309
- _ap_Country: 'Italy',
310
309
  },
311
310
  state: {},
312
311
  },
@@ -335,7 +334,6 @@ const stateAndParamsForAP3 = {
335
334
  Country: '',
336
335
  Year: '',
337
336
  'd079937f-6bc4-4133-9171-40092bb20d6f': '',
338
- _ap_Country: 'Italy',
339
337
  },
340
338
  state: {},
341
339
  },
@@ -412,64 +410,6 @@ const stateAndParamsForAP5 = {
412
410
  },
413
411
  },
414
412
  };
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
- };
473
413
  const configs = configs_json_1.default.configs;
474
414
  describe('getItemsStateAndParamsDL', () => {
475
415
  describe('old version fallback', () => {
@@ -562,15 +502,4 @@ describe('getItemsStateAndParams actionParams variants check', () => {
562
502
  expect(resultItemsStateAndParams).toEqual((0, omit_1.default)(stateAndParamsForAP5.out, constants_1.META_KEY));
563
503
  });
564
504
  });
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
- });
576
505
  });
@@ -262,7 +262,12 @@ class UpdateManager {
262
262
  let commandUpdateParams = ((_b = itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params)
263
263
  ? '$merge'
264
264
  : '$set';
265
- if (isTabSwitched) {
265
+ const initialedStateAndParams = initiatorId in itemsStateAndParams &&
266
+ itemsStateAndParams[initiatorId];
267
+ const needResetCurrentAP = initialedStateAndParams &&
268
+ Object.keys((0, shared_1.pickActionParamsFromParams)(initialedStateAndParams.params)).length &&
269
+ !Object.keys(allowableActionParams).length;
270
+ if (isTabSwitched || needResetCurrentAP) {
266
271
  commandUpdateParams = '$set';
267
272
  }
268
273
  const obj = {
@@ -69,4 +69,13 @@ 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[];
72
81
  export {};
@@ -3,6 +3,7 @@ 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';
6
7
  import { META_KEY, CURRENT_VERSION, ACTION_PARAM_PREFIX } from '../constants';
7
8
  function getNormalizedPlugins(plugins) {
8
9
  return keyBy(plugins, 'type');
@@ -239,3 +240,22 @@ export function hasActionParams(stateAndParams) {
239
240
  }
240
241
  return hasActionParam(stateAndParams.params);
241
242
  }
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,6 +1,8 @@
1
1
  import groupBy from 'lodash/groupBy';
2
+ import intersection from 'lodash/intersection';
3
+ import omit from 'lodash/omit';
2
4
  import { META_KEY } from '../constants';
3
- import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, isItemWithTabs, resolveItemInnerId, } from './helpers';
5
+ import { prerenderItems, formQueueData, getMapItemsIgnores, mergeParamsWithAliases, getCurrentVersion, pickActionParamsFromParams, hasActionParam, pickExceptActionParamsFromParams, transformParamsToActionParams, isItemWithTabs, resolveItemInnerId, getDefaultsActionParamsToClear, } from './helpers';
4
6
  export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
5
7
  const { aliases, connections } = config;
6
8
  const items = prerenderItems({ items: config.items, plugins });
@@ -48,7 +50,8 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
48
50
  }
49
51
  else {
50
52
  // params according to queue of its applying
51
- let queueDataItemsParams = {};
53
+ let prevQueueDataWithActionParams = {};
54
+ let queueDataItems = {};
52
55
  for (const data of Object.values(queueData)) {
53
56
  if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
54
57
  continue;
@@ -61,9 +64,24 @@ export function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, co
61
64
  params = pickExceptActionParamsFromParams(data.params);
62
65
  }
63
66
  const mergedParams = getMergedParams(params, actionParams);
64
- queueDataItemsParams = Object.assign(Object.assign({}, queueDataItemsParams), mergedParams);
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);
65
83
  }
66
- itemParams = Object.assign(itemParams, queueDataItemsParams);
84
+ itemParams = Object.assign(itemParams, queueDataItems);
67
85
  }
68
86
  return Object.assign(Object.assign({}, itemsParams), { [id]: Object.assign(Object.assign({}, defaultWidgetParams), itemParams) });
69
87
  }, {});
@@ -302,7 +302,6 @@ const stateAndParamsForAP2 = {
302
302
  Country: 'Belgium',
303
303
  Year: '',
304
304
  'd079937f-6bc4-4133-9171-40092bb20d6f': 'Belgium',
305
- _ap_Country: 'Italy',
306
305
  },
307
306
  state: {},
308
307
  },
@@ -331,7 +330,6 @@ const stateAndParamsForAP3 = {
331
330
  Country: '',
332
331
  Year: '',
333
332
  'd079937f-6bc4-4133-9171-40092bb20d6f': '',
334
- _ap_Country: 'Italy',
335
333
  },
336
334
  state: {},
337
335
  },
@@ -408,64 +406,6 @@ const stateAndParamsForAP5 = {
408
406
  },
409
407
  },
410
408
  };
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
- };
469
409
  const configs = mockConfigs.configs;
470
410
  describe('getItemsStateAndParamsDL', () => {
471
411
  describe('old version fallback', () => {
@@ -558,15 +498,4 @@ describe('getItemsStateAndParams actionParams variants check', () => {
558
498
  expect(resultItemsStateAndParams).toEqual(omit(stateAndParamsForAP5.out, META_KEY));
559
499
  });
560
500
  });
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
- });
572
501
  });
@@ -258,7 +258,12 @@ export class UpdateManager {
258
258
  let commandUpdateParams = ((_b = itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params)
259
259
  ? '$merge'
260
260
  : '$set';
261
- if (isTabSwitched) {
261
+ const initialedStateAndParams = initiatorId in itemsStateAndParams &&
262
+ itemsStateAndParams[initiatorId];
263
+ const needResetCurrentAP = initialedStateAndParams &&
264
+ Object.keys(pickActionParamsFromParams(initialedStateAndParams.params)).length &&
265
+ !Object.keys(allowableActionParams).length;
266
+ if (isTabSwitched || needResetCurrentAP) {
262
267
  commandUpdateParams = '$set';
263
268
  }
264
269
  const obj = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "6.6.1-beta-v.shangin.0",
3
+ "version": "6.6.1-beta-v.marginy.1",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {