Skip to content

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

Add collection products

dominik-zeglena353b144a9b4
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index aa50f4f3af..75112164b6 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -1,5 +1,6 @@
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
+import { PageListProps } from "../../..";
import { CardSpacer } from "../../../components/CardSpacer";
import { Container } from "../../../components/Container";
import Form from "../../../components/Form";
@@ -8,6 +9,7 @@ import SaveButtonBar from "../../../components/SaveButtonBar";
import { maybe } from "../../../misc";
import { CollectionDetails_collection } from "../../types/CollectionDetails";
import CollectionDetails from "../CollectionDetails/CollectionDetails";
+import CollectionProducts from "../CollectionProducts/CollectionProducts";
export interface CollectionDetailsPageFormData {
name: string;
@@ -16,9 +18,8 @@ export interface CollectionDetailsPageFormData {
isPublished: boolean;
}
-export interface CollectionDetailsPageProps {
+export interface CollectionDetailsPageProps extends PageListProps {
collection: CollectionDetails_collection;
- disabled: boolean;
onBack: () => void;
onCollectionRemove: () => void;
onImageUpload: () => void;
@@ -33,7 +34,15 @@ const decorate = withStyles(theme => ({
}
}));
const CollectionDetailsPage = decorate<CollectionDetailsPageProps>(
- ({ classes, collection, disabled, onBack, onCollectionRemove, onSubmit }) => (
+ ({
+ classes,
+ collection,
+ disabled,
+ onBack,
+ onCollectionRemove,
+ onSubmit,
+ ...pageListProps
+ }) => (
<Form
initial={{
isPublished: maybe(() => collection.isPublished),
@@ -56,9 +65,9 @@ const CollectionDetailsPage = decorate<CollectionDetailsPageProps>(
/>
<CardSpacer />
<CollectionProducts
- products={maybe(() =>
- collection.products.edges.map(edge => edge.node)
- )}
+ disabled={disabled}
+ collection={collection}
+ {...pageListProps}
/>
</div>
<div />
diff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
index 6402ffd655..5c945e7408 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
@@ -1,9 +1,145 @@
+import Button from "@material-ui/core/Button";
+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 TableFooter from "@material-ui/core/TableFooter";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
-export interface CollectionProductsProps {}
+import { PageListProps } from "../../..";
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import StatusLabel from "../../../components/StatusLabel";
+import TableCellAvatar from "../../../components/TableCellAvatar";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { CollectionDetails_collection } from "../../types/CollectionDetails";
-const decorate = withStyles(theme => ({ root: {} }));
-const CollectionProducts = decorate<CollectionProductsProps>(({ classes }) => <div />);
+export interface CollectionProductsProps extends PageListProps {
+ collection: CollectionDetails_collection;
+}
+
+const decorate = withStyles({
+ tableRow: {
+ cursor: "pointer" as "pointer"
+ },
+ textCenter: {
+ textAlign: "center" as "center"
+ }
+});
+const CollectionProducts = decorate<CollectionProductsProps>(
+ ({
+ classes,
+ collection,
+ disabled,
+ onAdd,
+ onNextPage,
+ onPreviousPage,
+ onRowClick,
+ pageInfo
+ }) => (
+ <Card>
+ <CardTitle
+ title={
+ !!collection ? (
+ i18n.t("Products in {{ collectionName }}", {
+ collectionName: collection.name
+ })
+ ) : (
+ <Skeleton />
+ )
+ }
+ toolbar={
+ <Button
+ disabled={disabled}
+ variant="flat"
+ color="secondary"
+ onClick={onAdd}
+ >
+ {i18n.t("Assign product", {
+ context: "button"
+ })}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell />
+ <TableCell>{i18n.t("Name", { context: "table header" })}</TableCell>
+ <TableCell className={classes.textCenter}>
+ {i18n.t("Type", { context: "table header" })}
+ </TableCell>
+ <TableCell>
+ {i18n.t("Published", { context: "table header" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={4}
+ hasNextPage={pageInfo.hasNextPage}
+ onNextPage={onNextPage}
+ hasPreviousPage={pageInfo.hasPreviousPage}
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ maybe(() => collection.products.edges.map(edge => edge.node)),
+ product => (
+ <TableRow
+ className={classes.tableRow}
+ hover={!!product}
+ onClick={!!product ? onRowClick(product.id) : undefined}
+ key={product ? product.id : "skeleton"}
+ >
+ <TableCellAvatar
+ thumbnail={maybe(() => product.thumbnailUrl)}
+ />
+ <TableCell>
+ {maybe<React.ReactNode>(() => product.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textCenter}>
+ {maybe<React.ReactNode>(
+ () => product.productType.name,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell>
+ {maybe(
+ () => (
+ <StatusLabel
+ label={
+ product.isPublished
+ ? i18n.t("Published")
+ : i18n.t("Not published")
+ }
+ status={product.isPublished ? "success" : "error"}
+ />
+ ),
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell />
+ <TableCell colSpan={3}>{i18n.t("No products found")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
CollectionProducts.displayName = "CollectionProducts";
export default CollectionProducts;
diff --git a/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
index 0094d4eec6..ef49b83709 100644
--- a/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
@@ -6,12 +6,15 @@ import CollectionDetailsPage, {
CollectionDetailsPageProps
} from "../../../collections/components/CollectionDetailsPage";
import { collection as collectionFixture } from "../../../collections/fixtures";
+import { pageListProps } from "../../../fixtures";
import Decorator from "../../Decorator";
const collection = collectionFixture(placeholderImage);
const props: CollectionDetailsPageProps = {
+ ...pageListProps.default,
collection,
+ disabled: false,
onBack: () => undefined,
onCollectionRemove: () => undefined,
onImageUpload: () => undefined,
@@ -21,6 +24,19 @@ const props: CollectionDetailsPageProps = {
storiesOf("Views / Collections / Collection details", module)
.addDecorator(Decorator)
.add("default", () => <CollectionDetailsPage {...props} />)
- .add("other", () => (
- <CollectionDetailsPage {...props} collection={undefined} />
+ .add("loading", () => (
+ <CollectionDetailsPage {...props} collection={undefined} disabled={true} />
+ ))
+ .add("no products", () => (
+ <CollectionDetailsPage
+ {...props}
+ collection={{
+ ...collection,
+ products: {
+ ...collection.products,
+ edges: []
+ }
+ }}
+ disabled={true}
+ />
));