Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add list views
dominik-zeglen9c0f680487d8
diff --git a/saleor/static/dashboard-next/AppRoot.tsx b/saleor/static/dashboard-next/AppRoot.tsxindex 8c50815c1e..4bf8e49778 100644--- a/saleor/static/dashboard-next/AppRoot.tsx+++ b/saleor/static/dashboard-next/AppRoot.tsx@@ -18,6 +18,7 @@ import {import Toolbar from "@material-ui/core/Toolbar";import Typography from "@material-ui/core/Typography";import MenuIcon from "@material-ui/icons/Menu";+import MoneyIcon from "@material-ui/icons/MoneyOutlined";import Person from "@material-ui/icons/Person";import PersonOutline from "@material-ui/icons/PersonOutline";import SettingsIcon from "@material-ui/icons/Settings";@@ -37,6 +38,7 @@ import Navigator from "./components/Navigator";import Toggle from "./components/Toggle";import { configurationMenu, configurationMenuUrl } from "./configuration";import { customerListUrl } from "./customers/urls";+import { saleListUrl, voucherListUrl } from "./discounts/urls";import i18n from "./i18n";import ArrowDropdown from "./icons/ArrowDropdown";import Home from "./icons/Home";@@ -96,6 +98,26 @@ const menuStructure: IMenuItem[] = [label: i18n.t("Customers", { context: "Menu label" }),permission: PermissionEnum.MANAGE_USERS,url: customerListUrl+ },+ {+ ariaLabel: "discounts",+ 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/discounts/index.tsx b/saleor/static/dashboard-next/discounts/index.tsxnew file mode 100644index 0000000000..2064f49344--- /dev/null+++ b/saleor/static/dashboard-next/discounts/index.tsx@@ -0,0 +1,44 @@+import { parse as parseQs } from "qs";+import * as React from "react";+import { Route, RouteComponentProps, Switch } from "react-router-dom";++import { WindowTitle } from "../components/WindowTitle";+import i18n from "../i18n";+import { saleListPath, voucherListPath } from "./urls";+import SaleListViewComponent, { SaleListQueryParams } from "./views/SaleList";+import VoucherListViewComponent, {+ VoucherListQueryParams+} from "./views/VoucherList";++const SaleListView: React.StatelessComponent<RouteComponentProps<{}>> = ({+ location+}) => {+ const qs = parseQs(location.search.substr(1));+ const params: SaleListQueryParams = {+ after: qs.after,+ before: qs.before+ };+ return <SaleListViewComponent params={params} />;+};++const VoucherListView: React.StatelessComponent<RouteComponentProps<{}>> = ({+ location+}) => {+ const qs = parseQs(location.search.substr(1));+ const params: VoucherListQueryParams = {+ after: qs.after,+ before: qs.before+ };+ return <VoucherListViewComponent params={params} />;+};++export const DiscountSection: React.StatelessComponent<{}> = () => (+ <>+ <WindowTitle title={i18n.t("Discounts")} />+ <Switch>+ <Route exact path={saleListPath} component={SaleListView} />+ <Route exact path={voucherListPath} component={VoucherListView} />+ </Switch>+ </>+);+export default DiscountSection;diff --git a/saleor/static/dashboard-next/discounts/queries.ts b/saleor/static/dashboard-next/discounts/queries.tsindex 87a891b845..8eeeef8c37 100644--- a/saleor/static/dashboard-next/discounts/queries.ts+++ b/saleor/static/dashboard-next/discounts/queries.ts@@ -17,6 +17,12 @@ export const saleList = gql`value}}+ pageInfo {+ endCursor+ hasNextPage+ hasPreviousPage+ startCursor+ }}}`;@@ -40,6 +46,12 @@ export const voucherList = gql`}}}+ pageInfo {+ endCursor+ hasNextPage+ hasPreviousPage+ startCursor+ }}}`;diff --git a/saleor/static/dashboard-next/discounts/types/SaleList.ts b/saleor/static/dashboard-next/discounts/types/SaleList.tsindex 792631cb36..142c3930d5 100644--- a/saleor/static/dashboard-next/discounts/types/SaleList.ts+++ b/saleor/static/dashboard-next/discounts/types/SaleList.ts@@ -22,9 +22,18 @@ export interface SaleList_sales_edges {node: SaleList_sales_edges_node;}+export interface SaleList_sales_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}+export interface SaleList_sales {__typename: "SaleCountableConnection";edges: SaleList_sales_edges[];+ pageInfo: SaleList_sales_pageInfo;}export interface SaleList {diff --git a/saleor/static/dashboard-next/discounts/types/VoucherList.ts b/saleor/static/dashboard-next/discounts/types/VoucherList.tsindex d881de4707..917cb2d8db 100644--- a/saleor/static/dashboard-next/discounts/types/VoucherList.ts+++ b/saleor/static/dashboard-next/discounts/types/VoucherList.ts@@ -30,9 +30,18 @@ export interface VoucherList_vouchers_edges {node: VoucherList_vouchers_edges_node;}+export interface VoucherList_vouchers_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}+export interface VoucherList_vouchers {__typename: "VoucherCountableConnection";edges: VoucherList_vouchers_edges[];+ pageInfo: VoucherList_vouchers_pageInfo;}export interface VoucherList {diff --git a/saleor/static/dashboard-next/discounts/urls.ts b/saleor/static/dashboard-next/discounts/urls.tsnew file mode 100644index 0000000000..b2afa988c7--- /dev/null+++ b/saleor/static/dashboard-next/discounts/urls.ts@@ -0,0 +1,14 @@+import * as urlJoin from "url-join";++export const discountSection = "/discounts/";++export const saleSection = urlJoin(discountSection, "sales");+export const saleListPath = saleSection;+export const saleListUrl = saleListPath;+export const salePath = (id: string) => urlJoin(saleSection, id);+export const saleUrl = (id: string) => salePath(encodeURIComponent(id));+export const saleAddPath = urlJoin(saleSection, "add");+export const saleAddUrl = saleAddPath;++export const voucherListPath = urlJoin(discountSection, "vouchers");+export const voucherListUrl = voucherListPath;diff --git a/saleor/static/dashboard-next/discounts/views/SaleList.tsx b/saleor/static/dashboard-next/discounts/views/SaleList.tsxnew file mode 100644index 0000000000..3eeb9f240f--- /dev/null+++ b/saleor/static/dashboard-next/discounts/views/SaleList.tsx@@ -0,0 +1,66 @@+import * as React from "react";++import Navigator from "../../components/Navigator";+import { createPaginationState, Paginator } from "../../components/Paginator";+import Shop from "../../components/Shop";+import { WindowTitle } from "../../components/WindowTitle";+import i18n from "../../i18n";+import { maybe } from "../../misc";+import SaleListPage from "../components/SaleListPage";+import { TypedSaleList } from "../queries";+import { saleAddUrl, saleUrl } from "../urls";++const PAGINATE_BY = 20;++export type SaleListQueryParams = Partial<{+ after: string;+ before: string;+}>;++interface SaleListProps {+ params: SaleListQueryParams;+}++export const SaleList: React.StatelessComponent<SaleListProps> = ({+ params+}) => (+ <>+ <WindowTitle title={i18n.t("Sales")} />+ <Shop>+ {shop => (+ <Navigator>+ {navigate => {+ const paginationState = createPaginationState(PAGINATE_BY, params);+ return (+ <TypedSaleList displayLoader variables={paginationState}>+ {({ data, loading }) => (+ <Paginator+ pageInfo={maybe(() => data.sales.pageInfo)}+ paginationState={paginationState}+ queryString={params}+ >+ {({ loadNextPage, loadPreviousPage, pageInfo }) => (+ <SaleListPage+ defaultCurrency={maybe(() => shop.defaultCurrency)}+ sales={maybe(() =>+ data.sales.edges.map(edge => edge.node)+ )}+ disabled={loading}+ pageInfo={pageInfo}+ onAdd={() => navigate(saleAddUrl)}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={id => () => navigate(saleUrl(id))}+ />+ )}+ </Paginator>+ )}+ </TypedSaleList>+ );+ }}+ </Navigator>+ )}+ </Shop>+ </>+);+export default SaleList;diff --git a/saleor/static/dashboard-next/discounts/views/VoucherList.tsx b/saleor/static/dashboard-next/discounts/views/VoucherList.tsxnew file mode 100644index 0000000000..0a8e399ab8--- /dev/null+++ b/saleor/static/dashboard-next/discounts/views/VoucherList.tsx@@ -0,0 +1,66 @@+import * as React from "react";++import Navigator from "../../components/Navigator";+import { createPaginationState, Paginator } from "../../components/Paginator";+import Shop from "../../components/Shop";+import { maybe } from "../../misc";+import VoucherListPage from "../components/VoucherListPage";+import { TypedVoucherList } from "../queries";+import { voucherAddUrl, voucherUrl } from "../urls";+import { WindowTitle } from "../../components/WindowTitle";+import i18n from "../../i18n";++const PAGINATE_BY = 20;++export type VoucherListQueryParams = Partial<{+ after: string;+ before: string;+}>;++interface VoucherListProps {+ params: VoucherListQueryParams;+}++export const VoucherList: React.StatelessComponent<VoucherListProps> = ({+ params+}) => (+ <>+ <WindowTitle title={i18n.t("Vouchers")} />+ <Shop>+ {shop => (+ <Navigator>+ {navigate => {+ const paginationState = createPaginationState(PAGINATE_BY, params);+ return (+ <TypedVoucherList displayLoader variables={paginationState}>+ {({ data, loading }) => (+ <Paginator+ pageInfo={maybe(() => data.vouchers.pageInfo)}+ paginationState={paginationState}+ queryString={params}+ >+ {({ loadNextPage, loadPreviousPage, pageInfo }) => (+ <VoucherListPage+ defaultCurrency={maybe(() => shop.defaultCurrency)}+ vouchers={maybe(() =>+ data.vouchers.edges.map(edge => edge.node)+ )}+ disabled={loading}+ pageInfo={pageInfo}+ onAdd={() => navigate(voucherAddUrl)}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={id => () => navigate(voucherUrl(id))}+ />+ )}+ </Paginator>+ )}+ </TypedVoucherList>+ );+ }}+ </Navigator>+ )}+ </Shop>+ </>+);+export default VoucherList;diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsxindex 4b04a61bb9..2b5ce44c1d 100644--- a/saleor/static/dashboard-next/index.tsx+++ b/saleor/static/dashboard-next/index.tsx@@ -31,6 +31,7 @@ import { ShopProvider } from "./components/Shop";import { WindowTitle } from "./components/WindowTitle";import ConfigurationSection, { configurationMenu } from "./configuration";import { CustomerSection } from "./customers";+import DiscountSection from "./discounts";import HomePage from "./home";import i18n from "./i18n";import { NotFound } from "./NotFound";@@ -144,6 +145,11 @@ render(path="/customers"component={CustomerSection}/>+ <SectionRoute+ permissions={[PermissionEnum.MANAGE_DISCOUNTS]}+ path="/discounts"+ component={DiscountSection}+ /><SectionRoutepermissions={[PermissionEnum.MANAGE_PAGES]}path="/pages"