Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Combine product list components into one and fix skeletons while loading stage
Lukasz Szewczyk0c5bf38f5507
diff --git a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductList.tsx b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductList.tsxdeleted file mode 100644index 1fcfddac6e..0000000000--- a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductList.tsx+++ /dev/null@@ -1,117 +0,0 @@-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 => ({- avatarSize: {- height: "64px",- width: "64px"- },- tableRow: {- 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.tableRow]: !!product- })}- onClick={!!product ? onRowClick(product.id) : undefined}- >- <TableCellAvatar- className={classes.tableRowSize}- thumbnail={product && product.thumbnailUrl}- avatarSize={classes.avatarSize}- />- {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.tsxindex 2d7be7cb12..36f05170ea 100644--- a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx+++ b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx@@ -1,19 +1,25 @@-import Card from "@material-ui/core/Card";-import { withStyles } from "@material-ui/core/styles";-// import Container from "../../../components/Container";+import * as classNames from "classnames";import * as React from "react";import CardTitle from "../../../components/CardTitle";-// import PageHeader from "../../../components/PageHeader";+import Money from "../../../components/Money";+import Skeleton from "../../../components/Skeleton";+import TableCellAvatar from "../../../components/TableCellAvatar";import i18n from "../../../i18n";-// import CardSpacer from "../../../components/CardSpacer";-import HomeProductList from "./HomeProductList";+import { renderCollection } from "../../../misc";++import Card from "@material-ui/core/Card";+import { 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 TableRow from "@material-ui/core/TableRow";+import Typography from "@material-ui/core/Typography";interface MoneyType {amount: number;currency: string;}-interface HomeProductListCardProps {- disabled: boolean;+interface HomeProductListProps {topProducts: Array<{id: string;name: string;@@ -23,21 +29,93 @@ interface HomeProductListCardProps {variant: string;}>;onRowClick: (id: string) => () => void;+ disabled: boolean;}-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>- );+const decorate = withStyles(theme => ({+ avatarSize: {+ height: "64px",+ width: "64px"+ },+ avatarSpacing: {+ paddingBottom: theme.spacing.unit * 2,+ paddingTop: theme.spacing.unit * 2+ },+ tableRow: {+ cursor: "pointer" as "pointer"}+}));++export const HomeProductList = decorate<HomeProductListProps>(+ ({ classes, topProducts, onRowClick }) => (+ <Card>+ <CardTitle title={i18n.t("Top products")} />+ <Table>+ <TableBody>+ {renderCollection(+ topProducts,+ product => (+ <TableRow+ key={product ? product.id : "skeleton"}+ hover={!!product}+ className={classNames({+ [classes.tableRow]: !!product+ })}+ onClick={!!product ? onRowClick(product.id) : undefined}+ >+ <TableCellAvatar+ className={classes.avatarSpacing}+ thumbnail={product && product.thumbnailUrl}+ avatarSize={classes.avatarSize}+ />++ <TableCell>+ {product ? (+ <>+ <Typography color={"primary"}>{product.name}</Typography>+ <Typography color={"textSecondary"}>+ {product.variant}+ </Typography>+ <Typography color={"textSecondary"}>+ {i18n.t("{{ordersCount}} Orders", {+ ordersCount: product.orders+ })}+ </Typography>+ </>+ ) : (+ <Skeleton />+ )}+ </TableCell>++ <TableCell>+ <Typography 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>{i18n.t("No products found")}</Typography>+ </TableCell>+ </TableRow>+ )+ )}+ </TableBody>+ </Table>+ </Card>+ ));-export default HomeProductListCard;++export default HomeProductList;