ydb-embedded-ui 4.27.0 → 4.27.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.27.1](https://github.com/ydb-platform/ydb-embedded-ui/compare/v4.27.0...v4.27.1) (2024-01-10)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * enable extract and set user settings manually ([#629](https://github.com/ydb-platform/ydb-embedded-ui/issues/629)) ([5eecd58](https://github.com/ydb-platform/ydb-embedded-ui/commit/5eecd58249688b4a8b3ecad766564f7b404e839c))
9
+
3
10
  ## [4.27.0](https://github.com/ydb-platform/ydb-embedded-ui/compare/v4.26.0...v4.27.0) (2023-12-28)
4
11
 
5
12
 
@@ -23,7 +23,7 @@ export type SettingsObject = Record<string, unknown>;
23
23
  const USE_LOCAL_STORAGE_FOR_SETTINGS_KEY = 'useLocalStorageForSettings';
24
24
 
25
25
  /** User settings keys and their default values */
26
- const DEFAULT_USER_SETTINGS: SettingsObject = {
26
+ export const DEFAULT_USER_SETTINGS: SettingsObject = {
27
27
  [THEME_KEY]: 'system',
28
28
  [LANGUAGE_KEY]: undefined,
29
29
  [INVERTED_DISKS_KEY]: false,
@@ -59,20 +59,13 @@ class SettingsManager {
59
59
  }
60
60
  }
61
61
 
62
- /**
63
- * User settings - settings stored in LS or external store
64
- */
65
- getUserSettings() {
66
- return this.extractSettingsFromLS();
67
- }
68
-
69
62
  /**
70
63
  * Returns parsed settings value.
71
64
  * If value cannot be parsed, returns initially stored string.
72
65
  * If there is no value, return default value
73
66
  */
74
67
  readUserSettingsValue(key: string, defaultValue?: unknown) {
75
- return this.readValueFromLS(key) ?? defaultValue ?? DEFAULT_USER_SETTINGS[key];
68
+ return this.readValueFromLS(key) ?? defaultValue;
76
69
  }
77
70
 
78
71
  /**
@@ -82,8 +75,11 @@ class SettingsManager {
82
75
  return this.setValueToLS(key, value);
83
76
  }
84
77
 
85
- private extractSettingsFromLS = () => {
86
- return Object.entries(DEFAULT_USER_SETTINGS).reduce<SettingsObject>((acc, [key, value]) => {
78
+ /**
79
+ * Extract values by provided settings object
80
+ */
81
+ extractSettingsFromLS = (settings: SettingsObject) => {
82
+ return Object.entries(settings).reduce<SettingsObject>((acc, [key, value]) => {
87
83
  acc[key] = this.readUserSettingsValue(key, value);
88
84
  return acc;
89
85
  }, {});
@@ -2,7 +2,7 @@ import type {Reducer} from 'redux';
2
2
  import type {ThunkAction} from 'redux-thunk';
3
3
 
4
4
  import '../../../services/api';
5
- import {settingsManager} from '../../../services/settings';
5
+ import {DEFAULT_USER_SETTINGS, SettingsObject, settingsManager} from '../../../services/settings';
6
6
 
7
7
  import type {RootState} from '..';
8
8
  import type {
@@ -15,13 +15,14 @@ import type {
15
15
 
16
16
  const CHANGE_PROBLEM_FILTER = 'settings/CHANGE_PROBLEM_FILTER';
17
17
  export const SET_SETTING_VALUE = 'settings/SET_VALUE';
18
+ export const SET_USER_SETTINGS = 'settings/SET_USER_SETTINGS';
18
19
 
19
20
  export const ProblemFilterValues = {
20
21
  ALL: 'All',
21
22
  PROBLEMS: 'With problems',
22
23
  } as const;
23
24
 
24
- const userSettings = settingsManager.getUserSettings();
25
+ const userSettings = settingsManager.extractSettingsFromLS(DEFAULT_USER_SETTINGS);
25
26
  const systemSettings = window.systemSettings || {};
26
27
 
27
28
  export const initialState = {
@@ -49,7 +50,15 @@ const settings: Reducer<SettingsState, SettingsAction> = (state = initialState,
49
50
  userSettings: newSettings,
50
51
  };
51
52
  }
52
-
53
+ case SET_USER_SETTINGS: {
54
+ return {
55
+ ...state,
56
+ userSettings: {
57
+ ...state.userSettings,
58
+ ...action.data,
59
+ },
60
+ };
61
+ }
53
62
  default:
54
63
  return state;
55
64
  }
@@ -66,6 +75,10 @@ export const setSettingValue = (
66
75
  };
67
76
  };
68
77
 
78
+ export const setUserSettings = (data: SettingsObject) => {
79
+ return {type: SET_USER_SETTINGS, data} as const;
80
+ };
81
+
69
82
  export const getSettingValue = (state: SettingsRootStateSlice, name: string) => {
70
83
  return state.settings.userSettings[name];
71
84
  };
@@ -1,6 +1,6 @@
1
1
  import type {ValueOf} from '../../../types/common';
2
2
  import type {SettingsObject} from '../../../services/settings';
3
- import {changeFilter, ProblemFilterValues, SET_SETTING_VALUE} from './settings';
3
+ import {changeFilter, setUserSettings, ProblemFilterValues, SET_SETTING_VALUE} from './settings';
4
4
 
5
5
  export type ProblemFilterValue = ValueOf<typeof ProblemFilterValues>;
6
6
 
@@ -15,7 +15,10 @@ export type SetSettingValueAction = {
15
15
  data: {name: string; value: unknown};
16
16
  };
17
17
 
18
- export type SettingsAction = ReturnType<typeof changeFilter> | SetSettingValueAction;
18
+ export type SettingsAction =
19
+ | ReturnType<typeof changeFilter>
20
+ | ReturnType<typeof setUserSettings>
21
+ | SetSettingValueAction;
19
22
 
20
23
  export interface SettingsRootStateSlice {
21
24
  settings: SettingsState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ydb-embedded-ui",
3
- "version": "4.27.0",
3
+ "version": "4.27.1",
4
4
  "files": [
5
5
  "dist"
6
6
  ],