Use sortBy for search products (#997)
This commit is contained in:
parent
a7736e2bf9
commit
bf9b7c5120
4 changed files with 26 additions and 5 deletions
|
@ -23,6 +23,7 @@ All notable, unreleased changes to this project will be documented in this file.
|
||||||
- Fix no channels crash - #984 by @dominik-zeglen
|
- Fix no channels crash - #984 by @dominik-zeglen
|
||||||
- Update webhooks - #982 by @piotrgrundas
|
- Update webhooks - #982 by @piotrgrundas
|
||||||
- Fix trigger form change when collections are being added to list of product collections - #987 by @gax97
|
- Fix trigger form change when collections are being added to list of product collections - #987 by @gax97
|
||||||
|
- Use default sort for search products list - #997 by @orzechdev
|
||||||
|
|
||||||
# 2.11.1
|
# 2.11.1
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ export enum ProductListUrlSortField {
|
||||||
name = "name",
|
name = "name",
|
||||||
productType = "productType",
|
productType = "productType",
|
||||||
status = "status",
|
status = "status",
|
||||||
price = "price"
|
price = "price",
|
||||||
|
rank = "rank"
|
||||||
}
|
}
|
||||||
export type ProductListUrlSort = Sort<ProductListUrlSortField>;
|
export type ProductListUrlSort = Sort<ProductListUrlSortField>;
|
||||||
export interface ProductListUrlQueryParams
|
export interface ProductListUrlQueryParams
|
||||||
|
|
|
@ -53,7 +53,7 @@ import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandl
|
||||||
import createFilterHandlers from "@saleor/utils/handlers/filterHandlers";
|
import createFilterHandlers from "@saleor/utils/handlers/filterHandlers";
|
||||||
import { getSortUrlVariables } from "@saleor/utils/sort";
|
import { getSortUrlVariables } from "@saleor/utils/sort";
|
||||||
import { useWarehouseList } from "@saleor/warehouses/queries";
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
import ProductListPage from "../../components/ProductListPage";
|
import ProductListPage from "../../components/ProductListPage";
|
||||||
|
@ -192,6 +192,21 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
params
|
params
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const sortWithQuery = ProductListUrlSortField.rank;
|
||||||
|
const sortWithoutQuery =
|
||||||
|
params.sort === ProductListUrlSortField.rank
|
||||||
|
? ProductListUrlSortField.name
|
||||||
|
: params.sort;
|
||||||
|
navigate(
|
||||||
|
productListUrl({
|
||||||
|
...params,
|
||||||
|
asc: params.query ? undefined : params.asc,
|
||||||
|
sort: params.query ? sortWithQuery : sortWithoutQuery
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}, [params.query]);
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
navigate(
|
navigate(
|
||||||
|
|
|
@ -17,6 +17,8 @@ export function getSortQueryField(
|
||||||
return ProductOrderField.TYPE;
|
return ProductOrderField.TYPE;
|
||||||
case ProductListUrlSortField.status:
|
case ProductListUrlSortField.status:
|
||||||
return ProductOrderField.PUBLISHED;
|
return ProductOrderField.PUBLISHED;
|
||||||
|
case ProductListUrlSortField.rank:
|
||||||
|
return ProductOrderField.RANK;
|
||||||
default:
|
default:
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -26,15 +28,17 @@ export function getSortQueryVariables(
|
||||||
params: ProductListUrlQueryParams,
|
params: ProductListUrlQueryParams,
|
||||||
channel: string
|
channel: string
|
||||||
): ProductOrder {
|
): ProductOrder {
|
||||||
|
const direction = getOrderDirection(params.asc);
|
||||||
if (params.sort === ProductListUrlSortField.attribute) {
|
if (params.sort === ProductListUrlSortField.attribute) {
|
||||||
return {
|
return {
|
||||||
attributeId: params.attributeId,
|
attributeId: params.attributeId,
|
||||||
direction: getOrderDirection(params.asc)
|
direction
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const field = getSortQueryField(params.sort);
|
||||||
return {
|
return {
|
||||||
channel,
|
channel,
|
||||||
direction: getOrderDirection(params.asc),
|
direction,
|
||||||
field: getSortQueryField(params.sort)
|
field
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue