Skip to content

Commit ff692df

Browse files
feat: always use localStorage if no settingsApi (#603)
1 parent 8faeabc commit ff692df

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/services/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ import type {StorageApiRequestParams} from '../store/reducers/storage/types';
3434

3535
import {backend as BACKEND} from '../store';
3636
import {prepareSortValue} from '../utils/filters';
37+
import {settingsApi} from '../utils/settings';
3738

3839
const config = {withCredentials: !window.custom_backend};
3940

40-
const settingsApi = window.web_version ? window.systemSettings?.settingsApi : undefined;
41-
4241
type AxiosOptions = {
4342
concurrentId?: string;
4443
};

src/store/reducers/settings/settings.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import {
2121
import '../../../services/api';
2222
import {parseJson} from '../../../utils/utils';
2323
import {QUERY_ACTIONS, QUERY_MODES} from '../../../utils/query';
24-
import {readSavedSettingsValue, systemSettings, userSettings} from '../../../utils/settings';
24+
import {
25+
readSavedSettingsValue,
26+
settingsApi,
27+
systemSettings,
28+
userSettings,
29+
} from '../../../utils/settings';
2530

2631
import {TENANT_PAGES_IDS} from '../tenant/constants';
2732

@@ -115,13 +120,16 @@ export const setSettingValue = (
115120
name: string,
116121
value: string,
117122
): ThunkAction<void, RootState, unknown, SetSettingValueAction> => {
118-
return (dispatch, getState) => {
123+
return (dispatch) => {
119124
dispatch({type: SET_SETTING_VALUE, data: {name, value}});
120-
const {singleClusterMode} = getState();
121-
if (singleClusterMode) {
122-
localStorage.setItem(name, value);
123-
} else {
125+
126+
// If there is no settingsApi, use localStorage
127+
if (settingsApi) {
124128
window.api.postSetting(name, value);
129+
} else {
130+
try {
131+
localStorage.setItem(name, value);
132+
} catch {}
125133
}
126134
};
127135
};

src/utils/settings.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import {getValueFromLS} from './utils';
33
export const userSettings = window.userSettings || {};
44
export const systemSettings = window.systemSettings || {};
55

6+
export const settingsApi = window.web_version ? systemSettings.settingsApi : undefined;
7+
68
export function readSavedSettingsValue(key: string, defaultValue?: string) {
7-
const savedValue = window.web_version ? userSettings[key] : getValueFromLS(key);
9+
// If there is no settingsApi, use localStorage
10+
const savedValue = settingsApi ? userSettings[key] : getValueFromLS(key);
811

912
return savedValue ?? defaultValue;
1013
}

0 commit comments

Comments
 (0)