/******************************************************************************** * Copyright (c) 2020 TypeFox and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent } from 'react'; import { Box, Card, CardActionArea, CardContent, Divider, Grid, Typography } from '@mui/material'; import { useNavigate } from 'react-router-dom'; import { isNavGroup, NavEntry, RouteEntry } from './nav-types'; interface NavSection { groupName?: string; entries: RouteEntry[]; } /** Preserve the original group structure: ungrouped items come first as a section without a title. */ function buildSections(items: NavEntry[]): NavSection[] { const ungrouped: RouteEntry[] = items.filter((e): e is RouteEntry => !isNavGroup(e)); const groups: NavSection[] = items .filter(isNavGroup) .map(group => ({ groupName: group.name, entries: group.children })); return ungrouped.length > 0 ? [{ entries: ungrouped }, ...groups] : groups; } const NavCard: FunctionComponent<{ entry: RouteEntry }> = ({ entry }) => { const navigate = useNavigate(); return ( navigate(entry.path)} sx={{ height: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center', py: 3, px: 2 }} > {entry.icon} {entry.name} {entry.description && ( {entry.description} )} ); }; export interface WelcomeProps { items: NavEntry[]; } export const Welcome: FunctionComponent = ({ items }) => { const sections = buildSections(items); return ( Welcome to the Admin Dashboard Select a section below to get started {sections.map((section, i) => ( {section.groupName && ( <> {section.groupName} )} {!section.groupName && i > 0 && } {section.entries.map(entry => ( ))} ))} ); };