From 5ace78f27971d0e53867aae6e4ec59e5924250ab Mon Sep 17 00:00:00 2001 From: Jakub Majorek Date: Mon, 24 May 2021 15:50:41 +0200 Subject: [PATCH] Change rateType from enum to string (#1121) * Change rateType from enum to string * Update snapshots * Fix accidental recurrency caused by race condition * Handle null type on SEO form * Trigger deployment * Fallback to empty string for undefined/null values --- locale/defaultMessages.json | 100 ---- schema.graphql | 59 +-- src/components/SeoForm/SeoForm.tsx | 12 +- .../SingleAutocompleteSelectField.tsx | 17 +- .../types/CountryWithTaxesFragment.ts | 4 +- .../__snapshots__/Stories.test.ts.snap | 46 +- src/storybook/stories/taxes/fixtures.ts | 429 +++++++++--------- .../CountryTaxesPage/CountryTaxesPage.tsx | 114 +---- src/taxes/types/CountryList.ts | 4 +- src/types/globalTypes.ts | 28 -- 10 files changed, 282 insertions(+), 531 deletions(-) diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 6cce5c472..abada90d7 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -6562,119 +6562,19 @@ "src_dot_taxes_dot_components_dot_CountryList_dot_577035076": { "string": "Country Name" }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_1040021611": { - "context": "tax rate", - "string": "Accommodation" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_1260218997": { - "context": "tax rate", - "string": "Social housing" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_1323923780": { - "context": "tax rate", - "string": "Bikes" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_1451721797": { - "context": "tax rate", - "string": "Newspapers" - }, "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_1755013298": { "string": "Category" }, "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2022558114": { "string": "Tax Rate" }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2185495435": { - "context": "tax rate", - "string": "Admission to cultural events" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2201910191": { - "context": "tax rate", - "string": "Baby foodstuffs" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_231341634": { - "context": "tax rate", - "string": "Domestic services" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2332795012": { - "context": "tax rate", - "string": "Foodstuffs" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2394675125": { - "context": "tax rate", - "string": "Books" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2465450918": { - "context": "tax rate", - "string": "Agricultural supplies" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2482229874": { - "context": "tax rate", - "string": "Standard" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2553129615": { - "context": "tax rate", - "string": "Passenger transport" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2557534380": { - "context": "tax rate", - "string": "Admission to entertainment events" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2584490289": { - "context": "tax rate", - "string": "Children's clothing" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2616794607": { - "context": "tax rate", - "string": "Admission to sporting events" - }, "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2737618795": { "context": "header", "string": "Tax Rates in {countryName}" }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_2948462144": { - "context": "tax rate", - "string": "Medical" - }, "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_3066312070": { "string": "No reduced tax categories found" }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_331632763": { - "context": "tax rate", - "string": "Hotels" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_331757068": { - "context": "tax rate", - "string": "E-books" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_3500730003": { - "context": "tax rate", - "string": "Domestic fuel" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_3525010870": { - "context": "tax rate", - "string": "Water" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_3911019760": { - "context": "tax rate", - "string": "Advertising" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_4199760668": { - "context": "tax rate", - "string": "Property renovations" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_752780599": { - "context": "tax rate", - "string": "Wine" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_776474251": { - "context": "tax rate", - "string": "Restaurants" - }, - "src_dot_taxes_dot_components_dot_CountryTaxesPage_dot_815189256": { - "context": "tax rate", - "string": "Pharmaceuticals" - }, "src_dot_taxes_dot_components_dot_TaxConfiguration_dot_142803418": { "string": "All products prices are entered with tax included" }, diff --git a/schema.graphql b/schema.graphql index ef042fadc..9fed07a1e 100644 --- a/schema.graphql +++ b/schema.graphql @@ -699,9 +699,9 @@ input CatalogueInput { } type Category implements Node & ObjectWithMetadata { + id: ID! seoTitle: String seoDescription: String - id: ID! name: String! description: JSONString slug: String! @@ -774,9 +774,9 @@ input CategorySortingInput { } type CategoryTranslatableContent implements Node { + id: ID! seoTitle: String seoDescription: String - id: ID! name: String! description: JSONString descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") @@ -791,9 +791,9 @@ type CategoryTranslate { } type CategoryTranslation implements Node { + id: ID! seoTitle: String seoDescription: String - id: ID! name: String! description: JSONString language: LanguageDisplay! @@ -813,7 +813,6 @@ type Channel implements Node { slug: String! currencyCode: String! hasOrders: Boolean! - shippingZones: [ShippingZone!]! } type ChannelActivate { @@ -1094,9 +1093,9 @@ type ChoiceValue { } type Collection implements Node & ObjectWithMetadata { + id: ID! seoTitle: String seoDescription: String - id: ID! name: String! description: JSONString slug: String! @@ -1122,9 +1121,9 @@ type CollectionBulkDelete { } type CollectionChannelListing implements Node { + id: ID! publicationDate: Date isPublished: Boolean! - id: ID! channel: Channel! } @@ -1250,9 +1249,9 @@ input CollectionSortingInput { } type CollectionTranslatableContent implements Node { + id: ID! seoTitle: String seoDescription: String - id: ID! name: String! description: JSONString descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") @@ -1267,9 +1266,9 @@ type CollectionTranslate { } type CollectionTranslation implements Node { + id: ID! seoTitle: String seoDescription: String - id: ID! name: String! description: JSONString language: LanguageDisplay! @@ -2975,6 +2974,8 @@ type Order implements Node & ObjectWithMetadata { availableShippingMethods: [ShippingMethod] invoices: [Invoice] number: String + original: ID + origin: OrderOriginEnum! isPaid: Boolean! paymentStatus: PaymentChargeStatusEnum! paymentStatusDisplay: String! @@ -3359,6 +3360,12 @@ type OrderMarkAsPaid { errors: [OrderError!]! } +enum OrderOriginEnum { + CHECKOUT + DRAFT + REISSUE +} + type OrderRefund { order: Order orderErrors: [OrderError!]! @deprecated(reason: "Use errors field instead. This field will be removed in Saleor 4.0.") @@ -3489,9 +3496,9 @@ type OrderVoid { } type Page implements Node & ObjectWithMetadata { + id: ID! seoTitle: String seoDescription: String - id: ID! title: String! content: JSONString publicationDate: Date @@ -3625,9 +3632,9 @@ input PageSortingInput { } type PageTranslatableContent implements Node { + id: ID! seoTitle: String seoDescription: String - id: ID! title: String! content: JSONString contentJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.") @@ -3642,9 +3649,9 @@ type PageTranslate { } type PageTranslation implements Node { + id: ID! seoTitle: String seoDescription: String - id: ID! title: String! content: JSONString language: LanguageDisplay! @@ -4759,7 +4766,7 @@ type Query { type ReducedRate { rate: Float! - rateType: TaxRateType! + rateType: String! } type RefreshToken { @@ -5443,34 +5450,6 @@ input StockInput { quantity: Int! } -enum TaxRateType { - ACCOMMODATION - ADMISSION_TO_CULTURAL_EVENTS - ADMISSION_TO_ENTERTAINMENT_EVENTS - ADMISSION_TO_SPORTING_EVENTS - ADVERTISING - AGRICULTURAL_SUPPLIES - BABY_FOODSTUFFS - BIKES - BOOKS - CHILDRENS_CLOTHING - DOMESTIC_FUEL - DOMESTIC_SERVICES - E_BOOKS - FOODSTUFFS - HOTELS - MEDICAL - NEWSPAPERS - PASSENGER_TRANSPORT - PHARMACEUTICALS - PROPERTY_RENOVATIONS - RESTAURANTS - SOCIAL_HOUSING - STANDARD - WATER - WINE -} - type TaxType { description: String taxCode: String diff --git a/src/components/SeoForm/SeoForm.tsx b/src/components/SeoForm/SeoForm.tsx index 702caae74..ab7a12063 100644 --- a/src/components/SeoForm/SeoForm.tsx +++ b/src/components/SeoForm/SeoForm.tsx @@ -81,7 +81,7 @@ const useStyles = makeStyles( ); interface SeoFormProps { - description?: string; + description?: string | null; descriptionPlaceholder: string; disabled?: boolean; errors?: Array< @@ -90,7 +90,7 @@ interface SeoFormProps { loading?: boolean; helperText?: string; allowEmptySlug?: boolean; - title: string; + title: string | null; slug: string; slugPlaceholder?: string; titlePlaceholder: string; @@ -224,7 +224,7 @@ const SeoForm: React.FC = props => { /> maxTitleLength} + error={title?.length > maxTitleLength} name={SeoField.title} label={
@@ -251,7 +251,7 @@ const SeoForm: React.FC = props => { } }} helperText={intl.formatMessage(seoFieldMessage)} - value={title} + value={title ?? ""} disabled={loading || disabled} placeholder={titlePlaceholder} onChange={onChange} @@ -259,7 +259,7 @@ const SeoForm: React.FC = props => { /> maxDescriptionLength} + error={description?.length > maxDescriptionLength} name={SeoField.description} label={
@@ -286,7 +286,7 @@ const SeoForm: React.FC = props => { maxLength: maxDescriptionLength } }} - value={description} + value={description ?? ""} onChange={onChange} disabled={loading || disabled} fullWidth diff --git a/src/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx b/src/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx index b88c0730d..350030dcc 100644 --- a/src/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx +++ b/src/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx @@ -4,7 +4,7 @@ import { ExtendedFormHelperTextProps } from "@saleor/channels/components/Channel import { makeStyles } from "@saleor/theme"; import { FetchMoreProps } from "@saleor/types"; import classNames from "classnames"; -import Downshift, { ControllerStateAndHelpers } from "downshift"; +import Downshift from "downshift"; import { filter } from "fuzzaldrin"; import React from "react"; @@ -81,13 +81,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC { - stateAndHelpers.reset({ - inputValue: "" - }); + const handleChange = (item: string) => { onChange({ target: { name, @@ -104,7 +98,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC displayValue || ""} onInputValueChange={value => debounceFn(value)} onSelect={handleChange} - selectedItem={value} + selectedItem={value || ""} > {({ getInputProps, @@ -157,11 +151,6 @@ const SingleAutocompleteSelectFieldComponent: React.FC
+ > + +
+ > + +
- Admission to cultural events + ADMISSION_TO_CULTURAL_EVENTS - Admission to entertainment events + ADMISSION_TO_ENTERTAINMENT_EVENTS - Books + BOOKS - Foodstuffs + FOODSTUFFS - Hotels + HOTELS - Newspapers + NEWSPAPERS - Passenger transport + PASSENGER_TRANSPORT - Pharmaceuticals + PHARMACEUTICALS { - return { - [TaxRateType.ACCOMMODATION]: intl.formatMessage({ - defaultMessage: "Accommodation", - description: "tax rate" - }), - [TaxRateType.ADMISSION_TO_CULTURAL_EVENTS]: intl.formatMessage({ - defaultMessage: "Admission to cultural events", - description: "tax rate" - }), - [TaxRateType.ADMISSION_TO_ENTERTAINMENT_EVENTS]: intl.formatMessage({ - defaultMessage: "Admission to entertainment events", - description: "tax rate" - }), - [TaxRateType.ADMISSION_TO_SPORTING_EVENTS]: intl.formatMessage({ - defaultMessage: "Admission to sporting events", - description: "tax rate" - }), - [TaxRateType.ADVERTISING]: intl.formatMessage({ - defaultMessage: "Advertising", - description: "tax rate" - }), - [TaxRateType.AGRICULTURAL_SUPPLIES]: intl.formatMessage({ - defaultMessage: "Agricultural supplies", - description: "tax rate" - }), - [TaxRateType.BABY_FOODSTUFFS]: intl.formatMessage({ - defaultMessage: "Baby foodstuffs", - description: "tax rate" - }), - [TaxRateType.BIKES]: intl.formatMessage({ - defaultMessage: "Bikes", - description: "tax rate" - }), - [TaxRateType.BOOKS]: intl.formatMessage({ - defaultMessage: "Books", - description: "tax rate" - }), - [TaxRateType.CHILDRENS_CLOTHING]: intl.formatMessage({ - defaultMessage: "Children's clothing", - description: "tax rate" - }), - [TaxRateType.DOMESTIC_FUEL]: intl.formatMessage({ - defaultMessage: "Domestic fuel", - description: "tax rate" - }), - [TaxRateType.DOMESTIC_SERVICES]: intl.formatMessage({ - defaultMessage: "Domestic services", - description: "tax rate" - }), - [TaxRateType.E_BOOKS]: intl.formatMessage({ - defaultMessage: "E-books", - description: "tax rate" - }), - [TaxRateType.FOODSTUFFS]: intl.formatMessage({ - defaultMessage: "Foodstuffs", - description: "tax rate" - }), - [TaxRateType.HOTELS]: intl.formatMessage({ - defaultMessage: "Hotels", - description: "tax rate" - }), - [TaxRateType.MEDICAL]: intl.formatMessage({ - defaultMessage: "Medical", - description: "tax rate" - }), - [TaxRateType.NEWSPAPERS]: intl.formatMessage({ - defaultMessage: "Newspapers", - description: "tax rate" - }), - [TaxRateType.PASSENGER_TRANSPORT]: intl.formatMessage({ - defaultMessage: "Passenger transport", - description: "tax rate" - }), - [TaxRateType.PHARMACEUTICALS]: intl.formatMessage({ - defaultMessage: "Pharmaceuticals", - description: "tax rate" - }), - [TaxRateType.PROPERTY_RENOVATIONS]: intl.formatMessage({ - defaultMessage: "Property renovations", - description: "tax rate" - }), - [TaxRateType.RESTAURANTS]: intl.formatMessage({ - defaultMessage: "Restaurants", - description: "tax rate" - }), - [TaxRateType.SOCIAL_HOUSING]: intl.formatMessage({ - defaultMessage: "Social housing", - description: "tax rate" - }), - [TaxRateType.STANDARD]: intl.formatMessage({ - defaultMessage: "Standard", - description: "tax rate" - }), - [TaxRateType.WATER]: intl.formatMessage({ - defaultMessage: "Water", - description: "tax rate" - }), - [TaxRateType.WINE]: intl.formatMessage({ - defaultMessage: "Wine", - description: "tax rate" - }) - }; -} - export interface CountryTaxesPageProps { countryName: string; taxCategories: CountryList_shop_countries_vat_reducedRates[]; @@ -145,7 +39,6 @@ const CountryTaxesPage: React.FC = props => { const classes = useStyles(props); const intl = useIntl(); - const translatedTaxRates = translateTaxRates(intl); return ( @@ -189,10 +82,7 @@ const CountryTaxesPage: React.FC = props => { key={taxCategory ? taxCategory.rateType : "skeleton"} > - {maybe( - () => translatedTaxRates[taxCategory.rateType], - - )} + {taxCategory?.rateType ?? } {maybe( diff --git a/src/taxes/types/CountryList.ts b/src/taxes/types/CountryList.ts index e8d00d586..6513e863b 100644 --- a/src/taxes/types/CountryList.ts +++ b/src/taxes/types/CountryList.ts @@ -3,15 +3,13 @@ // @generated // This file was automatically generated and should not be edited. -import { TaxRateType } from "./../../types/globalTypes"; - // ==================================================== // GraphQL query operation: CountryList // ==================================================== export interface CountryList_shop_countries_vat_reducedRates { __typename: "ReducedRate"; - rateType: TaxRateType; + rateType: string; rate: number; } diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts index 5c46094be..8f9e814e2 100644 --- a/src/types/globalTypes.ts +++ b/src/types/globalTypes.ts @@ -951,34 +951,6 @@ export enum StockErrorCode { UNIQUE = "UNIQUE", } -export enum TaxRateType { - ACCOMMODATION = "ACCOMMODATION", - ADMISSION_TO_CULTURAL_EVENTS = "ADMISSION_TO_CULTURAL_EVENTS", - ADMISSION_TO_ENTERTAINMENT_EVENTS = "ADMISSION_TO_ENTERTAINMENT_EVENTS", - ADMISSION_TO_SPORTING_EVENTS = "ADMISSION_TO_SPORTING_EVENTS", - ADVERTISING = "ADVERTISING", - AGRICULTURAL_SUPPLIES = "AGRICULTURAL_SUPPLIES", - BABY_FOODSTUFFS = "BABY_FOODSTUFFS", - BIKES = "BIKES", - BOOKS = "BOOKS", - CHILDRENS_CLOTHING = "CHILDRENS_CLOTHING", - DOMESTIC_FUEL = "DOMESTIC_FUEL", - DOMESTIC_SERVICES = "DOMESTIC_SERVICES", - E_BOOKS = "E_BOOKS", - FOODSTUFFS = "FOODSTUFFS", - HOTELS = "HOTELS", - MEDICAL = "MEDICAL", - NEWSPAPERS = "NEWSPAPERS", - PASSENGER_TRANSPORT = "PASSENGER_TRANSPORT", - PHARMACEUTICALS = "PHARMACEUTICALS", - PROPERTY_RENOVATIONS = "PROPERTY_RENOVATIONS", - RESTAURANTS = "RESTAURANTS", - SOCIAL_HOUSING = "SOCIAL_HOUSING", - STANDARD = "STANDARD", - WATER = "WATER", - WINE = "WINE", -} - export enum UploadErrorCode { GRAPHQL_ERROR = "GRAPHQL_ERROR", }