Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Separate TableAction component
Krzysztof Bialoglowicz0f0ed676fefe
diff --git a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsxindex 32180f142f..d6c83b46b2 100644--- a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx@@ -35,7 +35,9 @@ const styles = (theme: Theme) =>width: 160}},- colName: {},+ colName: {+ paddingLeft: "0 !important"+ },colProducts: {textAlign: "center"},@@ -75,6 +77,7 @@ const CategoryList = withStyles(styles, { name: "CategoryList" })(isChecked,selected,toggle,+ toggleAll,toolbar,onAdd,onNextPage,@@ -93,22 +96,28 @@ const CategoryList = withStyles(styles, { name: "CategoryList" })(/>)}<Table>- <TableHead selected={selected} toolbar={toolbar}>- <TableRow>- <TableCell />- <TableCell className={classes.colName}>- {i18n.t("Category Name", { context: "object" })}- </TableCell>- <TableCell className={classes.colSubcategories}>- {i18n.t("Subcategories", { context: "object" })}- </TableCell>- <TableCell className={classes.colProducts}>- {i18n- .t("No. Products", { context: "object" })- .replace(" ", "\xa0")}- </TableCell>- </TableRow>- </TableHead>+ <TableHead+ selected={selected}+ disabled={disabled}+ items={categories}+ toggleAll={toggleAll}+ toolbar={toolbar}+ tablebar={+ <>+ <TableCell className={classes.colName}>+ {i18n.t("Category Name", { context: "object" })}+ </TableCell>+ <TableCell className={classes.colSubcategories}>+ {i18n.t("Subcategories", { context: "object" })}+ </TableCell>+ <TableCell className={classes.colProducts}>+ {i18n+ .t("No. Products", { context: "object" })+ .replace(" ", "\xa0")}+ </TableCell>+ </>+ }+ /><TableFooter><TableRow><TablePaginationdiff --git a/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx b/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsxindex 02c2b51649..c8bae05d99 100644--- a/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx@@ -32,6 +32,7 @@ export const CategoryListPage: React.StatelessComponent<CategoryTableProps> = ({isChecked,selected,toggle,+ toggleAll,toolbar}) => (<Container>@@ -52,6 +53,7 @@ export const CategoryListPage: React.StatelessComponent<CategoryTableProps> = ({isChecked={isChecked}selected={selected}toggle={toggle}+ toggleAll={toggleAll}toolbar={toolbar}/></Container>diff --git a/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsxindex 74d0a52e9a..620cd343c4 100644--- a/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx@@ -27,6 +27,7 @@ export const CategoryProductsCard: React.StatelessComponent<isChecked,selected,toggle,+ toggleAll,toolbar}) => (<Card>@@ -48,6 +49,7 @@ export const CategoryProductsCard: React.StatelessComponent<selected={selected}isChecked={isChecked}toggle={toggle}+ toggleAll={toggleAll}toolbar={toolbar}/></Card>diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsxindex ac4d0be58d..6c504e53c1 100644--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx@@ -94,7 +94,8 @@ export const CategoryUpdatePage: React.StatelessComponent<productListToolbar,selected,subcategoryListToolbar,- toggle+ toggle,+ toggleAll}: CategoryUpdatePageProps) => {const initialData: FormData = category? {@@ -177,6 +178,7 @@ export const CategoryUpdatePage: React.StatelessComponent<onPreviousPage={onPreviousPage}pageInfo={pageInfo}toggle={toggle}+ toggleAll={toggleAll}selected={selected}isChecked={isChecked}toolbar={subcategoryListToolbar}@@ -193,6 +195,7 @@ export const CategoryUpdatePage: React.StatelessComponent<onRowClick={onProductClick}onAdd={onAddProduct}toggle={toggle}+ toggleAll={toggleAll}selected={selected}isChecked={isChecked}toolbar={productListToolbar}diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails.tsxindex 11f7c685a5..325b17a0de 100644--- a/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx@@ -55,7 +55,7 @@ export const CategoryDetails: React.StatelessComponent<const navigate = useNavigator();const notify = useNotifier();const paginate = usePaginator();- const { isSelected, listElements, reset, toggle } = useBulkActions(+ const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(params.ids);@@ -307,6 +307,7 @@ export const CategoryDetails: React.StatelessComponent<isChecked={isSelected}selected={listElements.length}toggle={toggle}+ toggleAll={toggleAll}/><ActionDialogconfirmButtonState={diff --git a/saleor/static/dashboard-next/categories/views/CategoryList.tsx b/saleor/static/dashboard-next/categories/views/CategoryList.tsxindex 2bc50c1221..e01685e2ea 100644--- a/saleor/static/dashboard-next/categories/views/CategoryList.tsx+++ b/saleor/static/dashboard-next/categories/views/CategoryList.tsx@@ -31,7 +31,7 @@ export const CategoryList: React.StatelessComponent<CategoryListProps> = ({}) => {const navigate = useNavigator();const paginate = usePaginator();- const { isSelected, listElements, toggle, reset } = useBulkActions(+ const { isSelected, listElements, toggle, toggleAll, reset } = useBulkActions(params.ids);@@ -81,6 +81,7 @@ export const CategoryList: React.StatelessComponent<CategoryListProps> = ({isChecked={isSelected}selected={listElements.length}toggle={toggle}+ toggleAll={toggleAll}toolbar={<IconButtoncolor="primary"diff --git a/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx b/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsxindex f8140d50e6..03980513e8 100644--- a/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx+++ b/saleor/static/dashboard-next/collections/components/CollectionList/CollectionList.tsx@@ -62,26 +62,33 @@ const CollectionList = withStyles(styles, { name: "CollectionList" })(isChecked,selected,toggle,+ toggleAll,toolbar}: CollectionListProps) => (<Card><Table>- <TableHead selected={selected} toolbar={toolbar}>- <TableRow>- <TableCell />- <TableCell className={classes.colName}>- {i18n.t("Category Name", { context: "table cell" })}- </TableCell>- <TableCell className={classes.colProducts}>- {i18n- .t("No. Products", { context: "table cell" })- .replace(" ", "\xa0")}- </TableCell>- <TableCell className={classes.colAvailability}>- {i18n.t("Availability", { context: "table cell" })}- </TableCell>- </TableRow>- </TableHead>+ <TableHead+ selected={selected}+ disabled={disabled}+ items={collections}+ toggleAll={toggleAll}+ toolbar={toolbar}+ tablebar={+ <>+ <TableCell className={classes.colName}>+ {i18n.t("Category Name", { context: "table cell" })}+ </TableCell>+ <TableCell className={classes.colProducts}>+ {i18n+ .t("No. Products", { context: "table cell" })+ .replace(" ", "\xa0")}+ </TableCell>+ <TableCell className={classes.colAvailability}>+ {i18n.t("Availability", { context: "table cell" })}+ </TableCell>+ </>+ }+ /><TableFooter><TableRow><TablePaginationdiff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsxindex ae2986d882..8515214a61 100644--- a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx@@ -62,6 +62,7 @@ const CollectionProducts = withStyles(styles, { name: "CollectionProducts" })(isChecked,selected,toggle,+ toggleAll,toolbar}: CollectionProductsProps) => (<Card>diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsxindex c51e2ff107..0f21f9b047 100644--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx@@ -42,7 +42,7 @@ export const CollectionDetails: React.StatelessComponent<> = ({ id, params }) => {const navigate = useNavigator();const notify = useNotifier();- const { isSelected, listElements, reset, toggle } = useBulkActions(+ const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(params.ids);const paginate = usePaginator();@@ -276,6 +276,7 @@ export const CollectionDetails: React.StatelessComponent<isChecked={isSelected}selected={listElements.length}toggle={toggle}+ toggleAll={toggleAll}/><SearchProductsProvider>{(searchProducts, searchProductsOpts) => (diff --git a/saleor/static/dashboard-next/collections/views/CollectionList.tsx b/saleor/static/dashboard-next/collections/views/CollectionList.tsxindex 15e62ff9ee..e345c174e7 100644--- a/saleor/static/dashboard-next/collections/views/CollectionList.tsx+++ b/saleor/static/dashboard-next/collections/views/CollectionList.tsx@@ -39,7 +39,7 @@ export const CollectionList: React.StatelessComponent<CollectionListProps> = ({const navigate = useNavigator();const notify = useNotifier();const paginate = usePaginator();- const { isSelected, listElements, reset, toggle } = useBulkActions(+ const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(params.ids);@@ -159,6 +159,7 @@ export const CollectionList: React.StatelessComponent<CollectionListProps> = ({isChecked={isSelected}selected={listElements.length}toggle={toggle}+ toggleAll={toggleAll}/><ActionDialogopen={params.action === "publish"}diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsxindex 16b2c5cd1d..c2d28ba58a 100644--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx@@ -77,30 +77,38 @@ export const ProductList = withStyles(styles, { name: "ProductList" })(products,selected,toggle,+ toggleAll,toolbar,onNextPage,onPreviousPage,onRowClick}: ProductListProps) => (<Table>- <TableHead selected={selected} toolbar={toolbar}>- <TableRow>- <TableCell />- <TableCell />- <TableCell className={classes.colName}>- {i18n.t("Name", { context: "object" })}- </TableCell>- <TableCell className={classes.colType}>- {i18n.t("Type", { context: "object" })}- </TableCell>- <TableCell className={classes.colPublished}>- {i18n.t("Published", { context: "object" })}- </TableCell>- <TableCell className={classes.colPrice}>- {i18n.t("Price", { context: "object" })}- </TableCell>- </TableRow>- </TableHead>+ <TableHead+ selected={selected}+ disabled={disabled}+ items={products}+ toggleAll={toggleAll}+ toolbar={toolbar}+ tablebar={+ <>+ <TableCell />+ <TableCell />+ <TableCell className={classes.colName}>+ {i18n.t("Name", { context: "object" })}+ </TableCell>+ <TableCell className={classes.colType}>+ {i18n.t("Type", { context: "object" })}+ </TableCell>+ <TableCell className={classes.colPublished}>+ {i18n.t("Published", { context: "object" })}+ </TableCell>+ <TableCell className={classes.colPrice}>+ {i18n.t("Price", { context: "object" })}+ </TableCell>+ </>+ }+ /><TableFooter><TableRow><TablePaginationdiff --git a/saleor/static/dashboard-next/components/TableActions/TableActions.tsx b/saleor/static/dashboard-next/components/TableActions/TableActions.tsxindex 822970ce62..a528dc00b1 100644--- a/saleor/static/dashboard-next/components/TableActions/TableActions.tsx+++ b/saleor/static/dashboard-next/components/TableActions/TableActions.tsx@@ -49,21 +49,19 @@ const TableActions = withStyles(styles, { name: "TableActions" })(children,selected}: TableActionsProps & WithStyles<typeof styles>) => (- <TableRow className={classNames(classes.root, className)}>- <TableCell className={classes.cell} colSpan={9999}>- <div className={classes.container}>- {selected && (- <Typography>- {i18n.t("Selected {{ number }} items", {- number: selected- })}- </Typography>- )}- <div className={classes.spacer} />- <div className={classes.toolbar}>{children}</div>- </div>- </TableCell>- </TableRow>+ <div className={classNames(classes.root, className)}>+ <div className={classes.container}>+ {selected && (+ <Typography>+ {i18n.t("Selected {{ number }} items", {+ number: selected+ })}+ </Typography>+ )}+ <div className={classes.spacer} />+ <div className={classes.toolbar}>{children}</div>+ </div>+ </div>));TableActions.displayName = "TableActions";diff --git a/saleor/static/dashboard-next/components/TableHead/TableHead.tsx b/saleor/static/dashboard-next/components/TableHead/TableHead.tsxindex f4a0ff0279..9ec7f9da4c 100644--- a/saleor/static/dashboard-next/components/TableHead/TableHead.tsx+++ b/saleor/static/dashboard-next/components/TableHead/TableHead.tsx@@ -1,19 +1,58 @@-import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";import MuiTableHead, {TableHeadProps as MuiTableHeadProps} from "@material-ui/core/TableHead";import * as React from "react";-+import { fade } from "@material-ui/core/styles/colorManipulator";import TableActions from "../TableActions";+import TableCell from "@material-ui/core/TableCell";+import TableRow from "@material-ui/core/TableRow";+import Typography from "@material-ui/core/Typography";+import * as classNames from "classnames";++import Checkbox from "../Checkbox";+import i18n from "../../i18n";export interface TableHeadProps extends MuiTableHeadProps {selected: number;toolbar: React.ReactNode | React.ReactNodeArray;}-const styles = createStyles({- shrink: {}-});+const styles = (theme: Theme) =>+ createStyles({+ cell: {+ padding: 0+ },+ container: {+ alignItems: "center",+ display: "flex",+ height: 56,+ marginRight: -theme.spacing.unit * 2+ },+ padding: {+ "&:last-child": {+ padding: 0+ }+ },+ root: {+ backgroundColor: fade(theme.palette.primary.main, 0.05),+ paddingLeft: 12,+ paddingRight: 24+ },+ spacer: {+ flex: 1+ },+ toolbar: {+ "& > *": {+ marginLeft: theme.spacing.unit+ }+ }+ });const TableHead = withStyles(styles, {name: "TableHead"@@ -21,18 +60,52 @@ const TableHead = withStyles(styles, {({children,classes,+ disabled,+ items,selected,+ tablebar,+ toggleAll,toolbar,...muiTableHeadProps- }: TableHeadProps & WithStyles<typeof styles>) => (- <MuiTableHead {...muiTableHeadProps}>- {selected ? (- <TableActions selected={selected}>{toolbar}</TableActions>- ) : (- children- )}- </MuiTableHead>- )+ }: TableHeadProps & WithStyles<typeof styles>) => {+ const [isSelected, setSelected] = React.useState(false);+ return (+ <MuiTableHead {...muiTableHeadProps}>+ <TableRow>+ <TableCell padding="checkbox">+ <Checkbox+ checked={isSelected}+ disabled={disabled}+ onChange={event => {+ toggleAll(items, selected);+ setSelected(!isSelected);+ event.stopPropagation();+ }}+ />+ </TableCell>+ {selected ? (+ <>+ <div className={classNames(classes.root)}>+ <div className={classes.container}>+ {selected && (+ <Typography>+ {i18n.t("Selected {{ number }} items", {+ number: selected+ })}+ </Typography>+ )}+ <div className={classes.spacer} />+ <div className={classes.toolbar}>{toolbar}</div>+ </div>+ </div>+ </>+ ) : (+ tablebar+ )}+ </TableRow>+ </MuiTableHead>+ );+ });TableHead.displayName = "TableHead";export default TableHead;diff --git a/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsx b/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsxindex b5f2426857..a7da16ae90 100644--- a/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsx+++ b/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsx@@ -58,25 +58,33 @@ const CustomerList = withStyles(styles, { name: "CustomerList" })(onRowClick,toolbar,toggle,+ toggleAll,selected,isChecked}: CustomerListProps) => (<Card><Table>- <TableHead selected={selected} toolbar={toolbar}>- <TableRow>- <TableCell />- <TableCell className={classes.colName}>- {i18n.t("Customer Name", { context: "table header" })}- </TableCell>- <TableCell className={classes.colEmail}>- {i18n.t("Customer e-mail", { context: "table header" })}- </TableCell>- <TableCell className={classes.colOrders}>- {i18n.t("Orders", { context: "table header" })}- </TableCell>- </TableRow>- </TableHead>+ <TableHead+ selected={selected}+ disabled={disabled}+ items={products}+ toggleAll={toggleAll}+ toolbar={toolbar}+ tablebar={+ <>+ <TableCell />+ <TableCell className={classes.colName}>+ {i18n.t("Customer Name", { context: "table header" })}+ </TableCell>+ <TableCell className={classes.colEmail}>+ {i18n.t("Customer e-mail", { context: "table header" })}+ </TableCell>+ <TableCell className={classes.colOrders}>+ {i18n.t("Orders", { context: "table header" })}+ </TableCell>+ </>+ }+ /><TableFooter><TableRow><TablePaginationdiff --git a/saleor/static/dashboard-next/customers/views/CustomerList.tsx b/saleor/static/dashboard-next/customers/views/CustomerList.tsxindex e8629203a2..cc46903d4e 100644--- a/saleor/static/dashboard-next/customers/views/CustomerList.tsx+++ b/saleor/static/dashboard-next/customers/views/CustomerList.tsx@@ -33,7 +33,7 @@ export const CustomerList: React.StatelessComponent<CustomerListProps> = ({const navigate = useNavigator();const notify = useNotifier();const paginate = usePaginator();- const { isSelected, listElements, reset, toggle } = useBulkActions(+ const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(params.ids);@@ -110,6 +110,7 @@ export const CustomerList: React.StatelessComponent<CustomerListProps> = ({isChecked={isSelected}selected={listElements.length}toggle={toggle}+ toggleAll={toggleAll}/><ActionDialogopen={params.action === "remove"}diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsxindex 31298aec4d..f39a21b916 100644--- a/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx+++ b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx@@ -65,6 +65,7 @@ const DiscountCategories = withStyles(styles, {onNextPage,toolbar,toggle,+ toggleAll,selected,isChecked}: DiscountCategoriesProps & WithStyles<typeof styles>) => (diff --git a/saleor/static/dashboard-next/hooks/useBulkActions.ts b/saleor/static/dashboard-next/hooks/useBulkActions.tsindex eb3ead61bf..48ef9d501a 100644--- a/saleor/static/dashboard-next/hooks/useBulkActions.ts+++ b/saleor/static/dashboard-next/hooks/useBulkActions.ts@@ -23,13 +23,27 @@ function useBulkActions(initial: string[] = []) {isSelected(id) ? remove(id) : add(id);}+ function toggleAll(items, selected) {+ const allItems = [];+ items.map(item => {+ allItems.push(item.id);+ });+ if (selected === allItems.length) {+ reset();+ } else {+ reset();+ setListElements(allItems);+ }+ }+return {add,isSelected,listElements,remove,reset,- toggle+ toggle,+ toggleAll};}export default useBulkActions;diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsxindex a9547cdb5d..cc0866aaac 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx@@ -41,6 +41,7 @@ export const ProductListCard: React.StatelessComponent<isChecked,selected,toggle,+ toggleAll,toolbar}) => (<Container>@@ -63,6 +64,7 @@ export const ProductListCard: React.StatelessComponent<disabled={disabled}pageInfo={pageInfo}toolbar={toolbar}+ toggleAll={toggleAll}selected={selected}isChecked={isChecked}toggle={toggle}diff --git a/saleor/static/dashboard-next/products/views/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList.tsxindex 143d921e57..3c767cdd90 100644--- a/saleor/static/dashboard-next/products/views/ProductList.tsx+++ b/saleor/static/dashboard-next/products/views/ProductList.tsx@@ -42,7 +42,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({const navigate = useNavigator();const notify = useNotifier();const paginate = usePaginator();- const { isSelected, listElements, reset, toggle } = useBulkActions(+ const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(params.ids);@@ -193,6 +193,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({isChecked={isSelected}selected={listElements.length}toggle={toggle}+ toggleAll={toggleAll}/><ActionDialogopen={params.action === "delete"}diff --git a/saleor/static/dashboard-next/types.ts b/saleor/static/dashboard-next/types.tsindex c75141a9e9..33c87fee6b 100644--- a/saleor/static/dashboard-next/types.ts+++ b/saleor/static/dashboard-next/types.ts@@ -17,6 +17,7 @@ export interface ListProps {}export interface ListActionsWithoutToolbar {toggle: (id: string) => void;+ toggleAll: () => void;isChecked: (id: string) => boolean;selected: number;}