Skip to content

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

Fix types

dominik-zeglenda065e60cf13
diff --git a/saleor/static/dashboard-next/attributes/fixtures.ts b/saleor/static/dashboard-next/attributes/fixtures.ts
index c61b092f9d..de11823c5a 100644
--- a/saleor/static/dashboard-next/attributes/fixtures.ts
+++ b/saleor/static/dashboard-next/attributes/fixtures.ts
@@ -1,4 +1,5 @@
import { AttributeList_attributes_edges_node } from "./types/AttributeList";
+import { AttributeValueType } from "@saleor/types/globalTypes";
export const attribute = {
__typename: "Attribute" as "Attribute",
@@ -12,7 +13,7 @@ export const attribute = {
name: "John Doe",
slug: "john-doe",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -21,7 +22,7 @@ export const attribute = {
name: "Milionare Pirate",
slug: "milionare-pirate",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -41,7 +42,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "John Doe",
slug: "john-doe",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -50,7 +51,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Milionare Pirate",
slug: "milionare-pirate",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -69,7 +70,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "100g",
slug: "100g",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -78,7 +79,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "250g",
slug: "250g",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -87,7 +88,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "500g",
slug: "500g",
sortOrder: 2,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -96,7 +97,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "1kg",
slug: "1kg",
sortOrder: 3,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -115,7 +116,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Saleor",
slug: "saleor",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -134,7 +135,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "100g",
slug: "100g",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -143,7 +144,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "250g",
slug: "250g",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -152,7 +153,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "500g",
slug: "500g",
sortOrder: 2,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -171,7 +172,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Arabica",
slug: "arabica",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -180,7 +181,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Robusta",
slug: "robusta",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -199,7 +200,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Round",
slug: "round",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -208,7 +209,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "V-Neck",
slug: "v-neck",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -217,7 +218,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Polo",
slug: "polo",
sortOrder: 2,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -236,7 +237,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Blue",
slug: "blue",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -245,7 +246,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "White",
slug: "white",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -264,7 +265,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Soft",
slug: "soft",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -273,7 +274,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Hard",
slug: "hard",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -282,7 +283,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Middle soft",
slug: "middle-soft",
sortOrder: 2,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -291,7 +292,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Middle hard",
slug: "middle-hard",
sortOrder: 3,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -300,7 +301,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Middle",
slug: "middle",
sortOrder: 4,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -309,7 +310,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Very hard",
slug: "very-hard",
sortOrder: 5,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -328,7 +329,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Sour",
slug: "sour",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -337,7 +338,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Sweet",
slug: "sweet",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -356,7 +357,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "English",
slug: "english",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -365,7 +366,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Pirate",
slug: "pirate",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -384,7 +385,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Mirumee Press",
slug: "mirumee-press",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -393,7 +394,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "Saleor Publishing",
slug: "saleor-publishing",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
@@ -412,7 +413,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "XS",
slug: "xs",
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -421,7 +422,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "S",
slug: "s",
sortOrder: 1,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -430,7 +431,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "M",
slug: "m",
sortOrder: 2,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -439,7 +440,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "L",
slug: "l",
sortOrder: 3,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -448,7 +449,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "XL",
slug: "xl",
sortOrder: 4,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
{
@@ -457,7 +458,7 @@ export const attributes: AttributeList_attributes_edges_node[] = [
name: "XXL",
slug: "xxl",
sortOrder: 5,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
}
]
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
index 68bec78659..1b219b00b5 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
@@ -19,7 +19,6 @@ import CardTitle from "@saleor/components/CardTitle";
import Skeleton from "@saleor/components/Skeleton";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
-import { AttributeTypeEnum } from "../../../types/globalTypes";
import {
ProductTypeDetails_productType_productAttributes,
ProductTypeDetails_productType_variantAttributes
@@ -45,8 +44,8 @@ interface ProductTypeAttributesProps extends WithStyles<typeof styles> {
attributes:
| ProductTypeDetails_productType_productAttributes[]
| ProductTypeDetails_productType_variantAttributes[];
- type: AttributeTypeEnum;
- onAttributeAdd: (type: AttributeTypeEnum) => void;
+ type: string;
+ onAttributeAdd: (type: string) => void;
onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;
onAttributeUpdate: (id: string) => void;
}
@@ -65,7 +64,7 @@ const ProductTypeAttributes = withStyles(styles, {
<Card>
<CardTitle
title={
- type === AttributeTypeEnum.PRODUCT
+ type === "PRODUCT"
? i18n.t("Product Attributes")
: i18n.t("Variant Attributes")
}
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index 6cdd24f904..cfb7a72a4f 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -11,8 +11,11 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
-import { AttributeTypeEnum, WeightUnitsEnum } from "../../../types/globalTypes";
-import { ProductTypeDetails_productType } from "../../types/ProductTypeDetails";
+import { WeightUnitsEnum } from "../../../types/globalTypes";
+import {
+ ProductTypeDetails_productType,
+ ProductTypeDetails_taxTypes
+} from "../../types/ProductTypeDetails";
import ProductTypeAttributes from "../ProductTypeAttributes/ProductTypeAttributes";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
@@ -46,11 +49,8 @@ export interface ProductTypeDetailsPageProps {
disabled: boolean;
pageTitle: string;
saveButtonBarState: ConfirmButtonTransitionState;
- taxTypes: Array<{
- description: string;
- taxCode: string;
- }>;
- onAttributeAdd: (type: AttributeTypeEnum) => void;
+ taxTypes: ProductTypeDetails_taxTypes[];
+ onAttributeAdd: (type: string) => void;
onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;
onAttributeUpdate: (id: string) => void;
onBack: () => void;
@@ -118,75 +118,71 @@ const ProductTypeDetailsPage: React.StatelessComponent<
onSubmit={onSubmit}
confirmLeave
>
- {({ change, data, hasChanged, submit }) => {
- return (
- <Container>
- <AppHeader onBack={onBack}>{i18n.t("Product Types")}</AppHeader>
- <PageHeader title={pageTitle} />
- <Grid>
- <div>
- <ProductTypeDetails
- data={data}
- disabled={disabled}
- onChange={change}
- />
- <CardSpacer />
- <ProductTypeTaxes
- disabled={disabled}
- data={data}
- taxTypes={maybe(() => taxTypes, [
- { description: "", taxCode: "" }
- ])}
- onChange={change}
- />
- <CardSpacer />
- <ProductTypeAttributes
- attributes={maybe(() => productType.productAttributes)}
- type={AttributeTypeEnum.PRODUCT}
- onAttributeAdd={onAttributeAdd}
- onAttributeDelete={onAttributeDelete}
- onAttributeUpdate={onAttributeUpdate}
- />
- <CardSpacer />
- <ControlledCheckbox
- checked={data.hasVariants}
- disabled={disabled}
- label={i18n.t("This product type has variants")}
- name="hasVariants"
- onChange={change}
- />
- {data.hasVariants && (
- <>
- <CardSpacer />
- <ProductTypeAttributes
- attributes={maybe(() => productType.variantAttributes)}
- type={AttributeTypeEnum.VARIANT}
- onAttributeAdd={onAttributeAdd}
- onAttributeDelete={onAttributeDelete}
- onAttributeUpdate={onAttributeUpdate}
- />
- </>
- )}
- </div>
- <div>
- <ProductTypeShipping
- disabled={disabled}
- data={data}
- defaultWeightUnit={defaultWeightUnit}
- onChange={change}
- />
- </div>
- </Grid>
- <SaveButtonBar
- onCancel={onBack}
- onDelete={onDelete}
- onSave={submit}
- disabled={disabled || !hasChanged}
- state={saveButtonBarState}
- />
- </Container>
- );
- }}
+ {({ change, data, hasChanged, submit }) => (
+ <Container>
+ <AppHeader onBack={onBack}>{i18n.t("Product Types")}</AppHeader>
+ <PageHeader title={pageTitle} />
+ <Grid>
+ <div>
+ <ProductTypeDetails
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ <ProductTypeTaxes
+ disabled={disabled}
+ data={data}
+ taxTypes={maybe(() => taxTypes, [])}
+ onChange={change}
+ />
+ <CardSpacer />
+ <CardSpacer />
+ <ProductTypeAttributes
+ attributes={maybe(() => productType.productAttributes)}
+ type="PRODUCT"
+ onAttributeAdd={onAttributeAdd}
+ onAttributeDelete={onAttributeDelete}
+ onAttributeUpdate={onAttributeUpdate}
+ />
+ <CardSpacer />
+ <ControlledCheckbox
+ checked={data.hasVariants}
+ disabled={disabled}
+ label={i18n.t("This product type has variants")}
+ name="hasVariants"
+ onChange={change}
+ />
+ {data.hasVariants && (
+ <>
+ <CardSpacer />
+ <ProductTypeAttributes
+ attributes={maybe(() => productType.variantAttributes)}
+ type="VARIANT"
+ onAttributeAdd={onAttributeAdd}
+ onAttributeDelete={onAttributeDelete}
+ onAttributeUpdate={onAttributeUpdate}
+ />
+ </>
+ )}
+ </div>
+ <div>
+ <ProductTypeShipping
+ disabled={disabled}
+ data={data}
+ defaultWeightUnit={defaultWeightUnit}
+ onChange={change}
+ />
+ </div>
+ </Grid>
+ <SaveButtonBar
+ onCancel={onBack}
+ onDelete={onDelete}
+ onSave={submit}
+ disabled={disabled || !hasChanged}
+ state={saveButtonBarState}
+ />
+ </Container>
+ )}
</Form>
);
};
diff --git a/saleor/static/dashboard-next/productTypes/urls.ts b/saleor/static/dashboard-next/productTypes/urls.ts
index 2ba27d6351..8e7c8e6290 100644
--- a/saleor/static/dashboard-next/productTypes/urls.ts
+++ b/saleor/static/dashboard-next/productTypes/urls.ts
@@ -2,7 +2,6 @@ import { stringify as stringifyQs } from "qs";
import urlJoin from "url-join";
import { BulkAction, Dialog, Pagination, SingleAction } from "../types";
-import { AttributeTypeEnum } from "../types/globalTypes";
const productTypeSection = "/product-types/";
@@ -24,7 +23,7 @@ export type ProductTypeUrlDialog =
| "remove";
export type ProductTypeUrlQueryParams = Dialog<ProductTypeUrlDialog> &
SingleAction & {
- type?: AttributeTypeEnum;
+ type?: string;
};
export const productTypeUrl = (
id: string,
diff --git a/saleor/static/dashboard-next/storybook/stories/attributes/AttributeValueEditDialog.tsx b/saleor/static/dashboard-next/storybook/stories/attributes/AttributeValueEditDialog.tsx
index 7175551afe..b92906d018 100644
--- a/saleor/static/dashboard-next/storybook/stories/attributes/AttributeValueEditDialog.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/attributes/AttributeValueEditDialog.tsx
@@ -3,6 +3,7 @@ import * as React from "react";
import { attributes } from "@saleor/attributes/fixtures";
import { formError } from "@saleor/storybook/misc";
+import { AttributeValueType } from "@saleor/types/globalTypes";
import AttributeValueEditDialog, {
AttributeValueEditDialogProps
} from "../../../attributes/components/AttributeValueEditDialog";
@@ -12,7 +13,7 @@ const props: AttributeValueEditDialogProps = {
attributeValue: {
...attributes[0].values[0],
sortOrder: 0,
- type: "STRING",
+ type: AttributeValueType.STRING,
value: ""
},
confirmButtonState: "default",