Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add order list filters
dominik-zeglenc5a527592fce
diff --git a/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsx b/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsxindex a75ce756ad..16fdf810ef 100644--- a/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderListFilter/OrderListFilter.tsx@@ -8,8 +8,10 @@ import {} from "../../../components/TableFilter";import i18n from "../../../i18n";+export type OrderListFilterTabs = "all" | "toFulfill" | "toCapture" | "custom";+interface OrderListFilterProps {- currentTab: number;+ currentTab: OrderListFilterTabs;filtersList: Filter[];onAllProducts: () => void;onToFulfill: () => void;@@ -26,23 +28,25 @@ const OrderListFilter: React.StatelessComponent<OrderListFilterProps> = ({onCustomFilter}) => (<>- <FilterTabs currentTab={currentTab}>- <FilterTab label={i18n.t("All Products")} onClick={onAllProducts} />+ <FilterTabs+ currentTab={["all", "toFulfill", "toCapture", "custom"].indexOf(+ currentTab+ )}+ >+ <FilterTab label={i18n.t("All Orders")} 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 && (- <FilterTab- onClick={onCustomFilter}- value={0}- label={i18n.t("Custom Filter")}- />- )}+ {currentTab === "custom" && filtersList && filtersList.length > 0 && (+ <FilterTab+ onClick={onCustomFilter}+ value={0}+ label={i18n.t("Custom Filter")}+ />+ )}</FilterTabs>- {(currentTab === 0 || undefined) &&- filtersList &&- filtersList.length > 0 && <FilterChip filtersList={filtersList} />}+ {currentTab === "custom" && filtersList && filtersList.length > 0 && (+ <FilterChip filtersList={filtersList} />+ )}</>);OrderListFilter.displayName = "OrderListFilter";diff --git a/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx b/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsxindex b92e96c9bb..c6cf6cdd5b 100644--- a/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx@@ -10,11 +10,11 @@ import i18n from "../../../i18n";import { PageListProps } from "../../../types";import { OrderList_orders_edges_node } from "../../types/OrderList";import OrderList from "../OrderList";-import OrderListFilter from "../OrderListFilter";+import OrderListFilter, { OrderListFilterTabs } from "../OrderListFilter";interface OrderListPageProps extends PageListProps {orders: OrderList_orders_edges_node[];- currentTab: number;+ currentTab: OrderListFilterTabs;filtersList: Filter[];onAllProducts: () => void;onToFulfill: () => void;diff --git a/saleor/static/dashboard-next/orders/index.tsx b/saleor/static/dashboard-next/orders/index.tsxindex 6751d53ca6..096c4a6fe8 100644--- a/saleor/static/dashboard-next/orders/index.tsx+++ b/saleor/static/dashboard-next/orders/index.tsx@@ -13,7 +13,8 @@ const OrderList: React.StatelessComponent<RouteComponentProps<any>> = ({const qs = parseQs(location.search.substr(1));const params: OrderListQueryParams = {after: qs.after,- before: qs.before+ before: qs.before,+ status: qs.status};return <OrderListComponent params={params} />;};diff --git a/saleor/static/dashboard-next/orders/misc.ts b/saleor/static/dashboard-next/orders/misc.tsnew file mode 100644index 0000000000..10ecb746c1--- /dev/null+++ b/saleor/static/dashboard-next/orders/misc.ts@@ -0,0 +1,22 @@+import { empty, only } from "../misc";+import { OrderStatusFilter } from "../types/globalTypes";+import { OrderListFilterTabs } from "./components/OrderListFilter";+import { OrderListQueryParams } from "./views/OrderList";++export const getTabName = (qs: OrderListQueryParams): OrderListFilterTabs => {+ const filters = {+ status: qs.status+ };+ if (empty(filters)) {+ return "all";+ }+ if (only(filters, "status")) {+ switch (filters.status) {+ case OrderStatusFilter.READY_TO_CAPTURE:+ return "toCapture";+ case OrderStatusFilter.READY_TO_FULFILL:+ return "toFulfill";+ }+ }+ return "custom";+};diff --git a/saleor/static/dashboard-next/orders/queries.ts b/saleor/static/dashboard-next/orders/queries.tsindex eadd3262d2..e17dd76b99 100644--- a/saleor/static/dashboard-next/orders/queries.ts+++ b/saleor/static/dashboard-next/orders/queries.ts@@ -157,8 +157,20 @@ export const fragmentOrderDetails = gql`export const orderListQuery = gql`${fragmentAddress}- query OrderList($first: Int, $after: String, $last: Int, $before: String) {- orders(before: $before, after: $after, first: $first, last: $last) {+ query OrderList(+ $first: Int+ $after: String+ $last: Int+ $before: String+ $status: OrderStatusFilter+ ) {+ orders(+ before: $before+ after: $after+ first: $first+ last: $last+ status: $status+ ) {edges {node {__typenamediff --git a/saleor/static/dashboard-next/orders/types/OrderList.ts b/saleor/static/dashboard-next/orders/types/OrderList.tsindex 0f1c69da60..b951862c16 100644--- a/saleor/static/dashboard-next/orders/types/OrderList.ts+++ b/saleor/static/dashboard-next/orders/types/OrderList.ts@@ -1,7 +1,7 @@/* tslint:disable */// This file was automatically generated and should not be edited.-import { PaymentChargeStatusEnum, OrderStatus } from "./../../types/globalTypes";+import { OrderStatusFilter, PaymentChargeStatusEnum, OrderStatus } from "./../../types/globalTypes";// ====================================================// GraphQL query operation: OrderList@@ -80,4 +80,5 @@ export interface OrderListVariables {after?: string | null;last?: number | null;before?: string | null;+ status?: OrderStatusFilter | null;}diff --git a/saleor/static/dashboard-next/orders/views/OrderList.tsx b/saleor/static/dashboard-next/orders/views/OrderList.tsxindex 8a04f0ba8a..704023dff0 100644--- a/saleor/static/dashboard-next/orders/views/OrderList.tsx+++ b/saleor/static/dashboard-next/orders/views/OrderList.tsx@@ -1,3 +1,4 @@+import { stringify as stringifyQs } from "qs";import * as React from "react";import { orderUrl } from "..";@@ -6,15 +7,22 @@ import Navigator from "../../components/Navigator";import { createPaginationState, Paginator } from "../../components/Paginator";import i18n from "../../i18n";import { maybe } from "../../misc";+import { OrderStatusFilter } from "../../types/globalTypes";import OrderListPage from "../components/OrderListPage/OrderListPage";+import { getTabName } from "../misc";import { TypedOrderDraftCreateMutation } from "../mutations";import { TypedOrderListQuery } from "../queries";import { OrderDraftCreate } from "../types/OrderDraftCreate";-export type OrderListQueryParams = Partial<{- after: string;- before: string;-}>;+export interface OrderListFilters {+ status: OrderStatusFilter;+}+export type OrderListQueryParams = Partial<+ {+ after: string;+ before: string;+ } & OrderListFilters+>;interface OrderListProps {params: OrderListQueryParams;@@ -37,6 +45,16 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({orderUrl(encodeURIComponent(data.draftOrderCreate.order.id)));};++ const changeFilters = (newParams: OrderListQueryParams) =>+ navigate(+ "?" ++ stringifyQs({+ ...params,+ ...newParams+ })+ );+return (<TypedOrderDraftCreateMutationonCompleted={handleCreateOrderCreateSuccess}@@ -46,8 +64,15 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({PAGINATE_BY,params);+ const currentTab = getTabName(params);+return (- <TypedOrderListQuery variables={paginationState}>+ <TypedOrderListQuery+ variables={{+ ...paginationState,+ status: params.status+ }}+ >{({ data, loading }) => (<PaginatorpageInfo={maybe(() => data.orders.pageInfo)}@@ -57,7 +82,7 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({{({ loadNextPage, loadPreviousPage, pageInfo }) => (<OrderListPagefiltersList={[]}- currentTab={0}+ currentTab={currentTab}disabled={loading}orders={maybe(() =>data.orders.edges.map(edge => edge.node)@@ -68,9 +93,21 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({onPreviousPage={loadPreviousPage}onRowClick={id => () =>navigate(orderUrl(encodeURIComponent(id)))}- onAllProducts={() => undefined}- onToFulfill={() => undefined}- onToCapture={() => undefined}+ onAllProducts={() =>+ changeFilters({+ status: undefined+ })+ }+ onToFulfill={() =>+ changeFilters({+ status: OrderStatusFilter.READY_TO_FULFILL+ })+ }+ onToCapture={() =>+ changeFilters({+ status: OrderStatusFilter.READY_TO_CAPTURE+ })+ }onCustomFilter={() => undefined}/>)}diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex b78f8eec9b..83cf71b219 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -62,6 +62,11 @@ export enum OrderStatus {UNFULFILLED = "UNFULFILLED",}+export enum OrderStatusFilter {+ READY_TO_CAPTURE = "READY_TO_CAPTURE",+ READY_TO_FULFILL = "READY_TO_FULFILL",+}+export enum PaymentChargeStatusEnum {CHARGED = "CHARGED",FULLY_REFUNDED = "FULLY_REFUNDED",