Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use FilterBar component
dominik-zeglenb1ecc984b0aa
diff --git a/saleor/static/dashboard-next/components/FilterBar/FilterBar.tsx b/saleor/static/dashboard-next/components/FilterBar/FilterBar.tsxnew file mode 100644index 0000000000..e8a75a2299--- /dev/null+++ b/saleor/static/dashboard-next/components/FilterBar/FilterBar.tsx@@ -0,0 +1,82 @@+import * as React from "react";++import i18n from "../../i18n";+import { FilterProps } from "../../types";+import Debounce from "../Debounce";+import { IFilter } from "../Filter/types";+import FilterTabs, { FilterChips, FilterTab } from "../TableFilter";++export interface FilterBarProps<TUrlFilters = object>+ extends FilterProps<TUrlFilters> {+ filterMenu: IFilter;+}++const FilterBar: React.FC<FilterBarProps> = ({+ allTabLabel,+ currencySymbol,+ filterLabel,+ filtersList,+ filterTabs,+ filterMenu,+ currentTab,+ initialSearch,+ searchPlaceholder,+ onAll,+ onSearchChange,+ onFilterAdd,+ onFilterSave,+ onTabChange,+ onFilterDelete+}) => {+ const [search, setSearch] = React.useState(initialSearch);+ React.useEffect(() => setSearch(initialSearch), [currentTab, initialSearch]);++ const isCustom = currentTab === filterTabs.length + 1;++ return (+ <>+ <FilterTabs currentTab={currentTab}>+ <FilterTab label={allTabLabel} onClick={onAll} />+ {filterTabs.map((tab, tabIndex) => (+ <FilterTab+ onClick={() => onTabChange(tabIndex + 1)}+ label={tab.name}+ />+ ))}+ {isCustom && (+ <FilterTab+ onClick={() => undefined}+ label={i18n.t("Custom Filter")}+ />+ )}+ </FilterTabs>+ <Debounce debounceFn={onSearchChange}>+ {debounceSearchChange => {+ const handleSearchChange = (event: React.ChangeEvent<any>) => {+ const value = event.target.value;+ setSearch(value);+ debounceSearchChange(value);+ };++ return (+ <FilterChips+ currencySymbol={currencySymbol}+ menu={filterMenu}+ filtersList={filtersList}+ filterLabel={filterLabel}+ placeholder={searchPlaceholder}+ search={search}+ onSearchChange={handleSearchChange}+ onFilterAdd={onFilterAdd}+ onFilterSave={onFilterSave}+ isCustomSearch={isCustom}+ onFilterDelete={onFilterDelete}+ />+ );+ }}+ </Debounce>+ </>+ );+};+FilterBar.displayName = "FilterBar";+export default FilterBar;diff --git a/saleor/static/dashboard-next/components/FilterBar/index.ts b/saleor/static/dashboard-next/components/FilterBar/index.tsnew file mode 100644index 0000000000..000078c21c--- /dev/null+++ b/saleor/static/dashboard-next/components/FilterBar/index.ts@@ -0,0 +1,2 @@+export { default } from './FilterBar';+export * from './FilterBar';\ No newline at end of filediff --git a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsxindex 0b9f9a35d2..663c766289 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx@@ -10,14 +10,14 @@ import ProductList from "@saleor/components/ProductList";import { Filter } from "@saleor/components/TableFilter";import { CategoryDetails_category_products_edges_node } from "../../../categories/types/CategoryDetails";import i18n from "../../../i18n";-import { FilterViewProps, ListActions, PageListProps } from "../../../types";+import { FilterPageProps, ListActions, PageListProps } from "../../../types";import { ProductListUrlFilters } from "../../urls";import ProductListFilter from "../ProductListFilter";export interface ProductListCardPropsextends PageListProps,ListActions,- FilterViewProps<FilterContentSubmitData, ProductListUrlFilters> {+ FilterPageProps<ProductListUrlFilters> {currencySymbol: string;products: CategoryDetails_category_products_edges_node[];}diff --git a/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx b/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsxindex 3d80f96ab4..26c570949c 100644--- a/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListFilter/ProductListFilter.tsx@@ -16,10 +16,7 @@ import { FilterProps } from "../../../types";import { StockAvailability } from "../../../types/globalTypes";import { ProductListUrlFilters } from "../../urls";-interface ProductListFilterProps- extends FilterProps<FilterContentSubmitData, ProductListUrlFilters> {- currencySymbol: string;-}+type ProductListFilterProps = FilterProps<ProductListUrlFilters>;export enum ProductFilterKeys {published,@@ -100,71 +97,8 @@ const filterMenu: IFilter = [}];-const ProductListFilter: React.FC<ProductListFilterProps> = ({- allTabLabel,- currencySymbol,- filterLabel,- filtersList,- filterTabs,- currentTab,- initialSearch,- searchPlaceholder,- onAll,- onSearchChange,- onFilterAdd,- onFilterSave,- onTabChange,- onFilterDelete-}) => {- const [search, setSearch] = React.useState(initialSearch);- React.useEffect(() => setSearch(initialSearch), [currentTab, initialSearch]);-- const isCustom = currentTab === filterTabs.length + 1;-- return (- <>- <FilterTabs currentTab={currentTab}>- <FilterTab label={allTabLabel} onClick={onAll} />- {filterTabs.map((tab, tabIndex) => (- <FilterTab- onClick={() => onTabChange(tabIndex + 1)}- label={tab.name}- />- ))}- {isCustom && (- <FilterTab- onClick={() => undefined}- label={i18n.t("Custom Filter")}- />- )}- </FilterTabs>- <Debounce debounceFn={onSearchChange}>- {debounceSearchChange => {- const handleSearchChange = (event: React.ChangeEvent<any>) => {- const value = event.target.value;- setSearch(value);- debounceSearchChange(value);- };-- return (- <FilterChips- currencySymbol={currencySymbol}- menu={filterMenu}- filtersList={filtersList}- filterLabel={filterLabel}- placeholder={searchPlaceholder}- search={search}- onSearchChange={handleSearchChange}- onFilterAdd={onFilterAdd}- onFilterSave={onFilterSave}- isCustomSearch={isCustom}- onFilterDelete={onFilterDelete}- />- );- }}- </Debounce>- </>- );-};+const ProductListFilter: React.FC<ProductListFilterProps> = props => (+ <FilterBar {...props} filterMenu={filterMenu} />+);ProductListFilter.displayName = "ProductListFilter";export default ProductListFilter;diff --git a/saleor/static/dashboard-next/types.ts b/saleor/static/dashboard-next/types.tsindex 0dfc837f28..d004b34d6a 100644--- a/saleor/static/dashboard-next/types.ts+++ b/saleor/static/dashboard-next/types.ts@@ -1,5 +1,6 @@import { MutationResult } from "react-apollo";+import { FilterContentSubmitData } from "./components/Filter";import { Filter } from "./components/TableFilter";import { GetFilterTabsOutput } from "./utils/filters";@@ -34,20 +35,20 @@ export interface ListActions extends ListActionsWithoutToolbar {export interface PageListProps extends ListProps {onAdd: () => void;}-export interface FilterViewProps<TFilterContentSubmitData, TUrlFilters> {+export interface FilterPageProps<TUrlFilters> {+ currencySymbol: string;currentTab: number;filterTabs: GetFilterTabsOutput<TUrlFilters>;filtersList: Filter[];initialSearch: string;onAll: () => void;onSearchChange: (value: string) => void;- onFilterAdd: (filter: TFilterContentSubmitData) => void;+ onFilterAdd: (filter: FilterContentSubmitData) => void;onFilterDelete: () => void;onFilterSave: () => void;onTabChange: (tab: number) => void;}-export interface FilterProps<TFilterContentSubmitData, TUrlFilters>- extends FilterViewProps<TFilterContentSubmitData, TUrlFilters> {+export interface FilterProps<TUrlFilters> extends FilterPageProps<TUrlFilters> {allTabLabel: string;filterLabel: string;searchPlaceholder: string;