Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add autocomplete select to taxes
Krzysztof Bialoglowicza7ab1045b260
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsxindex 051cf9b4ce..53d1764153 100644--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx@@ -11,11 +11,7 @@ import PageHeader from "@saleor/components/PageHeader";import SaveButtonBar from "@saleor/components/SaveButtonBar";import i18n from "../../../i18n";import { maybe } from "../../../misc";-import {- AttributeTypeEnum,- TaxRateType,- WeightUnitsEnum-} from "../../../types/globalTypes";+import { AttributeTypeEnum, WeightUnitsEnum } from "../../../types/globalTypes";import { ProductTypeDetails_productType } from "../../types/ProductTypeDetails";import ProductTypeAttributes from "../ProductTypeAttributes/ProductTypeAttributes";import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";@@ -31,7 +27,10 @@ export interface ProductTypeForm {name: string;hasVariants: boolean;isShippingRequired: boolean;- taxRate: TaxRateType;+ taxType: {+ label: string;+ value: string;+ };productAttributes: ChoiceType[];variantAttributes: ChoiceType[];weight: number;@@ -47,6 +46,10 @@ export interface ProductTypeDetailsPageProps {disabled: boolean;pageTitle: string;saveButtonBarState: ConfirmButtonTransitionState;+ taxTypes: Array<{+ description: string;+ taxCode: string;+ }>;onAttributeAdd: (type: AttributeTypeEnum) => void;onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;onAttributeUpdate: (id: string) => void;@@ -64,6 +67,7 @@ const ProductTypeDetailsPage: React.StatelessComponent<pageTitle,productType,saveButtonBarState,+ taxTypes,onAttributeAdd,onAttributeDelete,onAttributeUpdate,@@ -88,10 +92,16 @@ const ProductTypeDetailsPage: React.StatelessComponent<value: attribute.id})): [],- taxRate:- maybe(() => productType.taxRate) !== undefined- ? productType.taxRate- : null,+ taxType:+ maybe(() => productType.taxType) !== undefined+ ? {+ label: productType.taxType.description,+ value: productType.taxType.taxCode+ }+ : {+ label: "",+ value: ""+ },variantAttributes:maybe(() => productType.variantAttributes) !== undefined? productType.variantAttributes.map(attribute => ({@@ -108,70 +118,75 @@ const ProductTypeDetailsPage: React.StatelessComponent<onSubmit={onSubmit}confirmLeave>- {({ 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}- />- <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}- />- <CardSpacer />- <ProductTypeTaxes- disabled={disabled}- data={data}- onChange={change}- />- </div>- </Grid>- <SaveButtonBar- onCancel={onBack}- onDelete={onDelete}- onSave={submit}- disabled={disabled || !hasChanged}- state={saveButtonBarState}- />- </Container>- )}+ {({ 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 />+ <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}+ />+ <CardSpacer />+ <ProductTypeTaxes+ disabled={disabled}+ data={data}+ taxTypes={maybe(() => taxTypes, [+ { description: "", taxCode: "" }+ ])}+ 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/components/ProductTypeTaxes/ProductTypeTaxes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsxindex 77dff89644..8276e36340 100644--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx@@ -1,44 +1,61 @@import Card from "@material-ui/core/Card";import CardContent from "@material-ui/core/CardContent";+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";import React from "react";import CardTitle from "@saleor/components/CardTitle";-import SingleSelectField from "@saleor/components/SingleSelectField";+import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField";import i18n from "../../../i18n";-import { translatedTaxRates as taxRates } from "../../../misc";-import { TaxRateType } from "../../../types/globalTypes";+import { maybe } from "../../../misc";+import { ProductTypeForm } from "../ProductTypeDetailsPage/ProductTypeDetailsPage";-interface ProductTypeTaxesProps {+interface ProductTypeTaxesProps extends WithStyles<typeof styles> {data: {- taxRate: TaxRateType | null;+ taxType: {+ label: string;+ value: string;+ };};+ taxTypes: Array<{+ description: string;+ taxCode: string;+ }>;disabled: boolean;onChange: (event: React.ChangeEvent<any>) => void;}-const taxRateChoices = Object.keys(taxRates()).map(key => ({- label: taxRates()[key],- value: key-}));-const ProductTypeTaxes: React.StatelessComponent<ProductTypeTaxesProps> = ({- data,- disabled,- onChange-}) => (- <Card>- <CardTitle title={i18n.t("Taxes")} />- <CardContent>- <SingleSelectField- choices={taxRateChoices}- disabled={disabled}- label={i18n.t("Tax rate (optional)", {- context: "select field label"- })}- name="taxRate"- onChange={onChange}- value={data.taxRate}- />- </CardContent>- </Card>++const styles = createStyles({+ root: {+ overflow: "visible"+ }+});++const ProductTypeTaxes = withStyles(styles, { name: "ProductTypeTaxes" })(+ ({ classes, data, disabled, taxTypes, onChange }: ProductTypeTaxesProps) => (+ <Card className={classes.root}>+ <CardTitle title={i18n.t("Taxes")} />+ <CardContent>+ <SingleAutocompleteSelectField+ disabled={disabled}+ label={i18n.t("Taxes")}+ name={"taxType" as keyof ProductTypeForm}+ onChange={onChange}+ value={{+ label: data.taxType.label,+ value: data.taxType.value+ }}+ choices={maybe(+ () =>+ taxTypes.map(c => ({ label: c.description, value: c.taxCode })),+ []+ )}+ InputProps={{+ autoComplete: "off"+ }}+ />+ </CardContent>+ </Card>+ ));ProductTypeTaxes.displayName = "ProductTypeTaxes";export default ProductTypeTaxes;diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsxindex 9dccc06e2a..15a3973fbd 100644--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx@@ -21,7 +21,8 @@ const props: Omit<ProductTypeDetailsPageProps, "classes"> = {onSubmit: () => undefined,pageTitle: productType.name,productType,- saveButtonBarState: "default"+ saveButtonBarState: "default",+ taxTypes: []};storiesOf("Views / Product types / Product type details", module)