Fix product bulk actions
This commit is contained in:
parent
15f9535ca6
commit
56a5586b15
5 changed files with 13 additions and 6 deletions
|
@ -45,7 +45,7 @@
|
||||||
"lodash": "^4.17.14",
|
"lodash": "^4.17.14",
|
||||||
"lodash-es": "^4.17.14",
|
"lodash-es": "^4.17.14",
|
||||||
"moment-timezone": "^0.5.26",
|
"moment-timezone": "^0.5.26",
|
||||||
"qs": "^6.7.0",
|
"qs": "^6.9.0",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
"react-apollo": "^3.0.0",
|
"react-apollo": "^3.0.0",
|
||||||
"react-dom": "^16.9.0",
|
"react-dom": "^16.9.0",
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
import { useEffect, useState } from "react";
|
import useStateFromProps from "./useStateFromProps";
|
||||||
|
|
||||||
function useListActions<TData>(
|
function useListActions<TData>(
|
||||||
initial: TData[] = [],
|
initial: TData[] = [],
|
||||||
compareFunc: (a: TData, b: TData) => boolean = (a, b) => a === b
|
compareFunc: (a: TData, b: TData) => boolean = (a, b) => a === b
|
||||||
) {
|
) {
|
||||||
const [listElements, setListElements] = useState(initial);
|
const [listElements, setListElements] = useStateFromProps(initial);
|
||||||
|
|
||||||
useEffect(() => setListElements(initial), [JSON.stringify(initial)]);
|
|
||||||
|
|
||||||
function isSelected(data: TData) {
|
function isSelected(data: TData) {
|
||||||
return !!listElements.find(listElement => compareFunc(listElement, data));
|
return !!listElements.find(listElement => compareFunc(listElement, data));
|
||||||
|
|
|
@ -35,6 +35,7 @@ const ProductList: React.FC<RouteComponentProps<any>> = ({ location }) => {
|
||||||
? findInEnum(qs.sort, ProductListUrlSortField)
|
? findInEnum(qs.sort, ProductListUrlSortField)
|
||||||
: ProductListUrlSortField.name
|
: ProductListUrlSortField.name
|
||||||
};
|
};
|
||||||
|
|
||||||
return <ProductListComponent params={params} />;
|
return <ProductListComponent params={params} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { stringify as stringifyQs } from "qs";
|
|
||||||
import urlJoin from "url-join";
|
import urlJoin from "url-join";
|
||||||
|
|
||||||
|
import { stringifyQs } from "../utils/urls";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ActiveTab,
|
ActiveTab,
|
||||||
BulkAction,
|
BulkAction,
|
||||||
|
|
7
src/utils/urls.ts
Normal file
7
src/utils/urls.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { stringify } from "qs";
|
||||||
|
|
||||||
|
export function stringifyQs(params: object): string {
|
||||||
|
return stringify(params, {
|
||||||
|
indices: false
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue