Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add row number select to productList
Krzysztof Bialoglowicz02b5e2cfc775
diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsxindex ccbe45ffef..4f55b4db4d 100644--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx@@ -71,6 +71,7 @@ interface ProductListPropsexport const ProductList = withStyles(styles, { name: "ProductList" })(({classes,+ currentRowNum,disabled,isChecked,pageInfo,@@ -81,114 +82,120 @@ export const ProductList = withStyles(styles, { name: "ProductList" })(toolbar,onNextPage,onPreviousPage,+ onRowNumChange,onRowClick- }: ProductListProps) => (- <Table>- <TableHead- selected={selected}- disabled={disabled}- items={products}- toggleAll={toggleAll}- toolbar={toolbar}- >- <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>- </TableHead>- <TableFooter>- <TableRow>- <TablePagination- colSpan={6}- hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}- onNextPage={onNextPage}- hasPreviousPage={- pageInfo && !disabled ? pageInfo.hasPreviousPage : false- }- onPreviousPage={onPreviousPage}- />- </TableRow>- </TableFooter>- <TableBody>- {renderCollection(- products,- product => {- const isSelected = product ? isChecked(product.id) : false;+ }: ProductListProps) => {+ return (+ <Table>+ <TableHead+ selected={selected}+ disabled={disabled}+ items={products}+ toggleAll={toggleAll}+ toolbar={toolbar}+ >+ <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>+ </TableHead>+ <TableFooter>+ <TableRow>+ <TablePagination+ colSpan={6}+ currentRowNum={currentRowNum}+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}+ onNextPage={onNextPage}+ onRowNumChange={onRowNumChange}+ hasPreviousPage={+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false+ }+ onPreviousPage={onPreviousPage}+ />+ </TableRow>+ </TableFooter>+ <TableBody>+ {renderCollection(+ products,+ product => {+ const isSelected = product ? isChecked(product.id) : false;- return (- <TableRow- selected={isSelected}- hover={!!product}- key={product ? product.id : "skeleton"}- onClick={product && onRowClick(product.id)}- className={classes.link}- >- <TableCell padding="checkbox">- <Checkbox- checked={isSelected}- disabled={disabled}- onChange={() => toggle(product.id)}- />- </TableCell>- <TableCellAvatar- thumbnail={maybe(() => product.thumbnail.url)}- />- <TableCell className={classes.colName}>- {product ? product.name : <Skeleton />}- </TableCell>- <TableCell className={classes.colType}>- {product && product.productType ? (- product.productType.name- ) : (- <Skeleton />- )}- </TableCell>- <TableCell className={classes.colPublished}>- {product && maybe(() => product.isAvailable !== undefined) ? (- <StatusLabel- label={- product.isAvailable- ? i18n.t("Published", { context: "product status" })- : i18n.t("Not published", {- context: "product status"- })- }- status={product.isAvailable ? "success" : "error"}+ return (+ <TableRow+ selected={isSelected}+ hover={!!product}+ key={product ? product.id : "skeleton"}+ onClick={product && onRowClick(product.id)}+ className={classes.link}+ >+ <TableCell padding="checkbox">+ <Checkbox+ checked={isSelected}+ disabled={disabled}+ onChange={() => toggle(product.id)}/>- ) : (- <Skeleton />- )}- </TableCell>- <TableCell className={classes.colPrice}>- {maybe(() => product.basePrice) &&- maybe(() => product.basePrice.amount) !== undefined &&- maybe(() => product.basePrice.currency) !== undefined ? (- <Money money={product.basePrice} />- ) : (- <Skeleton />- )}- </TableCell>+ </TableCell>+ <TableCellAvatar+ thumbnail={maybe(() => product.thumbnail.url)}+ />+ <TableCell className={classes.colName}>+ {product ? product.name : <Skeleton />}+ </TableCell>+ <TableCell className={classes.colType}>+ {product && product.productType ? (+ product.productType.name+ ) : (+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.colPublished}>+ {product &&+ maybe(() => product.isAvailable !== undefined) ? (+ <StatusLabel+ label={+ product.isAvailable+ ? i18n.t("Published", { context: "product status" })+ : i18n.t("Not published", {+ context: "product status"+ })+ }+ status={product.isAvailable ? "success" : "error"}+ />+ ) : (+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.colPrice}>+ {maybe(() => product.basePrice) &&+ maybe(() => product.basePrice.amount) !== undefined &&+ maybe(() => product.basePrice.currency) !== undefined ? (+ <Money money={product.basePrice} />+ ) : (+ <Skeleton />+ )}+ </TableCell>+ </TableRow>+ );+ },+ () => (+ <TableRow>+ <TableCell colSpan={6}>{i18n.t("No products found")}</TableCell></TableRow>- );- },- () => (- <TableRow>- <TableCell colSpan={6}>{i18n.t("No products found")}</TableCell>- </TableRow>- )- )}- </TableBody>- </Table>- )+ )+ )}+ </TableBody>+ </Table>+ );+ });ProductList.displayName = "ProductList";export default ProductList;diff --git a/saleor/static/dashboard-next/components/RowNumberSelect/RowNumberSelect.tsx b/saleor/static/dashboard-next/components/RowNumberSelect/RowNumberSelect.tsxnew file mode 100644index 0000000000..a8ee6c1675--- /dev/null+++ b/saleor/static/dashboard-next/components/RowNumberSelect/RowNumberSelect.tsx@@ -0,0 +1,71 @@+import MenuItem from "@material-ui/core/MenuItem";+import Select from "@material-ui/core/Select";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";+import classNames from "classnames";+import React from "react";++import i18n from "../../i18n";++const styles = (theme: Theme) =>+ createStyles({+ label: {+ fontSize: "14px"+ },+ select: {+ "&:after, &:before, &:hover": {+ border: "none !important"+ },+ "& div": {+ color: theme.palette.primary.main,+ padding: "0 10px 0 5px"+ },+ "& svg": {+ color: theme.palette.primary.main+ }+ },+ ".MuiSelect-select": { padding: 0 }+ });++interface RowNumberSelectProps extends WithStyles<typeof styles> {+ choices: number[];+ className: string;+ currentRowNum: number;+ name: string;+ onChange(event: any);+}++const RowNumberSelect = withStyles(styles, { name: "RowNumberSelect" })(+ ({+ classes,+ className,+ choices,+ currentRowNum,+ onChange+ }: RowNumberSelectProps) => {+ return (+ <div className={classNames(classes.root, className)}>+ <span className={classes.label}>{i18n.t("No of Rows:")}</span>+ <Select+ className={classes.select}+ value={currentRowNum}+ onChange={onChange}+ >+ {choices.length > 0 &&+ choices.map(choice => (+ <MenuItem value={choice} key={choice}>+ {choice}+ </MenuItem>+ ))}+ </Select>+ </div>+ );+ }+);++RowNumberSelect.displayName = "RowNumberSelect";+export default RowNumberSelect;diff --git a/saleor/static/dashboard-next/components/RowNumberSelect/index.ts b/saleor/static/dashboard-next/components/RowNumberSelect/index.tsnew file mode 100644index 0000000000..380ec9594c--- /dev/null+++ b/saleor/static/dashboard-next/components/RowNumberSelect/index.ts@@ -0,0 +1,2 @@+export { default } from "./RowNumberSelect";+export * from "./RowNumberSelect";diff --git a/saleor/static/dashboard-next/components/TablePagination/TablePagination.tsx b/saleor/static/dashboard-next/components/TablePagination/TablePagination.tsxindex b5e9553f35..1fe787691d 100644--- a/saleor/static/dashboard-next/components/TablePagination/TablePagination.tsx+++ b/saleor/static/dashboard-next/components/TablePagination/TablePagination.tsx@@ -11,6 +11,7 @@ import TableCell from "@material-ui/core/TableCell";import Toolbar from "@material-ui/core/Toolbar";import React from "react";+import RowNumberSelect from "@saleor/components/RowNumberSelect";import TablePaginationActions from "./TablePaginationActions";const styles = (theme: Theme) =>@@ -50,7 +51,8 @@ const styles = (theme: Theme) =>toolbar: {height: 56,minHeight: 56,- paddingRight: 2+ paddingRight: 2,+ paddingLeft: 2}});@@ -59,11 +61,13 @@ interface TablePaginationProps extends WithStyles<typeof styles> {backIconButtonProps?: Partial<IconButtonProps>;colSpan: number;component?: string | typeof TableCell;+ currentRowNum: number;hasNextPage: boolean;hasPreviousPage: boolean;nextIconButtonProps?: Partial<IconButtonProps>;onNextPage(event);onPreviousPage(event);+ onRowNumChange: (event: React.ChangeEvent<any>) => void;}const TablePagination = withStyles(styles, { name: "TablePagination" })(@@ -73,11 +77,13 @@ const TablePagination = withStyles(styles, { name: "TablePagination" })(classes,colSpan: colSpanProp,component: Component,+ currentRowNum,hasNextPage,hasPreviousPage,nextIconButtonProps,onNextPage,onPreviousPage,+ onRowNumChange,...other}: TablePaginationProps) => {let colSpan;@@ -89,7 +95,13 @@ const TablePagination = withStyles(styles, { name: "TablePagination" })(return (<Component className={classes.root} colSpan={colSpan} {...other}><Toolbar className={classes.toolbar}>- <div className={classes.spacer} />+ <div className={classes.spacer}>+ <RowNumberSelect+ choices={[20, 30, 50, 100]}+ currentRowNum={currentRowNum}+ onChange={onRowNumChange}+ />+ </div><ActionsbackIconButtonProps={backIconButtonProps}hasNextPage={hasNextPage}diff --git a/saleor/static/dashboard-next/hooks/useRowChange.ts b/saleor/static/dashboard-next/hooks/useRowChange.tsnew file mode 100644index 0000000000..0a6ab33317--- /dev/null+++ b/saleor/static/dashboard-next/hooks/useRowChange.ts@@ -0,0 +1,18 @@+import { useState } from "react";++import { PAGINATE_BY } from "../config";++function useRowChange() {+ const [rowNumber, setRowNumber] = useState(PAGINATE_BY);++ function onRowChange(event: React.ChangeEvent<any>) {+ setRowNumber(event.target.value);+ }++ return {+ rowNumber,+ onRowChange+ };+}++export default useRowChange;diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsxindex 618c7a4805..0d25fa9b54 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx@@ -16,6 +16,7 @@ export interface ProductListCardPropsextends PageListProps,ListActions,FilterPageProps<ProductListUrlFilters> {+ currentRowNum: number;currencySymbol: string;products: CategoryDetails_category_products_edges_node[];}@@ -36,33 +37,35 @@ export const ProductListCard: React.StatelessComponent<onTabChange,onFilterDelete,...listProps-}) => (- <Container>- <PageHeader title={i18n.t("Products")}>- <Button onClick={onAdd} color="primary" variant="contained">- {i18n.t("Add product")} <AddIcon />- </Button>- </PageHeader>- <Card>- <ProductListFilter- allTabLabel={i18n.t("All Products")}- currencySymbol={currencySymbol}- currentTab={currentTab}- filterLabel={i18n.t("Select all products where:")}- filterTabs={filterTabs}- filtersList={filtersList}- initialSearch={initialSearch}- searchPlaceholder={i18n.t("Search Products...")}- onAll={onAll}- onSearchChange={onSearchChange}- onFilterAdd={onFilterAdd}- onFilterSave={onFilterSave}- onTabChange={onTabChange}- onFilterDelete={onFilterDelete}- />- <ProductList {...listProps} />- </Card>- </Container>-);+}) => {+ return (+ <Container>+ <PageHeader title={i18n.t("Products")}>+ <Button onClick={onAdd} color="primary" variant="contained">+ {i18n.t("Add product")} <AddIcon />+ </Button>+ </PageHeader>+ <Card>+ <ProductListFilter+ allTabLabel={i18n.t("All Products")}+ currencySymbol={currencySymbol}+ currentTab={currentTab}+ filterLabel={i18n.t("Select all products where:")}+ filterTabs={filterTabs}+ filtersList={filtersList}+ initialSearch={initialSearch}+ searchPlaceholder={i18n.t("Search Products...")}+ onAll={onAll}+ onSearchChange={onSearchChange}+ onFilterAdd={onFilterAdd}+ onFilterSave={onFilterSave}+ onTabChange={onTabChange}+ onFilterDelete={onFilterDelete}+ />+ <ProductList {...listProps} />+ </Card>+ </Container>+ );+};ProductListCard.displayName = "ProductListCard";export default ProductListCard;diff --git a/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsxindex 7494e6053c..67d2feaac5 100644--- a/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx+++ b/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx@@ -16,6 +16,7 @@ import useNotifier from "@saleor/hooks/useNotifier";import usePaginator, {createPaginationState} from "@saleor/hooks/usePaginator";+import useRowChange from "@saleor/hooks/useRowChange";import useShop from "@saleor/hooks/useShop";import { PAGINATE_BY } from "../../../config";import i18n from "../../../i18n";@@ -62,6 +63,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(params.ids);+ const { rowNumber, onRowChange } = useRowChange();const tabs = getFilterTabs();@@ -128,14 +130,14 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({handleTabChange(tabs.length + 1);};- const paginationState = createPaginationState(PAGINATE_BY, params);+ const paginationState = createPaginationState(rowNumber, params);const currencySymbol = maybe(() => shop.defaultCurrency, "USD");const queryVariables = React.useMemo(() => ({...paginationState,filter: getFilterVariables(params)}),- [params]+ [params, rowNumber]);return (@@ -196,6 +198,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({<ProductListCardcurrencySymbol={currencySymbol}currentTab={currentTab}+ currentRowNum={rowNumber}filtersList={createFilterChips(params,{@@ -211,6 +214,7 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({)}onNextPage={loadNextPage}onPreviousPage={loadPreviousPage}+ onRowNumChange={onRowChange}pageInfo={pageInfo}onRowClick={id => () => navigate(productUrl(id))}onAll={() =>diff --git a/saleor/static/dashboard-next/types.ts b/saleor/static/dashboard-next/types.tsindex d004b34d6a..a332416a27 100644--- a/saleor/static/dashboard-next/types.ts+++ b/saleor/static/dashboard-next/types.ts@@ -10,6 +10,7 @@ export interface UserError {}export interface ListProps {+ currentRowNum: number;disabled: boolean;pageInfo?: {hasNextPage: boolean;@@ -18,6 +19,7 @@ export interface ListProps {onNextPage: () => void;onPreviousPage: () => void;onRowClick: (id: string) => () => void;+ onRowNumChange: (event: React.ChangeEvent<any>) => void;}export interface ListActionsWithoutToolbar {toggle: (id: string) => void;