Files
SE-LTD/web/src/components/Sidebar.jsx
T
jhartworks a8b6cd4061 feat: add modal dialog, paged results, scan status, and trend value table components
- Introduced ModalDialog component for displaying modal dialogs with accessibility features.
- Added PagedResults component to handle pagination of items with customizable rendering.
- Created ScanStatus component to display the status of a scan with elapsed time.
- Implemented TrendValueTable component for displaying trend data in a paginated table format.
- Added measurement utility functions for formatting and validating measurement values.
- Included tests for measurement functions and trend series fetching logic to ensure correctness.
2026-11-25 15:45:49 +01:00

103 lines
4.1 KiB
React

const icons = {
dashboard: "M3 3h7v7H3z M14 3h7v7h-7z M3 14h7v7H3z M14 14h7v7h-7z",
trends: "M3 4v16h18 M6 15l5-5 4 3 6-7",
admin: "M12 22s7-3 7-10V5l-7-3-7 3v7c0 7 7 10 7 10Z M9 12l2 2 4-4",
settings: "M4 6h6m4 0h6 M4 12h10m4 0h2 M4 18h2m4 0h10 M10 4v4m4 2v4m-8 2v4",
expand: "M3 5h18v14H3z M9 5v14 M13 9l3 3-3 3",
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.5" strokeLinecap="round" strokeLinejoin="round">
<path d={icons[name]} />
</svg>
);
}
export function SmallFootnote() {
return <div className="tiny-note">by J.H. | SE Inno GmbH</div>;
}
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";
return (
<aside className={collapsed ? "sidebar collapsed" : "sidebar"}>
<div className="sidebar-top">
<div className="sidebar-brand-row">
<div className="logo-lockup">
<img src="/logo.png" alt={collapsed ? "SE" : ""} />
{collapsed ? null : (
<div className="logo-title">SE Local Trenddata</div>
)}
</div>
<button type="button" className="icon-button sidebar-toggle" title={toggleLabel} aria-label={toggleLabel} aria-expanded={!collapsed} onClick={onToggle}>
<SidebarIcon name={collapsed ? "expand" : "collapse"} />
</button>
</div>
<nav className="nav-list" aria-label="Hauptnavigation">
{views.map((view) => (
<button
key={view.id}
type="button"
className={activeView === view.id ? "nav-button active" : "nav-button"}
title={collapsed ? view.label : undefined}
aria-label={view.label}
aria-current={activeView === view.id ? "page" : undefined}
onClick={() => onNavigate(view.id)}
>
<SidebarIcon name={view.id} />
{collapsed ? null : <span>{view.label}</span>}
</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 ? (
<div className="user-card">
<strong>{userLabel}</strong>
<span>{user.role === "admin" ? "Systemzugang" : user.role === "technician" ? "Technikzugang" : "Benutzerzugang"}</span>
</div>
) : null}
<button
className={collapsed ? "icon-button sidebar-account" : "ghost-button compact-button sidebar-account"}
type="button"
title={collapsed ? accountLabel : undefined}
aria-label={accountLabel}
onClick={user ? onLogout : () => onNavigate("settings")}
>
<SidebarIcon name={user ? "logout" : "login"} />
{collapsed ? null : <span>{accountLabel}</span>}
</button>
{collapsed ? null : <SmallFootnote />}
</div>
</aside>
);
}