Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add filter for product list
Lukasz Szewczykeca85c4c43d4
diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsxindex efde323f2a..6d65ad938a 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx@@ -11,7 +11,13 @@ import i18n from "../../../i18n";import { PageListProps } from "../../../types";import ProductListFilter from "../ProductListFilter";+export interface Filter {+ label: string;+ onClick: () => void;+}interface ProductListCardProps extends PageListProps {+ currentTab: number;+ filtersList: Filter[];products: CategoryDetails_category_products_edges_node[];}@@ -24,7 +30,9 @@ export const ProductListCard: React.StatelessComponent<onAdd,onNextPage,onPreviousPage,- onRowClick+ onRowClick,+ filtersList,+ currentTab}) => (<Container width="md"><PageHeader title={i18n.t("Products")}>@@ -33,7 +41,7 @@ export const ProductListCard: React.StatelessComponent<</Button></PageHeader><Card>- <ProductListFilter />+ <ProductListFilter currentTab={currentTab} filtersList={filtersList} /><ProductListproducts={products}disabled={disabled}diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/index.ts b/saleor/static/dashboard-next/products/components/ProductListCard/index.tsindex 995a575ae1..05e63d02df 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/index.ts+++ b/saleor/static/dashboard-next/products/components/ProductListCard/index.ts@@ -1,2 +1,3 @@export { default } from "./ProductListCard";export * from "./ProductListCard";+export { Filter } from "./ProductListCard";diff --git a/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx b/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsxindex 833b76dc6a..e73715e380 100644--- a/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx@@ -1,22 +1,45 @@import { withStyles } from "@material-ui/core/styles";-import ClearIcon from "@material-ui/icons/Clear";-// import Typographt from "@material-ui/core/Typography";import Tab from "@material-ui/core/Tab";import Tabs from "@material-ui/core/Tabs";+import Typography from "@material-ui/core/Typography";+import ClearIcon from "@material-ui/icons/Clear";import * as React from "react";-// import i18n from "../../../i18n";-+import i18n from "../../../i18n";+import { Filter } from "../ProductListCard";interface ProductListFilterProps {- disabled?: boolean;+ currentTab: number;+ filtersList: Filter[];}const decorate = withStyles(theme => ({- clearIcon: {-color: "#b2b2b2",-heigh: "18px,-wodth" 18px"- }+ filterButton: {+ alignItems: "center",+ backgroundColor: "rgba(90, 179, 120, .25)",+ borderRadius: "19px",+ cursor: "pointer",+ display: "flex",+ height: "38px",+ justifyContent: "space-around",+ margin: "10px 0 10px 12px",+ minWidth: "160px",+ padding: "0 8px 0 16px"+ },+ filterContainer: {+ borderBottom: "1px solid #e8e8e8",+ display: "flex",+ flexWrap: "wrap" as "wrap",+ paddingLeft: "12px"+ },+ filterIcon: {+ color: "#616161",+ height: "20px",+ width: "20px"+ },+ filterText: {+ fontWeight: 400 as 400,+ marginRight: "12px"+ },tabLabel: {color: "#616161",fontSize: "0.875rem"@@ -27,43 +50,61 @@ wodth" 18px"paddingTop: `${theme.spacing.unit * 1}px`,textTransform: "initial" as "initial"},- tabWrapper: {- flexDirection: "row-reverse" as "row-reverse"- },tabsRoot: {borderBottom: "1px solid #e0e0e0",paddingLeft: `${theme.spacing.unit * 3}px`}}));-const ProductListFilter = decorate<ProductListFilterProps>(({ classes }) => (- <Tabs className={classes.tabsRoot} value={0} indicatorColor={"primary"}>- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={"All Products"}- />- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={"Available"}- />- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={"Out of stock"}- />- <Tab- disableRipple- classes={{- label: classes.tabLabel,- root: classes.tabRoot,- wrapper: classes.tabWrapper- }}- label={"Custom filter"}- icon={<ClearIcon />}- />- </Tabs>-));+const ProductListFilter = decorate<ProductListFilterProps>(+ ({ classes, filtersList, currentTab }) => (+ <>+ <Tabs className={classes.tabsRoot} value={0} indicatorColor={"primary"}>+ <Tab+ disableRipple+ classes={{ root: classes.tabRoot, label: classes.tabLabel }}+ label={i18n.t("All Products")}+ />+ <Tab+ disableRipple+ classes={{ root: classes.tabRoot, label: classes.tabLabel }}+ label={i18n.t("Available")}+ />+ <Tab+ disableRipple+ classes={{ root: classes.tabRoot, label: classes.tabLabel }}+ label={i18n.t("Out of stock")}+ />+ {(currentTab === 0 || undefined) &&+ filtersList &&+ filtersList.length > 0 && (+ <Tab+ value={0}+ disableRipple+ classes={{+ label: classes.tabLabel,+ root: classes.tabRoot+ }}+ label={i18n.t("Custom Filter")}+ />+ )}+ </Tabs>+ {(currentTab === 0 || undefined) &&+ filtersList &&+ filtersList.length > 0 && (+ <div className={classes.filterContainer}>+ {filtersList.map(filter => (+ <div className={classes.filterButton}>+ <Typography className={classes.filterText}>+ {i18n.t(filter.label)}+ </Typography>+ <ClearIcon className={classes.filterIcon} />+ </div>+ ))}+ </div>+ )}+ </>+ )+);ProductListFilter.displayName = "ProductListFilter";export default ProductListFilter;diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsxindex 5a37fe2271..e749eba2b3 100644--- a/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx@@ -4,21 +4,61 @@ import * as React from "react";import * as placeholderImage from "../../../../images/placeholder255x255.png";import { category as categoryFixture } from "../../../categories/fixtures";import { pageListProps } from "../../../fixtures";-import ProductListCard from "../../../products/components/ProductListCard";+import ProductListCard, {+ Filter+} from "../../../products/components/ProductListCard";import Decorator from "../../Decorator";const products = categoryFixture(placeholderImage).products.edges.map(edge => edge.node);+const filtersList: Filter[] = [+ {+ label: "Gardner-Schultz",+ onClick: () => undefined+ },+ {+ label: "Davis, Brown and Ray",+ onClick: () => undefined+ },+ {+ label: "Franklin Inc",+ onClick: () => undefined+ }+];+storiesOf("Views / Products / Product list", module).addDecorator(Decorator).add("default", () => (- <ProductListCard products={products} {...pageListProps.default} />+ <ProductListCard+ filtersList={[]}+ currentTab={0}+ products={products}+ {...pageListProps.default}+ />+ ))+ .add("with custom filters", () => (+ <ProductListCard+ products={products}+ {...pageListProps.default}+ filtersList={filtersList}+ currentTab={0}+ />)).add("loading", () => (- <ProductListCard {...pageListProps.loading} products={undefined} />+ <ProductListCard+ {...pageListProps.loading}+ products={undefined}+ filtersList={undefined}+ currentTab={undefined}+ />)).add("no data", () => (- <ProductListCard products={[]} {...pageListProps.default} />+ <ProductListCard+ products={[]}+ {...pageListProps.default}+ filtersList={[]}+ currentTab={0}+ />));