Skip to content

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

Use available attributes instad of all

dominik-zeglen3a718a2545fb
diff --git a/saleor/static/dashboard-next/containers/SearchAttributes/index.tsx b/saleor/static/dashboard-next/containers/SearchAttributes/index.tsx
deleted file mode 100644
index 22be619cc0..0000000000
--- a/saleor/static/dashboard-next/containers/SearchAttributes/index.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import gql from "graphql-tag";
-
-import { pageInfoFragment } from "@saleor/queries";
-import BaseSearch from "../BaseSearch";
-import {
- SearchAttributes,
- SearchAttributesVariables
-} from "./types/SearchAttributes";
-
-export const searchAttributes = gql`
- ${pageInfoFragment}
- query SearchAttributes($after: String, $first: Int!, $query: String!) {
- attributes(after: $after, first: $first, query: $query) {
- edges {
- node {
- id
- name
- slug
- }
- }
- pageInfo {
- ...PageInfoFragment
- }
- }
- }
-`;
-
-export default BaseSearch<SearchAttributes, SearchAttributesVariables>(
- searchAttributes
-);
diff --git a/saleor/static/dashboard-next/containers/SearchAttributes/types/SearchAttributes.ts b/saleor/static/dashboard-next/containers/SearchAttributes/types/SearchAttributes.ts
deleted file mode 100644
index bb552d2522..0000000000
--- a/saleor/static/dashboard-next/containers/SearchAttributes/types/SearchAttributes.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-/* tslint:disable */
-/* eslint-disable */
-// This file was automatically generated and should not be edited.
-
-// ====================================================
-// GraphQL query operation: SearchAttributes
-// ====================================================
-
-export interface SearchAttributes_attributes_edges_node {
- __typename: "Attribute";
- id: string;
- name: string | null;
- slug: string | null;
-}
-
-export interface SearchAttributes_attributes_edges {
- __typename: "AttributeCountableEdge";
- node: SearchAttributes_attributes_edges_node;
-}
-
-export interface SearchAttributes_attributes_pageInfo {
- __typename: "PageInfo";
- endCursor: string | null;
- hasNextPage: boolean;
- hasPreviousPage: boolean;
- startCursor: string | null;
-}
-
-export interface SearchAttributes_attributes {
- __typename: "AttributeCountableConnection";
- edges: SearchAttributes_attributes_edges[];
- pageInfo: SearchAttributes_attributes_pageInfo;
-}
-
-export interface SearchAttributes {
- attributes: SearchAttributes_attributes | null;
-}
-
-export interface SearchAttributesVariables {
- after?: string | null;
- first: number;
- query: string;
-}
diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/productTypes/components/AssignAttributeDialog/AssignAttributeDialog.tsx
similarity index 95%
rename from saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx
rename to saleor/static/dashboard-next/productTypes/components/AssignAttributeDialog/AssignAttributeDialog.tsx
index d20a5f3fde..b4607d97fb 100644
--- a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/AssignAttributeDialog/AssignAttributeDialog.tsx
@@ -16,16 +16,16 @@ import makeStyles from "@material-ui/styles/makeStyles";
import * as React from "react";
import InfiniteScroll from "react-infinite-scroller";
+import Checkbox from "@saleor/components/Checkbox";
import ConfirmButton, {
ConfirmButtonTransitionState
} from "@saleor/components/ConfirmButton";
import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
import useSearchQuery from "@saleor/hooks/useSearchQuery";
+import i18n from "@saleor/i18n";
import { maybe, renderCollection } from "@saleor/misc";
import { FetchMoreProps } from "@saleor/types";
-import { SearchAttributes_attributes_edges_node } from "../../containers/SearchAttributes/types/SearchAttributes";
-import i18n from "../../i18n";
-import Checkbox from "../Checkbox";
+import { SearchAttributes_productType_availableAttributes_edges_node } from "../../containers/SearchAttributes/types/SearchAttributes";
const useStyles = makeStyles((theme: Theme) => ({
checkboxCell: {
@@ -49,7 +49,7 @@ export interface AssignAttributeDialogProps extends FetchMoreProps {
confirmButtonState: ConfirmButtonTransitionState;
errors: string[];
open: boolean;
- attributes: SearchAttributes_attributes_edges_node[];
+ attributes: SearchAttributes_productType_availableAttributes_edges_node[];
selected: string[];
onClose: () => void;
onSubmit: () => void;
diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/index.ts b/saleor/static/dashboard-next/productTypes/components/AssignAttributeDialog/index.ts
similarity index 100%
rename from saleor/static/dashboard-next/components/AssignAttributeDialog/index.ts
rename to saleor/static/dashboard-next/productTypes/components/AssignAttributeDialog/index.ts
diff --git a/saleor/static/dashboard-next/productTypes/containers/SearchAttributes/index.tsx b/saleor/static/dashboard-next/productTypes/containers/SearchAttributes/index.tsx
new file mode 100644
index 0000000000..6af8faa86c
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/containers/SearchAttributes/index.tsx
@@ -0,0 +1,42 @@
+import gql from "graphql-tag";
+
+import { pageInfoFragment } from "@saleor/queries";
+import BaseSearch from "../../../containers/BaseSearch";
+import {
+ SearchAttributes,
+ SearchAttributesVariables
+} from "./types/SearchAttributes";
+
+export const searchAttributes = gql`
+ ${pageInfoFragment}
+ query SearchAttributes(
+ $id: ID!
+ $after: String
+ $first: Int!
+ $query: String!
+ ) {
+ productType(id: $id) {
+ id
+ availableAttributes(
+ after: $after
+ first: $first
+ filter: { search: $query }
+ ) {
+ edges {
+ node {
+ id
+ name
+ slug
+ }
+ }
+ pageInfo {
+ ...PageInfoFragment
+ }
+ }
+ }
+ }
+`;
+
+export default BaseSearch<SearchAttributes, SearchAttributesVariables>(
+ searchAttributes
+);
diff --git a/saleor/static/dashboard-next/productTypes/containers/SearchAttributes/types/SearchAttributes.ts b/saleor/static/dashboard-next/productTypes/containers/SearchAttributes/types/SearchAttributes.ts
new file mode 100644
index 0000000000..b45411fa9f
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/containers/SearchAttributes/types/SearchAttributes.ts
@@ -0,0 +1,50 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: SearchAttributes
+// ====================================================
+
+export interface SearchAttributes_productType_availableAttributes_edges_node {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ slug: string | null;
+}
+
+export interface SearchAttributes_productType_availableAttributes_edges {
+ __typename: "AttributeCountableEdge";
+ node: SearchAttributes_productType_availableAttributes_edges_node;
+}
+
+export interface SearchAttributes_productType_availableAttributes_pageInfo {
+ __typename: "PageInfo";
+ endCursor: string | null;
+ hasNextPage: boolean;
+ hasPreviousPage: boolean;
+ startCursor: string | null;
+}
+
+export interface SearchAttributes_productType_availableAttributes {
+ __typename: "AttributeCountableConnection";
+ edges: SearchAttributes_productType_availableAttributes_edges[];
+ pageInfo: SearchAttributes_productType_availableAttributes_pageInfo;
+}
+
+export interface SearchAttributes_productType {
+ __typename: "ProductType";
+ id: string;
+ availableAttributes: SearchAttributes_productType_availableAttributes | null;
+}
+
+export interface SearchAttributes {
+ productType: SearchAttributes_productType | null;
+}
+
+export interface SearchAttributesVariables {
+ id: string;
+ after?: string | null;
+ first: number;
+ query: string;
+}
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
index 074c3c53c7..b5be01bfda 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
@@ -2,14 +2,13 @@ import Button from "@material-ui/core/Button";
import React from "react";
import { attributeUrl } from "@saleor/attributes/urls";
-import AssignAttributeDialog from "@saleor/components/AssignAttributeDialog";
import { WindowTitle } from "@saleor/components/WindowTitle";
-import SearchAttributes from "@saleor/containers/SearchAttributes";
import useBulkActions from "@saleor/hooks/useBulkActions";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import i18n from "@saleor/i18n";
import { getMutationState, maybe } from "@saleor/misc";
+import AssignAttributeDialog from "@saleor/productTypes/components/AssignAttributeDialog";
import { ReorderEvent } from "@saleor/types";
import { AttributeTypeEnum } from "@saleor/types/globalTypes";
import ProductTypeAttributeUnassignDialog from "../../components/ProductTypeAttributeUnassignDialog";
@@ -19,6 +18,7 @@ import ProductTypeDetailsPage, {
ProductTypeForm
} from "../../components/ProductTypeDetailsPage";
import ProductTypeOperations from "../../containers/ProductTypeOperations";
+import SearchAttributes from "../../containers/SearchAttributes";
import { TypedProductTypeDetailsQuery } from "../../queries";
import { AssignAttribute } from "../../types/AssignAttribute";
import { ProductTypeDelete } from "../../types/ProductTypeDelete";
@@ -326,6 +326,7 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({
<SearchAttributes
variables={{
first: 10,
+ id,
query: ""
}}
>
@@ -334,26 +335,36 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({
result.loadMore(
(prev, next) => {
if (
- prev.attributes.pageInfo.endCursor ===
- next.attributes.pageInfo.endCursor
+ prev.productType.availableAttributes
+ .pageInfo.endCursor ===
+ next.productType.availableAttributes
+ .pageInfo.endCursor
) {
return prev;
}
return {
...prev,
- attributes: {
- ...prev.attributes,
- edges: [
- ...prev.attributes.edges,
- ...next.attributes.edges
- ],
- pageInfo: next.attributes.pageInfo
+ productType: {
+ ...prev.productType,
+ availableAttributes: {
+ ...prev.productType.availableAttributes,
+ edges: [
+ ...prev.productType
+ .availableAttributes.edges,
+ ...next.productType
+ .availableAttributes.edges
+ ],
+ pageInfo:
+ next.productType.availableAttributes
+ .pageInfo
+ }
}
};
},
{
after:
- result.data.attributes.pageInfo.endCursor
+ result.data.productType.availableAttributes
+ .pageInfo.endCursor
}
);
@@ -362,7 +373,7 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({
{Object.keys(AttributeTypeEnum).map(key => (
<AssignAttributeDialog
attributes={maybe(() =>
- result.data.attributes.edges.map(
+ result.data.productType.availableAttributes.edges.map(
edge => edge.node
)
)}
@@ -381,7 +392,8 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({
onFetchMore={fetchMore}
hasMore={maybe(
() =>
- result.data.attributes.pageInfo
+ result.data.productType
+ .availableAttributes.pageInfo
.hasNextPage,
false
)}
diff --git a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx
index 689b43139d..1726eccfe8 100644
--- a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx
@@ -3,10 +3,10 @@ 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
-} from "../../../components/AssignAttributeDialog";
+} from "@saleor/productTypes/components/AssignAttributeDialog";
+import { formError } from "@saleor/storybook/misc";
import Decorator from "../../Decorator";
const props: AssignAttributeDialogProps = {