Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add input type to attributes
dominik-zeglen97ab3a413f48
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx b/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsxindex 7f49651240..311848106a 100644--- a/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx+++ b/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx@@ -5,17 +5,30 @@ import React from "react";import CardTitle from "@saleor/components/CardTitle";import FormSpacer from "@saleor/components/FormSpacer";+import SingleSelectField from "@saleor/components/SingleSelectField";import i18n from "@saleor/i18n";import { FormErrors } from "@saleor/types";+import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";import { AttributePageFormData } from "../AttributePage";export interface AttributeDetailsProps {data: AttributePageFormData;disabled: boolean;- errors: FormErrors<"name" | "slug">;+ errors: FormErrors<"name" | "slug" | "inputType">;onChange: (event: React.ChangeEvent<any>) => void;}+const inputTypeChoices = [+ {+ label: i18n.t("Dropdown"),+ value: AttributeInputTypeEnum.DROPDOWN+ },+ {+ label: i18n.t("Multiple Select"),+ value: AttributeInputTypeEnum.MULTISELECT+ }+];+const AttributeDetails: React.FC<AttributeDetailsProps> = ({data,disabled,@@ -42,10 +55,28 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({label={i18n.t("Attribute Code")}name={"slug" as keyof AttributePageFormData}fullWidth- helperText={errors.slug}+ helperText={+ errors.slug ||+ i18n.t("This is used internally. Make sure you don’t use spaces", {+ context: "slug input"+ })+ }value={data.slug}onChange={onChange}/>+ <FormSpacer />+ <SingleSelectField+ choices={inputTypeChoices}+ disabled={disabled}+ error={!!errors.inputType}+ hint={errors.inputType}+ label={i18n.t("Catalog Input type for Store Owner", {+ context: "attribute input type"+ })}+ name="inputType"+ onChange={onChange}+ value={data.inputType}+ /></CardContent></Card>);diff --git a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsxindex 0396b78e5f..5c001d36a7 100644--- a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx+++ b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx@@ -11,6 +11,7 @@ import SaveButtonBar from "@saleor/components/SaveButtonBar";import i18n from "@saleor/i18n";import { maybe } from "@saleor/misc";import { UserError } from "@saleor/types";+import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";import {AttributeDetailsFragment,AttributeDetailsFragment_values@@ -33,6 +34,7 @@ export interface AttributePageProps {}export interface AttributePageFormData {+ inputType: AttributeInputTypeEnum;name: string;slug: string;}@@ -53,10 +55,15 @@ const AttributePage: React.FC<AttributePageProps> = ({const initialForm: AttributePageFormData =attribute === null? {+ inputType: AttributeInputTypeEnum.DROPDOWN,name: "",slug: ""}: {+ inputType: maybe(+ () => attribute.inputType,+ AttributeInputTypeEnum.DROPDOWN+ ),name: maybe(() => attribute.name, ""),slug: maybe(() => attribute.slug, "")};diff --git a/saleor/static/dashboard-next/attributes/fixtures.ts b/saleor/static/dashboard-next/attributes/fixtures.tsindex 098f311d7e..c4b4d95730 100644--- a/saleor/static/dashboard-next/attributes/fixtures.ts+++ b/saleor/static/dashboard-next/attributes/fixtures.ts@@ -1,9 +1,13 @@-import { AttributeValueType } from "@saleor/types/globalTypes";+import {+ AttributeInputTypeEnum,+ AttributeValueType+} from "@saleor/types/globalTypes";import { AttributeList_attributes_edges_node } from "./types/AttributeList";export const attribute = {__typename: "Attribute" as "Attribute",id: "UHJvZHVjdEF0dHJpYnV0ZTo5",+ inputType: AttributeInputTypeEnum.DROPDOWN,name: "Author",slug: "author",values: [diff --git a/saleor/static/dashboard-next/attributes/queries.ts b/saleor/static/dashboard-next/attributes/queries.tsindex 7a06aa6e49..bec2fcaaf3 100644--- a/saleor/static/dashboard-next/attributes/queries.ts+++ b/saleor/static/dashboard-next/attributes/queries.ts@@ -19,6 +19,7 @@ export const attributeDetailsFragment = gql`${attributeFragment}fragment AttributeDetailsFragment on Attribute {...AttributeFragment+ inputTypevalues {idnamediff --git a/saleor/static/dashboard-next/attributes/types/AttributeCreate.ts b/saleor/static/dashboard-next/attributes/types/AttributeCreate.tsindex f6edb72fb8..c1461dc98e 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeCreate.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeCreate.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeCreateInput, AttributeValueType } from "./../../types/globalTypes";+import { AttributeCreateInput, AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL mutation operation: AttributeCreate@@ -29,6 +29,7 @@ export interface AttributeCreate_attributeCreate_attribute {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeCreate_attributeCreate_attribute_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeDetails.ts b/saleor/static/dashboard-next/attributes/types/AttributeDetails.tsindex 9c3947fa51..0bdcf6636f 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeDetails.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeDetails.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeValueType } from "./../../types/globalTypes";+import { AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL query operation: AttributeDetails@@ -23,6 +23,7 @@ export interface AttributeDetails_attribute {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeDetails_attribute_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeDetailsFragment.ts b/saleor/static/dashboard-next/attributes/types/AttributeDetailsFragment.tsindex 95d1fd1bd9..7115a88bdb 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeDetailsFragment.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeDetailsFragment.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeValueType } from "./../../types/globalTypes";+import { AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL fragment: AttributeDetailsFragment@@ -23,5 +23,6 @@ export interface AttributeDetailsFragment {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeDetailsFragment_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeUpdate.ts b/saleor/static/dashboard-next/attributes/types/AttributeUpdate.tsindex d6b0eecc59..692843b32d 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeUpdate.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeUpdate.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeUpdateInput, AttributeValueType } from "./../../types/globalTypes";+import { AttributeUpdateInput, AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL mutation operation: AttributeUpdate@@ -29,6 +29,7 @@ export interface AttributeUpdate_attributeUpdate_attribute {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeUpdate_attributeUpdate_attribute_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeValueCreate.ts b/saleor/static/dashboard-next/attributes/types/AttributeValueCreate.tsindex 79c42a914b..2fd60d2f1d 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeValueCreate.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeValueCreate.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeValueCreateInput, AttributeValueType } from "./../../types/globalTypes";+import { AttributeValueCreateInput, AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL mutation operation: AttributeValueCreate@@ -29,6 +29,7 @@ export interface AttributeValueCreate_attributeValueCreate_attribute {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeValueCreate_attributeValueCreate_attribute_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeValueDelete.ts b/saleor/static/dashboard-next/attributes/types/AttributeValueDelete.tsindex 3841344364..224e480d63 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeValueDelete.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeValueDelete.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeValueType } from "./../../types/globalTypes";+import { AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL mutation operation: AttributeValueDelete@@ -29,6 +29,7 @@ export interface AttributeValueDelete_attributeValueDelete_attribute {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeValueDelete_attributeValueDelete_attribute_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeValueUpdate.ts b/saleor/static/dashboard-next/attributes/types/AttributeValueUpdate.tsindex a223175d05..31e07d92a4 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeValueUpdate.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeValueUpdate.ts@@ -2,7 +2,7 @@/* eslint-disable */// This file was automatically generated and should not be edited.-import { AttributeValueCreateInput, AttributeValueType } from "./../../types/globalTypes";+import { AttributeValueCreateInput, AttributeInputTypeEnum, AttributeValueType } from "./../../types/globalTypes";// ====================================================// GraphQL mutation operation: AttributeValueUpdate@@ -29,6 +29,7 @@ export interface AttributeValueUpdate_attributeValueUpdate_attribute {id: string;name: string | null;slug: string | null;+ inputType: AttributeInputTypeEnum | null;values: (AttributeValueUpdate_attributeValueUpdate_attribute_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx b/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsxindex d9ba660ef7..82e4d30589 100644--- a/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx@@ -1,11 +1,12 @@import { storiesOf } from "@storybook/react";import React from "react";-import { attribute } from "@saleor/attributes/fixtures";-import { formError } from "@saleor/storybook/misc";import AttributePage, {AttributePageProps-} from "../../../attributes/components/AttributePage";+} from "@saleor/attributes/components/AttributePage";+import { attribute } from "@saleor/attributes/fixtures";+import { formError } from "@saleor/storybook/misc";+import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";import Decorator from "../../Decorator";const props: AttributePageProps = {@@ -37,4 +38,13 @@ storiesOf("Views / Attributes / Attribute details", module).add("form errors", () => (<AttributePage {...props} errors={["name", "slug"].map(formError)} />))+ .add("multiple select input", () => (+ <AttributePage+ {...props}+ attribute={{+ ...attribute,+ inputType: AttributeInputTypeEnum.MULTISELECT+ }}+ />+ )).add("create", () => <AttributePage {...props} attribute={null} />);