Merge pull request #396 from mirumee/add/order-filter-fields

Improve order filters
This commit is contained in:
Marcin Gębala 2020-02-12 14:27:33 +01:00 committed by GitHub
commit 287f20999d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 17 deletions

View file

@ -31,6 +31,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix crash when one product is selected - #391 by @dominik-zeglen - Fix crash when one product is selected - #391 by @dominik-zeglen
- Improve product update form error handling - #392 by @dominik-zeglen - Improve product update form error handling - #392 by @dominik-zeglen
- Fix column picker errors - #393 by @dominik-zeglen - Fix column picker errors - #393 by @dominik-zeglen
- Improve order filters - #396 by @dominik-zeglen
## 2.0.0 ## 2.0.0

View file

@ -1,6 +1,6 @@
msgid "" msgid ""
msgstr "" msgstr ""
"POT-Creation-Date: 2020-01-20T16:06:58.433Z\n" "POT-Creation-Date: 2020-02-03T11:54:24.949Z\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -2803,6 +2803,14 @@ msgctxt "draft order"
msgid "Created" msgid "Created"
msgstr "" msgstr ""
#: build/locale/src/orders/components/OrderListPage/filters.json
#. [src.orders.components.OrderListPage.placed] - order
#. defaultMessage is:
#. Created
msgctxt "order"
msgid "Created"
msgstr ""
#: build/locale/src/collections/views/CollectionCreate.json #: build/locale/src/collections/views/CollectionCreate.json
#. [src.collections.views.1597339737] #. [src.collections.views.1597339737]
#. defaultMessage is: #. defaultMessage is:
@ -2883,6 +2891,14 @@ msgctxt "e-mail or full name"
msgid "Customer" msgid "Customer"
msgstr "" msgstr ""
#: build/locale/src/orders/components/OrderListPage/filters.json
#. [src.orders.components.OrderListPage.customer] - order
#. defaultMessage is:
#. Customer
msgctxt "order"
msgid "Customer"
msgstr ""
#: build/locale/src/customers/components/CustomerList/CustomerList.json #: build/locale/src/customers/components/CustomerList/CustomerList.json
#. [src.customers.components.CustomerList.2339105195] #. [src.customers.components.CustomerList.2339105195]
#. defaultMessage is: #. defaultMessage is:
@ -6275,14 +6291,6 @@ msgctxt "product type"
msgid "Physical" msgid "Physical"
msgstr "" msgstr ""
#: build/locale/src/orders/components/OrderListPage/filters.json
#. [src.orders.components.OrderListPage.placed] - order
#. defaultMessage is:
#. Placed
msgctxt "order"
msgid "Placed"
msgstr ""
#: build/locale/src/staff/components/StaffPreferences/StaffPreferences.json #: build/locale/src/staff/components/StaffPreferences/StaffPreferences.json
#. [src.staff.components.StaffPreferences.2162129531] #. [src.staff.components.StaffPreferences.2162129531]
#. defaultMessage is: #. defaultMessage is:

View file

