Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use useSearchQuery hook

dominik-zeglende7cc0497d06
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx b/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx
index 528ffdf6fe..e0a36630c3 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributeValues/AttributeValues.tsx
@@ -98,7 +98,7 @@ const AttributeValues: React.FC<AttributeValuesProps> = ({
hover={!!value}
onClick={!!value ? () => onValueUpdate(value.id) : undefined}
key={maybe(() => value.id)}
- index={valueIndex}
+ index={valueIndex || 0}
>
<TableCell className={classes.columnAdmin}>
{maybe(() => value.slug) ? value.slug : <Skeleton />}
diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx
index 98aced300d..d49ebf9f24 100644
--- a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx
@@ -153,8 +153,10 @@ const AssignAttributeDialog: React.FC<AssignAttributeDialogProps> = ({
</DialogContent>
{errors.length > 0 && (
<DialogContent>
- {errors.map(error => (
- <DialogContentText color="error">{error}</DialogContentText>
+ {errors.map((error, errorIndex) => (
+ <DialogContentText color="error" key={errorIndex}>
+ {error}
+ </DialogContentText>
))}
</DialogContent>
)}
diff --git a/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx b/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx
index 242c3f6124..b8504b7290 100644
--- a/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx
@@ -16,8 +16,7 @@ import ConfirmButton, {
ConfirmButtonTransitionState
} from "@saleor/components/ConfirmButton";
import FormSpacer from "@saleor/components/FormSpacer";
-import { ChangeEvent } from "@saleor/hooks/useForm";
-import { onQueryChange } from "@saleor/misc";
+import useSearchQuery from "@saleor/hooks/useSearchQuery";
import { SearchCategories_categories_edges_node } from "../../containers/SearchCategories/types/SearchCategories";
import i18n from "../../i18n";
import Checkbox from "../Checkbox";
@@ -86,13 +85,11 @@ const AssignCategoriesDialog = withStyles(styles, {
onFetch,
onSubmit
}: AssignCategoriesDialogProps) => {
- const [query, setQuery] = React.useState("");
+ const [query, onQueryChange] = useSearchQuery(onFetch);
const [selectedCategories, setSelectedCategories] = React.useState<
SearchCategories_categories_edges_node[]
>([]);
- const handleQueryChange = (event: ChangeEvent) =>
- onQueryChange(event, onFetch, setQuery);
const handleSubmit = () => onSubmit(selectedCategories);
return (
@@ -108,7 +105,7 @@ const AssignCategoriesDialog = withStyles(styles, {
<TextField
name="query"
value={query}
- onChange={handleQueryChange}
+ onChange={onQueryChange}
label={i18n.t("Search Categories", {
context: "category search input label"
})}
diff --git a/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx b/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx
index 196fd44d27..915b8a3684 100644
--- a/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx
@@ -12,8 +12,7 @@ import TableRow from "@material-ui/core/TableRow";
import TextField from "@material-ui/core/TextField";
import React from "react";
-import { ChangeEvent } from "@saleor/hooks/useForm";
-import { onQueryChange } from "@saleor/misc";
+import useSearchQuery from "@saleor/hooks/useSearchQuery";
import { SearchCollections_collections_edges_node } from "../../containers/SearchCollections/types/SearchCollections";
import i18n from "../../i18n";
import Checkbox from "../Checkbox";
@@ -86,13 +85,11 @@ const AssignCollectionDialog = withStyles(styles, {
onFetch,
onSubmit
}: AssignCollectionDialogProps) => {
- const [query, setQuery] = React.useState("");
+ const [query, onQueryChange] = useSearchQuery(onFetch);
const [selectedCollections, setSelectedCollections] = React.useState<
SearchCollections_collections_edges_node[]
>([]);
- const handleQueryChange = (event: ChangeEvent) =>
- onQueryChange(event, onFetch, setQuery);
const handleSubmit = () => onSubmit(selectedCollections);
return (
@@ -108,7 +105,7 @@ const AssignCollectionDialog = withStyles(styles, {
<TextField
name="query"
value={query}
- onChange={handleQueryChange}
+ onChange={onQueryChange}
label={i18n.t("Search Collection", {
context: "product search input label"
})}
diff --git a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
index 5b6bda7ce8..c9360d5017 100644
--- a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
@@ -17,10 +17,10 @@ import ConfirmButton, {
} from "@saleor/components/ConfirmButton";
import FormSpacer from "@saleor/components/FormSpacer";
import TableCellAvatar from "@saleor/components/TableCellAvatar";
-import { ChangeEvent } from "@saleor/hooks/useForm";
+import useSearchQuery from "@saleor/hooks/useSearchQuery";
import { SearchProducts_products_edges_node } from "../../containers/SearchProducts/types/SearchProducts";
import i18n from "../../i18n";
-import { maybe, onQueryChange } from "../../misc";
+import { maybe } from "../../misc";
import Checkbox from "../Checkbox";
export interface FormData {
@@ -85,13 +85,11 @@ const AssignProductDialog = withStyles(styles, {
onFetch,
onSubmit
}: AssignProductDialogProps) => {
- const [query, setQuery] = React.useState("");
+ const [query, onQueryChange] = useSearchQuery(onFetch);
const [selectedProducts, setSelectedProducts] = React.useState<
SearchProducts_products_edges_node[]
>([]);
- const handleQueryChange = (event: ChangeEvent) =>
- onQueryChange(event, onFetch, setQuery);
const handleSubmit = () => onSubmit(selectedProducts);
return (
@@ -107,7 +105,7 @@ const AssignProductDialog = withStyles(styles, {
<TextField
name="query"
value={query}
- onChange={handleQueryChange}
+ onChange={onQueryChange}
label={i18n.t("Search Products", {
context: "product search input label"
})}
diff --git a/saleor/static/dashboard-next/fixtures.ts b/saleor/static/dashboard-next/fixtures.ts
index adbb177d87..2acedb9146 100644
--- a/saleor/static/dashboard-next/fixtures.ts
+++ b/saleor/static/dashboard-next/fixtures.ts
@@ -1,5 +1,10 @@
import { Filter } from "./components/TableFilter";
-import { FilterPageProps, ListActions, PageListProps } from "./types";
+import {
+ FilterPageProps,
+ ListActions,
+ PageListProps,
+ FetchMoreProps
+} from "./types";
const pageInfo = {
hasNextPage: true,
@@ -125,3 +130,10 @@ export const filters: Filter[] = [
...filter,
label: filter.label + filterIndex
}));
+
+export const fetchMoreProps: FetchMoreProps = {
+ hasMore: true,
+ loading: false,
+ onFetch: () => undefined,
+ onFetchMore: () => undefined
+};
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index 3c1f469c66..d27eeded25 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -5,7 +5,6 @@ import urlJoin from "url-join";
import { ConfirmButtonTransitionState } from "./components/ConfirmButton/ConfirmButton";
import { APP_MOUNT_URI } from "./config";
import { AddressType } from "./customers/types";
-import { ChangeEvent } from "./hooks/useForm";
import i18n from "./i18n";
import { PartialMutationProviderOutput, UserError } from "./types";
import {
diff --git a/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx b/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx
index 6289d416be..787d3b78cf 100644
--- a/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx
+++ b/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx
@@ -126,7 +126,7 @@ const ProductTypeOperations: React.StatelessComponent<
ProductTypeAttributeReorder,
ProductTypeAttributeReorderVariables
> = opts => {
- const optimisticResponse = {
+ const optimisticResponse: ProductTypeAttributeReorder = {
productTypeReorderAttributes: {
__typename: "ProductTypeReorderAttributes" as "ProductTypeReorderAttributes",
errors: [],
diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeAttributeReorder.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeAttributeReorder.ts
index 38991749af..b456d62c57 100644
--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeAttributeReorder.ts
+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeAttributeReorder.ts
@@ -2,7 +2,7 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeReorderInput, AttributeTypeEnum, TaxRateType } from "./../../types/globalTypes";
+import { AttributeReorderInput, AttributeTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductTypeAttributeReorder
@@ -14,11 +14,20 @@ export interface ProductTypeAttributeReorder_productTypeReorderAttributes_errors
message: string | null;
}
+export interface ProductTypeAttributeReorder_productTypeReorderAttributes_productType_taxType {
+ __typename: "TaxType";
+ description: string | null;
+ taxCode: string | null;
+}
+
export interface ProductTypeAttributeReorder_productTypeReorderAttributes_productType_productAttributes {
__typename: "Attribute";
id: string;
name: string | null;
slug: string | null;
+ visibleInStorefront: boolean | null;
+ filterableInDashboard: boolean | null;
+ filterableInStorefront: boolean | null;
}
export interface ProductTypeAttributeReorder_productTypeReorderAttributes_productType_variantAttributes {
@@ -26,6 +35,9 @@ export interface ProductTypeAttributeReorder_productTypeReorderAttributes_produc
id: string;
name: string | null;
slug: string | null;
+ visibleInStorefront: boolean | null;
+ filterableInDashboard: boolean | null;
+ filterableInStorefront: boolean | null;
}
export interface ProductTypeAttributeReorder_productTypeReorderAttributes_productType_weight {
@@ -40,7 +52,7 @@ export interface ProductTypeAttributeReorder_productTypeReorderAttributes_produc
name: string;
hasVariants: boolean;
isShippingRequired: boolean;
- taxRate: TaxRateType | null;
+ taxType: ProductTypeAttributeReorder_productTypeReorderAttributes_productType_taxType | null;
productAttributes: (ProductTypeAttributeReorder_productTypeReorderAttributes_productType_productAttributes | null)[] | null;
variantAttributes: (ProductTypeAttributeReorder_productTypeReorderAttributes_productType_variantAttributes | null)[] | null;
weight: ProductTypeAttributeReorder_productTypeReorderAttributes_productType_weight | null;
diff --git a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx
index 8f0e5fb78c..689b43139d 100644
--- a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx
@@ -2,6 +2,7 @@ import { storiesOf } from "@storybook/react";
import * as React from "react";
import { attributes } from "@saleor/attributes/fixtures";
+import { fetchMoreProps } from "@saleor/fixtures";
import { formError } from "@saleor/storybook/misc";
import AssignAttributeDialog, {
AssignAttributeDialogProps
@@ -9,12 +10,11 @@ import AssignAttributeDialog, {
import Decorator from "../../Decorator";
const props: AssignAttributeDialogProps = {
+ ...fetchMoreProps,
attributes: attributes.slice(0, 5),
confirmButtonState: "default",
errors: [],
- loading: false,
onClose: () => undefined,
- onFetch: () => undefined,
onSubmit: () => undefined,
onToggle: () => undefined,
open: true,