Skip to content

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

Fix bugs

dominik-zeglen6dcd072a0ac8
diff --git a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
index fb6c706622..8dc9818fee 100644
--- a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
+++ b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
@@ -114,14 +114,10 @@ const SingleAutocompleteSelectFieldComponent = decorate<
</MenuItem>
) : (
<>
- {choices.map(suggestion => (
+ {choices.map((suggestion, index) => (
<MenuItem
key={JSON.stringify(suggestion)}
- selected={
- selectedItem
- ? suggestion.value === selectedItem.value
- : false
- }
+ selected={highlightedIndex === index}
component="div"
{...getItemProps({ item: suggestion })}
>
diff --git a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
index 9b0bab7878..8ee05b662f 100644
--- a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
@@ -4,7 +4,7 @@ import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import * as React from "react";
-import { AttributeType, AttributeValueType } from "../..";
+import { AttributeType } from "../..";
import CardTitle from "../../../components/CardTitle";
import { FormSpacer } from "../../../components/FormSpacer";
import MultiSelectField from "../../../components/MultiSelectField";
@@ -56,6 +56,9 @@ interface ProductOrganizationProps {
}
const decorate = withStyles(theme => ({
+ card: {
+ overflow: "visible" as "visible"
+ },
cardSubtitle: {
fontSize: "1rem",
margin: `${theme.spacing.unit * 3}px 0`
@@ -89,8 +92,23 @@ const ProductOrganization = decorate<ProductOrganizationProps>(
: [];
const getAttributeName = (slug: string) =>
unrolledAttributes.filter(a => a.slug === slug)[0].slug;
- const getAttributeValue = (slug: string) =>
- data.attributes.filter(a => a.slug === slug)[0].value;
+ const getAttributeValue = (slug: string) => {
+ if (unrolledAttributes && unrolledAttributes.length > 0) {
+ const value = data.attributes.filter(a => a.slug === slug)[0];
+ const matches = unrolledAttributes
+ .filter(a => a.slug === slug)[0]
+ .values.filter(v => v.slug === value.value);
+ const label = matches.length > 0 ? matches[0].name : value.value;
+ return {
+ label,
+ value
+ };
+ }
+ return {
+ label: "",
+ value: ""
+ };
+ };
const getAttributeValues = (slug: string) =>
unrolledAttributes.filter(a => a.slug === slug)[0].values;
const handleProductTypeSelect = (
@@ -123,7 +141,7 @@ const ProductOrganization = decorate<ProductOrganizationProps>(
value: string;
};
}>
- ) =>
+ ) => {
onChange({
...event,
target: {
@@ -132,13 +150,14 @@ const ProductOrganization = decorate<ProductOrganizationProps>(
value: data.attributes.map(
a =>
a.slug === event.target.name
- ? { slug: a.slug, value: event.target.value }
+ ? { slug: a.slug, value: event.target.value.value }
: a
)
}
});
+ };
return (
- <Card>
+ <Card className={classes.card}>
<CardTitle title={i18n.t("Organize Product")} />
<CardContent>
<SingleAutocompleteSelectField
@@ -184,7 +203,7 @@ const ProductOrganization = decorate<ProductOrganizationProps>(
data.attributes.map((item, index) => {
return (
<React.Fragment key={index}>
- <SingleSelectField
+ <SingleAutocompleteSelectField
disabled={disabled}
name={item.slug}
label={getAttributeName(item.slug)}
@@ -195,6 +214,7 @@ const ProductOrganization = decorate<ProductOrganizationProps>(
value: v.slug
}))}
key={index}
+ custom
/>
<FormSpacer />
</React.Fragment>
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index 20c6b64b3a..1e3caca521 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -51,6 +51,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
pushMessage({
text: i18n.t("Image successfully uploaded")
});
+
const product = data ? data.product : undefined;
const allCollections =
data && data.collections
@@ -79,6 +80,27 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
reorderProductImages,
updateProduct
}) => {
+ const handleSubmit = data => {
+ if (product) {
+ updateProduct.mutate({
+ attributes: data.attributes,
+ availableOn:
+ data.availableOn !== ""
+ ? data.availableOn
+ : null,
+ category: data.category,
+ chargeTaxes: data.chargeTaxes,
+ collections: data.collections,
+ description: data.description,
+ id: product.id,
+ isFeatured: data.featured,
+ isPublished: data.available,
+ name: data.name,
+ price: data.price
+ });
+ }
+ };
+
const disableFormSave =
createProductImage.loading ||
deleteProduct.loading ||
@@ -130,42 +152,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
});
}
}}
- onSubmit={data => {
- if (product) {
- const attributes = product.attributes
- .map(item => ({
- slug: item.attribute.slug,
- values: item.attribute.values
- }))
- .map(({ slug, values }) => {
- const valueSlug = data[slug];
- const value = values.filter(
- item => item.slug === valueSlug
- );
- return {
- slug,
- value: value ? value[0].name : valueSlug
- };
- });
-
- updateProduct.mutate({
- attributes,
- availableOn:
- data.availableOn !== ""
- ? data.availableOn
- : null,
- category: data.category,
- chargeTaxes: data.chargeTaxes,
- collections: data.collections,
- description: data.description,
- id: product.id,
- isFeatured: data.featured,
- isPublished: data.available,
- name: data.name,
- price: data.price
- });
- }
- }}
+ onSubmit={handleSubmit}
onVariantAdd={() => {}}
onVariantShow={variantId => () =>
navigate(