Remove settings from setting menu

Signed-off-by: leonnicolas <leonloechner@gmx.de>
This commit is contained in:
leonnicolas 2025-01-13 17:56:11 +01:00
parent b3531a12f3
commit 36520fd8b2
No known key found for this signature in database
GPG key ID: 088D0743E2B65C07
5 changed files with 33 additions and 95 deletions

View file

@ -21,10 +21,8 @@ const SettingsMenu: FC = () => {
enableSyntaxHighlighting, enableSyntaxHighlighting,
enableLinter, enableLinter,
showAnnotations, showAnnotations,
hideEmptyGroups,
ruleGroupsPerPage, ruleGroupsPerPage,
alertGroupsPerPage, alertGroupsPerPage,
showEmptyPools,
} = useSettings(); } = useSettings();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -105,47 +103,21 @@ const SettingsMenu: FC = () => {
/> />
</Stack> </Stack>
</Fieldset> </Fieldset>
<Fieldset p="md" legend="Targets page settings">
<Checkbox
checked={showEmptyPools}
label="Show empty pools"
onChange={(event) =>
dispatch(
updateSettings({
showEmptyPools: event.currentTarget.checked,
})
)
}
/>
</Fieldset>
</Stack> </Stack>
<Stack> <Stack>
<Fieldset p="md" legend="Alerts page settings"> <Fieldset p="md" legend="Alerts page settings">
<Stack> <Checkbox
<Checkbox checked={showAnnotations}
checked={showAnnotations} label="Show expanded annotations"
label="Show expanded annotations" onChange={(event) =>
onChange={(event) => dispatch(
dispatch( updateSettings({
updateSettings({ showAnnotations: event.currentTarget.checked,
showAnnotations: event.currentTarget.checked, })
}) )
) }
} />
/>
<Checkbox
checked={hideEmptyGroups}
label="Hide empty groups"
onChange={(event) =>
dispatch(
updateSettings({
hideEmptyGroups: event.currentTarget.checked,
})
)
}
/>
</Stack>
</Fieldset> </Fieldset>
<Fieldset p="md" legend="Alerts page settings"> <Fieldset p="md" legend="Alerts page settings">
<NumberInput <NumberInput

View file

@ -23,8 +23,8 @@ import { Fragment, useEffect, useMemo } from "react";
import { StateMultiSelect } from "../components/StateMultiSelect"; import { StateMultiSelect } from "../components/StateMultiSelect";
import { IconInfoCircle, IconSearch } from "@tabler/icons-react"; import { IconInfoCircle, IconSearch } from "@tabler/icons-react";
import { LabelBadges } from "../components/LabelBadges"; import { LabelBadges } from "../components/LabelBadges";
import { useSettings, updateSettings } from "../state/settingsSlice"; import { useLocalStorage } from "@mantine/hooks";
import { useAppDispatch } from "../state/hooks"; import { useSettings } from "../state/settingsSlice";
import { import {
ArrayParam, ArrayParam,
NumberParam, NumberParam,
@ -150,8 +150,7 @@ export default function AlertsPage() {
}, },
}); });
const { hideEmptyGroups, showAnnotations } = useSettings(); const { showAnnotations } = useSettings();
const dispatch = useAppDispatch();
// Define URL query params. // Define URL query params.
const [stateFilter, setStateFilter] = useQueryParam( const [stateFilter, setStateFilter] = useQueryParam(
@ -163,6 +162,10 @@ export default function AlertsPage() {
withDefault(StringParam, "") withDefault(StringParam, "")
); );
const [debouncedSearch] = useDebouncedValue<string>(searchFilter.trim(), 250); const [debouncedSearch] = useDebouncedValue<string>(searchFilter.trim(), 250);
const [showEmptyGroups, setShowEmptyGroups] = useLocalStorage<boolean>({
key: "alerts-page-show-empty-groups",
defaultValue: true,
});
const { alertGroupsPerPage } = useSettings(); const { alertGroupsPerPage } = useSettings();
const [activePage, setActivePage] = useQueryParam( const [activePage, setActivePage] = useQueryParam(
@ -178,10 +181,10 @@ export default function AlertsPage() {
const shownGroups = useMemo( const shownGroups = useMemo(
() => () =>
!hideEmptyGroups showEmptyGroups
? alertsPageData.groups ? alertsPageData.groups
: alertsPageData.groups.filter((g) => g.rules.length > 0), : alertsPageData.groups.filter((g) => g.rules.length > 0),
[alertsPageData.groups, hideEmptyGroups] [alertsPageData.groups, showEmptyGroups]
); );
// If we were e.g. on page 10 and the number of total pages decreases to 5 (due to filtering // If we were e.g. on page 10 and the number of total pages decreases to 5 (due to filtering
@ -252,13 +255,7 @@ export default function AlertsPage() {
<Anchor <Anchor
ml="md" ml="md"
fz="1em" fz="1em"
onClick={() => { onClick={() => setShowEmptyGroups(false)}
dispatch(
updateSettings({
hideEmptyGroups: true,
})
);
}}
> >
Hide empty groups Hide empty groups
</Anchor> </Anchor>
@ -270,13 +267,7 @@ export default function AlertsPage() {
<Anchor <Anchor
ml="md" ml="md"
fz="1em" fz="1em"
onClick={() => { onClick={() => setShowEmptyGroups(false)}
dispatch(
updateSettings({
hideEmptyGroups: true,
})
);
}}
> >
Hide empty groups Hide empty groups
</Anchor> </Anchor>
@ -412,7 +403,7 @@ export default function AlertsPage() {
)} )}
</Card> </Card>
)), )),
[currentPageGroups, showAnnotations, dispatch] [currentPageGroups, showAnnotations, setShowEmptyGroups]
); );
return ( return (
@ -451,7 +442,7 @@ export default function AlertsPage() {
No rules found. No rules found.
</Alert> </Alert>
) : ( ) : (
hideEmptyGroups && !showEmptyGroups &&
alertsPageData.groups.length !== shownGroups.length && ( alertsPageData.groups.length !== shownGroups.length && (
<Alert <Alert
title="Hiding groups with no matching rules" title="Hiding groups with no matching rules"
@ -459,13 +450,7 @@ export default function AlertsPage() {
> >
Hiding {alertsPageData.groups.length - shownGroups.length} empty Hiding {alertsPageData.groups.length - shownGroups.length} empty
groups due to filters or no rules. groups due to filters or no rules.
<Anchor <Anchor ml="md" fz="1em" onClick={() => setShowEmptyGroups(true)}>
ml="md"
fz="1em"
onClick={() =>
dispatch(updateSettings({ hideEmptyGroups: false }))
}
>
Show empty groups Show empty groups
</Anchor> </Anchor>
</Alert> </Alert>

View file

@ -25,12 +25,12 @@ import {
humanizeDuration, humanizeDuration,
now, now,
} from "../../lib/formatTime"; } from "../../lib/formatTime";
import { useLocalStorage } from "@mantine/hooks";
import { useAppDispatch, useAppSelector } from "../../state/hooks"; import { useAppDispatch, useAppSelector } from "../../state/hooks";
import { import {
setCollapsedPools, setCollapsedPools,
setShowLimitAlert, setShowLimitAlert,
} from "../../state/targetsPageSlice"; } from "../../state/targetsPageSlice";
import { useSettings, updateSettings } from "../../state/settingsSlice";
import EndpointLink from "../../components/EndpointLink"; import EndpointLink from "../../components/EndpointLink";
import CustomInfiniteScroll from "../../components/CustomInfiniteScroll"; import CustomInfiniteScroll from "../../components/CustomInfiniteScroll";
@ -164,8 +164,11 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
}, },
}); });
const { showEmptyPools } = useSettings();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [showEmptyPools, setShowEmptyPools] = useLocalStorage<boolean>({
key: "targets-page-show-empty-pools",
defaultValue: true,
});
const { collapsedPools, showLimitAlert } = useAppSelector( const { collapsedPools, showLimitAlert } = useAppSelector(
(state) => state.targetsPage (state) => state.targetsPage
@ -204,11 +207,7 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
> >
Hiding {allPoolNames.length - shownPoolNames.length} empty pools due Hiding {allPoolNames.length - shownPoolNames.length} empty pools due
to filters or no targets. to filters or no targets.
<Anchor <Anchor ml="md" fz="1em" onClick={() => setShowEmptyPools(true)}>
ml="md"
fz="1em"
onClick={() => dispatch(updateSettings({ showEmptyPools: true }))}
>
Show empty pools Show empty pools
</Anchor> </Anchor>
</Alert> </Alert>
@ -282,9 +281,7 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
<Anchor <Anchor
ml="md" ml="md"
fz="1em" fz="1em"
onClick={() => onClick={() => setShowEmptyPools(false)}
dispatch(updateSettings({ showEmptyPools: false }))
}
> >
Hide empty pools Hide empty pools
</Anchor> </Anchor>
@ -296,9 +293,7 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
<Anchor <Anchor
ml="md" ml="md"
fz="1em" fz="1em"
onClick={() => onClick={() => setShowEmptyPools(false)}
dispatch(updateSettings({ showEmptyPools: false }))
}
> >
Hide empty pools Hide empty pools
</Anchor> </Anchor>

View file

@ -62,10 +62,8 @@ startAppListening({
case "enableAutocomplete": case "enableAutocomplete":
case "enableSyntaxHighlighting": case "enableSyntaxHighlighting":
case "enableLinter": case "enableLinter":
case "hideEmptyGroups":
case "showAnnotations": case "showAnnotations":
case "ruleGroupsPerPage": case "ruleGroupsPerPage":
case "showEmptyPools":
return persistToLocalStorage(`settings.${key}`, value); return persistToLocalStorage(`settings.${key}`, value);
} }
}); });

