Skip to content

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

Make category list a table

dominik-zeglen6322468feb4f
diff --git a/saleor/static/dashboard-next/categories/components/CategoryDetailsPage/CategoryDetailsPage.tsx b/saleor/static/dashboard-next/categories/components/CategoryDetailsPage/CategoryDetailsPage.tsx
index b6f1f02bd6..32486c7c89 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryDetailsPage/CategoryDetailsPage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryDetailsPage/CategoryDetailsPage.tsx
@@ -22,6 +22,12 @@ interface CategoryDetailsPageProps {
subcategories?: Array<{
id: string;
name: string;
+ children?: {
+ totalCount: number;
+ };
+ products?: {
+ totalCount: number;
+ };
}>;
products?: Array<{
id: string;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryEditPage/CategoryEditPage.tsx b/saleor/static/dashboard-next/categories/components/CategoryEditPage/CategoryEditPage.tsx
index 88d18c4c4e..371704b79f 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryEditPage/CategoryEditPage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryEditPage/CategoryEditPage.tsx
@@ -97,6 +97,7 @@ const CategoryEditPage: React.StatelessComponent<CategoryEditPageProps> = ({
<SaveButtonBar
disabled={disabled || !onSubmit || !hasChanged}
state={saveButtonBarState}
+ onCancel={onBack}
onSave={submit}
/>
</Container>
diff --git a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
index fdbebd1987..ccede05df6 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
@@ -1,11 +1,11 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
-import List from "@material-ui/core/List";
-import ListItem from "@material-ui/core/ListItem";
-import ListItemIcon from "@material-ui/core/ListItemIcon";
-import ListItemText from "@material-ui/core/ListItemText";
-import ListSubheader from "@material-ui/core/ListSubheader";
-import Folder from "@material-ui/icons/Folder";
+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 TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
@@ -17,51 +17,106 @@ interface CategoryListProps {
categories?: Array<{
id: string;
name: string;
+ children: {
+ totalCount: number;
+ };
+ products: {
+ totalCount: number;
+ };
}>;
isRoot: boolean;
onAdd?();
onRowClick?(id: string): () => void;
}
-const CategoryList: React.StatelessComponent<CategoryListProps> = ({
- categories,
- isRoot,
- onAdd,
- onRowClick
-}) => (
- <Card>
- {!isRoot && (
- <CardTitle
- title={i18n.t("Subcategories")}
- toolbar={
- <Button color="secondary" variant="flat" onClick={onAdd}>
- {i18n.t("Add subcategory")}
- </Button>
- }
- />
- )}
- <List>
- {renderCollection(
- categories,
- category => (
- <ListItem
- button={!!category && !!onRowClick}
- key={category ? category.id : "skeleton"}
- onClick={category && onRowClick && onRowClick(category.id)}
- >
- <ListItemIcon>
- <Folder />
- </ListItemIcon>
- <ListItemText>
- {category ? category.name : <Skeleton />}
- </ListItemText>
- </ListItem>
- ),
- () => (
- <ListSubheader>{i18n.t("No categories found")}</ListSubheader>
- )
+const decorate = withStyles(theme => ({
+ centerText: {
+ textAlign: "center" as "center"
+ },
+ tableRow: {
+ cursor: "pointer" as "pointer"
+ },
+ wideColumn: {
+ width: "100%"
+ }
+}));
+
+const CategoryList = decorate<CategoryListProps>(
+ ({ categories, classes, isRoot, onAdd, onRowClick }) => (
+ <Card>
+ {!isRoot && (
+ <CardTitle
+ title={i18n.t("Subcategories")}
+ toolbar={
+ <Button color="secondary" variant="flat" onClick={onAdd}>
+ {i18n.t("Add subcategory")}
+ </Button>
+ }
+ />
)}
- </List>
- </Card>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.wideColumn}>
+ {i18n.t("Name", { context: "object" })}
+ </TableCell>
+ <TableCell>
+ {i18n.t("Subcategories", { context: "object" })}
+ </TableCell>
+ <TableCell className={classes.centerText}>
+ {i18n
+ .t("No. Products", { context: "object" })
+ .replace(" ", "\xa0")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ categories,
+ category => (
+ <TableRow
+ className={classes.tableRow}
+ hover={!!category}
+ onClick={category ? onRowClick(category.id) : undefined}
+ key={category ? category.id : "skeleton"}
+ >
+ <TableCell>
+ {category && category.name ? category.name : <Skeleton />}
+ </TableCell>
+ <TableCell>
+ {category &&
+ category.children &&
+ category.children.totalCount !== undefined ? (
+ category.children.totalCount
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.centerText}>
+ {category &&
+ category.products &&
+ category.products.totalCount !== undefined ? (
+ category.products.totalCount
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={3}>
+ {isRoot
+ ? i18n.t("No categories found")
+ : i18n.t("No subcategories found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
);
+CategoryList.displayName = "CategoryList";
export default CategoryList;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx b/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
index 5516bc490d..1b16917958 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
@@ -66,7 +66,7 @@ export const ProductList = decorate<ProductListProps>(
<Table>
<TableHead>
<TableRow>
- <TableCell />
+ {(products === undefined || products.length > 0) && <TableCell />}
<TableCell className={classes.textLeft}>
{i18n.t("Name", { context: "object" })}
</TableCell>
diff --git a/saleor/static/dashboard-next/categories/queries.ts b/saleor/static/dashboard-next/categories/queries.ts
index d42fa1c08b..360e0c4313 100644
--- a/saleor/static/dashboard-next/categories/queries.ts
+++ b/saleor/static/dashboard-next/categories/queries.ts
@@ -37,6 +37,12 @@ export const rootCategoryChildrenQuery = gql`
node {
id
name
+ children {
+ totalCount
+ }
+ products {
+ totalCount
+ }
}
}
}
@@ -66,6 +72,12 @@ export const categoryPropertiesQuery = gql`
node {
id
name
+ children {
+ totalCount
+ }
+ products {
+ totalCount
+ }
}
}
}
diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
index 491c4868a7..99fe8c4389 100644
--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
@@ -28,6 +28,9 @@ const decorate = withStyles(theme => ({
},
textLeft: {
textAlign: "left" as "left"
+ },
+ textRight: {
+ textAlign: "right" as "right"
}
}));
@@ -59,13 +62,15 @@ export const ProductList = decorate<ProductListProps>(
<Table>
<TableHead>
<TableRow>
- <TableCell />
+ {(products === undefined || products.length > 0) && <TableCell />}
<TableCell className={classes.textLeft}>
{i18n.t("Name", { context: "object" })}
</TableCell>
<TableCell>{i18n.t("Type", { context: "object" })}</TableCell>
<TableCell>{i18n.t("Published", { context: "object" })}</TableCell>
- <TableCell>{i18n.t("Price", { context: "object" })}</TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Price", { context: "object" })}
+ </TableCell>
</TableRow>
</TableHead>
<TableFooter>
@@ -120,7 +125,7 @@ export const ProductList = decorate<ProductListProps>(
<Skeleton />
)}
</TableCell>
- <TableCell>
+ <TableCell className={classes.textRight}>
{product &&
product.price &&
product.price.amount !== undefined &&
diff --git a/saleor/static/dashboard-next/gql-types.ts b/saleor/static/dashboard-next/gql-types.ts
index 8275ec7317..b1a96e7311 100644
--- a/saleor/static/dashboard-next/gql-types.ts
+++ b/saleor/static/dashboard-next/gql-types.ts
@@ -170,6 +170,16 @@ export interface RootCategoryChildrenQuery {
// The ID of the object.
id: string,
name: string,
+ // List of children of the category.
+ children: {
+ // A total count of items in the collection
+ totalCount: number | null,
+ } | null,
+ // List of products in the category.
+ products: {
+ // A total count of items in the collection
+ totalCount: number | null,
+ } | null,
},
} >,
} | null,
@@ -202,6 +212,16 @@ export interface CategoryPropertiesQuery {
// The ID of the object.
id: string,
name: string,
+ // List of children of the category.
+ children: {
+ // A total count of items in the collection
+ totalCount: number | null,
+ } | null,
+ // List of products in the category.
+ products: {
+ // A total count of items in the collection
+ totalCount: number | null,
+ } | null,
},
} >,
} | null,
diff --git a/saleor/static/dashboard-next/theme.ts b/saleor/static/dashboard-next/theme.ts
index 340ade66d5..4e62f98dbd 100644
--- a/saleor/static/dashboard-next/theme.ts
+++ b/saleor/static/dashboard-next/theme.ts
@@ -103,9 +103,6 @@ export default createMuiTheme({
paddingLeft: 24 + "px",
textAlign: "left" as "left"
},
- "&:last-child": {
- textAlign: "right" as "right"
- },
paddingLeft: 0,
textAlign: "center" as "center"
}