[WIP] Import Plans
This commit is contained in:
92
frontend/dashboard/src/components/Breadcrumbs.tsx
Normal file
92
frontend/dashboard/src/components/Breadcrumbs.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import { ReactElement } from 'react';
|
||||
import { Link as RouterLink } from 'react-router-dom';
|
||||
// @mui
|
||||
import {
|
||||
Box,
|
||||
Link,
|
||||
Typography,
|
||||
BreadcrumbsProps,
|
||||
Breadcrumbs as MUIBreadcrumbs,
|
||||
} from '@mui/material';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type TLink = {
|
||||
href?: string;
|
||||
name: string;
|
||||
icon?: ReactElement;
|
||||
};
|
||||
|
||||
export interface Props extends BreadcrumbsProps {
|
||||
links: TLink[];
|
||||
activeLast?: boolean;
|
||||
}
|
||||
|
||||
export default function Breadcrumbs({ links, activeLast = false, ...other }: Props) {
|
||||
const currentLink = links[links.length - 1].name;
|
||||
|
||||
const listDefault = links.map((link) => <LinkItem key={link.name} link={link} />);
|
||||
|
||||
const listActiveLast = links.map((link) => (
|
||||
<div key={link.name}>
|
||||
{link.name !== currentLink ? (
|
||||
<LinkItem link={link} />
|
||||
) : (
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{
|
||||
maxWidth: 260,
|
||||
overflow: 'hidden',
|
||||
whiteSpace: 'nowrap',
|
||||
color: 'text.disabled',
|
||||
textOverflow: 'ellipsis',
|
||||
}}
|
||||
>
|
||||
{currentLink}
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
));
|
||||
|
||||
return (
|
||||
<MUIBreadcrumbs
|
||||
separator={
|
||||
<Box
|
||||
component="span"
|
||||
sx={{ width: 4, height: 4, borderRadius: '50%', bgcolor: 'text.disabled' }}
|
||||
/>
|
||||
}
|
||||
{...other}
|
||||
>
|
||||
{activeLast ? listDefault : listActiveLast}
|
||||
</MUIBreadcrumbs>
|
||||
);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type LinkItemProps = {
|
||||
link: TLink;
|
||||
};
|
||||
|
||||
function LinkItem({ link }: LinkItemProps) {
|
||||
const { href, name, icon } = link;
|
||||
return (
|
||||
<Link
|
||||
key={name}
|
||||
variant="body2"
|
||||
component={RouterLink}
|
||||
to={href || '#'}
|
||||
sx={{
|
||||
lineHeight: 2,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
color: 'text.primary',
|
||||
'& > div': { display: 'inherit' },
|
||||
}}
|
||||
>
|
||||
{icon && <Box sx={{ mr: 1, '& svg': { width: 20, height: 20 } }}>{icon}</Box>}
|
||||
{name}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
60
frontend/dashboard/src/components/HeaderBreadcrumbs.tsx
Normal file
60
frontend/dashboard/src/components/HeaderBreadcrumbs.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { isString } from 'lodash';
|
||||
// @mui
|
||||
import { Box, Typography, Link } from '@mui/material';
|
||||
//
|
||||
import Breadcrumbs, { Props as BreadcrumbsProps } from './Breadcrumbs';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
interface Props extends BreadcrumbsProps {
|
||||
action?: ReactNode;
|
||||
heading: string;
|
||||
moreLink?: string | string[];
|
||||
}
|
||||
|
||||
export default function HeaderBreadcrumbs({
|
||||
links,
|
||||
action,
|
||||
heading,
|
||||
moreLink = '' || [],
|
||||
sx,
|
||||
...other
|
||||
}: Props) {
|
||||
return (
|
||||
<Box sx={{ mb: 5, ...sx }}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
||||
<Box sx={{ flexGrow: 1 }}>
|
||||
<Typography variant="h4" gutterBottom>
|
||||
{heading}
|
||||
</Typography>
|
||||
<Breadcrumbs links={links} {...other} />
|
||||
</Box>
|
||||
|
||||
{action && <Box sx={{ flexShrink: 0 }}>{action}</Box>}
|
||||
</Box>
|
||||
|
||||
<Box sx={{ mt: 2 }}>
|
||||
{isString(moreLink) ? (
|
||||
<Link href={moreLink} target="_blank" rel="noopener" variant="body2">
|
||||
{moreLink}
|
||||
</Link>
|
||||
) : (
|
||||
moreLink.map((href) => (
|
||||
<Link
|
||||
noWrap
|
||||
key={href}
|
||||
href={href}
|
||||
variant="body2"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
sx={{ display: 'table' }}
|
||||
>
|
||||
{href}
|
||||
</Link>
|
||||
))
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import ReactQuill, { ReactQuillProps } from 'react-quill';
|
||||
import ReactQuill from 'react-quill';
|
||||
// @mui
|
||||
import { styled } from '@mui/material/styles';
|
||||
import { Box, BoxProps } from '@mui/material';
|
||||
@@ -33,9 +33,11 @@ const RootStyle = styled(Box)(({ theme }) => ({
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export interface Props extends ReactQuillProps {
|
||||
export interface Props {
|
||||
id?: string;
|
||||
error?: boolean;
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
simple?: boolean;
|
||||
helperText?: ReactNode;
|
||||
sx?: BoxProps;
|
||||
@@ -64,7 +66,7 @@ export default function Editor({
|
||||
maxStack: 100,
|
||||
userOnly: true,
|
||||
},
|
||||
syntax: true,
|
||||
syntax: false, // need highlightjs
|
||||
clipboard: {
|
||||
matchVisual: false,
|
||||
},
|
||||
|
||||
@@ -83,7 +83,7 @@ function NavListSub({ list }: NavListSubProps) {
|
||||
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const active = getActive(list.path, pathname);
|
||||
const active = getActive(list.path, pathname, list.openWhen);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ export function isExternalLink(path: string) {
|
||||
return path.includes('http');
|
||||
}
|
||||
|
||||
export function getActive(path: string, pathname: string) {
|
||||
return path ? !!matchPath({ path: path, end: false }, pathname) : false;
|
||||
export function getActive(path: string, pathname: string, openWhen?: string[]) {
|
||||
const listPathWhenActive = [ ...openWhen ?? [], path ];
|
||||
|
||||
return listPathWhenActive.includes(pathname);
|
||||
// return path ? !!matchPath({ path: path, end: false }, pathname) : false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export type NavListProps = {
|
||||
path: string;
|
||||
icon?: ReactElement;
|
||||
info?: ReactElement;
|
||||
openWhen? : string[];
|
||||
children?: {
|
||||
title: string;
|
||||
path: string;
|
||||
|
||||
@@ -18,7 +18,7 @@ type NavListRootProps = {
|
||||
export function NavListRoot({ list, isCollapse }: NavListRootProps) {
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const active = getActive(list.path, pathname);
|
||||
const active = getActive(list.path, pathname, list.openWhen);
|
||||
|
||||
const [open, setOpen] = useState(active);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user