Add a setting to leave unused integration pages out of the menu
Settings -> Display -> Menu: when on, the menu, command palette and shortcuts omit the pages of integration kinds nobody has added (off by default, the same for everyone). Pages useful without an integration always stay; adding an integration brings its page back at once. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f5068c6e0
commit
587e8856a0
13 files changed
+346
-7
No files matched your search
@@ -7,6 +7,7 @@ import DiagLogView from "../views/DiagLogView";
|
||||
import IntegrationEditForm from "../components/IntegrationEditForm";
|
||||
import TableToolbar from "../components/TableToolbar";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { MENU_CHANGED } from "../hooks/useMenuHiding";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
@@ -109,6 +110,7 @@ function IntegrationsList({ user, tabs }: { user: CurrentUser; tabs: ReactNode }
|
||||
.list()
|
||||
.then((res) => {
|
||||
setIntegrations(res.integrations);
|
||||
window.dispatchEvent(new Event(MENU_CHANGED)); // the menu may leave out pages of integrations nobody has added
|
||||
// Deep-link from global search (?editId=) — jump straight to that integration's edit form.
|
||||
const editId = Number(searchParams.get("editId"));
|
||||
const target = res.integrations.find((i) => i.id === editId);
|
||||
|
||||
@@ -2,6 +2,9 @@ import { useEffect, useState } from "react";
|
||||
import { api, type AppSettings, type DateFormat, type TimeFormat } from "../../api/client";
|
||||
import { setDateTimeSettings } from "../../utils/date";
|
||||
import { setPageSize } from "../../utils/pageSize";
|
||||
import { MENU_CHANGED } from "../../hooks/useMenuHiding";
|
||||
import { PAGE_KINDS, unusedPages } from "../../utils/navVisibility";
|
||||
import { NAV, isGroup } from "../../layout/nav";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import { PageSkeleton } from "../../components/Skeleton";
|
||||
|
||||
@@ -21,6 +24,9 @@ export default function DisplaySettings() {
|
||||
const [dateFormat, setDateFormatState] = useState<DateFormat>("ymd");
|
||||
const [timeFormat, setTimeFormatState] = useState<TimeFormat>("24h");
|
||||
const [pageSize, setPageSizeState] = useState(20);
|
||||
const [hideUnusedPages, setHideUnusedPages] = useState(false);
|
||||
// The kinds of integration that have been added, to say which pages the setting would leave out.
|
||||
const [added, setAdded] = useState<string[] | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [saved, setSaved] = useState(false);
|
||||
const [saveError, setSaveError] = useState<string | null>(null);
|
||||
@@ -32,9 +38,14 @@ export default function DisplaySettings() {
|
||||
setDateFormatState(res.settings.display.dateFormat);
|
||||
setTimeFormatState(res.settings.display.timeFormat);
|
||||
setPageSizeState(res.settings.display.pageSize);
|
||||
setHideUnusedPages(res.settings.display.hideUnusedPages);
|
||||
})
|
||||
.catch((err) => setLoadError(err instanceof Error ? err.message : String(err)))
|
||||
.finally(() => setLoading(false));
|
||||
api.integrations
|
||||
.list()
|
||||
.then((res) => setAdded(res.integrations.map((i) => i.type)))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
async function handleSave() {
|
||||
@@ -42,9 +53,10 @@ export default function DisplaySettings() {
|
||||
setSaveError(null);
|
||||
setSaved(false);
|
||||
try {
|
||||
const res = await api.settings.update({ display: { dateFormat, timeFormat, pageSize } });
|
||||
const res = await api.settings.update({ display: { dateFormat, timeFormat, pageSize, hideUnusedPages } });
|
||||
setDateTimeSettings(res.settings.display);
|
||||
setPageSize(res.settings.display.pageSize);
|
||||
window.dispatchEvent(new Event(MENU_CHANGED));
|
||||
setSaved(true);
|
||||
setTimeout(() => setSaved(false), 3000);
|
||||
} catch (err) {
|
||||
@@ -56,6 +68,8 @@ export default function DisplaySettings() {
|
||||
|
||||
if (loading) return <PageSkeleton />;
|
||||
|
||||
// The menu's pages the setting would leave out, by name, with what has been added so far.
|
||||
const wouldHide = added === null ? null : menuLabelsOf(unusedPages(added));
|
||||
const dateExample = DATE_FORMAT_OPTIONS.find((o) => o.value === dateFormat)?.example ?? "";
|
||||
|
||||
return (
|
||||
@@ -138,7 +152,47 @@ export default function DisplaySettings() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Menu</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<label className="form-check">
|
||||
<input type="checkbox" className="form-check-input" checked={hideUnusedPages} onChange={(e) => setHideUnusedPages(e.target.checked)} />
|
||||
<span className="form-check-label">Hide the pages of integrations I have not added</span>
|
||||
</label>
|
||||
<div className="form-hint mt-1">
|
||||
A page for something that is not in your homelab (Jellyfin, Gitea, n8n …) is left out of the menu, the command palette and the keyboard shortcuts until you add that integration under
|
||||
Administration → Integrations. It is still there by its address, and pages that are useful without an integration (Servers, Alerts, DNS, Secrets …) always stay. A group with nothing left disappears.
|
||||
</div>
|
||||
{wouldHide !== null && (
|
||||
<div className="mt-3 small" aria-live="polite">
|
||||
{wouldHide.length === 0 ? (
|
||||
<span className="text-secondary">With what you have added, there is nothing to leave out.</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="text-secondary">{hideUnusedPages ? "Left out now" : "Would leave out"} ({wouldHide.length}): </span>
|
||||
{wouldHide.join(", ")}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** The menu's names for pages, in the menu's order, for the pages given (by path). */
|
||||
function menuLabelsOf(pages: Set<string>): string[] {
|
||||
const out: string[] = [];
|
||||
for (const entry of NAV) {
|
||||
const leaves = isGroup(entry) ? entry.items : [entry];
|
||||
for (const leaf of leaves) if (pages.has(leaf.to.split("?")[0]) && PAGE_KINDS[leaf.to.split("?")[0]]) out.push(leaf.label);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user