2019-06-19 14:40:52 +00:00
|
|
|
import {
|
|
|
|
createStyles,
|
|
|
|
Theme,
|
|
|
|
withStyles,
|
|
|
|
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 TableRow from "@material-ui/core/TableRow";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-21 12:31:55 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import Checkbox from "@saleor/components/Checkbox";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
|
|
|
import StatusLabel from "@saleor/components/StatusLabel";
|
|
|
|
import TableHead from "@saleor/components/TableHead";
|
|
|
|
import TablePagination from "@saleor/components/TablePagination";
|
2019-08-09 11:14:35 +00:00
|
|
|
import { maybe, renderCollection } from "@saleor/misc";
|
|
|
|
import { ListActions, ListProps } from "@saleor/types";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { CollectionList_collections_edges_node } from "../../types/CollectionList";
|
|
|
|
|
2019-10-28 16:16:49 +00:00
|
|
|
const styles = theme =>
|
2019-06-19 14:40:52 +00:00
|
|
|
createStyles({
|
|
|
|
[theme.breakpoints.up("lg")]: {
|
|
|
|
colAvailability: {
|
|
|
|
width: 240
|
|
|
|
},
|
2019-09-02 08:44:26 +00:00
|
|
|
colName: {
|
|
|
|
paddingLeft: 0
|
|
|
|
},
|
2019-06-19 14:40:52 +00:00
|
|
|
colProducts: {
|
|
|
|
width: 240
|
|
|
|
}
|
|
|
|
},
|
|
|
|
colAvailability: {},
|
|
|
|
colName: {},
|
|
|
|
colProducts: {
|
|
|
|
textAlign: "center"
|
|
|
|
},
|
|
|
|
tableRow: {
|
|
|
|
cursor: "pointer" as "pointer"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
interface CollectionListProps
|
|
|
|
extends ListProps,
|
|
|
|
ListActions,
|
|
|
|
WithStyles<typeof styles> {
|
|
|
|
collections: CollectionList_collections_edges_node[];
|
|
|
|
}
|
|
|
|
|
2019-08-09 11:14:35 +00:00
|
|
|
const numberOfColumns = 5;
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
const CollectionList = withStyles(styles, { name: "CollectionList" })(
|
|
|
|
({
|
|
|
|
classes,
|
|
|
|
collections,
|
|
|
|
disabled,
|
2019-08-09 11:14:35 +00:00
|
|
|
settings,
|
2019-06-19 14:40:52 +00:00
|
|
|
onNextPage,
|
|
|
|
onPreviousPage,
|
2019-08-09 11:14:35 +00:00
|
|
|
onUpdateListSettings,
|
2019-06-19 14:40:52 +00:00
|
|
|
onRowClick,
|
|
|
|
pageInfo,
|
|
|
|
isChecked,
|
|
|
|
selected,
|
|
|
|
toggle,
|
|
|
|
toggleAll,
|
|
|
|
toolbar
|
2019-08-21 12:31:55 +00:00
|
|
|
}: CollectionListProps) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
2019-09-11 14:00:02 +00:00
|
|
|
<Table>
|
|
|
|
<TableHead
|
|
|
|
colSpan={numberOfColumns}
|
|
|
|
selected={selected}
|
|
|
|
disabled={disabled}
|
|
|
|
items={collections}
|
|
|
|
toggleAll={toggleAll}
|
|
|
|
toolbar={toolbar}
|
|
|
|
>
|
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
<FormattedMessage defaultMessage="Category Name" />
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colProducts}>
|
|
|
|
<FormattedMessage defaultMessage="No. of Products" />
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colAvailability}>
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Availability"
|
|
|
|
description="collection availability"
|
|
|
|
/>
|
|
|
|
</TableCell>
|
|
|
|
</TableHead>
|
|
|
|
<TableFooter>
|
|
|
|
<TableRow>
|
|
|
|
<TablePagination
|
|
|
|
colSpan={numberOfColumns}
|
|
|
|
settings={settings}
|
|
|
|
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
|
|
|
|
onNextPage={onNextPage}
|
|
|
|
onUpdateListSettings={onUpdateListSettings}
|
|
|
|
hasPreviousPage={
|
|
|
|
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
|
|
|
|
}
|
|
|
|
onPreviousPage={onPreviousPage}
|
|
|
|
/>
|
|
|
|
</TableRow>
|
|
|
|
</TableFooter>
|
|
|
|
<TableBody>
|
|
|
|
{renderCollection(
|
|
|
|
collections,
|
|
|
|
collection => {
|
|
|
|
const isSelected = collection ? isChecked(collection.id) : false;
|
|
|
|
return (
|
|
|
|
<TableRow
|
|
|
|
className={classes.tableRow}
|
|
|
|
hover={!!collection}
|
|
|
|
onClick={collection ? onRowClick(collection.id) : undefined}
|
|
|
|
key={collection ? collection.id : "skeleton"}
|
|
|
|
selected={isSelected}
|
2019-09-25 09:26:46 +00:00
|
|
|
data-tc="id"
|
|
|
|
data-tc-id={maybe(() => collection.id)}
|
2019-09-11 14:00:02 +00:00
|
|
|
>
|
|
|
|
<TableCell padding="checkbox">
|
|
|
|
<Checkbox
|
|
|
|
checked={isSelected}
|
|
|
|
disabled={disabled}
|
|
|
|
disableClickPropagation
|
|
|
|
onChange={() => toggle(collection.id)}
|
|
|
|
/>
|
|
|
|
</TableCell>
|
2019-09-25 09:26:46 +00:00
|
|
|
<TableCell className={classes.colName} data-tc="name">
|
2019-09-11 14:00:02 +00:00
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() => collection.name,
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colProducts}>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() => collection.products.totalCount,
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</TableCell>
|
2019-09-25 09:26:46 +00:00
|
|
|
<TableCell
|
|
|
|
className={classes.colAvailability}
|
|
|
|
data-tc="published"
|
|
|
|
data-tc-published={maybe(() => collection.isPublished)}
|
|
|
|
>
|
2019-09-11 14:00:02 +00:00
|
|
|
{maybe(
|
|
|
|
() => (
|
|
|
|
<StatusLabel
|
|
|
|
status={collection.isPublished ? "success" : "error"}
|
|
|
|
label={
|
|
|
|
collection.isPublished
|
|
|
|
? intl.formatMessage({
|
|
|
|
defaultMessage: "Published",
|
|
|
|
description: "collection is published"
|
|
|
|
})
|
|
|
|
: intl.formatMessage({
|
|
|
|
defaultMessage: "Not published",
|
|
|
|
description: "collection is not published"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
2019-06-19 14:40:52 +00:00
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
2019-09-11 14:00:02 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
() => (
|
|
|
|
<TableRow>
|
|
|
|
<TableCell colSpan={numberOfColumns}>
|
|
|
|
<FormattedMessage defaultMessage="No collections found" />
|
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
2019-08-21 12:31:55 +00:00
|
|
|
);
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
);
|
|
|
|
CollectionList.displayName = "CollectionList";
|
|
|
|
export default CollectionList;
|