Skip to content

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

Add collection list

dominik-zeglene919e1022c60
diff --git a/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx b/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx
index 01135484b3..dfa268e98c 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx
@@ -1,9 +1,127 @@
+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";
-interface CollectionListProps {}
+import { ListProps } from "../../..";
+import Skeleton from "../../../components/Skeleton";
+import StatusLabel from "../../../components/StatusLabel";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { CollectionList_collections_edges_node } from "../../types/CollectionList";
-const decorate = withStyles(theme => ({ root: {} }));
-const CollectionList = decorate<CollectionListProps>(({ classes }) => <div />);
+interface CollectionListProps extends ListProps {
+ collections: CollectionList_collections_edges_node[];
+}
+
+const decorate = withStyles({
+ name: {
+ width: "50%"
+ },
+ tableRow: {
+ cursor: "pointer" as "pointer"
+ },
+ textCenter: {
+ textAlign: "center" as "center"
+ },
+ textLeft: {
+ textAlign: "left" as "left"
+ }
+});
+const CollectionList = decorate<CollectionListProps>(
+ ({
+ classes,
+ collections,
+ disabled,
+ onNextPage,
+ onPreviousPage,
+ onRowClick,
+ pageInfo
+ }) => (
+ <Card>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.name}>
+ {i18n.t("Category Name", { context: "table cell" })}
+ </TableCell>
+ <TableCell className={classes.textCenter}>
+ {i18n
+ .t("No. Products", { context: "table cell" })
+ .replace(" ", "\xa0")}
+ </TableCell>
+ <TableCell className={classes.textLeft}>
+ {i18n.t("Availability", { context: "table cell" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={5}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ collections,
+ collection => (
+ <TableRow
+ className={classes.tableRow}
+ hover={!!collection}
+ onClick={collection ? onRowClick(collection.id) : undefined}
+ key={collection ? collection.id : "skeleton"}
+ >
+ <TableCell>
+ {maybe<React.ReactNode>(() => collection.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textCenter}>
+ {maybe<React.ReactNode>(
+ () => collection.products.totalCount,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textLeft}>
+ {maybe(
+ () => (
+ <StatusLabel
+ status={collection.isPublished ? "success" : "error"}
+ label={
+ collection.isPublished
+ ? i18n.t("Published")
+ : i18n.t("Not published")
+ }
+ />
+ ),
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={3}>
+ {i18n.t("No collections found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
CollectionList.displayName = "CollectionList";
export default CollectionList;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx
index 186df613e0..0ea296bf6f 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionListPage/CollectionListPage.tsx
@@ -7,8 +7,9 @@ import { Container } from "../../../components/Container";
import PageHeader from "../../../components/PageHeader";
import i18n from "../../../i18n";
import { CollectionList_collections_edges_node } from "../../types/CollectionList";
+import CollectionList from "../CollectionList/CollectionList";
-interface CollectionListPageProps extends PageListProps {
+export interface CollectionListPageProps extends PageListProps {
collections: CollectionList_collections_edges_node[];
}
@@ -29,6 +30,7 @@ const CollectionListPage: React.StatelessComponent<CollectionListPageProps> = ({
<AddIcon />
</Button>
</PageHeader>
+ <CollectionList disabled={disabled} {...listProps} />
</Container>
);
CollectionListPage.displayName = "CollectionListPage";
diff --git a/saleor/static/dashboard-next/collections/fixtures.ts b/saleor/static/dashboard-next/collections/fixtures.ts
new file mode 100644
index 0000000000..62fab4ae59
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/fixtures.ts
@@ -0,0 +1,24 @@
+import { CollectionList_collections_edges_node } from "./types/CollectionList";
+
+export const collections: CollectionList_collections_edges_node[] = [
+ {
+ __typename: "Collection",
+ id: "Q29sbGVjdGlvbjox",
+ isPublished: true,
+ name: "Summer collection",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 4
+ }
+ },
+ {
+ __typename: "Collection",
+ id: "Q29sbGVjdGlvbjoy",
+ isPublished: true,
+ name: "Winter sale",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 4
+ }
+ }
+];
diff --git a/saleor/static/dashboard-next/storybook/stories/collections/CollectionListPage.tsx b/saleor/static/dashboard-next/storybook/stories/collections/CollectionListPage.tsx
index 8bc728a4a0..bd645d8a2e 100644
--- a/saleor/static/dashboard-next/storybook/stories/collections/CollectionListPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/collections/CollectionListPage.tsx
@@ -1,10 +1,21 @@
import { storiesOf } from "@storybook/react";
import * as React from "react";
-import CollectionListPage from "../../../collections/components/CollectionListPage";
+import CollectionListPage, {
+ CollectionListPageProps
+} from "../../../collections/components/CollectionListPage";
+import { collections } from "../../../collections/fixtures";
+import { pageListProps } from "../../../fixtures";
import Decorator from "../../Decorator";
-storiesOf("Collections / CollectionListPage", module)
+const props: CollectionListPageProps = {
+ ...pageListProps.default,
+ collections
+};
+
+storiesOf("Views / Collections / Collection list", module)
.addDecorator(Decorator)
- .add("default", () => <CollectionListPage />)
- .add("other", () => <CollectionListPage />);
+ .add("default", () => <CollectionListPage {...props} />)
+ .add("loading", () => (
+ <CollectionListPage {...props} collections={undefined} disabled={true} />
+ ));