Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add custom component for table filters
Lukasz Szewczykd981e09fa36e
diff --git a/saleor/static/dashboard-next/components/TableFilter/FilterChip.tsx b/saleor/static/dashboard-next/components/TableFilter/FilterChip.tsxnew file mode 100644index 0000000000..654db02aad--- /dev/null+++ b/saleor/static/dashboard-next/components/TableFilter/FilterChip.tsx@@ -0,0 +1,96 @@+import { withStyles } from "@material-ui/core/styles";+import Typography from "@material-ui/core/Typography";+import AddIcon from "@material-ui/icons/Add";+import ClearIcon from "@material-ui/icons/Clear";+import * as classNames from "classnames";+import * as React from "react";++import i18n from "../../i18n";++export interface Filter {+ label: string;+ onClick: () => void;+}++interface FilterChipProps {+ filtersList: Filter[];+}++const decorate = withStyles({+ addFilterText: {+ fontWeight: 600 as 600,+ marginRight: "12px"+ },+ filterButton: {+ alignItems: "center",+ backgroundColor: "rgba(90, 179, 120, .25)",+ borderRadius: "19px",+ cursor: "pointer",+ display: "flex",+ height: "38px",+ justifyContent: "space-around",+ margin: "10px 0 0 12px",+ minWidth: "160px",+ padding: "0 8px 0 16px"+ },+ addFilterButtonPrimary: {+ "&:hover": {+ backgroundColor: "rgba(90, 179, 120, .25)"+ },+ backgroundColor: "#ffffff",+ border: "2px dashed #5AB378",+ width: "135px"+ },+ addFilterButtonSecondary: {+ "&:hover": {+ backgroundColor: "rgba(3, 169, 244, .25)"+ },+ backgroundColor: "#ffffff",+ border: "2px dashed #03A9F4",+ width: "135px"+ },+ filterContainer: {+ borderBottom: "1px solid #e8e8e8",+ display: "flex",+ flexWrap: "wrap" as "wrap",+ paddingBottom: "10px",+ paddingLeft: "12px"+ },+ filterIcon: {+ color: "#616161",+ height: "20px",+ width: "20px"+ },+ filterText: {+ fontWeight: 400 as 400,+ marginRight: "12px"+ }+});++export const FilterChip = decorate<FilterChipProps>(+ ({ classes, filtersList }) => (+ <div className={classes.filterContainer}>+ {filtersList.map(filter => (+ <div className={classes.filterButton} onClick={filter.onClick}>+ <Typography className={classes.filterText}>{filter.label}</Typography>+ <ClearIcon className={classes.filterIcon} />+ </div>+ ))}+ <div+ className={classNames({+ [classes.filterButton]: true,+ [filtersList.length > 0+ ? classes.addFilterButtonPrimary+ : classes.addFilterButtonSecondary]: true+ })}+ >+ <AddIcon color={filtersList.length > 0 ? "primary" : "secondary"} />+ <Typography className={classes.addFilterText}>+ {i18n.t("Add Filter")}+ </Typography>+ </div>+ </div>+ )+);++export default FilterChip;diff --git a/saleor/static/dashboard-next/components/TableFilter/FilterTab.tsx b/saleor/static/dashboard-next/components/TableFilter/FilterTab.tsxnew file mode 100644index 0000000000..ba9d5e7d7e--- /dev/null+++ b/saleor/static/dashboard-next/components/TableFilter/FilterTab.tsx@@ -0,0 +1,36 @@+import { withStyles } from "@material-ui/core/styles";+import Tab from "@material-ui/core/Tab";+import * as React from "react";++interface FilterTabProps {+ onClick: () => void;+ label: string;+ value?: number;+}++const decorate = withStyles(theme => ({+ tabLabel: {+ color: "#616161",+ fontSize: "0.875rem"+ },+ tabRoot: {+ minWidth: "80px",+ opacity: 1,+ paddingTop: `${theme.spacing.unit * 1}px`,+ textTransform: "initial" as "initial"+ }+}));++export const FilterTab = decorate<FilterTabProps>(+ ({ classes, onClick, label, value }) => (+ <Tab+ disableRipple+ label={label}+ classes={{ root: classes.tabRoot, label: classes.tabLabel }}+ onClick={onClick}+ value={value}+ />+ )+);++export default FilterTab;diff --git a/saleor/static/dashboard-next/components/TableFilter/FilterTabs.tsx b/saleor/static/dashboard-next/components/TableFilter/FilterTabs.tsxnew file mode 100644index 0000000000..0c0b6dc408--- /dev/null+++ b/saleor/static/dashboard-next/components/TableFilter/FilterTabs.tsx@@ -0,0 +1,28 @@+import { withStyles } from "@material-ui/core/styles";+import Tabs from "@material-ui/core/Tabs";+import * as React from "react";++interface FilterTabsProps {+ currentTab: number;+}++const decorate = withStyles(theme => ({+ tabsRoot: {+ borderBottom: "1px solid #e0e0e0",+ paddingLeft: `${theme.spacing.unit * 3}px`+ }+}));++export const FilterTabs = decorate<FilterTabsProps>(+ ({ classes, children, currentTab }) => (+ <Tabs+ className={classes.tabsRoot}+ value={currentTab}+ indicatorColor={"primary"}+ >+ {children}+ </Tabs>+ )+);++export default FilterTabs;diff --git a/saleor/static/dashboard-next/components/TableFilter/index.ts b/saleor/static/dashboard-next/components/TableFilter/index.tsnew file mode 100644index 0000000000..326f9104ec--- /dev/null+++ b/saleor/static/dashboard-next/components/TableFilter/index.ts@@ -0,0 +1,5 @@+export { default } from "./FilterTabs";+export { Filter } from "./FilterChip";+export * from "./FilterTabs";+export * from "./FilterTab";+export * from "./FilterChip";diff --git a/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsx b/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsxindex 229bb45799..a75ce756ad 100644--- a/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsx@@ -1,12 +1,12 @@-import { withStyles } from "@material-ui/core/styles";-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 {+ Filter,+ FilterChip,+ FilterTab,+ FilterTabs+} from "../../../components/TableFilter";import i18n from "../../../i18n";-import { Filter } from "../../../products/components/ProductListCard";interface OrderListFilterProps {currentTab: number;@@ -14,111 +14,36 @@ interface OrderListFilterProps {onAllProducts: () => void;onToFulfill: () => void;onToCapture: () => void;+ onCustomFilter: () => void;}-const decorate = withStyles(theme => ({- 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"- },- tabRoot: {- minWidth: "80px",- opacity: 1,- paddingTop: `${theme.spacing.unit * 1}px`,- textTransform: "initial" as "initial"- },- tabsRoot: {- borderBottom: "1px solid #e0e0e0",- paddingLeft: `${theme.spacing.unit * 3}px`- }-}));--const OrderListFilter = decorate<OrderListFilterProps>(- ({- classes,- filtersList,- currentTab,- onAllProducts,- onToFulfill,- onToCapture- }) => (- <>- <Tabs className={classes.tabsRoot} value={0} indicatorColor={"primary"}>- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={i18n.t("All Products")}- onClick={onAllProducts}- />- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={i18n.t("Ready to fulfill")}- onClick={onToFulfill}- />- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={i18n.t("Ready to capture")}- onClick={onToCapture}- />- {(currentTab === 0 || undefined) &&- filtersList &&- filtersList.length > 0 && (- <Tab- value={0}- disableRipple- classes={{- label: classes.tabLabel,- root: classes.tabRoot- }}- label={i18n.t("Custom Filter")}- />- )}- </Tabs>+const OrderListFilter: React.StatelessComponent<OrderListFilterProps> = ({+ filtersList,+ currentTab,+ onAllProducts,+ onToFulfill,+ onToCapture,+ onCustomFilter+}) => (+ <>+ <FilterTabs currentTab={currentTab}>+ <FilterTab label={i18n.t("All Products")} onClick={onAllProducts} />+ <FilterTab label={i18n.t("Ready to fulfill")} onClick={onToFulfill} />+ <FilterTab label={i18n.t("Ready to capture")} onClick={onToCapture} />{(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>+ <FilterTab+ onClick={onCustomFilter}+ value={0}+ label={i18n.t("Custom Filter")}+ />)}- </>- )+ </FilterTabs>+ {(currentTab === 0 || undefined) &&+ filtersList &&+ filtersList.length > 0 && <FilterChip filtersList={filtersList} />}+ </>);OrderListFilter.displayName = "OrderListFilter";export default OrderListFilter;diff --git a/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx b/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsxindex 3d1558317b..b92e96c9bb 100644--- a/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx@@ -5,8 +5,8 @@ import * as React from "react";import Container from "../../../components/Container";import PageHeader from "../../../components/PageHeader";+import { Filter } from "../../../components/TableFilter";import i18n from "../../../i18n";-import { Filter } from "../../../products/components/ProductListCard";import { PageListProps } from "../../../types";import { OrderList_orders_edges_node } from "../../types/OrderList";import OrderList from "../OrderList";@@ -19,6 +19,7 @@ interface OrderListPageProps extends PageListProps {onAllProducts: () => void;onToFulfill: () => void;onToCapture: () => void;+ onCustomFilter: () => void;}const OrderListPage: React.StatelessComponent<OrderListPageProps> = ({@@ -33,7 +34,8 @@ const OrderListPage: React.StatelessComponent<OrderListPageProps> = ({filtersList,onAllProducts,onToFulfill,- onToCapture+ onToCapture,+ onCustomFilter}) => (<Container width="md"><PageHeader title={i18n.t("Orders")}>@@ -53,6 +55,7 @@ const OrderListPage: React.StatelessComponent<OrderListPageProps> = ({onAllProducts={onAllProducts}onToFulfill={onToFulfill}onToCapture={onToCapture}+ onCustomFilter={onCustomFilter}/><OrderListdisabled={disabled}diff --git a/saleor/static/dashboard-next/orders/views/OrderList.tsx b/saleor/static/dashboard-next/orders/views/OrderList.tsxindex 60f8d4f957..8a04f0ba8a 100644--- a/saleor/static/dashboard-next/orders/views/OrderList.tsx+++ b/saleor/static/dashboard-next/orders/views/OrderList.tsx@@ -71,6 +71,7 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({onAllProducts={() => undefined}onToFulfill={() => undefined}onToCapture={() => undefined}+ onCustomFilter={() => undefined}/>)}</Paginator>diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsxindex 7da9df4ec4..25f1b54c2b 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx@@ -7,14 +7,11 @@ import { CategoryDetails_category_products_edges_node } from "../../../categorieimport Container from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import ProductList from "../../../components/ProductList";+import { Filter } from "../../../components/TableFilter";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[];@@ -22,6 +19,7 @@ interface ProductListCardProps extends PageListProps {onAllProducts: () => void;onAvailable: () => void;onOfStock: () => void;+ onCustomFilter: () => void;}export const ProductListCard: React.StatelessComponent<@@ -38,7 +36,8 @@ export const ProductListCard: React.StatelessComponent<currentTab,onAllProducts,onAvailable,- onOfStock+ onOfStock,+ onCustomFilter}) => (<Container width="md"><PageHeader title={i18n.t("Products")}>@@ -50,9 +49,10 @@ export const ProductListCard: React.StatelessComponent<<ProductListFiltercurrentTab={currentTab}filtersList={filtersList}- onAllProducts={onAllProducts}onAvailable={onAvailable}+ onAllProducts={onAllProducts}onOfStock={onOfStock}+ onCustomFilter={onCustomFilter}/><ProductListproducts={products}diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/index.ts b/saleor/static/dashboard-next/products/components/ProductListCard/index.tsindex 05e63d02df..995a575ae1 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/index.ts+++ b/saleor/static/dashboard-next/products/components/ProductListCard/index.ts@@ -1,3 +1,2 @@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 175a12718e..d191fa51ff 100644--- a/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx@@ -1,123 +1,49 @@-import { withStyles } from "@material-ui/core/styles";-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 {+ Filter,+ FilterChip,+ FilterTab,+ FilterTabs+} from "../../../components/TableFilter";import i18n from "../../../i18n";-import { Filter } from "../ProductListCard";+interface ProductListFilterProps {currentTab: number;filtersList: Filter[];onAllProducts: () => void;onAvailable: () => void;onOfStock: () => void;+ onCustomFilter: () => void;}-const decorate = withStyles(theme => ({- 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"- },- tabRoot: {- minWidth: "80px",- opacity: 1,- paddingTop: `${theme.spacing.unit * 1}px`,- textTransform: "initial" as "initial"- },- tabsRoot: {- borderBottom: "1px solid #e0e0e0",- paddingLeft: `${theme.spacing.unit * 3}px`- }-}));--const ProductListFilter = decorate<ProductListFilterProps>(- ({- classes,- filtersList,- currentTab,- onAllProducts,- onAvailable,- onOfStock- }) => (- <>- <Tabs className={classes.tabsRoot} value={0} indicatorColor={"primary"}>- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={i18n.t("All Products")}- onClick={onAllProducts}- />- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={i18n.t("Available")}- onClick={onAvailable}- />- <Tab- disableRipple- classes={{ root: classes.tabRoot, label: classes.tabLabel }}- label={i18n.t("Out of stock")}- onClick={onOfStock}- />- {(currentTab === 0 || undefined) &&- filtersList &&- filtersList.length > 0 && (- <Tab- value={0}- disableRipple- classes={{- label: classes.tabLabel,- root: classes.tabRoot- }}- label={i18n.t("Custom Filter")}- />- )}- </Tabs>+const ProductListFilter: React.StatelessComponent<ProductListFilterProps> = ({+ filtersList,+ currentTab,+ onAllProducts,+ onAvailable,+ onOfStock,+ onCustomFilter+}) => (+ <>+ <FilterTabs currentTab={currentTab}>+ <FilterTab label={i18n.t("All Products")} onClick={onAllProducts} />+ <FilterTab label={i18n.t("Availiable")} onClick={onAvailable} />+ <FilterTab label={i18n.t("Out Of Stock")} onClick={onOfStock} />{(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>+ <FilterTab+ onClick={onCustomFilter}+ value={0}+ label={i18n.t("Custom Filter")}+ />)}- </>- )+ </FilterTabs>+ {(currentTab === 0 || undefined) &&+ filtersList &&+ filtersList.length > 0 && <FilterChip filtersList={filtersList} />}+ </>);ProductListFilter.displayName = "ProductListFilter";export default ProductListFilter;diff --git a/saleor/static/dashboard-next/products/views/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList.tsxindex 4d72f1829b..5d552214c7 100644--- a/saleor/static/dashboard-next/products/views/ProductList.tsx+++ b/saleor/static/dashboard-next/products/views/ProductList.tsx@@ -60,8 +60,9 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({onRowClick={id => () =>navigate(productUrl(encodeURIComponent(id)))}onAllProducts={() => undefined}- onToFulfill={() => undefined}- onToCapture={() => undefined}+ onCustomFilter={() => undefined}+ onAvailable={() => undefined}+ onOfStock={() => undefined}/>)}</Paginator>diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderListPage.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderListPage.tsxindex 0c66f819d5..b931f6835b 100644--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderListPage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderListPage.tsx@@ -1,10 +1,10 @@import { storiesOf } from "@storybook/react";import * as React from "react";+import { Filter } from "../../../components/TableFilter/";import { pageListProps } from "../../../fixtures";import OrderListPage from "../../../orders/components/OrderListPage";import { orders } from "../../../orders/fixtures";-import { Filter } from "../../../products/components/ProductListCard";import Decorator from "../../Decorator";const filtersList: Filter[] = [@@ -33,6 +33,7 @@ storiesOf("Views / Orders / Order list", module)currentTab={0}onToFulfill={() => undefined}onToCapture={() => undefined}+ onCustomFilter={() => undefined}/>)).add("with custom filters", () => (@@ -44,6 +45,7 @@ storiesOf("Views / Orders / Order list", module)onAllProducts={() => undefined}onToFulfill={() => undefined}onToCapture={() => undefined}+ onCustomFilter={() => undefined}/>)).add("loading", () => (@@ -55,6 +57,7 @@ storiesOf("Views / Orders / Order list", module)onAllProducts={() => undefined}onToFulfill={() => undefined}onToCapture={() => undefined}+ onCustomFilter={() => undefined}/>)).add("when no data", () => (@@ -66,5 +69,6 @@ storiesOf("Views / Orders / Order list", module)onAllProducts={() => undefined}onToFulfill={() => undefined}onToCapture={() => undefined}+ onCustomFilter={() => undefined}/>));diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsxindex 7e7ba35ace..dd2b8caad4 100644--- a/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx@@ -3,10 +3,9 @@ import * as React from "react";import * as placeholderImage from "../../../../images/placeholder255x255.png";import { category as categoryFixture } from "../../../categories/fixtures";+import { Filter } from "../../../components/TableFilter";import { pageListProps } from "../../../fixtures";-import ProductListCard, {- Filter-} from "../../../products/components/ProductListCard";+import ProductListCard from "../../../products/components/ProductListCard";import Decorator from "../../Decorator";const products = categoryFixture(placeholderImage).products.edges.map(@@ -39,6 +38,7 @@ storiesOf("Views / Products / Product list", module)onAllProducts={() => undefined}onAvailable={() => undefined}onOfStock={() => undefined}+ onCustomFilter={() => undefined}/>)).add("with custom filters", () => (@@ -50,6 +50,7 @@ storiesOf("Views / Products / Product list", module)onAllProducts={() => undefined}onAvailable={() => undefined}onOfStock={() => undefined}+ onCustomFilter={() => undefined}/>)).add("loading", () => (@@ -61,6 +62,7 @@ storiesOf("Views / Products / Product list", module)onAllProducts={() => undefined}onAvailable={() => undefined}onOfStock={() => undefined}+ onCustomFilter={() => undefined}/>)).add("no data", () => (@@ -72,5 +74,6 @@ storiesOf("Views / Products / Product list", module)onAllProducts={() => undefined}onAvailable={() => undefined}onOfStock={() => undefined}+ onCustomFilter={() => undefined}/>));