Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Refactor top section

dominik-zeglena11857b07179
diff --git a/saleor/static/dashboard-next/components/AppHeader/AppHeader.tsx b/saleor/static/dashboard-next/components/AppHeader/AppHeader.tsx
new file mode 100644
index 0000000000..cdb77db4eb
--- /dev/null
+++ b/saleor/static/dashboard-next/components/AppHeader/AppHeader.tsx
@@ -0,0 +1,69 @@
+import IconButton from "@material-ui/core/IconButton";
+import Portal from "@material-ui/core/Portal";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import ArrowBackIcon from "@material-ui/icons/ArrowBack";
+import * as React from "react";
+import AppHeaderContext from "../AppLayout/AppHeaderContext";
+
+export interface AppHeaderProps {
+ children: React.ReactNode;
+ onBack();
+}
+
+const styles = (theme: Theme) =>
+ createStyles({
+ menuButton: {
+ flex: "0 0 auto",
+ marginLeft: theme.spacing.unit * -2,
+ marginRight: theme.spacing.unit,
+ marginTop: -theme.spacing.unit * 2
+ },
+ root: {
+ alignItems: "center",
+ color: theme.palette.grey[500],
+ display: "flex",
+ marginTop: theme.spacing.unit
+ },
+ title: {
+ color: theme.palette.grey[500],
+ flex: 1,
+ paddingBottom: theme.spacing.unit * 2,
+ textTransform: "uppercase"
+ }
+ });
+const AppHeader = withStyles(styles, { name: "AppHeader" })(
+ ({
+ children,
+ classes,
+ onBack
+ }: AppHeaderProps & WithStyles<typeof styles>) => (
+ <AppHeaderContext.Consumer>
+ {anchor =>
+ anchor ? (
+ <Portal container={anchor.current}>
+ <div className={classes.root}>
+ {onBack && (
+ <IconButton
+ color="inherit"
+ className={classes.menuButton}
+ onClick={onBack}
+ >
+ <ArrowBackIcon />
+ </IconButton>
+ )}
+ <Typography className={classes.title}>{children}</Typography>
+ </div>
+ </Portal>
+ ) : null
+ }
+ </AppHeaderContext.Consumer>
+ )
+);
+AppHeader.displayName = "AppHeader";
+export default AppHeader;
diff --git a/saleor/static/dashboard-next/components/AppHeader/index.ts b/saleor/static/dashboard-next/components/AppHeader/index.ts
new file mode 100644
index 0000000000..a179818434
--- /dev/null
+++ b/saleor/static/dashboard-next/components/AppHeader/index.ts
@@ -0,0 +1,2 @@
+export { default } from './AppHeader';
+export * from './AppHeader';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/components/AppLayout/AppHeaderContext.tsx b/saleor/static/dashboard-next/components/AppLayout/AppHeaderContext.tsx
new file mode 100644
index 0000000000..73255b6652
--- /dev/null
+++ b/saleor/static/dashboard-next/components/AppLayout/AppHeaderContext.tsx
@@ -0,0 +1,7 @@
+import * as React from "react";
+
+const AppHeaderContext = React.createContext<React.RefObject<HTMLDivElement>>(
+ undefined
+);
+
+export default AppHeaderContext;
diff --git a/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx b/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
index 1af616c1d0..1aed1bbfee 100644
--- a/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
+++ b/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
@@ -1,8 +1,6 @@
-import AppBar from "@material-ui/core/AppBar";
+import Chip from "@material-ui/core/Chip";
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
import Grow from "@material-ui/core/Grow";
-import Hidden from "@material-ui/core/Hidden";
-import IconButton from "@material-ui/core/IconButton";
import LinearProgress from "@material-ui/core/LinearProgress";
import MenuItem from "@material-ui/core/MenuItem";
import Menu from "@material-ui/core/MenuList";
@@ -14,34 +12,25 @@ import {
withStyles,
WithStyles
} from "@material-ui/core/styles";
-import Toolbar from "@material-ui/core/Toolbar";
-import Typography from "@material-ui/core/Typography";
-import MenuIcon from "@material-ui/icons/Menu";
-import Person from "@material-ui/icons/Person";
-import SettingsIcon from "@material-ui/icons/Settings";
import * as classNames from "classnames";
import * as React from "react";
import SVG from "react-inlinesvg";
-import { appMountPoint } from "../../";
import * as saleorLogo from "../../../images/logo-document.svg";
import { UserContext } from "../../auth";
-import {
- drawerWidth,
- navigationBarHeight
-} from "../../components/AppLayout/consts";
+import { drawerWidth } from "../../components/AppLayout/consts";
import MenuList from "../../components/AppLayout/MenuList";
import menuStructure from "../../components/AppLayout/menuStructure";
import ResponsiveDrawer from "../../components/AppLayout/ResponsiveDrawer";
import AppProgress from "../../components/AppProgress";
import MenuToggle from "../../components/MenuToggle";
import Navigator from "../../components/Navigator";
-import Anchor from "../../components/TextFieldWithChoice/Anchor";
import Toggle from "../../components/Toggle";
-import { configurationMenu, configurationMenuUrl } from "../../configuration";
import i18n from "../../i18n";
import ArrowDropdown from "../../icons/ArrowDropdown";
-import { removeDoubleSlashes } from "../../misc";
+import Anchor from "../Anchor";
+import Container from "../Container";
+import AppHeaderContext from "./AppHeaderContext";
const styles = (theme: Theme) =>
createStyles({
@@ -50,30 +39,34 @@ const styles = (theme: Theme) =>
},
arrow: {
marginLeft: theme.spacing.unit * 2,
- position: "relative",
- top: 6,
transition: theme.transitions.duration.standard + "ms"
},
content: {
backgroundColor: theme.palette.background.default,
flexGrow: 1,
marginLeft: 0,
- marginTop: navigationBarHeight,
padding: theme.spacing.unit,
[theme.breakpoints.up("sm")]: {
padding: theme.spacing.unit * 2
}
},
- drawer: {
- background: theme.palette.common.white,
- height: "100vh"
+ header: {
+ display: "flex",
+ height: 40,
+ marginTop: theme.spacing.unit * 2
+ },
+ hide: {
+ opacity: 0
},
logo: {
"& svg": {
height: "100%"
},
display: "block",
- height: 32
+ height: 28
+ },
+ menu: {
+ marginTop: theme.spacing.unit * 4
},
root: {
display: "grid",
@@ -85,6 +78,13 @@ const styles = (theme: Theme) =>
sideBar: {
background: theme.palette.common.white,
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 4}px`
+ },
+ spacer: {
+ flex: 1
+ },
+ userChip: {
+ backgroundColor: theme.palette.common.white,
+ border: `1px solid ${theme.palette.grey[200]}`
}
});
@@ -285,171 +285,157 @@ const AppLayout = withStyles(styles, {
{({ value: isProgressVisible }) => (
<UserContext.Consumer>
{({ logout, user }) => (
- <Navigator>
- {navigate => (
- <Toggle>
- {(
- isDrawerOpened,
- { toggle: toggleDrawer, disable: closeDrawer }
- ) => {
- const handleMenuItemClick = (
- url: string,
- event: React.MouseEvent<any>
- ) => {
- event.preventDefault();
- closeDrawer();
- navigate(url);
- };
- return (
- <>
- {isProgressVisible && (
- <LinearProgress
- className={classes.appLoader}
- color="secondary"
- />
- )}
- <div className={classes.root}>
- <div className={classes.sideBar}>
- <SVG className={classes.logo} src={saleorLogo} />
- <ResponsiveDrawer
- onClose={closeDrawer}
- open={isDrawerOpened}
- >
- <div className={classes.menuList}>
- <MenuList
- menuItems={menuStructure}
- user={user}
- onMenuItemClick={handleMenuItemClick}
- />
- <div className={classes.spacer} />
- {configurationMenu.filter(menuItem =>
- user.permissions
- .map(perm => perm.code)
- .includes(menuItem.permission)
- ).length > 0 && (
- <a
- className={classes.menuListItem}
- href={removeDoubleSlashes(
- appMountPoint + configurationMenuUrl
- )}
- onClick={event =>
- handleMenuItemClick(
- configurationMenuUrl,
- event
- )
- }
+ <Anchor>
+ {appHeaderAnchor => (
+ <AppHeaderContext.Provider value={appHeaderAnchor}>
+ <Navigator>
+ {navigate => (
+ <Toggle>
+ {(
+ isDrawerOpened,
+ { toggle: toggleDrawer, disable: closeDrawer }
+ ) => {
+ const handleMenuItemClick = (
+ url: string,
+ event: React.MouseEvent<any>
+ ) => {
+ event.preventDefault();
+ closeDrawer();
+ navigate(url);
+ };
+ return (
+ <>
+ <LinearProgress
+ className={classNames(classes.appLoader, {
+ [classes.hide]: !isProgressVisible
+ })}
+ color="secondary"
+ />
+ <div className={classes.root}>
+ <div className={classes.sideBar}>
+ <ResponsiveDrawer
+ onClose={closeDrawer}
+ open={isDrawerOpened}
>
- <SettingsIcon />
- <Typography
- aria-label="configure"
- className={classes.menuListItemText}
- >
- {i18n.t("Configure")}
- </Typography>
- </a>
- )}
- </div>
- </ResponsiveDrawer>
- </div>
- <div>
- <div>
- <MenuToggle ariaOwns="user-menu">
- {({
- open: menuOpen,
- actions: { open: openMenu, close: closeMenu }
- }) => {
- const handleLogout = () => {
- close();
- logout();
- };
- return (
- <Anchor>
- {anchor => (
- <>
- <div
- ref={anchor}
- onClick={
- !menuOpen ? openMenu : undefined
- }
- >
- <Hidden smDown>
- <Typography
- component="span"
- variant="subheading"
- >
- {user.email}
- </Typography>
- <ArrowDropdown
- className={classNames({
- [classes.arrow]: true,
- [classes.rotate]: menuOpen
- })}
- />
- </Hidden>
- <Hidden mdUp>
- <IconButton
- className={classes.userIcon}
- >
- <Person />
- </IconButton>
- </Hidden>
- </div>
- <Popper
- open={menuOpen}
- anchorEl={anchor.current}
- transition
- disablePortal
- placement="bottom-end"
- >
- {({ TransitionProps, placement }) => (
- <Grow
- {...TransitionProps}
- style={{
- minWidth: "10rem",
- transformOrigin:
- placement === "bottom"
- ? "right top"
- : "right bottom"
- }}
- >
- <Paper>
- <ClickAwayListener
- onClickAway={closeMenu}
- mouseEvent="onClick"
+ <SVG
+ className={classes.logo}
+ src={saleorLogo}
+ />
+ <MenuList
+ className={classes.menu}
+ menuItems={menuStructure}
+ user={user}
+ onMenuItemClick={handleMenuItemClick}
+ />
+ </ResponsiveDrawer>
+ </div>
+ <div>
+ <Container width="md">
+ <div className={classes.header}>
+ <div ref={appHeaderAnchor} />
+ <div className={classes.spacer} />
+ <MenuToggle ariaOwns="user-menu">
+ {({
+ open: menuOpen,
+ actions: {
+ open: openMenu,
+ close: closeMenu
+ }
+ }) => {
+ const handleLogout = () => {
+ close();
+ logout();
+ };
+ return (
+ <Anchor>
+ {anchor => (
+ <>
+ <Chip
+ className={classes.userChip}
+ label={
+ <>
+ {user.email}
+ <ArrowDropdown
+ className={classNames({
+ [classes.arrow]: true,
+ [classes.rotate]: menuOpen
+ })}
+ />
+ </>
+ }
+ innerRef={anchor}
+ onClick={openMenu}
+ />
+ <Popper
+ open={menuOpen}
+ anchorEl={anchor.current}
+ transition
+ disablePortal
+ placement="bottom-end"
>
- <Menu>
- <MenuItem
- className={
- classes.userMenuItem
- }
- onClick={handleLogout}
+ {({
+ TransitionProps,
+ placement
+ }) => (
+ <Grow
+ {...TransitionProps}
+ style={{
+ minWidth: "10rem",
+ transformOrigin:
+ placement === "bottom"
+ ? "right top"
+ : "right bottom"
+ }}
>
- {i18n.t("Log out", {
- context: "button"
- })}
- </MenuItem>
- </Menu>
- </ClickAwayListener>
- </Paper>
- </Grow>
- )}
- </Popper>
- </>
- )}
- </Anchor>
- );
- }}
- </MenuToggle>
- </div>
- <main className={classes.content}>{children}</main>
- </div>
- </div>
- </>
- );
- }}
- </Toggle>
+ <Paper>
+ <ClickAwayListener
+ onClickAway={
+ closeMenu
+ }
+ mouseEvent="onClick"
+ >
+ <Menu>
+ <MenuItem
+ onClick={
+ handleLogout
+ }
+ >
+ {i18n.t(
+ "Log out",
+ {
+ context:
+ "button"
+ }
+ )}
+ </MenuItem>
+ </Menu>
+ </ClickAwayListener>
+ </Paper>
+ </Grow>
+ )}
+ </Popper>
+ </>
+ )}
+ </Anchor>
+ );
+ }}
+ </MenuToggle>
+ </div>
+ </Container>
+ <main className={classes.content}>
+ {children}
+ </main>
+ </div>
+ </div>
+ </>
+ );
+ }}
+ </Toggle>
+ )}
+ </Navigator>
+ </AppHeaderContext.Provider>
)}
- </Navigator>
+ </Anchor>
)}
</UserContext.Consumer>
)}
diff --git a/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx b/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx
index ddceea5571..d68bb8ed72 100644
--- a/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx
+++ b/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx
@@ -9,6 +9,8 @@ import * as React from "react";
import { appMountPoint } from "../..";
import { User } from "../../auth/types/User";
+import { configurationMenu, configurationMenuUrl } from "../../configuration";
+import i18n from "../../i18n";
import { removeDoubleSlashes } from "../../misc";
import Toggle from "../Toggle";
import { IMenuItem } from "./menuStructure";
@@ -30,7 +32,7 @@ const styles = (theme: Theme) =>
alignItems: "center",
color: "#616161",
display: "flex",
- height: 40,
+ marginTop: theme.spacing.unit * 2,
paddingLeft: 0,
textDecoration: "none",
transition: theme.transitions.duration.standard + "ms"
@@ -41,7 +43,7 @@ const styles = (theme: Theme) =>
},
cursor: "pointer",
fontSize: "1rem",
- marginLeft: theme.spacing.unit * 2,
+ textTransform: "uppercase",
transition: theme.transitions.duration.standard + "ms"
},
menuListNested: {
@@ -50,6 +52,7 @@ const styles = (theme: Theme) =>
});
interface MenuListProps {
+ className?: string;
menuItems: IMenuItem[];
user: User;
onMenuItemClick: (url: string, event: React.MouseEvent<any>) => void;
@@ -57,11 +60,12 @@ interface MenuListProps {
const MenuList = withStyles(styles, { name: "MenuList" })(
({
classes,
+ className,
menuItems,
user,
onMenuItemClick
}: MenuListProps & WithStyles<typeof styles>) => (
- <div>
+ <div className={className}>
{menuItems.map(menuItem => {
if (
menuItem.permission &&
@@ -75,7 +79,6 @@ const MenuList = withStyles(styles, { name: "MenuList" })(
{(openedMenu, { toggle: toggleMenu }) => (
<>
<div onClick={toggleMenu} className={classes.menuListItem}>
- {menuItem.icon}
<Typography
aria-label={menuItem.ariaLabel}
className={classes.menuListItemText}
@@ -104,7 +107,6 @@ const MenuList = withStyles(styles, { name: "MenuList" })(
onClick={event => onMenuItemClick(menuItem.url, event)}
key={menuItem.label}
>
- {menuItem.icon}
<Typography
aria-label={menuItem.ariaLabel}
className={classes.menuListItemText}
@@ -114,6 +116,22 @@ const MenuList = withStyles(styles, { name: "MenuList" })(
</a>
);
})}
+ {configurationMenu.filter(menuItem =>
+ user.permissions.map(perm => perm.code).includes(menuItem.permission)
+ ).length > 0 && (
+ <a
+ className={classes.menuListItem}
+ href={removeDoubleSlashes(appMountPoint + configurationMenuUrl)}
+ onClick={event => onMenuItemClick(configurationMenuUrl, event)}
+ >
+ <Typography
+ aria-label="configure"
+ className={classes.menuListItemText}
+ >
+ {i18n.t("Configure")}
+ </Typography>
+ </a>
+ )}
</div>
)
);
diff --git a/saleor/static/dashboard-next/components/AppLayout/ResponsiveDrawer.tsx b/saleor/static/dashboard-next/components/AppLayout/ResponsiveDrawer.tsx
index d6907c8fb8..82c7856eb4 100644
--- a/saleor/static/dashboard-next/components/AppLayout/ResponsiveDrawer.tsx
+++ b/saleor/static/dashboard-next/components/AppLayout/ResponsiveDrawer.tsx
@@ -7,15 +7,14 @@ import {
WithStyles
} from "@material-ui/core/styles";
import * as React from "react";
-import { drawerWidth, navigationBarHeight } from "./consts";
+import { drawerWidth } from "./consts";
const styles = (theme: Theme) =>
createStyles({
drawerDesktop: {
- backgroundColor: "transparent",
- borderRight: "none",
- height: `calc(100vh - ${navigationBarHeight}px)`,
- marginTop: navigationBarHeight,
+ backgroundColor: theme.palette.common.white,
+ border: "none",
+ height: "100vh",
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 4}px`,
position: "fixed" as "fixed",
width: drawerWidth
diff --git a/saleor/static/dashboard-next/components/AppLayout/menuStructure.tsx b/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
similarity index 79%
rename from saleor/static/dashboard-next/components/AppLayout/menuStructure.tsx
rename to saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
index 0f041d6af5..0177cc4560 100644
--- a/saleor/static/dashboard-next/components/AppLayout/menuStructure.tsx
+++ b/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
@@ -1,15 +1,8 @@
-import MoneyIcon from "@material-ui/icons/MoneyOutlined";
-import PersonOutline from "@material-ui/icons/PersonOutline";
-import * as React from "react";
-
import { categoryListUrl } from "../../categories/urls";
import { collectionListUrl } from "../../collections/urls";
import { customerListUrl } from "../../customers/urls";
import { saleListUrl, voucherListUrl } from "../../discounts/urls";
import i18n from "../../i18n";
-import Home from "../../icons/Home";
-import Shop from "../../icons/Shop";
-import Truck from "../../icons/Truck";
import { orderListUrl } from "../../orders/urls";
import { productListUrl } from "../../products/urls";
import { PermissionEnum } from "../../types/globalTypes";
@@ -17,7 +10,6 @@ import { PermissionEnum } from "../../types/globalTypes";
export interface IMenuItem {
ariaLabel: string;
children?: IMenuItem[];
- icon: React.ReactNode;
label: string;
permission?: PermissionEnum;
url?: string;
@@ -26,7 +18,6 @@ export interface IMenuItem {
const menuStructure: IMenuItem[] = [
{
ariaLabel: "home",
- icon: <Home />,
label: i18n.t("Home", { context: "Menu label" }),
url: "/"
},
@@ -35,37 +26,31 @@ const menuStructure: IMenuItem[] = [
children: [
{
ariaLabel: "products",
- icon: <Shop />,
label: i18n.t("Products", { context: "Menu label" }),
url: productListUrl()
},
{
ariaLabel: "categories",
- icon: <Shop />,
label: i18n.t("Categories", { context: "Menu label" }),
url: categoryListUrl
},
{
ariaLabel: "collections",
- icon: <Shop />,
label: i18n.t("Collections", { context: "Menu label" }),
url: collectionListUrl
}
],
- icon: <Shop />,
label: i18n.t("Catalogue", { context: "Menu label" }),
permission: PermissionEnum.MANAGE_PRODUCTS
},
{
ariaLabel: "orders",
- icon: <Truck />,
label: i18n.t("Orders", { context: "Menu label" }),
permission: PermissionEnum.MANAGE_ORDERS,
url: orderListUrl()
},
{
ariaLabel: "customers",
- icon: <PersonOutline />,
label: i18n.t("Customers", { context: "Menu label" }),
permission: PermissionEnum.MANAGE_USERS,
url: customerListUrl
@@ -75,18 +60,15 @@ const menuStructure: IMenuItem[] = [
children: [
{
ariaLabel: "sales",
- icon: <MoneyIcon />,
label: i18n.t("Sales", { context: "Menu label" }),
url: saleListUrl
},
{
ariaLabel: "vouchers",
- icon: <MoneyIcon />,
label: i18n.t("Vouchers", { context: "Menu label" }),
url: voucherListUrl
}
],
- icon: <MoneyIcon />,
label: i18n.t("Discounts", { context: "Menu label" }),
permission: PermissionEnum.MANAGE_DISCOUNTS
}
diff --git a/saleor/static/dashboard-next/components/ExtendedPageHeader/ExtendedPageHeader.tsx b/saleor/static/dashboard-next/components/ExtendedPageHeader/ExtendedPageHeader.tsx
index d1c58ef55b..cbb8ec09c8 100644
--- a/saleor/static/dashboard-next/components/ExtendedPageHeader/ExtendedPageHeader.tsx
+++ b/saleor/static/dashboard-next/components/ExtendedPageHeader/ExtendedPageHeader.tsx
@@ -26,8 +26,7 @@ const styles = (theme: Theme) =>
root: {
alignItems: "center",
display: "flex",
- marginBottom: theme.spacing.unit * 3,
- marginTop: theme.spacing.unit * 3
+ marginBottom: theme.spacing.unit * 3
},
subtitle: {
alignItems: "center",