@ -112,7 +112,7 @@ export const CustomerDetailsView: React.FC<CustomerDetailsViewProps> = ({
onViewAllOrdersClick={() => onViewAllOrdersClick={() =>
navigate( navigate(
orderListUrl({ orderListUrl({
email: maybe(() => customerDetails.data.user.email) customer: maybe(() => customerDetails.data.user.email)
}) })
) )
} }

View file

@ -4,7 +4,8 @@ import { FilterOpts, MinMax } from "@saleor/types";
import { OrderStatusFilter } from "@saleor/types/globalTypes"; import { OrderStatusFilter } from "@saleor/types/globalTypes";
import { import {
createDateField, createDateField,
createOptionsField createOptionsField,
createTextField
} from "@saleor/utils/filters/fields"; } from "@saleor/utils/filters/fields";
import { IFilter } from "@saleor/components/Filter"; import { IFilter } from "@saleor/components/Filter";
import { orderStatusMessages } from "@saleor/misc"; import { orderStatusMessages } from "@saleor/misc";
@ -12,17 +13,23 @@ import { commonMessages } from "@saleor/intl";
export enum OrderFilterKeys { export enum OrderFilterKeys {
created = "created", created = "created",
customer = "customer",
status = "status" status = "status"
} }
export interface OrderListFilterOpts { export interface OrderListFilterOpts {
created: FilterOpts<MinMax>; created: FilterOpts<MinMax>;
customer: FilterOpts<string>;
status: FilterOpts<OrderStatusFilter[]>; status: FilterOpts<OrderStatusFilter[]>;
} }
const messages = defineMessages({ const messages = defineMessages({
customer: {
defaultMessage: "Customer",
description: "order"
},
placed: { placed: {
defaultMessage: "Placed", defaultMessage: "Created",
description: "order" description: "order"
} }
}); });
@ -32,6 +39,14 @@ export function createFilterStructure(
opts: OrderListFilterOpts opts: OrderListFilterOpts
): IFilter<OrderFilterKeys> { ): IFilter<OrderFilterKeys> {
return [ return [
{
...createTextField(
OrderFilterKeys.customer,
intl.formatMessage(messages.customer),
opts.customer.value
),
active: opts.customer.active
},
{ {
...createDateField( ...createDateField(
OrderFilterKeys.created, OrderFilterKeys.created,

View file

@ -19,7 +19,7 @@ export const orderListPath = orderSectionUrl;
export enum OrderListUrlFiltersEnum { export enum OrderListUrlFiltersEnum {
createdFrom = "createdFrom", createdFrom = "createdFrom",
createdTo = "createdTo", createdTo = "createdTo",
email = "email", customer = "customer",
payment = "payment", payment = "payment",
query = "query" query = "query"
} }

View file

@ -4,6 +4,7 @@ exports[`Filtering URL params should not be empty if active filters are present
Object { Object {
"createdFrom": "2019-12-09", "createdFrom": "2019-12-09",
"createdTo": "2019-12-38", "createdTo": "2019-12-38",
"customer": "email@example.com",
"status": Array [ "status": Array [
"FULFILLED", "FULFILLED",
"PARTIALLY_FULFILLED", "PARTIALLY_FULFILLED",
@ -11,4 +12,4 @@ Object {
} }
`; `;
exports[`Filtering URL params should not be empty if active filters are present 2`] = `"createdFrom=2019-12-09&createdTo=2019-12-38&status%5B0%5D=FULFILLED&status%5B1%5D=PARTIALLY_FULFILLED"`; exports[`Filtering URL params should not be empty if active filters are present 2`] = `"customer=email%40example.com&createdFrom=2019-12-09&createdTo=2019-12-38&status%5B0%5D=FULFILLED&status%5B1%5D=PARTIALLY_FULFILLED"`;

View file

@ -22,7 +22,7 @@ describe("Filtering query params", () => {
const params: OrderListUrlFilters = { const params: OrderListUrlFilters = {
createdFrom: date.from, createdFrom: date.from,
createdTo: date.to, createdTo: date.to,
email: "email@example.com", customer: "email@example.com",
status: [ status: [
OrderStatusFilter.FULFILLED, OrderStatusFilter.FULFILLED,
OrderStatusFilter.PARTIALLY_FULFILLED OrderStatusFilter.PARTIALLY_FULFILLED
@ -45,6 +45,10 @@ describe("Filtering URL params", () => {
min: date.from min: date.from
} }
}, },
customer: {
active: false,
value: "email@example.com"
},
status: { status: {
active: false, active: false,
value: [ value: [

View file

@ -15,7 +15,8 @@ import {
dedupeFilter, dedupeFilter,
getGteLteVariables, getGteLteVariables,
getMinMaxQueryParam, getMinMaxQueryParam,
getMultipleEnumValueQueryParam getMultipleEnumValueQueryParam,
getSingleValueQueryParam
} from "../../../utils/filters"; } from "../../../utils/filters";
import { import {
OrderListUrlFilters, OrderListUrlFilters,
@ -43,6 +44,10 @@ export function getFilterOpts(
min: maybe(() => params.createdFrom, "") min: maybe(() => params.createdFrom, "")
} }
}, },
customer: {
active: !!maybe(() => params.customer),
value: params.customer
},
status: { status: {
active: maybe(() => params.status !== undefined, false), active: maybe(() => params.status !== undefined, false),
value: maybe( value: maybe(
@ -66,7 +71,7 @@ export function getFilterVariables(
gte: params.createdFrom, gte: params.createdFrom,
lte: params.createdTo lte: params.createdTo
}), }),
customer: params.email, customer: params.customer,
search: params.query, search: params.query,
status: maybe(() => status: maybe(() =>
params.status.map(status => findInEnum(status, OrderStatusFilter)) params.status.map(status => findInEnum(status, OrderStatusFilter))
@ -93,6 +98,9 @@ export function getFilterQueryParam(
OrderListUrlFiltersWithMultipleValuesEnum.status, OrderListUrlFiltersWithMultipleValuesEnum.status,
OrderStatus OrderStatus
); );
case OrderFilterKeys.customer:
return getSingleValueQueryParam(filter, OrderListUrlFiltersEnum.customer);
} }
} }

View file

@ -28,6 +28,10 @@ const props: OrderListPageProps = {
min: "50" min: "50"
} }
}, },
customer: {
active: false,
value: "Jesse"
},
status: { status: {
active: false, active: false,
value: [OrderStatusFilter.CANCELED, OrderStatusFilter.FULFILLED] value: [OrderStatusFilter.CANCELED, OrderStatusFilter.FULFILLED]