feat: add global sidebar links management and settings UI

This commit is contained in:
jhartworks committed 2026-11-25 09:38:54 +01:00
1 parent 3203577a9d
commit f6f3c402cc
10 files changed
+463 -40

No files matched your search

+82 -6
View File
@@ -4,6 +4,7 @@ import { api } from "./api.js";
import Gauge from "./components/Gauge.jsx";
import TrendChart from "./components/TrendChart.jsx";
import Sidebar, { SmallFootnote } from "./components/Sidebar.jsx";
import SidebarLinkSettings from "./components/SidebarLinkSettings.jsx";
import { AUTO_UNIT, DEFAULT_UNITS as DEFAULT_UNIT_OPTIONS, DIGITAL_UNIT, normalizeUnitSymbol, resolveEngineeringUnit } from "../../shared/engineering-units.mjs";
import { DEFAULT_CHART_SETTINGS, normalizeTrendChartSettings } from "../../shared/trend-chart-settings.mjs";
import {
@@ -22,6 +23,7 @@ const views = [
];
const CHART_DRAFT_KEY = "seltd:trend-chart";
const TREND_TOUCH_KEY = "seltd:trend-touch";
function loadChartDraft() {
try {
@@ -602,12 +604,12 @@ function PointLibrary({ isp, metadata, metadataCache, selectedPoints, filterText
{filteredPoints.map((point) => {
const key = `${point.isp}:${point.pointIndex}`;
const selected = selectedKeys.has(key);
const alias = normalizeDisplayText(point.alias, `Wert ${point.pointIndex}`);
const alias = normalizeDisplayText(point.alias, "Datenpunkt");
return (
<button key={key} type="button" className="point-item" aria-pressed={selected} title={alias} onClick={() => onTogglePoint(point)}>
<div className="point-copy">
<strong>{alias}</strong>
<span>{selectedOnly ? `${normalizeDisplayText(metadataCache[point.isp]?.displayName, point.isp)} · ` : ""}{`Wert ${point.pointIndex}${point.unit ? ` · ${normalizeDisplayUnit(point.unit)}` : ""}`}</span>
{selectedOnly ? <span>{normalizeDisplayText(metadataCache[point.isp]?.displayName, point.isp)}</span> : null}
</div>
<span className="point-tag">{selected ? "\u2713" : point.kind}</span>
</button>
@@ -673,8 +675,18 @@ export default function App() {
const [themeMode, setThemeMode] = useState("system");
const [csvDelimiter, setCsvDelimiter] = useState(";");
const [sidebarPinned, setSidebarPinned] = useState(true);
const [sidebarLinkPreferences, setSidebarLinkPreferences] = useState(null);
const [globalSidebarLinks, setGlobalSidebarLinks] = useState(null);
const [globalSidebarLinksError, setGlobalSidebarLinksError] = useState("");
const [trendLineWidth, setTrendLineWidth] = useState("1.8");
const [trendFocus, setTrendFocus] = useState(false);
const [trendTouch, setTrendTouch] = useState(() => {
try {
return localStorage.getItem(TREND_TOUCH_KEY) === "1";
} catch {
return false;
}
});
const [adminIsp, setAdminIsp] = useState("");
const [aliasEditor, setAliasEditor] = useState(null);
const [passwordDraft, setPasswordDraft] = useState({ currentPassword: "", nextPassword: "", repeatPassword: "" });
@@ -719,6 +731,7 @@ export default function App() {
const canAccessAdmin = canEditAliases || canManageSources || canManageAlarms || canManageUsers || canManageRoles || canManageIntegrations || canManageRunner || canViewDebug;
const firstAdminSection = canEditAliases ? "aliases" : canManageSources ? "sources" : canManageAlarms ? "alarms" : canManageUsers ? "users" : canManageRoles ? "roles" : canManageIntegrations ? "integrations" : canManageRunner ? "runner" : canViewDebug ? "debug" : "aliases";
const sidebarCollapsed = !sidebarPinned;
const sidebarLinks = sidebarLinkPreferences?.token === token ? sidebarLinkPreferences.links : [];
const selectedSelection = selections.find((selection) => selection.id === selectedSelectionId);
const canEditSelectedSelection = Boolean(selectedSelection && (
selectedSelection.ownerId === user?.id || user?.role === "admin"
@@ -935,6 +948,7 @@ export default function App() {
setThemeMode(pref.theme || "system");
setCsvDelimiter(pref.csvDelimiter || ";");
setSidebarPinned(typeof pref.sidebarPinned === "boolean" ? pref.sidebarPinned : true);
setSidebarLinkPreferences({ token, links: pref.sidebarLinks || [] });
setTrendLineWidth(String(pref.trendLineWidth || 1.8));
setMaxTrendSeries(normalizeMaxTrendSeries(pref.maxTrendSeries));
setIsps(ispResult.isps || []);
@@ -1024,6 +1038,26 @@ export default function App() {
.catch(() => undefined);
}, [csvDelimiter, maxTrendSeries, preferencesReady, sidebarPinned, themeMode, token, trendLineWidth]);
const saveSidebarLinks = async (links) => {
const pending = preferenceWrite.current.then(() => api.savePreferences(token, { sidebarLinks: links }));
preferenceWrite.current = pending.catch(() => undefined);
const saved = await pending;
setSidebarLinkPreferences((current) => current?.token === token ? { token, links: saved.sidebarLinks } : current);
};
useEffect(() => {
let ignore = false;
api.getGlobalSidebarLinks()
.then(({ links }) => { if (!ignore) setGlobalSidebarLinks(links); })
.catch(() => { if (!ignore) setGlobalSidebarLinksError("Globale Links konnten nicht geladen werden."); });
return () => { ignore = true; };
}, []);
const saveGlobalSidebarLinks = async (links) => {
const saved = await api.saveGlobalSidebarLinks(token, links);
setGlobalSidebarLinks(saved.links);
};
useEffect(() => {
if (!selectedIsp || metadataCache[selectedIsp]) {
return;
@@ -1317,6 +1351,7 @@ export default function App() {
setTrendLoading(false);
setToken("");
setUser(null);
setSidebarLinkPreferences(null);
setIsps([]);
setSelections([]);
setDashboard({ widgets: [] });
@@ -1463,6 +1498,16 @@ export default function App() {
savingSettings: savingSelection,
};
const toggleTrendTouch = () => {
const enabled = !trendTouch;
setTrendTouch(enabled);
try {
localStorage.setItem(TREND_TOUCH_KEY, enabled ? "1" : "0");
} catch {
// The mode remains available for the current page without browser storage.
}
};
const addWidget = () => {
const widget = {
id: createWidgetId(),
@@ -2305,6 +2350,7 @@ export default function App() {
<div className={sidebarCollapsed ? "app-shell sidebar-collapsed" : "app-shell"}>
<Sidebar
collapsed={sidebarCollapsed}
links={[...(globalSidebarLinks || []), ...sidebarLinks]}
onToggle={() => setSidebarPinned((current) => !current)}
views={views.filter((view) => ({
dashboard: canViewDashboard,
@@ -2319,16 +2365,28 @@ export default function App() {
onLogout={handleLogout}
/>
<main className={activeView === "trends" && !trendFocus ? "content trend-content" : "content"}>
<main className={[
"content",
activeView === "trends" && !trendFocus && "trend-content",
activeView === "trends" && trendTouch && "trend-touch",
].filter(Boolean).join(" ")}>
<div className="view-strip">
<div>
<div className="eyebrow">Ansicht</div>
<strong>{currentView.label}</strong>
</div>
{activeView === "trends" && !trendFocus ? (
{activeView === "trends" ? (
<div className="view-meta">
<span className="small-badge">ISPs mit Daten: {trendIsps.length}</span>
<span className="small-badge">Aktuelle Auswahl: {workingPoints.length}</span>
{!trendFocus ? (
<>
<span className="small-badge">ISPs mit Daten: {trendIsps.length}</span>
<span className="small-badge">Aktuelle Auswahl: {workingPoints.length}</span>
</>
) : null}
<button className="ghost-button compact-button trend-touch-toggle" type="button"
aria-pressed={trendTouch} onClick={toggleTrendTouch}>
Touch-Modus
</button>
</div>
) : null}
</div>
@@ -2495,6 +2553,7 @@ export default function App() {
allowExports
allowFocusMode
lineWidth={Number(trendLineWidth)}
touchMode={trendTouch}
{...trendChartSettingsProps}
/>
) : (
@@ -2640,6 +2699,7 @@ export default function App() {
allowExports
allowFocusMode
lineWidth={Number(trendLineWidth)}
touchMode={trendTouch}
{...trendChartSettingsProps}
/>
) : (
@@ -3774,6 +3834,22 @@ export default function App() {
</div>
<button className="primary-button compact-button" type="button" onClick={changePassword}>Passwort speichern</button>
</div>
<SidebarLinkSettings title="Persönliche Seitenleisten-Links" links={sidebarLinks} onSave={saveSidebarLinks} />
{user?.role === "admin" ? (
globalSidebarLinks ? (
<SidebarLinkSettings
title="Globale Seitenleisten-Links"
description="Sichtbar für alle, auch ohne Anmeldung."
links={globalSidebarLinks}
onSave={saveGlobalSidebarLinks}
/>
) : (
<div className="panel slim-panel span-two">
<h3>Globale Seitenleisten-Links</h3>
<p role="status">{globalSidebarLinksError || "Globale Links werden geladen ..."}</p>
</div>
)
) : null}
</section>
)
) : null}
+2
View File
@@ -80,6 +80,8 @@ export const api = {
loadDashboardData: (token, body) => apiRequest("/dashboard/data", { method: "POST", token, body }),
getPreferences: (token) => apiRequest("/preferences", { token }),
savePreferences: (token, body) => apiRequest("/preferences", { method: "PUT", token, body }),
getGlobalSidebarLinks: () => apiRequest("/settings/sidebar-links"),
saveGlobalSidebarLinks: (token, links) => apiRequest("/settings/sidebar-links", { method: "PUT", token, body: { links } }),
getTrendDefaults: () => apiRequest("/settings/trend"),
saveTrendDefaults: (token, body) => apiRequest("/settings/trend", { method: "PUT", token, body }),
getIntegrations: (token) => apiRequest("/integrations", { token }),
+23 -1
View File
@@ -7,8 +7,16 @@ const icons = {
collapse: "M3 5h18v14H3z M9 5v14 M16 9l-3 3 3 3",
login: "M14 4h6v16h-6 M4 12h12 M12 8l4 4-4 4",
logout: "M10 4H4v16h6 M8 12h12 M16 8l4 4-4 4",
external: "M13 4h7v7 M20 4l-9 9 M10 4H4v16h16v-6",
};
function linkMonogram(label) {
const words = label.split(/\s+/);
return words.length > 1
? words.slice(0, 2).map((word) => Array.from(word)[0]).join("")
: Array.from(label).slice(0, 2).join("");
}
function SidebarIcon({ name }) {
return (
<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
@@ -21,7 +29,7 @@ export function SmallFootnote() {
return <div className="tiny-note">by J.H. | SE Inno GmbH</div>;
}
export default function Sidebar({ collapsed, onToggle, views, activeView, onNavigate, user, userLabel, onLogout }) {
export default function Sidebar({ collapsed, onToggle, views, activeView, onNavigate, links, user, userLabel, onLogout }) {
const toggleLabel = collapsed ? "Seitenleiste ausklappen" : "Seitenleiste einklappen";
const accountLabel = user ? "Abmelden" : "Anmelden";
@@ -58,6 +66,20 @@ export default function Sidebar({ collapsed, onToggle, views, activeView, onNavi
</button>
))}
</nav>
{links.length ? (
<nav className="nav-list sidebar-links" aria-label="Eigene Links">
{links.map((link, index) => (
<a key={index} className="sidebar-link nav-button" href={link.url} title={link.label} aria-label={link.label}>
{collapsed ? <span className="sidebar-link-monogram" aria-hidden="true">{linkMonogram(link.label)}</span> : (
<>
<SidebarIcon name="external" />
<span className="sidebar-link-label">{link.label}</span>
</>
)}
</a>
))}
</nav>
) : null}
</div>
<div className="sidebar-footer">
{user && !collapsed ? (
+109
View File
@@ -0,0 +1,109 @@
import { useState } from "react";
import { normalizeSidebarLink } from "../../../shared/sidebar-links.mjs";
const emptyLink = { label: "", url: "" };
export default function SidebarLinkSettings({ title, description, links, onSave }) {
const [draft, setDraft] = useState(emptyLink);
const [editingIndex, setEditingIndex] = useState(null);
const [saving, setSaving] = useState(false);
const [error, setError] = useState("");
const [notice, setNotice] = useState("");
function resetDraft() {
setDraft(emptyLink);
setEditingIndex(null);
}
async function persist(nextLinks) {
setSaving(true);
setError("");
setNotice("");
try {
await onSave(nextLinks);
setNotice("Seitenleisten-Links gespeichert.");
return true;
} catch (error) {
setError(error.message);
return false;
} finally {
setSaving(false);
}
}
async function submit(event) {
event.preventDefault();
setNotice("");
try {
const link = normalizeSidebarLink(draft);
const nextLinks = editingIndex === null
? [...links, link]
: links.map((existing, index) => index === editingIndex ? link : existing);
if (await persist(nextLinks)) resetDraft();
} catch (error) {
setError(error.message);
}
}
async function removeLink(index) {
if (!window.confirm(`Link „${links[index].label}“ aus der Seitenleiste entfernen?`)) return;
if (await persist(links.filter((_, linkIndex) => linkIndex !== index))) {
if (editingIndex === index) resetDraft();
else if (editingIndex !== null && index < editingIndex) setEditingIndex(editingIndex - 1);
}
}
return (
<div className="panel slim-panel span-two sidebar-link-settings">
<div className="panel-header compact-header">
<div>
<h3>{title}</h3>
{description ? <p>{description}</p> : null}
</div>
</div>
<form className="form-grid" onSubmit={submit}>
<label>
<span>Name</span>
<input required value={draft.label} placeholder="Leitstelle" disabled={saving}
onChange={(event) => setDraft({ ...draft, label: event.target.value })} />
</label>
<label>
<span>Adresse</span>
<input required type="url" placeholder="https://leitstelle.example" value={draft.url} disabled={saving}
onChange={(event) => setDraft({ ...draft, url: event.target.value })} />
</label>
<div className="button-row span-two">
<button className="primary-button compact-button" disabled={saving}>
{editingIndex === null ? "Link hinzufügen" : "Änderung speichern"}
</button>
{editingIndex === null ? null : (
<button className="ghost-button compact-button" type="button" disabled={saving} onClick={resetDraft}>Abbrechen</button>
)}
</div>
</form>
{error ? <div className="error-box" role="alert">{error}</div> : null}
{notice ? <small className="muted" role="status">{notice}</small> : null}
{links.length ? (
<ul className="sidebar-link-list">
{links.map((link, index) => (
<li key={index} className="sidebar-link-setting">
<div className="sidebar-link-copy"><strong>{link.label}</strong><small className="muted">{link.url}</small></div>
<div className="button-row">
<button className="ghost-button compact-button" type="button" disabled={saving}
aria-label={`${link.label} bearbeiten`}
onClick={() => { setEditingIndex(index); setDraft(link); setError(""); setNotice(""); }}>
Bearbeiten
</button>
<button className="ghost-button compact-button danger" type="button" disabled={saving}
aria-label={`${link.label} entfernen`} onClick={() => removeLink(index)}>
Entfernen
</button>
</div>
</li>
))}
</ul>
) : null}
</div>
);
}
+15 -4
View File
@@ -34,7 +34,7 @@ function formatTrendNumber(value) {
return Number.isFinite(numeric) ? numeric.toFixed(2) : "--";
}
function TimeZoomOverlay({ offset, onZoom }) {
function TimeZoomOverlay({ offset, onZoom, touchMode }) {
const activeDrag = useRef(null);
const [drag, setDrag] = useState(null);
if (!offset?.width || !offset.height) return null;
@@ -67,7 +67,7 @@ function TimeZoomOverlay({ offset, onZoom }) {
x={offset.left} y={offset.top} width={offset.width} height={offset.height}
fill="transparent"
onPointerDown={(event) => {
if (!event.isPrimary || event.button !== 0) return;
if (!event.isPrimary || event.button !== 0 || (touchMode && event.pointerType === "touch")) return;
const start = position(event);
event.currentTarget.setPointerCapture(event.pointerId);
activeDrag.current = { start, end: start, pointerId: event.pointerId };
@@ -101,6 +101,7 @@ export default function TrendChart({
allowExports = true,
allowFocusMode = true,
compact = false,
touchMode = false,
lineWidth = 1.8,
settings = DEFAULT_CHART_SETTINGS,
onSettingsChange,
@@ -144,6 +145,15 @@ export default function TrendChart({
if (domain) setZoomDomain({ result, domain });
}
function zoomOutTime() {
if (!activeZoom) return;
const [min, max] = activeZoom;
const padding = Math.round((max - min) / 2);
const from = Math.max(baseXDomain[0], min - padding);
const to = Math.min(baseXDomain[1], max + padding);
setZoomDomain(from === baseXDomain[0] && to === baseXDomain[1] ? null : { result, domain: [from, to] });
}
const clearFocus = () => {
setSelectedKeys([]);
};
@@ -298,7 +308,7 @@ export default function TrendChart({
<div className="panel-header compact-header chart-toolbar">
<div>
<h3>{title}</h3>
{rows.length > 1 && !compact ? <p>Zum Zeitzoom einen Bereich im Diagramm aufziehen.</p> : null}
{rows.length > 1 && !compact ? <p>{touchMode ? "Zeitzoom mit + und − einstellen." : "Zum Zeitzoom einen Bereich im Diagramm aufziehen."}</p> : null}
{seriesLimited ? <p>Diagrammlimit: {result.maxSeries} von {result.requestedSeriesCount} Datenpunkten.</p> : null}
</div>
<div className="chart-actions">
@@ -339,6 +349,7 @@ export default function TrendChart({
/>
) : null}
{!compact && rows.length > 1 ? <button className="ghost-button" type="button" onClick={() => zoomTime(0.25, 0.75)}>Zeitzoom +</button> : null}
{touchMode && rows.length > 1 ? <button className="ghost-button" type="button" disabled={!activeZoom} onClick={zoomOutTime}>Zeitzoom −</button> : null}
{activeZoom ? <button className="ghost-button" type="button" onClick={() => setZoomDomain(null)}>Zoom zurück</button> : null}
{allowFocusMode ? <button className="ghost-button" type="button" onClick={onToggleExpanded}>{expanded ? "Normalansicht" : "Vollbild"}</button> : null}
</div>
@@ -418,7 +429,7 @@ export default function TrendChart({
/>
);
})}
{rows.length > 1 ? <Customized component={TimeZoomOverlay} onZoom={zoomTime} /> : null}
{rows.length > 1 ? <Customized component={TimeZoomOverlay} onZoom={zoomTime} touchMode={touchMode} /> : null}
</LineChart>
</ResponsiveContainer>
</div>
+130 -4
View File
@@ -355,6 +355,63 @@ span {
flex-direction: column;
}
.sidebar-links {
border-top: 1px solid var(--border);
min-width: 0;
padding-top: 0.55rem;
}
.sidebar-link {
text-decoration: none;
min-width: 0;
}
.sidebar-link:hover {
border-color: var(--border-strong);
background: var(--surface-strong);
}
.sidebar-link-label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.sidebar-link-monogram {
font-weight: 600;
text-transform: uppercase;
}
.sidebar-link-settings {
min-width: 0;
}
.sidebar-link-list {
list-style: none;
padding: 0;
margin: 0;
display: grid;
gap: 0.35rem;
}
.sidebar-link-setting {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.45rem;
padding: 0.4rem 0.55rem;
border: 1px solid var(--border);
border-radius: 10px;
}
.sidebar-link-copy {
display: grid;
gap: 0.15rem;
min-width: 0;
overflow-wrap: anywhere;
}
.nav-button {
min-height: 34px;
padding: 0.38rem 0.58rem;
@@ -820,27 +877,89 @@ span {
margin-top: 0.44rem;
}
.trend-touch-toggle {
min-height: 44px;
padding-inline: 0.85rem;
}
.trend-touch-toggle[aria-pressed="true"] {
color: var(--brand-2);
border-color: var(--border-strong);
background: color-mix(in srgb, var(--brand-2) 9%, var(--surface-strong));
}
.trend-touch :is(.view-meta, .button-row, .chart-actions, .legend-grid) {
align-items: center;
gap: 0.55rem;
}
.trend-touch :is(button, input, select, summary, .checkbox-field, .chart-check) {
min-height: 44px;
}
.trend-touch :is(button, summary, .checkbox-field, .chart-check) {
touch-action: manipulation;
}
.trend-touch :is(input:not([type="checkbox"]), select) {
font-size: 16px;
}
.trend-touch :is(.checkbox-field, .chart-check) input[type="checkbox"] {
width: 20px;
height: 20px;
min-height: 0;
flex-shrink: 0;
}
.trend-touch :is(.point-item, .legend-item) {
align-items: center;
padding-inline: 0.7rem;
}
.trend-touch .point-copy strong {
font-size: 14px;
}
.trend-touch .point-list {
gap: 0.5rem;
max-height: min(42dvh, 28rem);
}
.trend-touch .trend-options > summary {
line-height: 1.5;
align-content: center;
}
.trend-touch .chart-toolbar {
flex-wrap: wrap;
}
.trend-touch .chart-wrapper {
touch-action: auto;
}
@media (min-width: 981px) and (min-height: 560px) {
.content.trend-content {
.content.trend-content:not(.trend-touch) {
display: flex;
flex-direction: column;
height: 100dvh;
}
.trend-content .trend-layout {
.trend-content:not(.trend-touch) .trend-layout {
flex: 1;
min-height: 0;
grid-template-rows: minmax(0, 1fr);
}
.trend-content .trend-side {
.trend-content:not(.trend-touch) .trend-side {
align-self: stretch;
align-content: stretch;
min-height: 0;
grid-template-rows: minmax(0, 1fr) auto;
}
.trend-content .trend-point-library .point-list {
.trend-content:not(.trend-touch) .trend-point-library .point-list {
max-height: none;
}
}
@@ -1178,6 +1297,13 @@ span {
flex-wrap: wrap;
}
.sidebar.collapsed .sidebar-links {
flex: 1 0 100%;
max-height: 6rem;
overflow: auto;
align-content: start;
}
.sidebar.collapsed .sidebar-brand-row,
.sidebar.collapsed .sidebar-footer {
padding: 0;