Skip to content

Commit

Permalink
SALEOR-1888-1889 - Fix voucher and sales sorting errors (#1063)
Browse files Browse the repository at this point in the history
* Fix voucher and sales sorting errors

* Update changelog

* Fix channel slug argument in sorting
  • Loading branch information
orzechdev authored Apr 19, 2021
1 parent e5df1b2 commit bddfa2c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Handle limit reached error - #990 by @dominik-zeglen
- Display Cloud limits - #1004 by @dominik-zeglen
- Add shipping method description - #1058 by @jwm0
- Fix voucher and sales sorting errors - #1063 by @orzechdev

# 2.11.1

Expand Down
2 changes: 1 addition & 1 deletion src/discounts/views/SaleList/SaleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const SaleList: React.FC<SaleListProps> = ({ params }) => {
() => ({
...paginationState,
filter: getFilterVariables(params),
sort: getSortQueryVariables(params)
sort: getSortQueryVariables(params, channel?.slug)
}),
[params]
);
Expand Down
2 changes: 1 addition & 1 deletion src/discounts/views/VoucherList/VoucherList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const VoucherList: React.FC<VoucherListProps> = ({ params }) => {
() => ({
...paginationState,
filter: getFilterVariables(params),
sort: getSortQueryVariables(params)
sort: getSortQueryVariables(params, channel?.slug)
}),
[params]
);
Expand Down
7 changes: 4 additions & 3 deletions src/utils/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@ type GetSortQueryField<TUrlField extends string, TSortField extends string> = (
type GetSortQueryVariables<
TSortField extends string,
TParams extends Record<any, any>
> = (params: TParams) => SortingInput<TSortField>;
> = (params: TParams, channelSlug?: string) => SortingInput<TSortField>;
export function createGetSortQueryVariables<
TUrlField extends string,
TSortField extends string,
TParams extends Record<any, any>
>(
getSortQueryField: GetSortQueryField<TUrlField, TSortField>
): GetSortQueryVariables<TSortField, TParams> {
return (params: TParams) => {
return (params: TParams, channelSlug?: string) => {
const field = getSortQueryField(params.sort);

if (!!field) {
return {
direction: getOrderDirection(params.asc),
field
field,
channel: channelSlug
};
}

Expand Down

0 comments on commit bddfa2c

Please sign in to comment.