2024-03-08 04:38:11 -08:00
|
|
|
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
2024-07-15 13:19:47 -07:00
|
|
|
import { useAppSelector } from "./hooks";
|
2024-03-08 04:38:11 -08:00
|
|
|
|
|
|
|
interface Settings {
|
2024-07-15 13:19:47 -07:00
|
|
|
consolesLink: string | null;
|
|
|
|
agentMode: boolean;
|
|
|
|
ready: boolean;
|
2024-03-08 04:38:11 -08:00
|
|
|
pathPrefix: string;
|
2024-03-14 04:07:13 -07:00
|
|
|
useLocalTime: boolean;
|
|
|
|
enableQueryHistory: boolean;
|
|
|
|
enableAutocomplete: boolean;
|
|
|
|
enableSyntaxHighlighting: boolean;
|
|
|
|
enableLinter: boolean;
|
|
|
|
showAnnotations: boolean;
|
2024-03-08 04:38:11 -08:00
|
|
|
}
|
|
|
|
|
2024-07-15 13:19:47 -07:00
|
|
|
// Declared/defined in public/index.html, value replaced by Prometheus when serving bundle.
|
|
|
|
declare const GLOBAL_CONSOLES_LINK: string;
|
|
|
|
declare const GLOBAL_AGENT_MODE: string;
|
|
|
|
declare const GLOBAL_READY: string;
|
|
|
|
|
2024-03-08 04:38:11 -08:00
|
|
|
const initialState: Settings = {
|
2024-07-15 13:19:47 -07:00
|
|
|
consolesLink:
|
|
|
|
GLOBAL_CONSOLES_LINK === "CONSOLES_LINK_PLACEHOLDER" ||
|
|
|
|
GLOBAL_CONSOLES_LINK === "" ||
|
|
|
|
GLOBAL_CONSOLES_LINK === null
|
|
|
|
? null
|
|
|
|
: GLOBAL_CONSOLES_LINK,
|
|
|
|
agentMode: GLOBAL_AGENT_MODE === "true",
|
|
|
|
ready: GLOBAL_READY === "true",
|
2024-03-08 04:38:11 -08:00
|
|
|
pathPrefix: "",
|
2024-03-14 04:07:13 -07:00
|
|
|
useLocalTime: false,
|
|
|
|
enableQueryHistory: false,
|
|
|
|
enableAutocomplete: true,
|
|
|
|
enableSyntaxHighlighting: true,
|
|
|
|
enableLinter: true,
|
|
|
|
showAnnotations: false,
|
2024-03-08 04:38:11 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const settingsSlice = createSlice({
|
|
|
|
name: "settings",
|
|
|
|
initialState,
|
|
|
|
reducers: {
|
|
|
|
updateSettings: (state, { payload }: PayloadAction<Partial<Settings>>) => {
|
|
|
|
Object.assign(state, payload);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const { updateSettings } = settingsSlice.actions;
|
|
|
|
|
2024-07-15 13:19:47 -07:00
|
|
|
export const useSettings = () => {
|
|
|
|
return useAppSelector((state) => state.settings);
|
|
|
|
};
|
|
|
|
|
2024-03-08 04:38:11 -08:00
|
|
|
export default settingsSlice.reducer;
|