@gravity-ui/dashkit 6.6.1 → 6.7.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.
- package/build/cjs/components/Item/Item.d.ts +2 -2
- package/build/cjs/hocs/prepareItem.d.ts +2 -2
- package/build/cjs/hocs/prepareItem.js +2 -2
- package/build/cjs/hocs/withContext.js +2 -1
- package/build/cjs/shared/modules/helpers.d.ts +0 -9
- package/build/cjs/shared/modules/helpers.js +1 -22
- package/build/cjs/shared/modules/state-and-params.js +3 -21
- package/build/cjs/shared/types/state-and-params.d.ts +3 -0
- package/build/cjs/shared/units/__tests__/state-and-params.test.js +71 -0
- package/build/cjs/typings/plugin.d.ts +2 -2
- package/build/cjs/utils/__tests__/update-manager.test.d.ts +1 -0
- package/build/cjs/utils/__tests__/update-manager.test.js +476 -0
- package/build/cjs/utils/update-manager.d.ts +3 -2
- package/build/cjs/utils/update-manager.js +24 -10
- package/build/esm/components/Item/Item.d.ts +2 -2
- package/build/esm/hocs/prepareItem.d.ts +2 -2
- package/build/esm/hocs/prepareItem.js +2 -2
- package/build/esm/hocs/withContext.js +2 -1
- package/build/esm/shared/modules/helpers.d.ts +0 -9
- package/build/esm/shared/modules/helpers.js +0 -20
- package/build/esm/shared/modules/state-and-params.js +4 -22
- package/build/esm/shared/types/state-and-params.d.ts +3 -0
- package/build/esm/shared/units/__tests__/state-and-params.test.js +71 -0
- package/build/esm/typings/plugin.d.ts +2 -2
- package/build/esm/utils/__tests__/update-manager.test.d.ts +1 -0
- package/build/esm/utils/__tests__/update-manager.test.js +474 -0
- package/build/esm/utils/update-manager.d.ts +3 -2
- package/build/esm/utils/update-manager.js +24 -10
- package/package.json +1 -1
- package/build/cjs/utils/__tests__/mock.test.d.ts +0 -1
- package/build/cjs/utils/__tests__/mock.test.js +0 -8
- package/build/esm/utils/__tests__/mock.test.d.ts +0 -1
- package/build/esm/utils/__tests__/mock.test.js +0 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
new (props: any): {
|
|
3
3
|
shouldComponentUpdate(nextProps: any): boolean;
|
|
4
|
-
_onStateAndParamsChange: (stateAndParams: any) => void;
|
|
4
|
+
_onStateAndParamsChange: (stateAndParams: any, options: any) => void;
|
|
5
5
|
render(): JSX.Element;
|
|
6
6
|
context: unknown;
|
|
7
7
|
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
@@ -25,7 +25,7 @@ declare const _default: {
|
|
|
25
25
|
};
|
|
26
26
|
new (props: any, context: any): {
|
|
27
27
|
shouldComponentUpdate(nextProps: any): boolean;
|
|
28
|
-
_onStateAndParamsChange: (stateAndParams: any) => void;
|
|
28
|
+
_onStateAndParamsChange: (stateAndParams: any, options: any) => void;
|
|
29
29
|
render(): JSX.Element;
|
|
30
30
|
context: unknown;
|
|
31
31
|
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function prepareItem(Component: any): {
|
|
2
2
|
new (props: any): {
|
|
3
3
|
shouldComponentUpdate(nextProps: any): boolean;
|
|
4
|
-
_onStateAndParamsChange: (stateAndParams: any) => void;
|
|
4
|
+
_onStateAndParamsChange: (stateAndParams: any, options: any) => void;
|
|
5
5
|
render(): JSX.Element;
|
|
6
6
|
context: unknown;
|
|
7
7
|
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
@@ -25,7 +25,7 @@ export function prepareItem(Component: any): {
|
|
|
25
25
|
};
|
|
26
26
|
new (props: any, context: any): {
|
|
27
27
|
shouldComponentUpdate(nextProps: any): boolean;
|
|
28
|
-
_onStateAndParamsChange: (stateAndParams: any) => void;
|
|
28
|
+
_onStateAndParamsChange: (stateAndParams: any, options: any) => void;
|
|
29
29
|
render(): JSX.Element;
|
|
30
30
|
context: unknown;
|
|
31
31
|
setState<K extends string | number | symbol>(state: any, callback?: (() => void) | undefined): void;
|
|
@@ -10,8 +10,8 @@ function prepareItem(Component) {
|
|
|
10
10
|
return _a = class PrepareItem extends react_1.default.Component {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(...arguments);
|
|
13
|
-
this._onStateAndParamsChange = (stateAndParams) => {
|
|
14
|
-
this.context.onItemStateAndParamsChange(this.props.id, stateAndParams);
|
|
13
|
+
this._onStateAndParamsChange = (stateAndParams, options) => {
|
|
14
|
+
this.context.onItemStateAndParamsChange(this.props.id, stateAndParams, options);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
shouldComponentUpdate(nextProps) {
|
|
@@ -51,13 +51,14 @@ function useMemoStateContext(props) {
|
|
|
51
51
|
itemsStateAndParams: props.itemsStateAndParams,
|
|
52
52
|
}));
|
|
53
53
|
}, [props.config, props.itemsStateAndParams, onChange]);
|
|
54
|
-
const onItemStateAndParamsChange = react_1.default.useCallback((id, stateAndParams) => {
|
|
54
|
+
const onItemStateAndParamsChange = react_1.default.useCallback((id, stateAndParams, options) => {
|
|
55
55
|
onChange({
|
|
56
56
|
itemsStateAndParams: utils_1.UpdateManager.changeStateAndParams({
|
|
57
57
|
id,
|
|
58
58
|
config: props.config,
|
|
59
59
|
stateAndParams,
|
|
60
60
|
itemsStateAndParams: props.itemsStateAndParams,
|
|
61
|
+
options,
|
|
61
62
|
}),
|
|
62
63
|
});
|
|
63
64
|
}, [props.config, props.itemsStateAndParams, onChange]);
|
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
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,
|
|
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
|
}, {});
|
|
@@ -18,5 +18,8 @@ export type ItemStateAndParams = {
|
|
|
18
18
|
params?: StringParams;
|
|
19
19
|
state?: ItemState;
|
|
20
20
|
};
|
|
21
|
+
export type ItemStateAndParamsChangeOptions = {
|
|
22
|
+
action: 'setParams' | 'removeItem';
|
|
23
|
+
};
|
|
21
24
|
export type ItemsStateAndParamsBase = Record<string, ItemStateAndParams>;
|
|
22
25
|
export type ItemsStateAndParams = ItemsStateAndParamsBase | StateAndParamsMeta;
|
|
@@ -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
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ContextProps, SettingsProps, WidgetLayout } from './common';
|
|
3
|
-
import { StringParams, ConfigItem, ItemState, ItemStateAndParams, PluginBase } from '../shared';
|
|
3
|
+
import { StringParams, ConfigItem, ItemState, ItemStateAndParams, PluginBase, ItemStateAndParamsChangeOptions } from '../shared';
|
|
4
4
|
import type { ReactGridLayoutProps } from 'react-grid-layout';
|
|
5
5
|
export interface PluginWidgetProps {
|
|
6
6
|
id: string;
|
|
7
7
|
editMode: boolean;
|
|
8
8
|
params: StringParams;
|
|
9
9
|
state: ItemState;
|
|
10
|
-
onStateAndParamsChange: (stateAndParams: ItemStateAndParams) => void;
|
|
10
|
+
onStateAndParamsChange: (stateAndParams: ItemStateAndParams, options?: ItemStateAndParamsChangeOptions) => void;
|
|
11
11
|
width: number;
|
|
12
12
|
height: number;
|
|
13
13
|
data: ConfigItem['data'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|