View file

@ -13,11 +13,9 @@ interface Settings {
enableAutocomplete: boolean; enableAutocomplete: boolean;
enableSyntaxHighlighting: boolean; enableSyntaxHighlighting: boolean;
enableLinter: boolean; enableLinter: boolean;
hideEmptyGroups: boolean;
showAnnotations: boolean; showAnnotations: boolean;
ruleGroupsPerPage: number; ruleGroupsPerPage: number;
alertGroupsPerPage: number; alertGroupsPerPage: number;
showEmptyPools: boolean;
} }
// Declared/defined in public/index.html, value replaced by Prometheus when serving bundle. // Declared/defined in public/index.html, value replaced by Prometheus when serving bundle.
@ -32,11 +30,9 @@ export const localStorageKeyEnableAutocomplete = "settings.enableAutocomplete";
export const localStorageKeyEnableSyntaxHighlighting = export const localStorageKeyEnableSyntaxHighlighting =
"settings.enableSyntaxHighlighting"; "settings.enableSyntaxHighlighting";
export const localStorageKeyEnableLinter = "settings.enableLinter"; export const localStorageKeyEnableLinter = "settings.enableLinter";
export const localStorageKeyHideEmptyGroups = "settings.hideEmptyGroups";
export const localStorageKeyShowAnnotations = "settings.showAnnotations"; export const localStorageKeyShowAnnotations = "settings.showAnnotations";
export const localStorageKeyRuleGroupsPerPage = "settings.ruleGroupsPerPage"; export const localStorageKeyRuleGroupsPerPage = "settings.ruleGroupsPerPage";
export const localStorageKeyAlertGroupsPerPage = "settings.alertGroupsPerPage"; export const localStorageKeyAlertGroupsPerPage = "settings.alertGroupsPerPage";
export const localStorageKeyShowEmptyPools = "settings.showEmptyPools";
// This dynamically/generically determines the pathPrefix by stripping the first known // This dynamically/generically determines the pathPrefix by stripping the first known
// endpoint suffix from the window location path. It works out of the box for both direct // endpoint suffix from the window location path. It works out of the box for both direct
@ -99,10 +95,6 @@ export const initialState: Settings = {
localStorageKeyEnableLinter, localStorageKeyEnableLinter,
true true
), ),
hideEmptyGroups: initializeFromLocalStorage<boolean>(
localStorageKeyHideEmptyGroups,
false
),
showAnnotations: initializeFromLocalStorage<boolean>( showAnnotations: initializeFromLocalStorage<boolean>(
localStorageKeyShowAnnotations, localStorageKeyShowAnnotations,
true true
@ -115,10 +107,6 @@ export const initialState: Settings = {
localStorageKeyAlertGroupsPerPage, localStorageKeyAlertGroupsPerPage,
10 10
), ),
showEmptyPools: initializeFromLocalStorage<boolean>(
localStorageKeyShowEmptyPools,
true
),
}; };
export const settingsSlice = createSlice({ export const settingsSlice = createSlice({