@gravity-ui/chartkit 4.23.2 → 4.23.3
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeSettingStrategy(objValue: any, srcValue: any, key: string): any;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import isObject from 'lodash/isObject';
|
|
2
|
+
import mergeWith from 'lodash/mergeWith';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
export function mergeSettingStrategy(objValue, srcValue, key) {
|
|
5
|
+
if (key === 'plugins') {
|
|
6
|
+
const currentPlugins = [...objValue];
|
|
7
|
+
const newPlugins = [...srcValue];
|
|
8
|
+
// modify existing plugins
|
|
9
|
+
let newSettingsPlugins = currentPlugins.map((currentPlugin) => {
|
|
10
|
+
const newPluginIndex = newPlugins.findIndex(({ type }) => type === currentPlugin.type);
|
|
11
|
+
if (newPluginIndex !== -1) {
|
|
12
|
+
const newPlugin = newPlugins[newPluginIndex];
|
|
13
|
+
newPlugins.splice(newPluginIndex, 1);
|
|
14
|
+
return {
|
|
15
|
+
type: currentPlugin.type,
|
|
16
|
+
renderer: newPlugin.renderer,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return currentPlugin;
|
|
20
|
+
});
|
|
21
|
+
// add new plugins if it exist after modified
|
|
22
|
+
if (newPlugins.length > 0) {
|
|
23
|
+
newSettingsPlugins = [...newSettingsPlugins, ...newPlugins];
|
|
24
|
+
}
|
|
25
|
+
return newSettingsPlugins;
|
|
26
|
+
}
|
|
27
|
+
if (isObject(objValue)) {
|
|
28
|
+
return mergeWith(objValue, srcValue, mergeSettingStrategy);
|
|
29
|
+
}
|
|
30
|
+
return srcValue;
|
|
31
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import
|
|
2
|
+
import mergeWith from 'lodash/mergeWith';
|
|
3
3
|
import { configure } from '@gravity-ui/uikit';
|
|
4
4
|
import { i18nFactory } from '../../i18n';
|
|
5
5
|
import { EventEmitter } from './eventEmitter';
|
|
6
|
+
import { mergeSettingStrategy } from './mergeSettingStrategy';
|
|
6
7
|
export const settingsEventEmitter = new EventEmitter();
|
|
7
8
|
const removeUndefinedValues = (data) => {
|
|
8
9
|
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
@@ -29,7 +30,7 @@ class ChartKitSettings {
|
|
|
29
30
|
}
|
|
30
31
|
set(updates) {
|
|
31
32
|
const filteredUpdates = removeUndefinedValues(updates);
|
|
32
|
-
this.settings =
|
|
33
|
+
this.settings = mergeWith(this.settings, filteredUpdates, mergeSettingStrategy);
|
|
33
34
|
if (filteredUpdates.lang) {
|
|
34
35
|
const lang = filteredUpdates.lang || this.get('lang');
|
|
35
36
|
updateLang(lang);
|
package/package.json
CHANGED