Skip to content

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

Add basic components

dominik-zeglen73fc08dcdc14
diff --git a/saleor/static/dashboard-next/collections/fixtures.ts b/saleor/static/dashboard-next/collections/fixtures.ts
index 423cf82fc8..8fc75b09be 100644
--- a/saleor/static/dashboard-next/collections/fixtures.ts
+++ b/saleor/static/dashboard-next/collections/fixtures.ts
@@ -22,6 +22,46 @@ export const collections: CollectionList_collections_edges_node[] = [
__typename: "ProductCountableConnection",
totalCount: 4
}
+ },
+ {
+ __typename: "Collection",
+ id: "Q29sbGVjdGlvbjoz",
+ isPublished: true,
+ name: "Vintage vibes",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 4
+ }
+ },
+ {
+ __typename: "Collection",
+ id: "Q29sbGVjdGlvbjoa",
+ isPublished: true,
+ name: "Merry Christmas",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 4
+ }
+ },
+ {
+ __typename: "Collection",
+ id: "Q29sbGVjdGlvbjob",
+ isPublished: true,
+ name: "80s Miami",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 4
+ }
+ },
+ {
+ __typename: "Collection",
+ id: "Q29sbGVjdGlvbjoc",
+ isPublished: true,
+ name: "Yellow Submarine 2019",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 4
+ }
}
];
export const collection: (
diff --git a/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx
index 0c177fc5ea..8faa438768 100644
--- a/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx
+++ b/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx
@@ -10,12 +10,14 @@ import {
import TextField from "@material-ui/core/TextField";
import Downshift, { ControllerStateAndHelpers } from "downshift";
import React from "react";
+import { compareTwoStrings } from "string-similarity";
-import i18n from "../../i18n";
-import ArrowDropdownIcon from "../../icons/ArrowDropdown";
-import Debounce, { DebounceProps } from "../Debounce";
+import Checkbox from "@saleor/components/Checkbox";
+import Debounce, { DebounceProps } from "@saleor/components/Debounce";
+import i18n from "@saleor/i18n";
+import ArrowDropdownIcon from "@saleor/icons/ArrowDropdown";
-interface ChoiceType {
+export interface MultiAutocompleteChoiceType {
label: string;
value: string;
}
@@ -39,25 +41,16 @@ const styles = (theme: Theme) =>
}
});
-export interface MultiAutocompleteSelectFieldChildrenFunc {
- deleteItem: (item: ChoiceType) => void;
- items: ChoiceType[];
-}
-export type MultiAutocompleteSelectFieldChildren = (
- props: MultiAutocompleteSelectFieldChildrenFunc
-) => React.ReactNode;
-
-export interface MultiAutocompleteSelectFieldProps
- extends WithStyles<typeof styles> {
+export interface MultiAutocompleteSelectFieldProps {
+ displayValue: string;
name: string;
- children: MultiAutocompleteSelectFieldChildren;
- choices: ChoiceType[];
- value?: ChoiceType[];
+ choices: MultiAutocompleteChoiceType[];
+ value: string[];
loading?: boolean;
placeholder?: string;
helperText?: string;
label?: string;
- fetchChoices(value: string);
+ fetchChoices?(value: string);
onChange(event);
}
@@ -65,13 +58,13 @@ const DebounceAutocomplete: React.ComponentType<
DebounceProps<string>
> = Debounce;
-export const MultiAutocompleteSelectField = withStyles(styles, {
+export const MultiAutocompleteSelectFieldComponent = withStyles(styles, {
name: "MultiAutocompleteSelectField"
})(
({
- children,
choices,
classes,
+ displayValue,
helperText,
label,
loading,
@@ -80,102 +73,130 @@ export const MultiAutocompleteSelectField = withStyles(styles, {
value,
fetchChoices,
onChange
- }: MultiAutocompleteSelectFieldProps) => {
+ }: MultiAutocompleteSelectFieldProps & WithStyles<typeof styles>) => {
+ const [focused, setFocus] = React.useState(false);
const handleSelect = (
- item: ChoiceType,
+ item: MultiAutocompleteChoiceType,
{ reset }: ControllerStateAndHelpers
) => {
reset({ inputValue: "" });
- onChange({ target: { name, value: [...value, item] } });
- };
- const handleDelete = (item: ChoiceType) => {
- const newValue = value.slice();
- newValue.splice(
- value.findIndex(listItem => listItem.value === item.value),
- 1
- );
- onChange({ target: { name, value: newValue } });
+ onChange({ target: { name, value: item } });
};
- const filteredChoices = choices.filter(
- suggestion => value.map(v => v.value).indexOf(suggestion.value) === -1
+ return (
+ <Downshift
+ selectedItem={value}
+ itemToString={item => (item ? item.label : "")}
+ onSelect={handleSelect}
+ onInputValueChange={fetchChoices}
+ >
+ {({
+ getInputProps,
+ getItemProps,
+ isOpen,
+ toggleMenu,
+ openMenu,
+ highlightedIndex,
+ inputValue
+ }) => {
+ return (
+ <div className={classes.container}>
+ <TextField
+ InputProps={{
+ ...getInputProps({
+ placeholder,
+ value: focused ? inputValue : displayValue
+ }),
+ endAdornment: (
+ <div>
+ {loading ? (
+ <CircularProgress size={20} />
+ ) : (
+ <ArrowDropdownIcon onClick={toggleMenu} />
+ )}
+ </div>
+ ),
+ id: undefined,
+ onBlur: () => setFocus(false),
+ onFocus: () => {
+ openMenu();
+ setFocus(true);
+ }
+ }}
+ helperText={helperText}
+ label={label}
+ fullWidth={true}
+ />
+ {isOpen && (
+ <Paper className={classes.paper} square>
+ {!loading && choices.length > 0
+ ? choices.map((suggestion, index) => (
+ <MenuItem
+ key={suggestion.value}
+ selected={highlightedIndex === index}
+ component="div"
+ {...getItemProps({
+ item: suggestion.value
+ })}
+ >
+ <Checkbox
+ checked={value.includes(suggestion.value)}
+ disableRipple
+ />
+ {suggestion.label}
+ </MenuItem>
+ ))
+ : !loading && (
+ <MenuItem disabled={true} component="div">
+ {i18n.t("No results found")}
+ </MenuItem>
+ )}
+ </Paper>
+ )}
+ </div>
+ );
+ }}
+ </Downshift>
);
-
+ }
+);
+const MultiAutocompleteSelectField: React.FC<
+ MultiAutocompleteSelectFieldProps
+> = ({ choices, fetchChoices, ...props }) => {
+ const [query, setQuery] = React.useState("");
+ if (fetchChoices) {
return (
<DebounceAutocomplete debounceFn={fetchChoices}>
- {debounce => (
- <Downshift
- selectedItem={value}
- itemToString={item => (item ? item.label : "")}
- onSelect={handleSelect}
- onInputValueChange={value => debounce(value)}
- >
- {({
- getInputProps,
- getItemProps,
- isOpen,
- selectedItem,
- toggleMenu,
- closeMenu,
- openMenu,
- highlightedIndex
- }) => {
- return (
- <div className={classes.container}>
- <TextField
- InputProps={{
- ...getInputProps({
- placeholder
- }),
- endAdornment: (
- <div>
- {loading ? (
- <CircularProgress size={20} />
- ) : (
- <ArrowDropdownIcon onClick={toggleMenu} />
- )}
- </div>
- ),
- id: undefined,
- onBlur: closeMenu,
- onFocus: openMenu
- }}
- helperText={helperText}
- label={label}
- fullWidth={true}
- />
- {isOpen && (
- <Paper className={classes.paper} square>
- {!loading && filteredChoices.length > 0
- ? filteredChoices.map((suggestion, index) => (
- <MenuItem
- key={suggestion.value}
- selected={highlightedIndex === index}
- component="div"
- {...getItemProps({ item: suggestion })}
- >
- {suggestion.label}
- </MenuItem>
- ))
- : !loading && (
- <MenuItem disabled={true} component="div">
- {i18n.t("No results found")}
- </MenuItem>
- )}
- </Paper>
- )}
- {children({
- deleteItem: handleDelete,
- items: selectedItem
- })}
- </div>
- );
- }}
- </Downshift>
+ {debounceFn => (
+ <MultiAutocompleteSelectFieldComponent
+ choices={choices}
+ {...props}
+ fetchChoices={debounceFn}
+ />
)}
</DebounceAutocomplete>
);
}
-);
+
+ const sortedChoices = choices.sort((a, b) => {
+ const ratingA = compareTwoStrings(query, a.label);
+ const ratingB = compareTwoStrings(query, b.label);
+ if (ratingA > ratingB) {
+ return -1;
+ }
+ if (ratingA < ratingB) {
+ return 1;
+ }
+ return 0;
+ });
+
+ return (
+ <MultiAutocompleteSelectFieldComponent
+ fetchChoices={q => setQuery(q || "")}
+ choices={sortedChoices}
+ {...props}
+ />
+ );
+};
MultiAutocompleteSelectField.displayName = "MultiAutocompleteSelectField";
export default MultiAutocompleteSelectField;
diff --git a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
index 74c47c9db0..37e83686a5 100644
--- a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
+++ b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
@@ -1,3 +1,4 @@
+import CircularProgress from "@material-ui/core/CircularProgress";
import { Omit } from "@material-ui/core";
import { InputProps } from "@material-ui/core/Input";
import MenuItem from "@material-ui/core/MenuItem";
@@ -34,17 +35,16 @@ const styles = (theme: Theme) =>
}
});
+export interface SingleAutocompleteChoiceType {
+ label: string;
+ value: any;
+}
export interface SingleAutocompleteSelectFieldProps {
error?: boolean;
name: string;
- choices: Array<{
- label: string;
- value: any;
- }>;
- value?: {
- label: string;
- value: any;
- };
+ displayValue: string;
+ choices: SingleAutocompleteChoiceType[];
+ value?: string;
disabled?: boolean;
loading?: boolean;
placeholder?: string;
@@ -75,6 +75,7 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {
classes,
custom,
disabled,
+ displayValue,
error,
helperText,
label,
@@ -93,7 +94,7 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {
{debounceFn => (
<Downshift
selectedItem={value}
- itemToString={item => (item ? item.label : "")}
+ itemToString={() => displayValue}
onSelect={handleChange}
onInputValueChange={value => debounceFn(value)}
>
@@ -122,9 +123,13 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {
placeholder
}),
endAdornment: (
- <ArrowDropdownIcon
- onClick={disabled ? undefined : toggleMenu}
- />
+ <div>
+ {loading ? (
+ <CircularProgress size={20} />
+ ) : (
+ <ArrowDropdownIcon onClick={toggleMenu} />
+ )}
+ </div>
),
error,
id: undefined,
@@ -138,18 +143,14 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {
/>
{isOpen && (
<Paper className={classes.paper} square>
- {loading ? (
- <MenuItem disabled={true} component="div">
- {i18n.t("Loading...")}
- </MenuItem>
- ) : choices.length > 0 || custom ? (
+ {choices.length > 0 || custom ? (
<>
{choices.map((suggestion, index) => (
<MenuItem
key={JSON.stringify(suggestion)}
selected={highlightedIndex === index}
component="div"
- {...getItemProps({ item: suggestion })}
+ {...getItemProps({ item: suggestion.value })}
>
{suggestion.label}
</MenuItem>
diff --git a/saleor/static/dashboard-next/hooks/useFormset.ts b/saleor/static/dashboard-next/hooks/useFormset.ts
new file mode 100644
index 0000000000..3f9e15f57c
--- /dev/null
+++ b/saleor/static/dashboard-next/hooks/useFormset.ts
@@ -0,0 +1,40 @@
+import { useEffect, useState } from "react";
+
+export interface FormsetAtomicData<TData = object> {
+ data: TData;
+ id: string;
+ label: string;
+ value: string;
+}
+export type FormsetData<TData = object> = Array<FormsetAtomicData<TData>>;
+export interface UseFormsetOutput<TData = object> {
+ change: (id: string, value: string) => void;
+ data: FormsetData<TData>;
+}
+function useFormset<TData = object>(
+ initial: FormsetData<TData>
+): UseFormsetOutput<TData> {
+ const [data, setData] = useState<FormsetData<TData>>(initial || []);
+
+ // Reload formset after fetching new initial data
+ useEffect(() => setData(initial), [JSON.stringify(initial)]);
+
+ function setItemValue(id: string, value: string) {
+ const itemIndex = data.findIndex(item => item.id === id);
+ setData([
+ ...data.slice(0, itemIndex),
+ {
+ ...data[itemIndex],
+ value
+ },
+ ...data.slice(itemIndex + 1)
+ ]);
+ }
+
+ return {
+ change: setItemValue,
+ data
+ };
+}
+
+export default useFormset;
diff --git a/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx b/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx
new file mode 100644
index 0000000000..d2f8c8d90c
--- /dev/null
+++ b/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx
@@ -0,0 +1,162 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import IconButton from "@material-ui/core/IconButton";
+import { Theme } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown";
+import makeStyles from "@material-ui/styles/makeStyles";
+import classNames from "classnames";
+import * as React from "react";
+
+import CardSpacer from "@saleor/components/CardSpacer";
+import CardTitle from "@saleor/components/CardTitle";
+import Grid from "@saleor/components/Grid";
+import Hr from "@saleor/components/Hr";
+import MultiAutocompleteSelectField, {
+ MultiAutocompleteChoiceType
+} from "@saleor/components/MultiAutocompleteSelectField";
+import SingleAutocompleteSelectField, {
+ SingleAutocompleteChoiceType
+} from "@saleor/components/SingleAutocompleteSelectField";
+import { FormsetAtomicData } from "@saleor/hooks/useFormset";
+import i18n from "@saleor/i18n";
+import { ProductDetails_product_attributes_attribute_values } from "@saleor/products/types/ProductDetails";
+import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
+
+export type ProductAttributeInput = FormsetAtomicData<{
+ inputType: AttributeInputTypeEnum;
+ values: ProductDetails_product_attributes_attribute_values[];
+}>;
+export interface ProductAttributesProps {
+ attributes: ProductAttributeInput[];
+ disabled: boolean;
+ onChange: (id: string, value: string) => void;
+}
+
+const useStyles = makeStyles((theme: Theme) => ({
+ attributeSection: {
+ padding: `${theme.spacing.unit * 2}px 0`
+ },
+ attributeSectionLabel: {
+ alignItems: "center",
+ display: "flex"
+ },
+ card: {
+ overflow: "visible"
+ },
+ cardContent: {
+ paddingTop: theme.spacing.unit
+ },
+ expansionBar: {
+ display: "flex"
+ },
+ expansionBarButton: {
+ marginBottom: theme.spacing.unit
+ },
+ expansionBarButtonIcon: {
+ transition: theme.transitions.duration.short + "ms"
+ },
+ expansionBarLabel: {
+ color: theme.palette.text.disabled,
+ fontSize: 14
+ },
+ expansionBarLabelContainer: {
+ alignItems: "center",
+ display: "flex",
+ flex: 1
+ },
+ rotate: {
+ transform: "rotate(180deg)"
+ }
+}));
+
+function getMultiChoices(
+ values: ProductDetails_product_attributes_attribute_values[]
+): MultiAutocompleteChoiceType[] {
+ return values.map(value => ({
+ label: value.name,
+ value: value.id
+ }));
+}
+
+function getSingleChoices(
+ values: ProductDetails_product_attributes_attribute_values[]
+): SingleAutocompleteChoiceType[] {
+ return values.map(value => ({
+ label: value.name,
+ value: value.id
+ }));
+}
+
+const ProductAttributes: React.FC<ProductAttributesProps> = ({
+ attributes,
+ disabled,
+ onChange
+}) => {
+ const classes = useStyles({});
+ const [expanded, setExpansionStatus] = React.useState(true);
+ const toggleExpansion = () => setExpansionStatus(!expanded);
+
+ return (
+ <Card className={classes.card}>
+ <CardTitle title={i18n.t("Attributes")} />
+ <CardContent className={classes.cardContent}>
+ <div className={classes.expansionBar}>
+ <div className={classes.expansionBarLabelContainer}>
+ <Typography className={classes.expansionBarLabel} variant="caption">
+ {i18n.t("{{ number }} Attributes", {
+ context: "number of attribute",
+ number: attributes.length
+ })}
+ </Typography>
+ </div>
+ <IconButton
+ className={classes.expansionBarButton}
+ onClick={toggleExpansion}
+ >
+ <ArrowDropDownIcon
+ className={classNames(classes.expansionBarButtonIcon, {
+ [classes.rotate]: expanded
+ })}
+ />
+ </IconButton>
+ </div>
+ <Hr />
+ {expanded &&
+ attributes.map(attribute => (
+ <>
+ <Grid className={classes.attributeSection} variant="uniform">
+ <div className={classes.attributeSectionLabel}>
+ <Typography>{attribute.label}</Typography>
+ </div>
+ <div>
+ {attribute.data.inputType ===
+ AttributeInputTypeEnum.DROPDOWN ? (
+ <SingleAutocompleteSelectField
+ choices={getSingleChoices(attribute.data.values)}
+ disabled={disabled}
+ displayValue={
+ attribute.data.values.find(
+ value => value.id === attribute.value
+ ).name
+ }
+ name={`attribute:${attribute.label}`}
+ label={i18n.t("Value")}
+ value={attribute.value}
+ onChange={event =>
+ onChange(attribute.id, event.target.value)
+ }
+ />
+ ) : // <MultiAutocompleteSelectField choices={getMultiChoices(attribute.data.values)} label={i18n.t("Values")} value={attribute.value}/>
+ null}
+ </div>
+ </Grid>
+ <Hr />
+ </>
+ ))}
+ </CardContent>
+ </Card>
+ );
+};
+ProductAttributes.displayName = "ProductAttributes";
+export default ProductAttributes;
diff --git a/saleor/static/dashboard-next/products/components/ProductAttributes/index.ts b/saleor/static/dashboard-next/products/components/ProductAttributes/index.ts
new file mode 100644
index 0000000000..090807d298
--- /dev/null
+++ b/saleor/static/dashboard-next/products/components/ProductAttributes/index.ts
@@ -0,0 +1,2 @@
+export { default } from './ProductAttributes';
+export * from './ProductAttributes';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
index 45c44a3a56..033b4d6412 100644
--- a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
@@ -11,14 +11,14 @@ import React from "react";
import CardSpacer from "@saleor/components/CardSpacer";
import CardTitle from "@saleor/components/CardTitle";
-import Chip from "@saleor/components/Chip";
import { FormSpacer } from "@saleor/components/FormSpacer";
+import Hr from "@saleor/components/Hr";
import MultiAutocompleteSelectField from "@saleor/components/MultiAutocompleteSelectField";
import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField";
-import Skeleton from "@saleor/components/Skeleton";
import { ChangeEvent } from "@saleor/hooks/useForm";
-import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
+import i18n from "@saleor/i18n";
+import { maybe } from "@saleor/misc";
+import { FormErrors } from "@saleor/types";
import { ProductCreateData_productTypes_edges_node_productAttributes } from "../../types/ProductCreateData";
interface ChoiceType {
@@ -41,12 +41,6 @@ const styles = (theme: Theme) =>
fontSize: "1rem",
marginBottom: theme.spacing.unit / 2
},
- hr: {
- backgroundColor: theme.overrides.MuiCard.root.borderColor,
- border: "none",
- height: 1,
- margin: `0 -${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`
- },
label: {
marginBottom: theme.spacing.unit / 2
}
@@ -74,9 +68,26 @@ interface ProductOrganizationProps extends WithStyles<typeof styles> {
canChangeType: boolean;
categories?: Array<{ value: string; label: string }>;
collections?: Array<{ value: string; label: string }>;
- data: ProductOrganizationFormData;
+ collectionInputDisplayValue: string;
+ data: {
+ attributes: Array<{
+ slug: string;
+ values: string[];
+ }>;
+ category: ChoiceType;
+ collections: string[];
+ productType: {
+ label: string;
+ value: {
+ hasVariants: boolean;
+ id: string;
+ name: string;
+ productAttributes: ProductCreateData_productTypes_edges_node_productAttributes[];
+ };
+ };
+ };
disabled: boolean;
- errors: { [key: string]: string };
+ errors: FormErrors<"productType" | "category">;
product?: {
productType?: {
hasVariants?: boolean;
@@ -87,6 +98,7 @@ interface ProductOrganizationProps extends WithStyles<typeof styles> {
fetchCategories: (query: string) => void;
fetchCollections: (query: string) => void;
onChange: (event: ChangeEvent<any>) => void;
+ onCollectionChange: (event: ChangeEvent<any>) => void;
onSet: (data: Partial<ProductOrganizationFormData>) => void;
}
@@ -96,6 +108,7 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
categories,
classes,
collections,
+ collectionInputDisplayValue,
data,
disabled,
errors,
@@ -104,56 +117,9 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
product,
productTypes,
onChange,
+ onCollectionChange,
onSet
}: ProductOrganizationProps) => {
- const unrolledAttributes = maybe(
- () => data.productType.value.productAttributes,
- []
- );
- const getAttributeName = (slug: string) => {
- const match = unrolledAttributes.find(a => a.slug === slug);
- if (!match) {
- return "";
- }
- return match.name;
- };
- const getAttributeValue = (slug: string) => {
- if (unrolledAttributes.length > 0) {
- const value = data.attributes.find(a => a.slug === slug);
- const attributeMatch = unrolledAttributes.find(a => a.slug === slug);
- if (!attributeMatch) {
- return {
- label: "",
- value: ""
- };
- }
- const attributeValueMatch = attributeMatch.values.find(
- v => v.slug === value.values[0]
- );
- const label = !!attributeValueMatch
- ? attributeValueMatch.name
- : value.values[0];
- return {
- label,
- value
- };
- }
- return {
- label: "",
- value: ""
- };
- };
- const getAttributeValues = (slug: string) => {
- const match = unrolledAttributes.find(a => a.slug === slug);
- if (match) {
- return match.values.map(v => ({
- label: v.name,
- value: v.slug
- }));
- }
-
- return [];
- };
const handleProductTypeSelect = (
event: ChangeEvent<
string,
@@ -173,28 +139,7 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
productType: event.target.value
});
};
- const handleAttributeValueSelect = (
- event: React.ChangeEvent<{
- name: string;
- value: {
- label: string;
- value: string;
- };
- }>
- ) => {
- onChange({
- ...event,
- target: {
- ...event.target,
- name: "attributes",
- value: data.attributes.map(a =>
- a.slug === event.target.name
- ? { slug: a.slug, value: event.target.value.value }
- : a
- )
- }
- });
- };
+
return (
<Card className={classes.card}>
<CardTitle title={i18n.t("Organize Product")} />
@@ -204,17 +149,12 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
error={!!errors.productType}
helperText={errors.productType}
name="productType"
- disabled={!!product || disabled}
+ disabled={disabled}
label={i18n.t("Product Type")}
- choices={
- product &&
- product.productType &&
- product.productType.name !== undefined
- ? [{ label: product.productType.name, value: "1" }]
- : productTypes
- ? productTypes.map(pt => ({ label: pt.name, value: pt }))
- : []
- }
+ choices={maybe(
+ () => productTypes.map(pt => ({ label: pt.name, value: pt })),
+ []
+ )}
value={data.productType}
onChange={handleProductTypeSelect}
/>
@@ -241,38 +181,9 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
</Typography>
</>
)}
- {!(data && data.attributes && data.attributes.length === 0) ? (
- <>
- <CardSpacer />
- <Typography className={classes.cardSubtitle}>
- {i18n.t("Attributes")}
- </Typography>
- <hr className={classes.hr} />
- </>
- ) : (
- <FormSpacer />
- )}
- {data.attributes ? (
- data.attributes.map((item, index) => {
- return (
- <React.Fragment key={index}>
- <SingleAutocompleteSelectField
- disabled={disabled}
- name={item.slug}
- label={getAttributeName(item.slug)}
- onChange={handleAttributeValueSelect}
- value={getAttributeValue(item.slug)}
- choices={getAttributeValues(item.slug)}
- custom
- />
- <FormSpacer />
- </React.Fragment>
- );
- })
- ) : (
- <Skeleton />
- )}
- <hr className={classes.hr} />
+ <FormSpacer />
+ <Hr />
+ <FormSpacer />
<SingleAutocompleteSelectField
error={!!errors.category}
helperText={errors.category}
@@ -285,30 +196,20 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
fetchChoices={fetchCategories}
/>
<FormSpacer />
- <hr className={classes.hr} />
+ <Hr />
+ <FormSpacer />
<MultiAutocompleteSelectField
+ displayValue={collectionInputDisplayValue}
label={i18n.t("Collections")}
choices={disabled ? [] : collections}
name="collections"
value={data.collections}
- onChange={onChange}
- fetchChoices={fetchCollections}
- >
- {({ deleteItem, items }) => (
- <>
- <FormSpacer />
- <div>
- {items.map(item => (
- <Chip
- key={item.value}
- label={item.label}
- onClose={() => deleteItem(item)}
- />
- ))}
- </div>
- </>
+ helperText={i18n.t(
+ "*Optional. Adding product to collection helps users find it."
)}
- </MultiAutocompleteSelectField>
+ onChange={onCollectionChange}
+ fetchChoices={fetchCollections}
+ />
</CardContent>
</Card>
);
diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
index e3e9eb8f0f..e1e9306e70 100644
--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
@@ -11,15 +11,19 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import SeoForm from "@saleor/components/SeoForm";
import VisibilityCard from "@saleor/components/VisibilityCard";
-import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
-import { ListActions, UserError } from "../../../types";
+import { SearchCategories_categories_edges_node } from "@saleor/containers/SearchCategories/types/SearchCategories";
+import { SearchCollections_collections_edges_node } from "@saleor/containers/SearchCollections/types/SearchCollections";
+import useFormset from "@saleor/hooks/useFormset";
+import i18n from "@saleor/i18n";
+import { maybe } from "@saleor/misc";
+import { ListActions, UserError } from "@saleor/types";
import {
ProductDetails_product,
ProductDetails_product_attributes_attribute,
ProductDetails_product_images,
ProductDetails_product_variants
} from "../../types/ProductDetails";
+import ProductAttributes, { ProductAttributeInput } from "../ProductAttributes";
import ProductDetailsForm from "../ProductDetailsForm";
import ProductImages from "../ProductImages";
import ProductOrganization from "../ProductOrganization";
@@ -30,22 +34,16 @@ import ProductVariants from "../ProductVariants";
interface ProductUpdateProps extends ListActions {
errors: UserError[];
placeholderImage: string;
- collections?: Array<{
- id: string;
- name: string;
- }>;
- categories?: Array<{
- id: string;
- name: string;
- }>;
- disabled?: boolean;
- productCollections?: Array<{
+ collections: SearchCollections_collections_edges_node[];
+ categories: SearchCategories_categories_edges_node[];
+ disabled: boolean;
+ productCollections: Array<{
id: string;
name: string;
}>;
variants: ProductDetails_product_variants[];
- images?: ProductDetails_product_images[];
- product?: ProductDetails_product;
+ images: ProductDetails_product_images[];
+ product: ProductDetails_product;
header: string;
saveButtonBarState: ConfirmButtonTransitionState;
fetchCategories: (query: string) => void;
@@ -76,7 +74,7 @@ export interface FormData {
basePrice: number;
category: ChoiceType | null;
chargeTaxes: boolean;
- collections: ChoiceType[];
+ collections: string[];
description: RawDraftContentState;
isPublished: boolean;
name: string;
@@ -129,6 +127,37 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
toggleAll,
toolbar
}) => {
+ const { change: changeAttributeData, data: attributes } = useFormset(
+ maybe(
+ (): ProductAttributeInput[] =>
+ product.attributes.map(attribute => ({
+ data: {
+ inputType: attribute.attribute.inputType,
+ values: attribute.attribute.values
+ },
+ id: attribute.attribute.id,
+ label: attribute.attribute.name,
+ value: attribute.value.id
+ })),
+ []
+ )
+ );
+ const [selectedCollections, setSelectedCollections] = React.useState<
+ Array<{
+ id: string;
+ label: string;
+ }>
+ >(
+ maybe(
+ () =>
+ productCollections.map(collection => ({
+ id: collection.id,
+ label: collection.name
+ })),
+ []
+ )
+ );
+
const initialDescription = maybe<RawDraftContentState>(() =>
JSON.parse(product.descriptionJson)
);
@@ -149,10 +178,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
},
chargeTaxes: maybe(() => product.chargeTaxes, false),
collections: productCollections
- ? productCollections.map(collection => ({
- label: collection.name,
- value: collection.id
- }))
+ ? productCollections.map(collection => collection.id)
: [],
description: initialDescription,
isPublished: maybe(() => product.isPublished, false),
@@ -210,108 +236,146 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
initial={initialData}
confirmLeave
>
- {({ change, data, errors, hasChanged, set, submit }) => (
- <>
- <Container>
- <AppHeader onBack={onBack}>{i18n.t("Products")}</AppHeader>
- <PageHeader title={header} />
- <Grid>
- <div>
- <ProductDetailsForm
- data={data}
- disabled={disabled}
- errors={errors}
- initialDescription={initialDescription}
- onChange={change}
- />
- <CardSpacer />
- <ProductImages
- images={images}
- placeholderImage={placeholderImage}
- onImageDelete={onImageDelete}
- onImageReorder={onImageReorder}
- onImageEdit={onImageEdit}
- onImageUpload={onImageUpload}
- />
- <CardSpacer />
- <ProductPricing
- currency={currency}
- data={data}
- disabled={disabled}
- onChange={change}
- />
- <CardSpacer />
- {hasVariants ? (
- <ProductVariants
+ {({ change, data, errors, hasChanged, submit }) => {
+ const handleCollectionSelect = (event: React.ChangeEvent<any>) => {
+ const id = event.target.value;
+ const collectionIndex = data.collections.indexOf(id);
+ const collectionList =
+ collectionIndex === -1
+ ? [
+ ...selectedCollections,
+ {
+ id,
+ label: collections.find(
+ collection => collection.value === id
+ ).label
+ }
+ ]
+ : [
+ ...selectedCollections.slice(0, collectionIndex),
+ ...selectedCollections.slice(collectionIndex + 1)
+ ];
+
+ setSelectedCollections(collectionList);
+ change({
+ target: {
+ name: "collections",
+ value: collectionList.map(collection => collection.id)
+ }
+ } as any);
+ };
+
+ return (
+ <>
+ <Container>
+ <AppHeader onBack={onBack}>{i18n.t("Products")}</AppHeader>
+ <PageHeader title={header} />
+ <Grid>
+ <div>
+ <ProductDetailsForm
+ data={data}
disabled={disabled}
- variants={variants}
- fallbackPrice={product ? product.basePrice : undefined}
- onAttributesEdit={onAttributesEdit}
- onRowClick={onVariantShow}
- onVariantAdd={onVariantAdd}
- toolbar={toolbar}
- isChecked={isChecked}
- selected={selected}
- toggle={toggle}
- toggleAll={toggleAll}
+ errors={errors}
+ initialDescription={initialDescription}
+ onChange={change}
/>
- ) : (
- <ProductStock
+ <CardSpacer />
+ <ProductImages
+ images={images}
+ placeholderImage={placeholderImage}
+ onImageDelete={onImageDelete}
+ onImageReorder={onImageReorder}
+ onImageEdit={onImageEdit}
+ onImageUpload={onImageUpload}
+ />
+ <CardSpacer />
+ <ProductAttributes
+ attributes={attributes}
+ onChange={changeAttributeData}
+ />
+ <CardSpacer />
+ <ProductPricing
+ currency={currency}
data={data}
disabled={disabled}
+ onChange={change}
+ />
+ <CardSpacer />
+ {hasVariants ? (
+ <ProductVariants
+ disabled={disabled}
+ variants={variants}
+ fallbackPrice={product ? product.basePrice : undefined}
+ onAttributesEdit={onAttributesEdit}
+ onRowClick={onVariantShow}
+ onVariantAdd={onVariantAdd}
+ toolbar={toolbar}
+ isChecked={isChecked}
+ selected={selected}
+ toggle={toggle}
+ toggleAll={toggleAll}
+ />
+ ) : (
+ <ProductStock
+ data={data}
+ disabled={disabled}
+ product={product}
+ onChange={change}
+ errors={errors}
+ />
+ )}
+ <CardSpacer />
+ <SeoForm
+ title={data.seoTitle}
+ titlePlaceholder={data.name}
+ description={data.seoDescription}
+ descriptionPlaceholder={maybe(() =>
+ convertFromRaw(data.description)
+ .getPlainText()
+ .slice(0, 300)
+ )}
+ loading={disabled}
+ onClick={onSeoClick}
+ onChange={change}
+ />
+ </div>
+ <div>
+ <ProductOrganization
+ canChangeType={false}
+ categories={categories}
+ collectionInputDisplayValue={selectedCollections
+ .map(c => c.label)
+ .join(", ")}
+ errors={errors}
+ fetchCategories={fetchCategories}
+ fetchCollections={fetchCollections}
+ collections={collections}
product={product}
+ data={data}
+ disabled={disabled}
onChange={change}
+ onCollectionChange={handleCollectionSelect}
+ />
+ <CardSpacer />
+ <VisibilityCard
+ data={data}
errors={errors}
+ disabled={disabled}
+ onChange={change}
/>
- )}
- <CardSpacer />
- <SeoForm
- title={data.seoTitle}
- titlePlaceholder={data.name}
- description={data.seoDescription}
- descriptionPlaceholder={maybe(() =>
- convertFromRaw(data.description)
- .getPlainText()
- .slice(0, 300)
- )}
- loading={disabled}
- onClick={onSeoClick}
- onChange={change}
- />
- </div>
- <div>
- <ProductOrganization
- canChangeType={false}
- categories={categories}
- errors={errors}
- fetchCategories={fetchCategories}
- fetchCollections={fetchCollections}
- collections={collections}
- product={product}
- data={data}
- disabled={disabled}
- onChange={change}
- onSet={set}
- />
- <CardSpacer />
- <VisibilityCard
- data={data}
- errors={errors}
- disabled={disabled}
- onChange={change}
- />
- </div>
- </Grid>
- <SaveButtonBar
- onCancel={onBack}
- onDelete={onDelete}
- onSave={submit}
- state={saveButtonBarState}
- disabled={disabled || !hasChanged}
- />
- </Container>
- </>
- )}
+ </div>
+ </Grid>
+ <SaveButtonBar
+ onCancel={onBack}
+ onDelete={onDelete}
+ onSave={submit}
+ state={saveButtonBarState}
+ disabled={disabled || !hasChanged}
+ />
+ </Container>
+ </>
+ );
+ }}
</Form>
);
};
diff --git a/saleor/static/dashboard-next/products/fixtures.ts b/saleor/static/dashboard-next/products/fixtures.ts
index 2fc48bc955..6c67af5ab7 100644
--- a/saleor/static/dashboard-next/products/fixtures.ts
+++ b/saleor/static/dashboard-next/products/fixtures.ts
@@ -1,3 +1,4 @@
+import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
import { content } from "../storybook/stories/components/RichTextEditor";
import { ProductDetails_product } from "./types/ProductDetails";
import { ProductVariant } from "./types/ProductVariant";
@@ -14,23 +15,21 @@ export const product: (
attribute: {
__typename: "Attribute",
id: "pta18161",
+ inputType: AttributeInputTypeEnum.DROPDOWN,
name: "Borders",
slug: "Borders",
- sortNumber: 0,
values: [
{
__typename: "AttributeValue",
id: "ptav47282",
name: "portals",
- slug: "portals",
- sortNumber: 0
+ slug: "portals"
},
{
__typename: "AttributeValue",
id: "ptav17253",
name: "Baht",
- slug: "Baht",
- sortNumber: 1
+ slug: "Baht"
}
]
},
@@ -38,8 +37,7 @@ export const product: (
__typename: "AttributeValue",
id: "ptav47282",
name: "portals",
- slug: "portals",
- sortNumber: 0
+ slug: "portals"
}
},
{
@@ -47,37 +45,33 @@ export const product: (
attribute: {
__typename: "Attribute",
id: "pta22785",
+ inputType: AttributeInputTypeEnum.MULTISELECT,
name: "Legacy",
slug: "Legacy",
- sortNumber: 1,
values: [
{
__typename: "AttributeValue",
id: "ptav31282",
name: "payment",
- slug: "payment",
- sortNumber: 0
+ slug: "payment"
},
{
__typename: "AttributeValue",
id: "ptav14907",
name: "Auto Loan Account",
- slug: "Auto-Loan-Account",
- sortNumber: 1
+ slug: "Auto-Loan-Account"
},
{
__typename: "AttributeValue",
id: "ptav27366",
name: "Garden",
- slug: "Garden",
- sortNumber: 2
+ slug: "Garden"
},
{
__typename: "AttributeValue",
id: "ptav11873",
name: "override",
- slug: "override",
- sortNumber: 3
+ slug: "override"
}
]
},
@@ -85,8 +79,7 @@ export const product: (
__typename: "AttributeValue",
id: "ptav14907",
name: "Auto Loan Account",
- slug: "Auto-Loan-Account",
- sortNumber: 1
+ slug: "Auto-Loan-Account"
}
}
],
diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.ts
index 84c3c345d2..040de93344 100644
--- a/saleor/static/dashboard-next/products/queries.ts
+++ b/saleor/static/dashboard-next/products/queries.ts
@@ -95,7 +95,9 @@ export const productFragmentDetails = gql`
id
slug
name
+ inputType
values {
+ id
name
slug
}
diff --git a/saleor/static/dashboard-next/products/types/Product.ts b/saleor/static/dashboard-next/products/types/Product.ts
index 5a7fb789df..37ce1df32d 100644
--- a/saleor/static/dashboard-next/products/types/Product.ts
+++ b/saleor/static/dashboard-next/products/types/Product.ts
@@ -2,6 +2,8 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL fragment: Product
// ====================================================
@@ -50,6 +52,7 @@ export interface Product_purchaseCost {
export interface Product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -59,6 +62,7 @@ export interface Product_attributes_attribute {
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (Product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/products/types/ProductCreate.ts b/saleor/static/dashboard-next/products/types/ProductCreate.ts
index afa3fc2b14..3aab6b4a71 100644
--- a/saleor/static/dashboard-next/products/types/ProductCreate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductCreate.ts
@@ -2,7 +2,7 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeValueInput, SeoInput } from "./../../types/globalTypes";
+import { AttributeValueInput, SeoInput, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductCreate
@@ -58,6 +58,7 @@ export interface ProductCreate_productCreate_product_purchaseCost {
export interface ProductCreate_productCreate_product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -67,6 +68,7 @@ export interface ProductCreate_productCreate_product_attributes_attribute {
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (ProductCreate_productCreate_product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/products/types/ProductDetails.ts b/saleor/static/dashboard-next/products/types/ProductDetails.ts
index de8697966e..1a11767431 100644
--- a/saleor/static/dashboard-next/products/types/ProductDetails.ts
+++ b/saleor/static/dashboard-next/products/types/ProductDetails.ts
@@ -2,6 +2,8 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL query operation: ProductDetails
// ====================================================
@@ -50,6 +52,7 @@ export interface ProductDetails_product_purchaseCost {
export interface ProductDetails_product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -59,6 +62,7 @@ export interface ProductDetails_product_attributes_attribute {
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (ProductDetails_product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/products/types/ProductImageCreate.ts b/saleor/static/dashboard-next/products/types/ProductImageCreate.ts
index 04e8c39d8e..104e73e455 100644
--- a/saleor/static/dashboard-next/products/types/ProductImageCreate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductImageCreate.ts
@@ -2,6 +2,8 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ProductImageCreate
// ====================================================
@@ -56,6 +58,7 @@ export interface ProductImageCreate_productImageCreate_product_purchaseCost {
export interface ProductImageCreate_productImageCreate_product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -65,6 +68,7 @@ export interface ProductImageCreate_productImageCreate_product_attributes_attrib
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (ProductImageCreate_productImageCreate_product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts b/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts
index 1db5000cc0..b48433c713 100644
--- a/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts
@@ -2,6 +2,8 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ProductImageUpdate
// ====================================================
@@ -56,6 +58,7 @@ export interface ProductImageUpdate_productImageUpdate_product_purchaseCost {
export interface ProductImageUpdate_productImageUpdate_product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -65,6 +68,7 @@ export interface ProductImageUpdate_productImageUpdate_product_attributes_attrib
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (ProductImageUpdate_productImageUpdate_product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/products/types/ProductUpdate.ts b/saleor/static/dashboard-next/products/types/ProductUpdate.ts
index b11f789925..140de8dc87 100644
--- a/saleor/static/dashboard-next/products/types/ProductUpdate.ts
+++ b/saleor/static/dashboard-next/products/types/ProductUpdate.ts
@@ -2,7 +2,7 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeValueInput, SeoInput } from "./../../types/globalTypes";
+import { AttributeValueInput, SeoInput, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductUpdate
@@ -58,6 +58,7 @@ export interface ProductUpdate_productUpdate_product_purchaseCost {
export interface ProductUpdate_productUpdate_product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -67,6 +68,7 @@ export interface ProductUpdate_productUpdate_product_attributes_attribute {
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (ProductUpdate_productUpdate_product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts b/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts
index 389f64694c..6ba6e054ea 100644
--- a/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts
+++ b/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts
@@ -2,7 +2,7 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeValueInput, ProductVariantInput, SeoInput } from "./../../types/globalTypes";
+import { AttributeValueInput, ProductVariantInput, SeoInput, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: SimpleProductUpdate
@@ -58,6 +58,7 @@ export interface SimpleProductUpdate_productUpdate_product_purchaseCost {
export interface SimpleProductUpdate_productUpdate_product_attributes_attribute_values {
__typename: "AttributeValue";
+ id: string;
name: string | null;
slug: string | null;
}
@@ -67,6 +68,7 @@ export interface SimpleProductUpdate_productUpdate_product_attributes_attribute
id: string;
slug: string | null;
name: string | null;
+ inputType: AttributeInputTypeEnum | null;
values: (SimpleProductUpdate_productUpdate_product_attributes_attribute_values | null)[] | null;
}
diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
index 0d1fdefdb8..a45b3d187d 100644
--- a/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
@@ -1,10 +1,11 @@
import { storiesOf } from "@storybook/react";
import React from "react";
+import { collections } from "@saleor/collections/fixtures";
+import { listActionsProps } from "@saleor/fixtures";
+import ProductUpdatePage from "@saleor/products/components/ProductUpdatePage";
+import { product as productFixture } from "@saleor/products/fixtures";
import placeholderImage from "../../../../images/placeholder255x255.png";
-import { listActionsProps } from "../../../fixtures";
-import ProductUpdatePage from "../../../products/components/ProductUpdatePage";
-import { product as productFixture } from "../../../products/fixtures";
import Decorator from "../../Decorator";
const product = productFixture(placeholderImage);
@@ -13,15 +14,16 @@ storiesOf("Views / Products / Product edit", module)
.addDecorator(Decorator)
.add("when data is fully loaded", () => (
<ProductUpdatePage
+ disabled={false}
errors={[]}
onBack={() => undefined}
onSubmit={() => undefined}
product={product}
header={product.name}
- collections={product.collections}
+ collections={collections}
categories={[product.category]}
fetchCategories={() => undefined}
- fetchCollections={() => undefined}
+ fetchCollections={undefined}
placeholderImage={placeholderImage}
images={product.images}
variants={product.variants}
@@ -39,15 +41,16 @@ storiesOf("Views / Products / Product edit", module)
))
.add("when product has no images", () => (
<ProductUpdatePage
+ disabled={false}
errors={[]}
onBack={() => undefined}
onSubmit={() => undefined}
product={product}
header={product.name}
- collections={product.collections}
+ collections={collections}
categories={[product.category]}
fetchCategories={() => undefined}
- fetchCollections={() => undefined}
+ fetchCollections={undefined}
placeholderImage={placeholderImage}
images={[]}
variants={product.variants}
@@ -65,6 +68,7 @@ storiesOf("Views / Products / Product edit", module)
))
.add("when product has no variants", () => (
<ProductUpdatePage
+ disabled={false}
errors={[]}
onBack={() => undefined}
onSubmit={() => undefined}
@@ -75,10 +79,10 @@ storiesOf("Views / Products / Product edit", module)
} as any
}
header={product.name}
- collections={product.collections}
+ collections={collections}
categories={[product.category]}
fetchCategories={() => undefined}
- fetchCollections={() => undefined}
+ fetchCollections={undefined}
placeholderImage={placeholderImage}
images={product.images}
variants={product.variants}
@@ -100,7 +104,7 @@ storiesOf("Views / Products / Product edit", module)
header={undefined}
categories={[]}
fetchCategories={() => undefined}
- fetchCollections={() => undefined}
+ fetchCollections={undefined}
onBack={() => undefined}
onSubmit={() => undefined}
disabled={true}
@@ -112,6 +116,10 @@ storiesOf("Views / Products / Product edit", module)
onImageUpload={() => undefined}
saveButtonBarState="default"
variants={undefined}
+ product={undefined}
+ collections={undefined}
+ images={undefined}
+ productCollections={undefined}
{...listActionsProps}
/>
));