Skip to content

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

Unify search behavior and API

dominik-zeglen6e573a93f527
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
index 741e9c2ecf..e4a58584d8 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -5,7 +5,8 @@ import * as React from "react";
import ActionDialog from "../../components/ActionDialog";
import AssignProductDialog from "../../components/AssignProductDialog";
import { WindowTitle } from "../../components/WindowTitle";
-import { SearchProductsProvider } from "../../containers/SearchProducts";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../config";
+import SearchProducts from "../../containers/SearchProducts";
import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
@@ -279,13 +280,13 @@ export const CollectionDetails: React.StatelessComponent<
toggle={toggle}
toggleAll={toggleAll}
/>
- <SearchProductsProvider>
- {(searchProducts, searchProductsOpts) => (
+ <SearchProducts variables={DEFAULT_INITIAL_SEARCH_DATA}>
+ {({ search, result }) => (
<AssignProductDialog
confirmButtonState={assignTransitionState}
open={params.action === "assign"}
- onFetch={searchProducts}
- loading={searchProductsOpts.loading}
+ onFetch={search}
+ loading={result.loading}
onClose={() => navigate(collectionUrl(id), true, true)}
onSubmit={formData =>
assignProduct.mutate({
@@ -297,13 +298,13 @@ export const CollectionDetails: React.StatelessComponent<
})
}
products={maybe(() =>
- searchProductsOpts.data.products.edges
+ result.data.products.edges
.map(edge => edge.node)
.filter(suggestedProduct => suggestedProduct.id)
)}
/>
)}
- </SearchProductsProvider>
+ </SearchProducts>
<ActionDialog
confirmButtonState={removeTransitionState}
onClose={closeModal}
diff --git a/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx b/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx
index 3b2ab75a84..abf17c055f 100644
--- a/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignCategoryDialog/AssignCategoryDialog.tsx
@@ -15,7 +15,6 @@ import * as React from "react";
import ConfirmButton, {
ConfirmButtonTransitionState
} from "../../components/ConfirmButton/ConfirmButton";
-import Debounce from "../../components/Debounce";
import Form from "../../components/Form";
import FormSpacer from "../../components/FormSpacer";
import { SearchCategories_categories_edges_node } from "../../containers/SearchCategories/types/SearchCategories";
@@ -82,29 +81,25 @@ const AssignCategoriesDialog = withStyles(styles, {
<>
<DialogTitle>{i18n.t("Assign Categories")}</DialogTitle>
<DialogContent className={classes.overflow}>
- <Debounce debounceFn={onFetch}>
- {fetch => (
- <TextField
- name="query"
- value={data.query}
- onChange={event => change(event, () => fetch(data.query))}
- label={i18n.t("Search Categories", {
- context: "product search input label"
- })}
- placeholder={i18n.t(
- "Search by product name, attribute, product type etc...",
- {
- context: "product search input placeholder"
- }
- )}
- fullWidth
- InputProps={{
- autoComplete: "off",
- endAdornment: loading && <CircularProgress size={16} />
- }}
- />
+ <TextField
+ name="query"
+ value={data.query}
+ onChange={event => change(event, () => onFetch(data.query))}
+ label={i18n.t("Search Categories", {
+ context: "product search input label"
+ })}
+ placeholder={i18n.t(
+ "Search by product name, attribute, product type etc...",
+ {
+ context: "product search input placeholder"
+ }
)}
- </Debounce>
+ fullWidth
+ InputProps={{
+ autoComplete: "off",
+ endAdornment: loading && <CircularProgress size={16} />
+ }}
+ />
<FormSpacer />
<Table>
<TableBody>
diff --git a/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx b/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx
index 9492a77793..6d35c12764 100644
--- a/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignCollectionDialog/AssignCollectionDialog.tsx
@@ -18,7 +18,6 @@ import Checkbox from "../Checkbox";
import ConfirmButton, {
ConfirmButtonTransitionState
} from "../ConfirmButton/ConfirmButton";
-import Debounce from "../Debounce";
import Form from "../Form";
import FormSpacer from "../FormSpacer";
@@ -82,29 +81,25 @@ const AssignCollectionDialog = withStyles(styles, {
<>
<DialogTitle>{i18n.t("Assign Collection")}</DialogTitle>
<DialogContent className={classes.overflow}>
- <Debounce debounceFn={onFetch}>
- {fetch => (
- <TextField
- name="query"
- value={data.query}
- onChange={event => change(event, () => fetch(data.query))}
- label={i18n.t("Search Collection", {
- context: "product search input label"
- })}
- placeholder={i18n.t(
- "Search by product name, attribute, product type etc...",
- {
- context: "product search input placeholder"
- }
- )}
- fullWidth
- InputProps={{
- autoComplete: "off",
- endAdornment: loading && <CircularProgress size={16} />
- }}
- />
+ <TextField
+ name="query"
+ value={data.query}
+ onChange={event => change(event, () => onFetch(data.query))}
+ label={i18n.t("Search Collection", {
+ context: "product search input label"
+ })}
+ placeholder={i18n.t(
+ "Search by product name, attribute, product type etc...",
+ {
+ context: "product search input placeholder"
+ }
)}
- </Debounce>
+ fullWidth
+ InputProps={{
+ autoComplete: "off",
+ endAdornment: loading && <CircularProgress size={16} />
+ }}
+ />
<FormSpacer />
<Table>
<TableBody>
diff --git a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
index cf356868d4..1ed89ee7b0 100644
--- a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
@@ -15,7 +15,6 @@ import * as React from "react";
import ConfirmButton, {
ConfirmButtonTransitionState
} from "../../components/ConfirmButton/ConfirmButton";
-import Debounce from "../../components/Debounce";
import Form from "../../components/Form";
import FormSpacer from "../../components/FormSpacer";
import TableCellAvatar from "../../components/TableCellAvatar";
@@ -84,29 +83,25 @@ const AssignProductDialog = withStyles(styles, {
<>
<DialogTitle>{i18n.t("Assign Product")}</DialogTitle>
<DialogContent className={classes.overflow}>
- <Debounce debounceFn={onFetch}>
- {fetch => (
- <TextField
- name="query"
- value={data.query}
- onChange={event => change(event, () => fetch(data.query))}
- label={i18n.t("Search Products", {
- context: "product search input label"
- })}
- placeholder={i18n.t(
- "Search by product name, attribute, product type etc...",
- {
- context: "product search input placeholder"
- }
- )}
- fullWidth
- InputProps={{
- autoComplete: "off",
- endAdornment: loading && <CircularProgress size={16} />
- }}
- />
+ <TextField
+ name="query"
+ value={data.query}
+ onChange={event => change(event, () => onFetch(data.query))}
+ label={i18n.t("Search Products", {
+ context: "product search input label"
+ })}
+ placeholder={i18n.t(
+ "Search by product name, attribute, product type etc...",
+ {
+ context: "product search input placeholder"
+ }
)}
- </Debounce>
+ fullWidth
+ InputProps={{
+ autoComplete: "off",
+ endAdornment: loading && <CircularProgress size={16} />
+ }}
+ />
<FormSpacer />
<Table>
<TableBody>
diff --git a/saleor/static/dashboard-next/config.ts b/saleor/static/dashboard-next/config.ts
index 611186762d..ba5ade028c 100644
--- a/saleor/static/dashboard-next/config.ts
+++ b/saleor/static/dashboard-next/config.ts
@@ -1,2 +1,10 @@
+import { SearchQueryVariables } from "./containers/BaseSearch";
+
export const APP_MOUNT_URI = "/dashboard/next/";
export const API_URI = "/graphql/";
+
+export const DEFAULT_INITIAL_SEARCH_DATA: SearchQueryVariables = {
+ after: null,
+ first: 5,
+ query: ""
+};
diff --git a/saleor/static/dashboard-next/containers/BaseSearch.tsx b/saleor/static/dashboard-next/containers/BaseSearch.tsx
index 359502ec2a..40fd331ba1 100644
--- a/saleor/static/dashboard-next/containers/BaseSearch.tsx
+++ b/saleor/static/dashboard-next/containers/BaseSearch.tsx
@@ -1,70 +1,60 @@
import { DocumentNode } from "graphql";
import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedQuery } from "../queries";
+import Debounce from "../components/Debounce";
+import { TypedQuery, TypedQueryResult } from "../queries";
-const DEFAULT_SEARCH_RESULTS = 5;
-
-interface SearchQueryVariables {
+export interface SearchQueryVariables {
+ after?: string;
first: number;
query: string;
}
-interface BaseSearchProps<
- TQuery,
- TQueryVariables extends SearchQueryVariables
-> {
- children: (props: {
- search: (query: string) => void;
- searchOpts: QueryResult<TQuery, TQueryVariables>;
- }) => React.ReactElement<any>;
- first?: number;
- query: DocumentNode;
-}
-interface BaseSearchState {
- query: string;
-}
-
-class BaseSearchComponent<
- TQuery,
- TQueryVariables extends SearchQueryVariables
-> extends React.Component<
- BaseSearchProps<TQuery, TQueryVariables>,
- BaseSearchState
-> {
- state: BaseSearchState = {
- query: ""
- };
- queryComponent = TypedQuery<TQuery, TQueryVariables>(this.props.query);
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const Query = this.queryComponent;
- const { children, first } = this.props;
-
- return (
- <Query
- displayLoader={true}
- variables={
- {
- first: first || DEFAULT_SEARCH_RESULTS,
- query: this.state.query
- } as any
- }
- >
- {searchOpts => children({ search: this.search, searchOpts })}
- </Query>
- );
- }
-}
-
function BaseSearch<TQuery, TQueryVariables extends SearchQueryVariables>(
query: DocumentNode
) {
- return (props: BaseSearchProps<TQuery, TQueryVariables>) => (
- <BaseSearchComponent {...props} query={query} />
- );
+ const Query = TypedQuery<TQuery, TQueryVariables>(query);
+ interface BaseSearchProps {
+ children: (props: {
+ search: (query: string) => void;
+ result: TypedQueryResult<TQuery, TQueryVariables>;
+ }) => React.ReactElement<any>;
+ variables: TQueryVariables;
+ }
+ interface BaseSearchState {
+ query: string;
+ }
+
+ class BaseSearchComponent extends React.Component<
+ BaseSearchProps,
+ BaseSearchState
+ > {
+ state: BaseSearchState = {
+ query: this.props.variables.query
+ };
+
+ search = (query: string) => this.setState({ query });
+
+ render() {
+ const { children, variables } = this.props;
+
+ return (
+ <Debounce debounceFn={this.search} time={200}>
+ {search => (
+ <Query
+ displayLoader={true}
+ variables={{
+ ...variables,
+ query: this.state.query
+ }}
+ >
+ {result => children({ search, result })}
+ </Query>
+ )}
+ </Debounce>
+ );
+ }
+ }
+ return BaseSearchComponent;
}
export default BaseSearch;
diff --git a/saleor/static/dashboard-next/containers/SearchCategories/index.tsx b/saleor/static/dashboard-next/containers/SearchCategories/index.tsx
index 86c4a75246..0179c7e582 100644
--- a/saleor/static/dashboard-next/containers/SearchCategories/index.tsx
+++ b/saleor/static/dashboard-next/containers/SearchCategories/index.tsx
@@ -1,35 +1,24 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedSearchCategoriesQuery } from "./query";
+import gql from "graphql-tag";
+
+import BaseSearch from "../BaseSearch";
import {
SearchCategories,
SearchCategoriesVariables
} from "./types/SearchCategories";
-interface SearchCategoriesProviderProps {
- children: ((
- search: (query: string) => void,
- searchOpts: QueryResult<SearchCategories, SearchCategoriesVariables>
- ) => React.ReactElement<any>);
-}
-interface SearchCategoriesProviderState {
- query: string;
-}
-
-export class SearchCategoriesProvider extends React.Component<
- SearchCategoriesProviderProps,
- SearchCategoriesProviderState
-> {
- state: SearchCategoriesProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const { children } = this.props;
- return (
- <TypedSearchCategoriesQuery variables={{ query: this.state.query }}>
- {searchOpts => children(this.search, searchOpts)}
- </TypedSearchCategoriesQuery>
- );
+export const searchCategories = gql`
+ query SearchCategories($after: String, $first: Int!, $query: String!) {
+ categories(after: $after, first: $first, query: $query) {
+ edges {
+ node {
+ id
+ name
+ }
+ }
+ }
}
-}
+`;
+
+export default BaseSearch<SearchCategories, SearchCategoriesVariables>(
+ searchCategories
+);
diff --git a/saleor/static/dashboard-next/containers/SearchCategories/query.ts b/saleor/static/dashboard-next/containers/SearchCategories/query.ts
deleted file mode 100644
index 99af8cdd3c..0000000000
--- a/saleor/static/dashboard-next/containers/SearchCategories/query.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import gql from "graphql-tag";
-
-import { TypedQuery } from "../../queries";
-import {
- SearchCategories,
- SearchCategoriesVariables
-} from "./types/SearchCategories";
-
-export const searchCategories = gql`
- query SearchCategories($query: String!) {
- categories(first: 5, query: $query) {
- edges {
- node {
- id
- name
- }
- }
- }
- }
-`;
-export const TypedSearchCategoriesQuery = TypedQuery<
- SearchCategories,
- SearchCategoriesVariables
->(searchCategories);
diff --git a/saleor/static/dashboard-next/containers/SearchCategories/types/SearchCategories.ts b/saleor/static/dashboard-next/containers/SearchCategories/types/SearchCategories.ts
index 4e4ef48ed8..0bd976f19b 100644
--- a/saleor/static/dashboard-next/containers/SearchCategories/types/SearchCategories.ts
+++ b/saleor/static/dashboard-next/containers/SearchCategories/types/SearchCategories.ts
@@ -27,5 +27,7 @@ export interface SearchCategories {
}
export interface SearchCategoriesVariables {
+ after?: string | null;
+ first: number;
query: string;
}
diff --git a/saleor/static/dashboard-next/containers/SearchCollections/index.tsx b/saleor/static/dashboard-next/containers/SearchCollections/index.tsx
index 28e9428acf..54f2177f90 100644
--- a/saleor/static/dashboard-next/containers/SearchCollections/index.tsx
+++ b/saleor/static/dashboard-next/containers/SearchCollections/index.tsx
@@ -1,35 +1,24 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedSearchCollectionsQuery } from "./query";
+import gql from "graphql-tag";
+
+import BaseSearch from "../BaseSearch";
import {
SearchCollections,
SearchCollectionsVariables
} from "./types/SearchCollections";
-interface SearchCollectionsProviderProps {
- children: ((
- search: (query: string) => void,
- searchOpts: QueryResult<SearchCollections, SearchCollectionsVariables>
- ) => React.ReactElement<any>);
-}
-interface SearchCollectionsProviderState {
- query: string;
-}
-
-export class SearchCollectionsProvider extends React.Component<
- SearchCollectionsProviderProps,
- SearchCollectionsProviderState
-> {
- state: SearchCollectionsProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const { children } = this.props;
- return (
- <TypedSearchCollectionsQuery variables={{ query: this.state.query }}>
- {searchOpts => children(this.search, searchOpts)}
- </TypedSearchCollectionsQuery>
- );
+export const searchCollections = gql`
+ query SearchCollections($after: String, $first: Int!, $query: String!) {
+ collections(after: $after, first: $first, query: $query) {
+ edges {
+ node {
+ id
+ name
+ }
+ }
+ }
}
-}
+`;
+
+export default BaseSearch<SearchCollections, SearchCollectionsVariables>(
+ searchCollections
+);
diff --git a/saleor/static/dashboard-next/containers/SearchCollections/query.ts b/saleor/static/dashboard-next/containers/SearchCollections/query.ts
deleted file mode 100644
index b7eb390afd..0000000000
--- a/saleor/static/dashboard-next/containers/SearchCollections/query.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import gql from "graphql-tag";
-
-import { TypedQuery } from "../../queries";
-import {
- SearchCollections,
- SearchCollectionsVariables
-} from "./types/SearchCollections";
-
-export const searchCollections = gql`
- query SearchCollections($query: String!) {
- collections(first: 5, query: $query) {
- edges {
- node {
- id
- name
- }
- }
- }
- }
-`;
-export const TypedSearchCollectionsQuery = TypedQuery<
- SearchCollections,
- SearchCollectionsVariables
->(searchCollections);
diff --git a/saleor/static/dashboard-next/containers/SearchCollections/types/SearchCollections.ts b/saleor/static/dashboard-next/containers/SearchCollections/types/SearchCollections.ts
index 6a2690b51b..ce9c70ccaf 100644
--- a/saleor/static/dashboard-next/containers/SearchCollections/types/SearchCollections.ts
+++ b/saleor/static/dashboard-next/containers/SearchCollections/types/SearchCollections.ts
@@ -27,5 +27,7 @@ export interface SearchCollections {
}
export interface SearchCollectionsVariables {
+ after?: string | null;
+ first: number;
query: string;
}
diff --git a/saleor/static/dashboard-next/containers/SearchCustomers/index.ts b/saleor/static/dashboard-next/containers/SearchCustomers/index.ts
new file mode 100644
index 0000000000..2ed50f4a27
--- /dev/null
+++ b/saleor/static/dashboard-next/containers/SearchCustomers/index.ts
@@ -0,0 +1,24 @@
+import gql from "graphql-tag";
+
+import BaseSearch from "../BaseSearch";
+import {
+ SearchCustomers,
+ SearchCustomersVariables
+} from "./types/SearchCustomers";
+
+export const searchCustomers = gql`
+ query SearchCustomers($after: String, $first: Int!, $query: String!) {
+ customers(after: $after, first: $first, query: $query) {
+ edges {
+ node {
+ id
+ email
+ }
+ }
+ }
+ }
+`;
+
+export default BaseSearch<SearchCustomers, SearchCustomersVariables>(
+ searchCustomers
+);
diff --git a/saleor/static/dashboard-next/containers/SearchCustomers/types/SearchCustomers.ts b/saleor/static/dashboard-next/containers/SearchCustomers/types/SearchCustomers.ts
new file mode 100644
index 0000000000..ad51c10ab0
--- /dev/null
+++ b/saleor/static/dashboard-next/containers/SearchCustomers/types/SearchCustomers.ts
@@ -0,0 +1,33 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: SearchCustomers
+// ====================================================
+
+export interface SearchCustomers_customers_edges_node {
+ __typename: "User";
+ id: string;
+ email: string;
+}
+
+export interface SearchCustomers_customers_edges {
+ __typename: "UserCountableEdge";
+ node: SearchCustomers_customers_edges_node;
+}
+
+export interface SearchCustomers_customers {
+ __typename: "UserCountableConnection";
+ edges: SearchCustomers_customers_edges[];
+}
+
+export interface SearchCustomers {
+ customers: SearchCustomers_customers | null;
+}
+
+export interface SearchCustomersVariables {
+ after?: string | null;
+ first: number;
+ query: string;
+}
diff --git a/saleor/static/dashboard-next/containers/SearchPages/index.tsx b/saleor/static/dashboard-next/containers/SearchPages/index.tsx
index 1309cad577..70bf130538 100644
--- a/saleor/static/dashboard-next/containers/SearchPages/index.tsx
+++ b/saleor/static/dashboard-next/containers/SearchPages/index.tsx
@@ -1,32 +1,19 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedSearchPagesQuery } from "./query";
-import { SearchPages, SearchPagesVariables } from "./types/SearchPages";
-
-interface SearchPagesProviderProps {
- children: (props: {
- search: (query: string) => void;
- searchOpts: QueryResult<SearchPages, SearchPagesVariables>;
- }) => React.ReactElement<any>;
-}
-interface SearchPagesProviderState {
- query: string;
-}
-
-export class SearchPagesProvider extends React.Component<
- SearchPagesProviderProps,
- SearchPagesProviderState
-> {
- state: SearchPagesProviderState = { query: "" };
+import gql from "graphql-tag";
- search = (query: string) => this.setState({ query });
+import BaseSearch from "../BaseSearch";
+import { SearchPages, SearchPagesVariables } from "./types/SearchPages";
- render() {
- const { children } = this.props;
- return (
- <TypedSearchPagesQuery variables={{ query: this.state.query }}>
- {searchOpts => children({ search: this.search, searchOpts })}
- </TypedSearchPagesQuery>
- );
+export const searchPages = gql`
+ query SearchPages($after: String, $first: Int!, $query: String!) {
+ pages(after: $after, first: $first, query: $query) {
+ edges {
+ node {
+ id
+ title
+ }
+ }
+ }
}
-}
+`;
+
+export default BaseSearch<SearchPages, SearchPagesVariables>(searchPages);
diff --git a/saleor/static/dashboard-next/containers/SearchPages/query.ts b/saleor/static/dashboard-next/containers/SearchPages/query.ts
deleted file mode 100644
index 4459e7bb29..0000000000
--- a/saleor/static/dashboard-next/containers/SearchPages/query.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import gql from "graphql-tag";
-
-import { TypedQuery } from "../../queries";
-import { SearchPages, SearchPagesVariables } from "./types/SearchPages";
-
-export const searchPages = gql`
- query SearchPages($query: String!) {
- pages(first: 5, query: $query) {
- edges {
- node {
- id
- title
- }
- }
- }
- }
-`;
-export const TypedSearchPagesQuery = TypedQuery<
- SearchPages,
- SearchPagesVariables
->(searchPages);
diff --git a/saleor/static/dashboard-next/containers/SearchPages/types/SearchPages.ts b/saleor/static/dashboard-next/containers/SearchPages/types/SearchPages.ts
index 371be3e534..7357bb965d 100644
--- a/saleor/static/dashboard-next/containers/SearchPages/types/SearchPages.ts
+++ b/saleor/static/dashboard-next/containers/SearchPages/types/SearchPages.ts
@@ -27,5 +27,7 @@ export interface SearchPages {
}
export interface SearchPagesVariables {
+ after?: string | null;
+ first: number;
query: string;
}
diff --git a/saleor/static/dashboard-next/containers/SearchProducts/index.tsx b/saleor/static/dashboard-next/containers/SearchProducts/index.tsx
index 07121543d4..c5029eff37 100644
--- a/saleor/static/dashboard-next/containers/SearchProducts/index.tsx
+++ b/saleor/static/dashboard-next/containers/SearchProducts/index.tsx
@@ -1,35 +1,27 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedSearchProductsQuery } from "./query";
+import gql from "graphql-tag";
+
+import BaseSearch from "../BaseSearch";
import {
SearchProducts,
SearchProductsVariables
} from "./types/SearchProducts";
-interface SearchProductsProviderProps {
- children: ((
- search: (query: string) => void,
- searchOpts: QueryResult<SearchProducts, SearchProductsVariables>
- ) => React.ReactElement<any>);
-}
-interface SearchProductsProviderState {
- query: string;
-}
-
-export class SearchProductsProvider extends React.Component<
- SearchProductsProviderProps,
- SearchProductsProviderState
-> {
- state: SearchProductsProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const { children } = this.props;
- return (
- <TypedSearchProductsQuery variables={{ query: this.state.query }}>
- {searchOpts => children(this.search, searchOpts)}
- </TypedSearchProductsQuery>
- );
+export const searchProducts = gql`
+ query SearchProducts($after: String, $first: Int!, $query: String!) {
+ products(after: $after, first: $first, query: $query) {
+ edges {
+ node {
+ id
+ name
+ thumbnail {
+ url
+ }
+ }
+ }
+ }
}
-}
+`;
+
+export default BaseSearch<SearchProducts, SearchProductsVariables>(
+ searchProducts
+);
diff --git a/saleor/static/dashboard-next/containers/SearchProducts/query.ts b/saleor/static/dashboard-next/containers/SearchProducts/query.ts
deleted file mode 100644
index 480727eff6..0000000000
--- a/saleor/static/dashboard-next/containers/SearchProducts/query.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import gql from "graphql-tag";
-
-import { TypedQuery } from "../../queries";
-import {
- SearchProducts,
- SearchProductsVariables
-} from "./types/SearchProducts";
-
-export const searchProducts = gql`
- query SearchProducts($query: String!) {
- products(first: 5, query: $query) {
- edges {
- node {
- id
- thumbnail {
- url
- }
- name
- }
- }
- }
- }
-`;
-export const TypedSearchProductsQuery = TypedQuery<
- SearchProducts,
- SearchProductsVariables
->(searchProducts);
diff --git a/saleor/static/dashboard-next/containers/SearchProducts/types/SearchProducts.ts b/saleor/static/dashboard-next/containers/SearchProducts/types/SearchProducts.ts
index 4375eccc9b..fdafa6e104 100644
--- a/saleor/static/dashboard-next/containers/SearchProducts/types/SearchProducts.ts
+++ b/saleor/static/dashboard-next/containers/SearchProducts/types/SearchProducts.ts
@@ -14,8 +14,8 @@ export interface SearchProducts_products_edges_node_thumbnail {
export interface SearchProducts_products_edges_node {
__typename: "Product";
id: string;
- thumbnail: SearchProducts_products_edges_node_thumbnail | null;
name: string;
+ thumbnail: SearchProducts_products_edges_node_thumbnail | null;
}
export interface SearchProducts_products_edges {
@@ -33,5 +33,7 @@ export interface SearchProducts {
}
export interface SearchProductsVariables {
+ after?: string | null;
+ first: number;
query: string;
}
diff --git a/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx b/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx
index 5d3b2154f8..9d6e66c71c 100644
--- a/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx
+++ b/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx
@@ -9,9 +9,10 @@ import AssignCategoriesDialog from "../../components/AssignCategoryDialog";
import AssignCollectionDialog from "../../components/AssignCollectionDialog";
import AssignProductDialog from "../../components/AssignProductDialog";
import { WindowTitle } from "../../components/WindowTitle";
-import { SearchCategoriesProvider } from "../../containers/SearchCategories";
-import { SearchCollectionsProvider } from "../../containers/SearchCollections";
-import { SearchProductsProvider } from "../../containers/SearchProducts";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../config";
+import SearchCategories from "../../containers/SearchCategories";
+import SearchCollections from "../../containers/SearchCollections";
+import SearchProducts from "../../containers/SearchProducts";
import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
@@ -325,8 +326,13 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
toggle={toggle}
toggleAll={toggleAll}
/>
- <SearchProductsProvider>
- {(searchProducts, searchProductsOpts) => (
+ <SearchProducts
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
+ {({
+ search: searchProducts,
+ result: searchProductsOpts
+ }) => (
<AssignProductDialog
confirmButtonState={assignTransitionState}
open={params.action === "assign-product"}
@@ -355,9 +361,14 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
)}
/>
)}
- </SearchProductsProvider>
- <SearchCategoriesProvider>
- {(searchCategories, searchCategoriesOpts) => (
+ </SearchProducts>
+ <SearchCategories
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
+ {({
+ search: searchCategories,
+ result: searchCategoriesOpts
+ }) => (
<AssignCategoriesDialog
categories={maybe(() =>
searchCategoriesOpts.data.categories.edges
@@ -387,9 +398,14 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
}
/>
)}
- </SearchCategoriesProvider>
- <SearchCollectionsProvider>
- {(searchCollections, searchCollectionsOpts) => (
+ </SearchCategories>
+ <SearchCollections
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
+ {({
+ search: searchCollections,
+ result: searchCollectionsOpts
+ }) => (
<AssignCollectionDialog
collections={maybe(() =>
searchCollectionsOpts.data.collections.edges
@@ -419,7 +435,7 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
}
/>
)}
- </SearchCollectionsProvider>
+ </SearchCollections>
<ActionDialog
open={params.action === "unassign-category"}
title={i18n.t("Unassign Categories From Sale")}
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
index 3b1971db34..271cd6ac4b 100644
--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
@@ -9,9 +9,10 @@ import AssignCategoriesDialog from "../../components/AssignCategoryDialog";
import AssignCollectionDialog from "../../components/AssignCollectionDialog";
import AssignProductDialog from "../../components/AssignProductDialog";
import { WindowTitle } from "../../components/WindowTitle";
-import { SearchCategoriesProvider } from "../../containers/SearchCategories";
-import { SearchCollectionsProvider } from "../../containers/SearchCollections";
-import { SearchProductsProvider } from "../../containers/SearchProducts";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../config";
+import SearchCategories from "../../containers/SearchCategories";
+import SearchCollections from "../../containers/SearchCollections";
+import SearchProducts from "../../containers/SearchProducts";
import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
@@ -379,8 +380,13 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
toggle={toggle}
toggleAll={toggleAll}
/>
- <SearchCategoriesProvider>
- {(searchCategories, searchCategoriesOpts) => (
+ <SearchCategories
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
+ {({
+ search: searchCategories,
+ result: searchCategoriesOpts
+ }) => (
<AssignCategoriesDialog
categories={maybe(() =>
searchCategoriesOpts.data.categories.edges
@@ -410,9 +416,14 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
}
/>
)}
- </SearchCategoriesProvider>
- <SearchCollectionsProvider>
- {(searchCollections, searchCollectionsOpts) => (
+ </SearchCategories>
+ <SearchCollections
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
+ {({
+ search: searchCollections,
+ result: searchCollectionsOpts
+ }) => (
<AssignCollectionDialog
collections={maybe(() =>
searchCollectionsOpts.data.collections.edges
@@ -442,7 +453,7 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
}
/>
)}
- </SearchCollectionsProvider>
+ </SearchCollections>
<DiscountCountrySelectDialog
confirmButtonState={formTransitionState}
countries={maybe(() => shop.countries, [])}
@@ -466,8 +477,13 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
[]
)}
/>
- <SearchProductsProvider>
- {(searchProducts, searchProductsOpts) => (
+ <SearchProducts
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
+ {({
+ search: searchProducts,
+ result: searchProductsOpts
+ }) => (
<AssignProductDialog
confirmButtonState={assignTransitionState}
open={params.action === "assign-product"}
@@ -496,7 +512,7 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
)}
/>
)}
- </SearchProductsProvider>
+ </SearchProducts>
<ActionDialog
open={params.action === "unassign-category"}
title={i18n.t("Unassign Categories From Sale")}
diff --git a/saleor/static/dashboard-next/navigation/views/MenuDetails/index.tsx b/saleor/static/dashboard-next/navigation/views/MenuDetails/index.tsx
index 618816d395..80c0140bd8 100644
--- a/saleor/static/dashboard-next/navigation/views/MenuDetails/index.tsx
+++ b/saleor/static/dashboard-next/navigation/views/MenuDetails/index.tsx
@@ -4,14 +4,15 @@ import * as React from "react";
import { categoryUrl } from "../../../categories/urls";
import { collectionUrl } from "../../../collections/urls";
import ActionDialog from "../../../components/ActionDialog";
-import { SearchPagesProvider } from "../../../containers/SearchPages";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../../config";
+import SearchCategories from "../../../containers/SearchCategories";
+import SearchCollections from "../../../containers/SearchCollections";
+import SearchPages from "../../../containers/SearchPages";
import useNavigator from "../../../hooks/useNavigator";
import useNotifier from "../../../hooks/useNotifier";
import i18n from "../../../i18n";
import { getMutationState, maybe } from "../../../misc";
import { pageUrl } from "../../../pages/urls";
-import { CategorySearchProvider } from "../../../products/containers/CategorySearch";
-import { CollectionSearchProvider } from "../../../products/containers/CollectionSearch";
import MenuDetailsPage, {
MenuDetailsSubmitData
} from "../../components/MenuDetailsPage";
@@ -92,11 +93,11 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
};
return (
- <SearchPagesProvider>
+ <SearchPages variables={DEFAULT_INITIAL_SEARCH_DATA}>
{pageSearch => (
- <CategorySearchProvider>
+ <SearchCategories variables={DEFAULT_INITIAL_SEARCH_DATA}>
{categorySearch => (
- <CollectionSearchProvider>
+ <SearchCollections variables={DEFAULT_INITIAL_SEARCH_DATA}>
{collectionSearch => (
<MenuDetailsQuery displayLoader variables={{ id }}>
{({ data, loading, refetch }) => {
@@ -108,7 +109,7 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
const categories = maybe(
() =>
- categorySearch.searchOpts.data.categories.edges.map(
+ categorySearch.result.data.categories.edges.map(
edge => edge.node
),
[]
@@ -116,7 +117,7 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
const collections = maybe(
() =>
- collectionSearch.searchOpts.data.collections.edges.map(
+ collectionSearch.result.data.collections.edges.map(
edge => edge.node
),
[]
@@ -124,7 +125,7 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
const pages = maybe(
() =>
- pageSearch.searchOpts.data.pages.edges.map(
+ pageSearch.result.data.pages.edges.map(
edge => edge.node
),
[]
@@ -287,8 +288,8 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
collections={collections}
pages={pages}
loading={
- categorySearch.searchOpts.loading ||
- collectionSearch.searchOpts.loading
+ categorySearch.result.loading ||
+ collectionSearch.result.loading
}
confirmButtonState={
formTransitionState
@@ -360,8 +361,8 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
menuItem
)}
loading={
- categorySearch.searchOpts.loading ||
- collectionSearch.searchOpts.loading
+ categorySearch.result.loading ||
+ collectionSearch.result.loading
}
confirmButtonState={
formTransitionState
@@ -384,11 +385,11 @@ const MenuDetails: React.FC<MenuDetailsProps> = ({ id, params }) => {
}}
</MenuDetailsQuery>
)}
- </CollectionSearchProvider>
+ </SearchCollections>
)}
- </CategorySearchProvider>
+ </SearchCategories>
)}
- </SearchPagesProvider>
+ </SearchPages>
);
};
MenuDetails.displayName = "MenuDetails";
diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
index 36067997b4..090b10973f 100644
--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
@@ -17,11 +17,11 @@ import Hr from "../../../components/Hr";
import Link from "../../../components/Link";
import SingleAutocompleteSelectField from "../../../components/SingleAutocompleteSelectField";
import Skeleton from "../../../components/Skeleton";
+import { SearchCustomers_customers_edges_node } from "../../../containers/SearchCustomers/types/SearchCustomers";
import { customerUrl } from "../../../customers/urls";
import i18n from "../../../i18n";
import { createHref, maybe } from "../../../misc";
import { OrderDetails_order } from "../../types/OrderDetails";
-import { UserSearch_customers_edges_node } from "../../types/UserSearch";
const styles = (theme: Theme) =>
createStyles({
@@ -47,7 +47,7 @@ const styles = (theme: Theme) =>
export interface OrderCustomerProps extends WithStyles<typeof styles> {
order: OrderDetails_order;
- users?: UserSearch_customers_edges_node[];
+ users?: SearchCustomers_customers_edges_node[];
loading?: boolean;
canEditAddresses: boolean;
canEditCustomer: boolean;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
index 79d5b1f093..4aacd0642d 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
@@ -16,11 +16,11 @@ import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
import Skeleton from "../../../components/Skeleton";
+import { SearchCustomers_customers_edges_node } from "../../../containers/SearchCustomers/types/SearchCustomers";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { DraftOrderInput } from "../../../types/globalTypes";
import { OrderDetails_order } from "../../types/OrderDetails";
-import { UserSearch_customers_edges_node } from "../../types/UserSearch";
import OrderCustomer from "../OrderCustomer";
import OrderDraftDetails from "../OrderDraftDetails/OrderDraftDetails";
import { FormData as OrderDraftDetailsProductsFormData } from "../OrderDraftDetailsProducts";
@@ -40,7 +40,7 @@ const styles = (theme: Theme) =>
export interface OrderDraftPageProps extends WithStyles<typeof styles> {
disabled: boolean;
order: OrderDetails_order;
- users: UserSearch_customers_edges_node[];
+ users: SearchCustomers_customers_edges_node[];
usersLoading: boolean;
countries: Array<{
code: string;
diff --git a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
index 86ca2723a7..7208dba686 100644
--- a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
@@ -22,19 +22,18 @@ import Checkbox from "../../../components/Checkbox";
import ConfirmButton, {
ConfirmButtonTransitionState
} from "../../../components/ConfirmButton";
-import Debounce from "../../../components/Debounce";
import Form from "../../../components/Form";
import Money from "../../../components/Money";
import TableCellAvatar from "../../../components/TableCellAvatar";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
import {
- OrderVariantSearch_products_edges_node,
- OrderVariantSearch_products_edges_node_variants
-} from "../../types/OrderVariantSearch";
+ SearchOrderVariant_products_edges_node,
+ SearchOrderVariant_products_edges_node_variants
+} from "../../types/SearchOrderVariant";
export interface FormData {
- variants: OrderVariantSearch_products_edges_node_variants[];
+ variants: SearchOrderVariant_products_edges_node_variants[];
query: string;
}
@@ -79,7 +78,7 @@ const styles = (theme: Theme) =>
interface OrderProductAddDialogProps extends WithStyles<typeof styles> {
confirmButtonState: ConfirmButtonTransitionState;
open: boolean;
- products: OrderVariantSearch_products_edges_node[];
+ products: SearchOrderVariant_products_edges_node[];
loading: boolean;
hasMore: boolean;
onClose: () => void;
@@ -94,8 +93,8 @@ const initialForm: FormData = {
};
function hasAllVariantsSelected(
- productVariants: OrderVariantSearch_products_edges_node_variants[],
- selectedVariants: OrderVariantSearch_products_edges_node_variants[]
+ productVariants: SearchOrderVariant_products_edges_node_variants[],
+ selectedVariants: SearchOrderVariant_products_edges_node_variants[]
): boolean {
return productVariants.reduce(
(acc, productVariant) =>
@@ -108,8 +107,8 @@ function hasAllVariantsSelected(
}
function isVariantSelected(
- variant: OrderVariantSearch_products_edges_node_variants,
- selectedVariants: OrderVariantSearch_products_edges_node_variants[]
+ variant: SearchOrderVariant_products_edges_node_variants,
+ selectedVariants: SearchOrderVariant_products_edges_node_variants[]
): boolean {
return !!selectedVariants.find(
selectedVariant => selectedVariant.id === variant.id
@@ -153,7 +152,7 @@ const OrderProductAddDialog = withStyles(styles, {
: [];
const onProductAdd = (
- product: OrderVariantSearch_products_edges_node,
+ product: SearchOrderVariant_products_edges_node,
productIndex: number
) =>
selectedProducts[productIndex]
@@ -185,7 +184,7 @@ const OrderProductAddDialog = withStyles(styles, {
}
} as any);
const onVariantAdd = (
- variant: OrderVariantSearch_products_edges_node_variants,
+ variant: SearchOrderVariant_products_edges_node_variants,
variantIndex: number,
productIndex: number
) =>
@@ -209,29 +208,25 @@ const OrderProductAddDialog = withStyles(styles, {
<>
<DialogTitle>{i18n.t("Add product")}</DialogTitle>
<DialogContent className={classes.overflow}>
- <Debounce debounceFn={onFetch}>
- {fetch => (
- <TextField
- name="query"
- value={data.query}
- onChange={event => change(event, () => fetch(data.query))}
- label={i18n.t("Search Products", {
- context: "product search input label"
- })}
- placeholder={i18n.t(
- "Search by product name, attribute, product type etc...",
- {
- context: "product search input placeholder"
- }
- )}
- fullWidth
- InputProps={{
- autoComplete: "off",
- endAdornment: loading && <CircularProgress size={16} />
- }}
- />
+ <TextField
+ name="query"
+ value={data.query}
+ onChange={event => change(event, () => onFetch(data.query))}
+ label={i18n.t("Search Products", {
+ context: "product search input label"
+ })}
+ placeholder={i18n.t(
+ "Search by product name, attribute, product type etc...",
+ {
+ context: "product search input placeholder"
+ }
)}
- </Debounce>
+ fullWidth
+ InputProps={{
+ autoComplete: "off",
+ endAdornment: loading && <CircularProgress size={16} />
+ }}
+ />
</DialogContent>
<DialogContent className={classes.content}>
<InfiniteScroll
diff --git a/saleor/static/dashboard-next/orders/containers/OrderVariantSearch.tsx b/saleor/static/dashboard-next/orders/containers/OrderVariantSearch.tsx
deleted file mode 100644
index 60311ab301..0000000000
--- a/saleor/static/dashboard-next/orders/containers/OrderVariantSearch.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-
-import { LoadMore } from "../../queries";
-import { TypedOrderVariantSearch } from "../queries";
-import {
- OrderVariantSearch,
- OrderVariantSearchVariables
-} from "../types/OrderVariantSearch";
-
-interface OrderVariantSearchProviderProps {
- children: ((
- props: {
- variants: {
- search: (query: string) => void;
- searchOpts: QueryResult<
- OrderVariantSearch,
- OrderVariantSearchVariables
- > &
- LoadMore<OrderVariantSearch, OrderVariantSearchVariables>;
- };
- }
- ) => React.ReactElement<any>);
-}
-interface OrderVariantSearchProviderState {
- query: string;
-}
-
-export class OrderVariantSearchProvider extends React.Component<
- OrderVariantSearchProviderProps,
- OrderVariantSearchProviderState
-> {
- state: OrderVariantSearchProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const { children } = this.props;
- return (
- <TypedOrderVariantSearch variables={{ search: this.state.query }}>
- {searchOpts =>
- children({ variants: { search: this.search, searchOpts } })
- }
- </TypedOrderVariantSearch>
- );
- }
-}
diff --git a/saleor/static/dashboard-next/orders/containers/UserSearch.tsx b/saleor/static/dashboard-next/orders/containers/UserSearch.tsx
deleted file mode 100644
index a79dfd8f33..0000000000
--- a/saleor/static/dashboard-next/orders/containers/UserSearch.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedUserSearch } from "../queries";
-import { UserSearch, UserSearchVariables } from "../types/UserSearch";
-
-interface UserSearchProviderProps {
- children: ((
- props: {
- search: (query: string) => void;
- searchOpts: QueryResult<UserSearch, UserSearchVariables>;
- }
- ) => React.ReactElement<any>);
-}
-interface UserSearchProviderState {
- query: string;
-}
-
-export class UserSearchProvider extends React.Component<
- UserSearchProviderProps,
- UserSearchProviderState
-> {
- state: UserSearchProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const { children } = this.props;
- return (
- <TypedUserSearch variables={{ search: this.state.query }}>
- {searchOpts => children({ search: this.search, searchOpts })}
- </TypedUserSearch>
- );
- }
-}
diff --git a/saleor/static/dashboard-next/orders/fixtures.ts b/saleor/static/dashboard-next/orders/fixtures.ts
index dbf3a30d05..7060179678 100644
--- a/saleor/static/dashboard-next/orders/fixtures.ts
+++ b/saleor/static/dashboard-next/orders/fixtures.ts
@@ -1,3 +1,4 @@
+import { SearchCustomers_customers_edges_node } from "../containers/SearchCustomers/types/SearchCustomers";
import { transformOrderStatus, transformPaymentStatus } from "../misc";
import {
FulfillmentStatus,
@@ -8,9 +9,8 @@ import {
} from "../types/globalTypes";
import { OrderDetails_order } from "./types/OrderDetails";
import { OrderList_orders_edges_node } from "./types/OrderList";
-import { UserSearch_customers_edges_node } from "./types/UserSearch";
-export const clients: UserSearch_customers_edges_node[] = [
+export const clients: SearchCustomers_customers_edges_node[] = [
{
__typename: "User" as "User",
diff --git a/saleor/static/dashboard-next/orders/queries.ts b/saleor/static/dashboard-next/orders/queries.ts
index bf0d074dce..87a006b286 100644
--- a/saleor/static/dashboard-next/orders/queries.ts
+++ b/saleor/static/dashboard-next/orders/queries.ts
@@ -1,5 +1,6 @@
import gql from "graphql-tag";
+import BaseSearch from "../containers/BaseSearch";
import { TypedQuery } from "../queries";
import { OrderDetails, OrderDetailsVariables } from "./types/OrderDetails";
import {
@@ -8,10 +9,9 @@ import {
} from "./types/OrderDraftList";
import { OrderList, OrderListVariables } from "./types/OrderList";
import {
- OrderVariantSearch,
- OrderVariantSearchVariables
-} from "./types/OrderVariantSearch";
-import { UserSearch, UserSearchVariables } from "./types/UserSearch";
+ SearchOrderVariant as SearchOrderVariantType,
+ SearchOrderVariantVariables
+} from "./types/SearchOrderVariant";
export const fragmentOrderEvent = gql`
fragment OrderEventFragment on OrderEvent {
@@ -279,9 +279,9 @@ export const TypedOrderDetailsQuery = TypedQuery<
OrderDetailsVariables
>(orderDetailsQuery);
-export const orderVariantSearchQuery = gql`
- query OrderVariantSearch($search: String!, $after: String) {
- products(query: $search, first: 5, after: $after) {
+export const searchOrderVariant = gql`
+ query SearchOrderVariant($first: Int!, $query: String!, $after: String) {
+ products(query: $query, first: $first, after: $after) {
edges {
node {
id
@@ -309,23 +309,7 @@ export const orderVariantSearchQuery = gql`
}
}
`;
-export const TypedOrderVariantSearch = TypedQuery<
- OrderVariantSearch,
- OrderVariantSearchVariables
->(orderVariantSearchQuery);
-
-export const userSearchQuery = gql`
- query UserSearch($search: String!) {
- customers(query: $search, first: 5) {
- edges {
- node {
- id
- email
- }
- }
- }
- }
-`;
-export const TypedUserSearch = TypedQuery<UserSearch, UserSearchVariables>(
- userSearchQuery
-);
+export const SearchOrderVariant = BaseSearch<
+ SearchOrderVariantType,
+ SearchOrderVariantVariables
+>(searchOrderVariant);
diff --git a/saleor/static/dashboard-next/orders/types/OrderVariantSearch.ts b/saleor/static/dashboard-next/orders/types/OrderVariantSearch.ts
deleted file mode 100644
index 259d44d574..0000000000
--- a/saleor/static/dashboard-next/orders/types/OrderVariantSearch.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
-// ====================================================
-// GraphQL query operation: OrderVariantSearch
-// ====================================================
-
-export interface OrderVariantSearch_products_edges_node_thumbnail {
- __typename: "Image";
- url: string;
-}
-
-export interface OrderVariantSearch_products_edges_node_variants_price {
- __typename: "Money";
- amount: number;
- currency: string;
-}
-
-export interface OrderVariantSearch_products_edges_node_variants {
- __typename: "ProductVariant";
- id: string;
- name: string;
- sku: string;
- price: OrderVariantSearch_products_edges_node_variants_price | null;
-}
-
-export interface OrderVariantSearch_products_edges_node {
- __typename: "Product";
- id: string;
- name: string;
- thumbnail: OrderVariantSearch_products_edges_node_thumbnail | null;
- variants: (OrderVariantSearch_products_edges_node_variants | null)[] | null;
-}
-
-export interface OrderVariantSearch_products_edges {
- __typename: "ProductCountableEdge";
- node: OrderVariantSearch_products_edges_node;
-}
-
-export interface OrderVariantSearch_products_pageInfo {
- __typename: "PageInfo";
- endCursor: string | null;
- hasNextPage: boolean;
- hasPreviousPage: boolean;
- startCursor: string | null;
-}
-
-export interface OrderVariantSearch_products {
- __typename: "ProductCountableConnection";
- edges: OrderVariantSearch_products_edges[];
- pageInfo: OrderVariantSearch_products_pageInfo;
-}
-
-export interface OrderVariantSearch {
- products: OrderVariantSearch_products | null;
-}
-
-export interface OrderVariantSearchVariables {
- search: string;
- after?: string | null;
-}
diff --git a/saleor/static/dashboard-next/orders/types/SearchOrderVariant.ts b/saleor/static/dashboard-next/orders/types/SearchOrderVariant.ts
new file mode 100644
index 0000000000..f2f0949ebb
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/types/SearchOrderVariant.ts
@@ -0,0 +1,63 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: SearchOrderVariant
+// ====================================================
+
+export interface SearchOrderVariant_products_edges_node_thumbnail {
+ __typename: "Image";
+ url: string;
+}
+
+export interface SearchOrderVariant_products_edges_node_variants_price {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface SearchOrderVariant_products_edges_node_variants {
+ __typename: "ProductVariant";
+ id: string;
+ name: string;
+ sku: string;
+ price: SearchOrderVariant_products_edges_node_variants_price | null;
+}
+
+export interface SearchOrderVariant_products_edges_node {
+ __typename: "Product";
+ id: string;
+ name: string;
+ thumbnail: SearchOrderVariant_products_edges_node_thumbnail | null;
+ variants: (SearchOrderVariant_products_edges_node_variants | null)[] | null;
+}
+
+export interface SearchOrderVariant_products_edges {
+ __typename: "ProductCountableEdge";
+ node: SearchOrderVariant_products_edges_node;
+}
+
+export interface SearchOrderVariant_products_pageInfo {
+ __typename: "PageInfo";
+ endCursor: string | null;
+ hasNextPage: boolean;
+ hasPreviousPage: boolean;
+ startCursor: string | null;
+}
+
+export interface SearchOrderVariant_products {
+ __typename: "ProductCountableConnection";
+ edges: SearchOrderVariant_products_edges[];
+ pageInfo: SearchOrderVariant_products_pageInfo;
+}
+
+export interface SearchOrderVariant {
+ products: SearchOrderVariant_products | null;
+}
+
+export interface SearchOrderVariantVariables {
+ first: number;
+ query: string;
+ after?: string | null;
+}
diff --git a/saleor/static/dashboard-next/orders/types/UserSearch.ts b/saleor/static/dashboard-next/orders/types/UserSearch.ts
deleted file mode 100644
index 2727e13587..0000000000
--- a/saleor/static/dashboard-next/orders/types/UserSearch.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
-// ====================================================
-// GraphQL query operation: UserSearch
-// ====================================================
-
-export interface UserSearch_customers_edges_node {
- __typename: "User";
- id: string;
- email: string;
-}
-
-export interface UserSearch_customers_edges {
- __typename: "UserCountableEdge";
- node: UserSearch_customers_edges_node;
-}
-
-export interface UserSearch_customers {
- __typename: "UserCountableConnection";
- edges: UserSearch_customers_edges[];
-}
-
-export interface UserSearch {
- customers: UserSearch_customers | null;
-}
-
-export interface UserSearchVariables {
- search: string;
-}
diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
index 63f3a4b566..936049d3cd 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
@@ -1,6 +1,8 @@
import * as React from "react";
import { WindowTitle } from "../../../components/WindowTitle";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../../config";
+import SearchCustomers from "../../../containers/SearchCustomers";
import { customerUrl } from "../../../customers/urls";
import useNavigator from "../../../hooks/useNavigator";
import { getMutationState, maybe, transformAddressToForm } from "../../../misc";
@@ -23,9 +25,7 @@ import OrderPaymentVoidDialog from "../../components/OrderPaymentVoidDialog";
import OrderProductAddDialog from "../../components/OrderProductAddDialog";
import OrderShippingMethodEditDialog from "../../components/OrderShippingMethodEditDialog";
import OrderOperations from "../../containers/OrderOperations";
-import { OrderVariantSearchProvider } from "../../containers/OrderVariantSearch";
-import { UserSearchProvider } from "../../containers/UserSearch";
-import { TypedOrderDetailsQuery } from "../../queries";
+import { SearchOrderVariant, TypedOrderDetailsQuery } from "../../queries";
import { OrderDetails_order } from "../../types/OrderDetails";
import {
orderListUrl,
@@ -92,8 +92,8 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
})
);
return (
- <UserSearchProvider>
- {users => (
+ <SearchCustomers variables={DEFAULT_INITIAL_SEARCH_DATA}>
+ {({ search: searchUsers, result: users }) => (
<OrderDetailsMessages>
{orderMessages => (
<OrderOperations
@@ -400,13 +400,13 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
}
users={maybe(
() =>
- users.searchOpts.data.customers.edges.map(
+ users.data.customers.edges.map(
edge => edge.node
),
[]
)}
- fetchUsers={users.search}
- usersLoading={users.searchOpts.loading}
+ fetchUsers={searchUsers}
+ usersLoading={users.loading}
onCustomerEdit={data =>
orderDraftUpdate.mutate({
id,
@@ -507,12 +507,12 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
})
}
/>
- <OrderVariantSearchProvider>
+ <SearchOrderVariant
+ variables={DEFAULT_INITIAL_SEARCH_DATA}
+ >
{({
- variants: {
- search: variantSearch,
- searchOpts: variantSearchOpts
- }
+ search: variantSearch,
+ result: variantSearchOpts
}) => {
const fetchMore = () =>
variantSearchOpts.loadMore(
@@ -581,7 +581,7 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
/>
);
}}
- </OrderVariantSearchProvider>
+ </SearchOrderVariant>
</>
)}
<OrderAddressEditDialog
@@ -663,7 +663,7 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
)}
</OrderDetailsMessages>
)}
- </UserSearchProvider>
+ </SearchCustomers>
);
}}
</TypedOrderDetailsQuery>
diff --git a/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx b/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx
deleted file mode 100644
index 64cfb9171f..0000000000
--- a/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedSearchAttributeQuery } from "../queries";
-import {
- SearchAttribute,
- SearchAttributeVariables
-} from "../types/SearchAttribute";
-
-interface AttributeSearchProviderProps {
- children: (
- search: (query: string) => void,
- props: QueryResult<SearchAttribute, SearchAttributeVariables>
- ) => React.ReactNode;
-}
-interface AttributeSearchProviderState {
- query: string;
-}
-
-export class AttributeSearchProvider extends React.Component<
- AttributeSearchProviderProps,
- AttributeSearchProviderState
-> {
- state: AttributeSearchProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- const { children } = this.props;
- if (typeof children === "function") {
- return (
- <TypedSearchAttributeQuery variables={{ search: this.state.query }}>
- {props => children(this.search, props)}
- </TypedSearchAttributeQuery>
- );
- }
- return this.props.children;
- }
-}
diff --git a/saleor/static/dashboard-next/productTypes/queries.ts b/saleor/static/dashboard-next/productTypes/queries.ts
index 9854b1e84f..f3012c73a7 100644
--- a/saleor/static/dashboard-next/productTypes/queries.ts
+++ b/saleor/static/dashboard-next/productTypes/queries.ts
@@ -10,10 +10,6 @@ import {
ProductTypeList,
ProductTypeListVariables
} from "./types/ProductTypeList";
-import {
- SearchAttribute,
- SearchAttributeVariables
-} from "./types/SearchAttribute";
export const attributeFragment = gql`
fragment AttributeFragment on Attribute {
@@ -110,20 +106,3 @@ export const TypedProductTypeCreateDataQuery = TypedQuery<
ProductTypeCreateData,
{}
>(productTypeCreateDataQuery);
-
-export const searchAttributeQuery = gql`
- ${attributeFragment}
- query SearchAttribute($search: String!) {
- attributes(query: $search, first: 5) {
- edges {
- node {
- ...AttributeFragment
- }
- }
- }
- }
-`;
-export const TypedSearchAttributeQuery = TypedQuery<
- SearchAttribute,
- SearchAttributeVariables
->(searchAttributeQuery);
diff --git a/saleor/static/dashboard-next/productTypes/types/SearchAttribute.ts b/saleor/static/dashboard-next/productTypes/types/SearchAttribute.ts
deleted file mode 100644
index 790cfaedde..0000000000
--- a/saleor/static/dashboard-next/productTypes/types/SearchAttribute.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
-// ====================================================
-// GraphQL query operation: SearchAttribute
-// ====================================================
-
-export interface SearchAttribute_attributes_edges_node_values {
- __typename: "AttributeValue";
- id: string;
- name: string | null;
- slug: string | null;
-}
-
-export interface SearchAttribute_attributes_edges_node {
- __typename: "Attribute";
- id: string;
- name: string | null;
- slug: string | null;
- values: (SearchAttribute_attributes_edges_node_values | null)[] | null;
-}
-
-export interface SearchAttribute_attributes_edges {
- __typename: "AttributeCountableEdge";
- node: SearchAttribute_attributes_edges_node;
-}
-
-export interface SearchAttribute_attributes {
- __typename: "AttributeCountableConnection";
- edges: SearchAttribute_attributes_edges[];
-}
-
-export interface SearchAttribute {
- attributes: SearchAttribute_attributes | null;
-}
-
-export interface SearchAttributeVariables {
- search: string;
-}
diff --git a/saleor/static/dashboard-next/products/containers/CategorySearch.tsx b/saleor/static/dashboard-next/products/containers/CategorySearch.tsx
deleted file mode 100644
index e60f01ebf3..0000000000
--- a/saleor/static/dashboard-next/products/containers/CategorySearch.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedCategorySearchQuery } from "../queries";
-import {
- CategorySearch,
- CategorySearchVariables
-} from "../types/CategorySearch";
-
-interface CategorySearchProviderProps {
- children: ((
- props: {
- search: (query: string) => void;
- searchOpts: QueryResult<CategorySearch, CategorySearchVariables>;
- }
- ) => React.ReactElement<any>);
-}
-interface CategorySearchProviderState {
- query: string;
-}
-
-export class CategorySearchProvider extends React.Component<
- CategorySearchProviderProps,
- CategorySearchProviderState
-> {
- state: CategorySearchProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- return (
- <TypedCategorySearchQuery variables={{ query: this.state.query }}>
- {searchOpts => this.props.children({ search: this.search, searchOpts })}
- </TypedCategorySearchQuery>
- );
- }
-}
diff --git a/saleor/static/dashboard-next/products/containers/CollectionSearch.tsx b/saleor/static/dashboard-next/products/containers/CollectionSearch.tsx
deleted file mode 100644
index 62e7ff1111..0000000000
--- a/saleor/static/dashboard-next/products/containers/CollectionSearch.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-import * as React from "react";
-import { QueryResult } from "react-apollo";
-import { TypedCollectionSearchQuery } from "../queries";
-import {
- CollectionSearch,
- CollectionSearchVariables
-} from "../types/CollectionSearch";
-
-interface CollectionSearchProviderProps {
- children: ((
- props: {
- search: (query: string) => void;
- searchOpts: QueryResult<CollectionSearch, CollectionSearchVariables>;
- }
- ) => React.ReactElement<any>);
-}
-interface CollectionSearchProviderState {
- query: string;
-}
-
-export class CollectionSearchProvider extends React.Component<
- CollectionSearchProviderProps,
- CollectionSearchProviderState
-> {
- state: CollectionSearchProviderState = { query: "" };
-
- search = (query: string) => this.setState({ query });
-
- render() {
- return (
- <TypedCollectionSearchQuery variables={{ query: this.state.query }}>
- {searchOpts => this.props.children({ search: this.search, searchOpts })}
- </TypedCollectionSearchQuery>
- );
- }
-}
diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.ts
index 2e1f048173..84c3c345d2 100644
--- a/saleor/static/dashboard-next/products/queries.ts
+++ b/saleor/static/dashboard-next/products/queries.ts
@@ -1,14 +1,6 @@
import gql from "graphql-tag";
import { TypedQuery } from "../queries";
-import {
- CategorySearch,
- CategorySearchVariables
-} from "./types/CategorySearch";
-import {
- CollectionSearch,
- CollectionSearchVariables
-} from "./types/CollectionSearch";
import { ProductCreateData } from "./types/ProductCreateData";
import {
ProductDetails,
@@ -364,37 +356,3 @@ export const TypedProductImageQuery = TypedQuery<
ProductImageById,
ProductImageByIdVariables
>(productImageQuery);
-
-const categorySearch = gql`
- query CategorySearch($query: String) {
- categories(first: 5, query: $query) {
- edges {
- node {
- id
- name
- }
- }
- }
- }
-`;
-export const TypedCategorySearchQuery = TypedQuery<
- CategorySearch,
- CategorySearchVariables
->(categorySearch);
-
-const collectionSearch = gql`
- query CollectionSearch($query: String) {
- collections(first: 5, query: $query) {
- edges {
- node {
- id
- name
- }
- }
- }
- }
-`;
-export const TypedCollectionSearchQuery = TypedQuery<
- CollectionSearch,
- CollectionSearchVariables
->(collectionSearch);
diff --git a/saleor/static/dashboard-next/products/types/CategorySearch.ts b/saleor/static/dashboard-next/products/types/CategorySearch.ts
deleted file mode 100644
index f3f8a9b79b..0000000000
--- a/saleor/static/dashboard-next/products/types/CategorySearch.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
-// ====================================================
-// GraphQL query operation: CategorySearch
-// ====================================================
-
-export interface CategorySearch_categories_edges_node {
- __typename: "Category";
- id: string;
- name: string;
-}
-
-export interface CategorySearch_categories_edges {
- __typename: "CategoryCountableEdge";
- node: CategorySearch_categories_edges_node;
-}
-
-export interface CategorySearch_categories {
- __typename: "CategoryCountableConnection";
- edges: CategorySearch_categories_edges[];
-}
-
-export interface CategorySearch {
- categories: CategorySearch_categories | null;
-}
-
-export interface CategorySearchVariables {
- query?: string | null;
-}
diff --git a/saleor/static/dashboard-next/products/types/CollectionSearch.ts b/saleor/static/dashboard-next/products/types/CollectionSearch.ts
deleted file mode 100644
index bbb19ffe9c..0000000000
--- a/saleor/static/dashboard-next/products/types/CollectionSearch.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
-// ====================================================
-// GraphQL query operation: CollectionSearch
-// ====================================================
-
-export interface CollectionSearch_collections_edges_node {
- __typename: "Collection";
- id: string;
- name: string;
-}
-
-export interface CollectionSearch_collections_edges {
- __typename: "CollectionCountableEdge";
- node: CollectionSearch_collections_edges_node;
-}
-
-export interface CollectionSearch_collections {
- __typename: "CollectionCountableConnection";
- edges: CollectionSearch_collections_edges[];
-}
-
-export interface CollectionSearch {
- collections: CollectionSearch_collections | null;
-}
-
-export interface CollectionSearchVariables {
- query?: string | null;
-}
diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
index 64ebb6abcb..a2c746e48b 100644
--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
@@ -1,14 +1,15 @@
import * as React from "react";
import { WindowTitle } from "../../components/WindowTitle";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../config";
+import SearchCategories from "../../containers/SearchCategories";
+import SearchCollections from "../../containers/SearchCollections";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
import useShop from "../../hooks/useShop";
import i18n from "../../i18n";
import { decimal, getMutationState, maybe } from "../../misc";
import ProductCreatePage, { FormData } from "../components/ProductCreatePage";
-import { CategorySearchProvider } from "../containers/CategorySearch";
-import { CollectionSearchProvider } from "../containers/CollectionSearch";
import { TypedProductCreateMutation } from "../mutations";
import { TypedProductCreateQuery } from "../queries";
import { ProductCreate } from "../types/ProductCreate";
@@ -29,10 +30,10 @@ export const ProductUpdate: React.StatelessComponent<
const handleBack = () => navigate(productListUrl());
return (
- <CategorySearchProvider>
- {({ search: searchCategory, searchOpts: searchCategoryOpts }) => (
- <CollectionSearchProvider>
- {({ search: searchCollection, searchOpts: searchCollectionOpts }) => (
+ <SearchCategories variables={DEFAULT_INITIAL_SEARCH_DATA}>
+ {({ search: searchCategory, result: searchCategoryOpts }) => (
+ <SearchCollections variables={DEFAULT_INITIAL_SEARCH_DATA}>
+ {({ search: searchCollection, result: searchCollectionOpts }) => (
<TypedProductCreateQuery displayLoader>
{({ data, loading }) => {
const handleSuccess = (data: ProductCreate) => {
@@ -127,9 +128,9 @@ export const ProductUpdate: React.StatelessComponent<
}}
</TypedProductCreateQuery>
)}
- </CollectionSearchProvider>
+ </SearchCollections>
)}
- </CategorySearchProvider>
+ </SearchCategories>
);
};
export default ProductUpdate;
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index 9d4d10311f..7f84f33a08 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -7,6 +7,9 @@ import { arrayMove } from "react-sortable-hoc";
import * as placeholderImg from "../../../images/placeholder255x255.png";
import ActionDialog from "../../components/ActionDialog";
import { WindowTitle } from "../../components/WindowTitle";
+import { DEFAULT_INITIAL_SEARCH_DATA } from "../../config";
+import SearchCategories from "../../containers/SearchCategories";
+import SearchCollections from "../../containers/SearchCollections";
import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
@@ -14,8 +17,6 @@ import i18n from "../../i18n";
import { decimal, getMutationState, maybe } from "../../misc";
import { productTypeUrl } from "../../productTypes/urls";
import ProductUpdatePage, { FormData } from "../components/ProductUpdatePage";
-import { CategorySearchProvider } from "../containers/CategorySearch";
-import { CollectionSearchProvider } from "../containers/CollectionSearch";
import ProductUpdateOperations from "../containers/ProductUpdateOperations";
import { TypedProductDetailsQuery } from "../queries";
import {
@@ -48,13 +49,10 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
);
return (
- <CategorySearchProvider>
- {({ search: searchCategories, searchOpts: searchCategoriesOpts }) => (
- <CollectionSearchProvider>
- {({
- search: searchCollections,
- searchOpts: searchCollectionsOpts
- }) => (
+ <SearchCategories variables={DEFAULT_INITIAL_SEARCH_DATA}>
+ {({ search: searchCategories, result: searchCategoriesOpts }) => (
+ <SearchCollections variables={DEFAULT_INITIAL_SEARCH_DATA}>
+ {({ search: searchCollections, result: searchCollectionsOpts }) => (
<TypedProductDetailsQuery
displayLoader
require={["product"]}
@@ -360,9 +358,9 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
}}
</TypedProductDetailsQuery>
)}
- </CollectionSearchProvider>
+ </SearchCollections>
)}
- </CategorySearchProvider>
+ </SearchCategories>
);
};
export default ProductUpdate;
diff --git a/saleor/static/dashboard-next/queries.tsx b/saleor/static/dashboard-next/queries.tsx
index c8c67f2ce7..2364ee6b79 100644
--- a/saleor/static/dashboard-next/queries.tsx
+++ b/saleor/static/dashboard-next/queries.tsx
@@ -18,10 +18,14 @@ export interface LoadMore<TData, TVariables> {
) => Promise<ApolloQueryResult<TData>>;
}
-interface TypedQueryInnerProps<TData, TVariables> {
- children: (
- result: QueryResult<TData, TVariables> & LoadMore<TData, TVariables>
- ) => React.ReactNode;
+export type TypedQueryResult<TData, TVariables> = QueryResult<
+ TData,
+ TVariables
+> &
+ LoadMore<TData, TVariables>;
+
+export interface TypedQueryInnerProps<TData, TVariables> {
+ children: (result: TypedQueryResult<TData, TVariables>) => React.ReactNode;
displayLoader?: boolean;
skip?: boolean;
variables?: TVariables;
@@ -58,9 +62,11 @@ class QueryProgress extends React.Component<QueryProgressProps, {}> {
}
}
-export function TypedQuery<TData, TVariables>(query: DocumentNode) {
+export function TypedQuery<TData, TVariables>(
+ query: DocumentNode
+): React.FC<TypedQueryInnerProps<TData, TVariables>> {
class StrictTypedQuery extends Query<TData, TVariables> {}
- return (props: TypedQueryInnerProps<TData, TVariables>) => {
+ return props => {
const navigate = useNavigator();
const pushMessage = useNotifier();