Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add menu list
dominik-zeglen0324f0000771
diff --git a/saleor/static/dashboard-next/configuration/index.tsx b/saleor/static/dashboard-next/configuration/index.tsxindex 40d336a95b..4223b1c0a8 100644--- a/saleor/static/dashboard-next/configuration/index.tsx+++ b/saleor/static/dashboard-next/configuration/index.tsx@@ -12,6 +12,7 @@ import SiteSettings from "../icons/SiteSettings";import StaffMembers from "../icons/StaffMembers";import Taxes from "../icons/Taxes";import { maybe } from "../misc";+import { menuListUrl } from "../navigation/urls";import { pageListUrl } from "../pages/urls";import { productTypeListUrl } from "../productTypes/urls";import { shippingZonesListUrl } from "../shipping/urls";@@ -54,7 +55,8 @@ export const configurationMenu: MenuItem[] = [description: i18n.t("Define how users can navigate through your store"),icon: <Navigation fontSize="inherit" viewBox="0 0 44 44" />,permission: PermissionEnum.MANAGE_MENUS,- title: i18n.t("Navigation")+ title: i18n.t("Navigation"),+ url: menuListUrl()},{description: i18n.t("View and update your site settings"),diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsxindex 922e19a513..ab330329d1 100644--- a/saleor/static/dashboard-next/index.tsx+++ b/saleor/static/dashboard-next/index.tsx@@ -34,6 +34,8 @@ import { CustomerSection } from "./customers";import DiscountSection from "./discounts";import HomePage from "./home";import i18n from "./i18n";+import NavigationSection from "./navigation";+import { navigationSection } from "./navigation/urls";import { NotFound } from "./NotFound";import OrdersSection from "./orders";import PageSection from "./pages";@@ -202,6 +204,11 @@ const App: React.FC = () => {path="/translations"component={TranslationsSection}/>+ <SectionRoute+ permissions={[PermissionEnum.MANAGE_MENUS]}+ path={navigationSection}+ component={NavigationSection}+ />{configurationMenu.filter(menuItem =>hasPermission(menuItem.permission, user)).length > 0 && (diff --git a/saleor/static/dashboard-next/navigation/components/MenuList/MenuList.tsx b/saleor/static/dashboard-next/navigation/components/MenuList/MenuList.tsxnew file mode 100644index 0000000000..5ef7c8bad6--- /dev/null+++ b/saleor/static/dashboard-next/navigation/components/MenuList/MenuList.tsx@@ -0,0 +1,127 @@+import Card from "@material-ui/core/Card";+import Checkbox from "@material-ui/core/Checkbox";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";+import Table from "@material-ui/core/Table";+import TableBody from "@material-ui/core/TableBody";+import TableCell from "@material-ui/core/TableCell";+import TableFooter from "@material-ui/core/TableFooter";+import TableHead from "@material-ui/core/TableHead";+import TableRow from "@material-ui/core/TableRow";+import DeleteIcon from "@material-ui/icons/Delete";+import * as React from "react";++import Skeleton from "../../../components/Skeleton";+import TablePagination from "../../../components/TablePagination";+import i18n from "../../../i18n";+import { maybe, renderCollection, stopPropagation } from "../../../misc";+import { ListProps } from "../../../types";+import { MenuList_menus_edges_node } from "../../types/MenuList";+import IconButtonTableCell from "../../../components/IconButtonTableCell";++export interface MenuListProps extends ListProps {+ menus: MenuList_menus_edges_node[];+ onDelete: (id: string) => void;+}++const styles = (theme: Theme) =>+ createStyles({+ [theme.breakpoints.up("lg")]: {+ colItems: {+ width: 200+ },+ colTitle: {}+ },+ colItems: {+ textAlign: "right"+ },+ colTitle: {},+ row: {+ cursor: "pointer"+ }+ });+const MenuList = withStyles(styles, { name: "MenuList" })(+ ({+ classes,+ disabled,+ menus,+ onDelete,+ onNextPage,+ onPreviousPage,+ onRowClick,+ pageInfo+ }: MenuListProps & WithStyles<typeof styles>) => (+ <Card>+ <Table>+ <TableHead>+ <TableRow>+ <TableCell padding="checkbox" />+ <TableCell className={classes.colTitle}>+ {i18n.t("Menu Title", { context: "object" })}+ </TableCell>+ <TableCell className={classes.colItems}>+ {i18n.t("Items", { context: "number of menu items" })}+ </TableCell>+ <TableCell />+ </TableRow>+ </TableHead>+ <TableFooter>+ <TableRow>+ <TablePagination+ colSpan={4}+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}+ onNextPage={onNextPage}+ hasPreviousPage={+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false+ }+ onPreviousPage={onPreviousPage}+ />+ </TableRow>+ </TableFooter>+ <TableBody>+ {renderCollection(+ menus,+ menu => (+ <TableRow+ hover={!!menu}+ key={menu ? menu.id : "skeleton"}+ onClick={menu && onRowClick(menu.id)}+ className={classes.row}+ >+ <TableCell>+ <Checkbox />+ </TableCell>+ <TableCell className={classes.colTitle}>+ {maybe<React.ReactNode>(() => menu.name, <Skeleton />)}+ </TableCell>+ <TableCell className={classes.colItems}>+ {maybe<React.ReactNode>(+ () => menu.items.length,+ <Skeleton />+ )}+ </TableCell>+ <IconButtonTableCell+ disabled={disabled}+ onClick={() => onDelete(menu.id)}+ >+ <DeleteIcon />+ </IconButtonTableCell>+ </TableRow>+ ),+ () => (+ <TableRow>+ <TableCell colSpan={4}>{i18n.t("No menus found")}</TableCell>+ </TableRow>+ )+ )}+ </TableBody>+ </Table>+ </Card>+ )+);+MenuList.displayName = "MenuList";+export default MenuList;diff --git a/saleor/static/dashboard-next/navigation/components/MenuList/index.ts b/saleor/static/dashboard-next/navigation/components/MenuList/index.tsnew file mode 100644index 0000000000..298313288f--- /dev/null+++ b/saleor/static/dashboard-next/navigation/components/MenuList/index.ts@@ -0,0 +1,2 @@+export { default } from './MenuList';+export * from './MenuList';\ No newline at end of filediff --git a/saleor/static/dashboard-next/navigation/components/MenuListPage/MenuListPage.tsx b/saleor/static/dashboard-next/navigation/components/MenuListPage/MenuListPage.tsxnew file mode 100644index 0000000000..315540b101--- /dev/null+++ b/saleor/static/dashboard-next/navigation/components/MenuListPage/MenuListPage.tsx@@ -0,0 +1,22 @@+import * as React from "react";++import Container from "../../../components/Container";+import { PageListProps } from "../../../types";+import { MenuList_menus_edges_node } from "../../types/MenuList";+import MenuList from "../MenuList/MenuList";++export interface MenuListPageProps extends PageListProps {+ menus: MenuList_menus_edges_node[];+ onDelete: (id: string) => void;+}++const MenuListPage: React.StatelessComponent<MenuListPageProps> = ({+ disabled,+ ...listProps+}) => (+ <Container>+ <MenuList disabled={disabled} {...listProps} />+ </Container>+);+MenuListPage.displayName = "MenuListPage";+export default MenuListPage;diff --git a/saleor/static/dashboard-next/navigation/components/MenuListPage/index.ts b/saleor/static/dashboard-next/navigation/components/MenuListPage/index.tsnew file mode 100644index 0000000000..eac89a2b21--- /dev/null+++ b/saleor/static/dashboard-next/navigation/components/MenuListPage/index.ts@@ -0,0 +1,2 @@+export { default } from './MenuListPage';+export * from './MenuListPage';\ No newline at end of filediff --git a/saleor/static/dashboard-next/navigation/index.tsx b/saleor/static/dashboard-next/navigation/index.tsxnew file mode 100644index 0000000000..8f67d22873--- /dev/null+++ b/saleor/static/dashboard-next/navigation/index.tsx@@ -0,0 +1,19 @@+import { parse as parseQs } from "qs";+import * as React from "react";+import { Route, RouteComponentProps, Switch } from "react-router-dom";++import { menuListPath } from "./urls";+import MenuListComponent from "./views/MenuList";++const MenuList: React.FC<RouteComponentProps<{}>> = ({ location }) => {+ const qs = parseQs(location.search.substr(1));+ return <MenuListComponent params={qs} />;+};++const NavigationRouter: React.FC = () => (+ <Switch>+ <Route exact component={MenuList} path={menuListPath} />+ </Switch>+);++export default NavigationRouter;diff --git a/saleor/static/dashboard-next/navigation/queries.ts b/saleor/static/dashboard-next/navigation/queries.tsnew file mode 100644index 0000000000..f96944fb34--- /dev/null+++ b/saleor/static/dashboard-next/navigation/queries.ts@@ -0,0 +1,31 @@+import gql from "graphql-tag";+import { pageInfoFragment, TypedQuery } from "../queries";+import { MenuList, MenuListVariables } from "./types/MenuList";++const menuFragment = gql`+ fragment MenuFragment on Menu {+ id+ name+ items {+ id+ }+ }+`;++const menuList = gql`+ ${menuFragment}+ ${pageInfoFragment}+ query MenuList($first: Int, $after: String, $last: Int, $before: String) {+ menus(first: $first, after: $after, before: $before, last: $last) {+ edges {+ node {+ ...MenuFragment+ }+ }+ pageInfo {+ ...PageInfoFragment+ }+ }+ }+`;+export const MenuListQuery = TypedQuery<MenuList, MenuListVariables>(menuList);diff --git a/saleor/static/dashboard-next/navigation/types/MenuFragment.ts b/saleor/static/dashboard-next/navigation/types/MenuFragment.tsnew file mode 100644index 0000000000..9b6f6fe99a--- /dev/null+++ b/saleor/static/dashboard-next/navigation/types/MenuFragment.ts@@ -0,0 +1,19 @@+/* tslint:disable */+/* eslint-disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL fragment: MenuFragment+// ====================================================++export interface MenuFragment_items {+ __typename: "MenuItem";+ id: string;+}++export interface MenuFragment {+ __typename: "Menu";+ id: string;+ name: string;+ items: (MenuFragment_items | null)[] | null;+}diff --git a/saleor/static/dashboard-next/navigation/types/MenuList.ts b/saleor/static/dashboard-next/navigation/types/MenuList.tsnew file mode 100644index 0000000000..8e95e11101--- /dev/null+++ b/saleor/static/dashboard-next/navigation/types/MenuList.ts@@ -0,0 +1,49 @@+/* tslint:disable */+/* eslint-disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL query operation: MenuList+// ====================================================++export interface MenuList_menus_edges_node_items {+ __typename: "MenuItem";+ id: string;+}++export interface MenuList_menus_edges_node {+ __typename: "Menu";+ id: string;+ name: string;+ items: (MenuList_menus_edges_node_items | null)[] | null;+}++export interface MenuList_menus_edges {+ __typename: "MenuCountableEdge";+ node: MenuList_menus_edges_node;+}++export interface MenuList_menus_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface MenuList_menus {+ __typename: "MenuCountableConnection";+ edges: MenuList_menus_edges[];+ pageInfo: MenuList_menus_pageInfo;+}++export interface MenuList {+ menus: MenuList_menus | null;+}++export interface MenuListVariables {+ first?: number | null;+ after?: string | null;+ last?: number | null;+ before?: string | null;+}diff --git a/saleor/static/dashboard-next/navigation/urls.ts b/saleor/static/dashboard-next/navigation/urls.tsnew file mode 100644index 0000000000..7cdcb25e3d--- /dev/null+++ b/saleor/static/dashboard-next/navigation/urls.ts@@ -0,0 +1,22 @@+import { stringify as stringifyQs } from "qs";+import * as urlJoin from "url-join";+import { Dialog, Pagination, SingleAction } from "../types";++type BulkAction = {};++export const navigationSection = "/navigation";++export const menuListPath = navigationSection;+export type MenuListUrlDialog = "add" | "remove" | "remove-many";+export type MenuListUrlQueryParams = BulkAction &+ Dialog<MenuListUrlDialog> &+ Pagination &+ SingleAction;+export const menuListUrl = (params?: MenuListUrlQueryParams) =>+ menuListPath + "?" + stringifyQs(params);++export const menuPath = (id: string) => urlJoin(navigationSection, id);+export type MenuUrlDialog = "remove" | "remove-item";+export type MenuUrlQueryParams = Dialog<MenuUrlDialog> & SingleAction;+export const menuUrl = (id: string, params?: MenuUrlQueryParams) =>+ menuPath(encodeURIComponent(id)) + "?" + stringifyQs(params);diff --git a/saleor/static/dashboard-next/navigation/views/MenuList.tsx b/saleor/static/dashboard-next/navigation/views/MenuList.tsxnew file mode 100644index 0000000000..1198d0b735--- /dev/null+++ b/saleor/static/dashboard-next/navigation/views/MenuList.tsx@@ -0,0 +1,62 @@+import * as React from "react";++import { createPaginationState } from "../../components/Paginator";+import useNavigator from "../../hooks/useNavigator";+import useNotifier from "../../hooks/useNotifier";+import usePaginator from "../../hooks/usePaginator";+import { maybe } from "../../misc";+import MenuListPage from "../components/MenuListPage";+import { MenuListQuery } from "../queries";+import { menuListUrl, MenuListUrlQueryParams, menuUrl } from "../urls";++const PAGINATE_BY = 20;++interface MenuListProps {+ params: MenuListUrlQueryParams;+}+const MenuList: React.FC<MenuListProps> = ({ params }) => {+ const navigate = useNavigator();+ const notify = useNotifier();+ const paginate = usePaginator();++ const paginationState = createPaginationState(PAGINATE_BY, params);++ return (+ <MenuListQuery variables={paginationState}>+ {({ data, loading }) => {+ const { loadNextPage, loadPreviousPage, pageInfo } = paginate(+ maybe(() => data.menus.pageInfo),+ paginationState,+ params+ );++ return (+ <MenuListPage+ disabled={loading}+ menus={maybe(() => data.menus.edges.map(edge => edge.node))}+ onAdd={() =>+ navigate(+ menuListUrl({+ action: "add"+ })+ )+ }+ onDelete={id =>+ navigate(+ menuListUrl({+ action: "remove",+ id+ })+ )+ }+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={id => () => navigate(menuUrl(id))}+ pageInfo={pageInfo}+ />+ );+ }}+ </MenuListQuery>+ );+};+export default MenuList;diff --git a/saleor/static/dashboard-next/storybook/stories/navigation/MenuListPage.tsx b/saleor/static/dashboard-next/storybook/stories/navigation/MenuListPage.tsxnew file mode 100644index 0000000000..d54c353027--- /dev/null+++ b/saleor/static/dashboard-next/storybook/stories/navigation/MenuListPage.tsx@@ -0,0 +1,15 @@+import { storiesOf } from "@storybook/react";+import * as React from "react";++import MenuListPage, {+ MenuListPageProps+} from "../../../navigation/components/MenuListPage";+import Decorator from "../../Decorator";++const props: MenuListPageProps = {++};++storiesOf("Navigation / MenuListPage", module)+ .addDecorator(Decorator)+ .add("default", () => <MenuListPage {...props} />);