Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add top product list for home page
Lukasz Szewczykfb0922f24ee6
diff --git a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsxindex 7039065b7e..b154939b10 100644--- a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx+++ b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx@@ -8,6 +8,7 @@ import PageHeader from "../../../components/PageHeader";import i18n from "../../../i18n";import HomeNotificationTable from "../HomeNotificationTable";import HomeOrdersCard from "../HomeOrdersCard";+import HomeProductListCard from "../HomeProductListCard";import HomeSalesCard from "../HomeSalesCard";interface MoneyType {@@ -27,7 +28,16 @@ export interface DashboardProps {problems: number;productsOut: number;};+ onRowClick: () => undefined;ownerName: string;+ topProducts?: Array<{+ id: string;+ name: string;+ orders: number;+ price: MoneyType;+ thumbnailUrl: string;+ variant: string;+ }>;toOrders: () => void;toPayments: () => void;toProblems: () => void;@@ -63,7 +73,9 @@ const Dashboard = decorate<DashboardProps>(toOrders,toPayments,toProblems,- toProductsOut+ toProductsOut,+ topProducts,+ onRowClick}) => {return (<Container width="md">@@ -93,7 +105,11 @@ const Dashboard = decorate<DashboardProps>(toProductsOut={toProductsOut}/><CardSpacer />- <Card>ProductListCard</Card>+ <HomeProductListCard+ onRowClick={onRowClick}+ disabled={false}+ topProducts={topProducts}+ /><CardSpacer /></div><div>diff --git a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductList.tsx b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductList.tsxnew file mode 100644index 0000000000..e02b021194--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductList.tsx@@ -0,0 +1,112 @@+import { withStyles } from "@material-ui/core/styles";+import Typography from "@material-ui/core/Typography";+import * as classNames from "classnames";+import * as React from "react";+import Money from "../../../components/Money";+import Skeleton from "../../../components/Skeleton";+import i18n from "../../../i18n";+import { renderCollection } from "../../../misc";++import Table from "@material-ui/core/Table";+import TableBody from "@material-ui/core/TableBody";+import TableCell from "@material-ui/core/TableCell";+import TableRow from "@material-ui/core/TableRow";+import TableCellAvatar from "../../../components/TableCellAvatar";++interface MoneyType {+ amount: number;+ currency: string;+}+interface HomeProductListProps {+ topProducts?: Array<{+ id: string;+ name: string;+ orders: number;+ price: MoneyType;+ thumbnailUrl: string;+ variant: string;+ }>;+ onRowClick: (id: string) => () => void;+ disabled: boolean;+}++const decorate = withStyles(theme => ({+ tableRowPointer: {+ cursor: "pointer" as "pointer"+ },+ tableRowSize: {+ paddingBottom: theme.spacing.unit * 2,+ paddingTop: theme.spacing.unit * 2+ }+}));++export const HomeProductList = decorate<HomeProductListProps>(+ ({ classes, topProducts, onRowClick }) => (+ <Table>+ <TableBody>+ {renderCollection(+ topProducts,+ product => (+ <TableRow+ key={product ? product.id : "skeleton"}+ hover={!!product}+ className={classNames({+ [classes.tableRowPointer]: !!product+ })}+ onClick={!!product ? onRowClick(product.id) : undefined}+ >+ <TableCellAvatar+ className={classes.tableRowSize}+ thumbnail={product && product.thumbnailUrl}+ />+ {product ? (+ <TableCell>+ <Typography color={"primary"} variant="body1">+ {product.name}+ </Typography>+ <Typography color={"textSecondary"} variant="body1">+ {product.variant}+ </Typography>+ <Typography color={"textSecondary"} variant="body1">+ {i18n.t("{{ordersCount}} Orders", {+ ordersCount: product.orders+ })}+ </Typography>+ </TableCell>+ ) : (+ <Skeleton />+ )}++ <TableCell>+ <Typography variant="body1" align={"right"}>+ {product &&+ product.price !== undefined &&+ product.price.amount !== undefined &&+ product.price.currency !== undefined ? (+ <Money+ amount={product.price.amount}+ currency={product.price.currency}+ />+ ) : (+ <Skeleton />+ )}+ </Typography>+ </TableCell>+ </TableRow>+ ),+ () => (+ <TableRow>+ <TableCell>+ <Typography variant="body1">+ {i18n.t("No products found")}+ </Typography>+ </TableCell>+ </TableRow>+ )+ )}+ </TableBody>+ </Table>+ )+);++export default HomeProductList;diff --git a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsxnew file mode 100644index 0000000000..7924b46699--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx@@ -0,0 +1,43 @@+import Card from "@material-ui/core/Card";+import { withStyles } from "@material-ui/core/styles";+// import Container from "../../../components/Container";+import * as React from "react";+import CardTitle from "../../../components/CardTitle";+// import PageHeader from "../../../components/PageHeader";+import i18n from "../../../i18n";+// import CardSpacer from "../../../components/CardSpacer";+import HomeProductList from "./HomeProductList";++interface MoneyType {+ amount: number;+ currency: string;+}+interface HomeProductListCardProps {+ disabled: boolean;+ topProducts?: Array<{+ id: string;+ name: string;+ orders: number;+ price: MoneyType;+ thumbnailUrl: string;+ variant: string;+ }>;+ onRowClick: (id: string) => () => void;+}++const decorate = withStyles({});+const HomeProductListCard = decorate<HomeProductListCardProps>(+ ({ topProducts, onRowClick }) => {+ return (+ <Card>+ <CardTitle title={i18n.t("Top products")} />+ <HomeProductList+ disabled={false}+ topProducts={topProducts}+ onRowClick={onRowClick}+ />+ </Card>+ );+ }+);+export default HomeProductListCard;diff --git a/saleor/static/dashboard-next/home/components/HomeProductListCard/index.ts b/saleor/static/dashboard-next/home/components/HomeProductListCard/index.tsnew file mode 100644index 0000000000..139cd4fe3d--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeProductListCard/index.ts@@ -0,0 +1,2 @@+export { default } from "./HomeProductListCard";+export * from "./HomeProductListCard";diff --git a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsxindex 315006fd2e..5b6e4a5252 100644--- a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx+++ b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx@@ -9,12 +9,14 @@ const shop = shopFixture(placeholderImage);const dashboardProps: DashboardProps = {daily: shop.daily,- ownerName: shop.ownerName,notifications: shop.notifications,+ onRowClick: () => undefined,+ ownerName: shop.ownerName,toOrders: () => undefined,toPayments: () => undefined,toProblems: () => undefined,- toProductsOut: () => undefined+ toProductsOut: () => undefined,+ topProducts: shop.topProducts};storiesOf("Views / Home / Dashboard", module)@@ -23,6 +25,7 @@ storiesOf("Views / Home / Dashboard", module).add("loading", () => (<Dashbaord{...dashboardProps}+ topProducts={undefined}daily={undefined}notifications={undefined}/>@@ -30,6 +33,7 @@ storiesOf("Views / Home / Dashboard", module).add("no data", () => (<Dashbaord{...dashboardProps}+ topProducts={[]}notifications={{orders: 0,payments: 0,