Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow assigning attributes to product types
dominik-zeglen70f9c13e3531
diff --git a/saleor/static/dashboard-next/productTypes/types/AttributeFragment.ts b/saleor/static/dashboard-next/attributes/types/AttributeFragment.tssimilarity index 66%rename from saleor/static/dashboard-next/productTypes/types/AttributeFragment.tsrename to saleor/static/dashboard-next/attributes/types/AttributeFragment.tsindex 35a35464f7..7c7d927ead 100644--- a/saleor/static/dashboard-next/productTypes/types/AttributeFragment.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeFragment.ts@@ -6,17 +6,9 @@// GraphQL fragment: AttributeFragment// ====================================================-export interface AttributeFragment_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;-}-export interface AttributeFragment {__typename: "Attribute";id: string;name: string | null;slug: string | null;- values: (AttributeFragment_values | null)[] | null;}diff --git a/saleor/static/dashboard-next/attributes/types/AttributeList.ts b/saleor/static/dashboard-next/attributes/types/AttributeList.tsindex 6fbcd8338a..dbd918720e 100644--- a/saleor/static/dashboard-next/attributes/types/AttributeList.ts+++ b/saleor/static/dashboard-next/attributes/types/AttributeList.ts@@ -6,19 +6,11 @@// GraphQL query operation: AttributeList// ====================================================-export interface AttributeList_attributes_edges_node_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;-}-export interface AttributeList_attributes_edges_node {__typename: "Attribute";id: string;name: string | null;slug: string | null;- values: (AttributeList_attributes_edges_node_values | null)[] | null;}export interface AttributeList_attributes_edges {diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsxnew file mode 100644index 0000000000..6b75117024--- /dev/null+++ b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx@@ -0,0 +1,161 @@+import Button from "@material-ui/core/Button";+import CircularProgress from "@material-ui/core/CircularProgress";+import Dialog from "@material-ui/core/Dialog";+import DialogActions from "@material-ui/core/DialogActions";+import DialogContent from "@material-ui/core/DialogContent";+import DialogTitle from "@material-ui/core/DialogTitle";+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";+import Table from "@material-ui/core/Table";+import TableBody from "@material-ui/core/TableBody";+import TableCell from "@material-ui/core/TableCell";+import TableRow from "@material-ui/core/TableRow";+import TextField from "@material-ui/core/TextField";+import * as React from "react";++import ConfirmButton, {+ ConfirmButtonTransitionState+} from "@saleor/components/ConfirmButton";+import Form from "@saleor/components/Form";+import FormSpacer from "@saleor/components/FormSpacer";+import { maybe, renderCollection } from "@saleor/misc";+import { SearchAttributes_attributes_edges_node } from "../../containers/SearchAttributes/types/SearchAttributes";+import i18n from "../../i18n";+import Checkbox from "../Checkbox";++interface FormData {+ query: string;+}++const styles = createStyles({+ checkboxCell: {+ paddingLeft: 0+ },+ overflow: {+ overflowY: "visible"+ },+ wideCell: {+ width: "100%"+ }+});++export interface AssignAttributeDialogProps {+ confirmButtonState: ConfirmButtonTransitionState;+ open: boolean;+ attributes: SearchAttributes_attributes_edges_node[];+ loading: boolean;+ selected: string[];+ onClose: () => void;+ onFetch: (value: string) => void;+ onSubmit: (data: FormData) => void;+ onToggle: (id: string) => void;+}++const initialForm: FormData = {+ query: ""+};+const AssignAttributeDialog = withStyles(styles, {+ name: "AssignAttributeDialog"+})(+ ({+ attributes,+ classes,+ confirmButtonState,+ loading,+ open,+ selected,+ onClose,+ onFetch,+ onSubmit,+ onToggle+ }: AssignAttributeDialogProps & WithStyles<typeof styles>) => (+ <Dialog+ onClose={onClose}+ open={open}+ classes={{ paper: classes.overflow }}+ fullWidth+ maxWidth="sm"+ >+ <Form initial={initialForm} onSubmit={onSubmit}>+ {({ data, change }) => (+ <>+ <DialogTitle>{i18n.t("Assign Attribute")}</DialogTitle>+ <DialogContent className={classes.overflow}>+ <TextField+ name="query"+ value={data.query}+ onChange={event => change(event, () => onFetch(data.query))}+ label={i18n.t("Search Attributes", {+ context: "attribute search input label"+ })}+ placeholder={i18n.t("Search by attribute name", {+ context: "attribute search input placeholder"+ })}+ fullWidth+ InputProps={{+ autoComplete: "off",+ endAdornment: loading && <CircularProgress size={16} />+ }}+ />+ <FormSpacer />+ <Table>+ <TableBody>+ {renderCollection(+ attributes,+ attribute => {+ if (!attribute) {+ return null;+ }+ const isChecked = !!selected.find(+ selectedAttribute => selectedAttribute === attribute.id+ );++ return (+ <TableRow key={maybe(() => attribute.id)}>+ <TableCell+ padding="checkbox"+ className={classes.checkboxCell}+ >+ <Checkbox+ checked={isChecked}+ onChange={() => onToggle(attribute.id)}+ />+ </TableCell>+ <TableCell className={classes.wideCell}>+ {attribute.name}+ </TableCell>+ </TableRow>+ );+ },+ () =>+ !loading && (+ <TableRow>+ <TableCell colSpan={2}>+ {i18n.t("No results found")}+ </TableCell>+ </TableRow>+ )+ )}+ </TableBody>+ </Table>+ </DialogContent>+ <DialogActions>+ <Button onClick={onClose}>+ {i18n.t("Cancel", { context: "button" })}+ </Button>+ <ConfirmButton+ transitionState={confirmButtonState}+ color="primary"+ variant="contained"+ type="submit"+ >+ {i18n.t("Assign attributes", { context: "button" })}+ </ConfirmButton>+ </DialogActions>+ </>+ )}+ </Form>+ </Dialog>+ )+);+AssignAttributeDialog.displayName = "AssignAttributeDialog";+export default AssignAttributeDialog;diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/index.ts b/saleor/static/dashboard-next/components/AssignAttributeDialog/index.tsnew file mode 100644index 0000000000..2960aa0024--- /dev/null+++ b/saleor/static/dashboard-next/components/AssignAttributeDialog/index.ts@@ -0,0 +1,2 @@+export { default } from './AssignAttributeDialog';+export * from './AssignAttributeDialog';\ No newline at end of filediff --git a/saleor/static/dashboard-next/containers/SearchAttributes/index.tsx b/saleor/static/dashboard-next/containers/SearchAttributes/index.tsxnew file mode 100644index 0000000000..5725da0773--- /dev/null+++ b/saleor/static/dashboard-next/containers/SearchAttributes/index.tsx@@ -0,0 +1,24 @@+import gql from "graphql-tag";++import BaseSearch from "../BaseSearch";+import {+ SearchAttributes,+ SearchAttributesVariables+} from "./types/SearchAttributes";++export const searchAttributes = gql`+ query SearchAttributes($after: String, $first: Int!, $query: String!) {+ attributes(after: $after, first: $first, query: $query) {+ edges {+ node {+ id+ name+ }+ }+ }+ }+`;++export default BaseSearch<SearchAttributes, SearchAttributesVariables>(+ searchAttributes+);diff --git a/saleor/static/dashboard-next/containers/SearchAttributes/types/SearchAttributes.ts b/saleor/static/dashboard-next/containers/SearchAttributes/types/SearchAttributes.tsnew file mode 100644index 0000000000..fc0d9e429a--- /dev/null+++ b/saleor/static/dashboard-next/containers/SearchAttributes/types/SearchAttributes.ts@@ -0,0 +1,33 @@+/* tslint:disable */+/* eslint-disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL query operation: SearchAttributes+// ====================================================++export interface SearchAttributes_attributes_edges_node {+ __typename: "Attribute";+ id: string;+ name: string | null;+}++export interface SearchAttributes_attributes_edges {+ __typename: "AttributeCountableEdge";+ node: SearchAttributes_attributes_edges_node;+}++export interface SearchAttributes_attributes {+ __typename: "AttributeCountableConnection";+ edges: SearchAttributes_attributes_edges[];+}++export interface SearchAttributes {+ attributes: SearchAttributes_attributes | null;+}++export interface SearchAttributesVariables {+ after?: string | null;+ first: number;+ query: string;+}diff --git a/saleor/static/dashboard-next/home/types/Home.ts b/saleor/static/dashboard-next/home/types/Home.tsindex 9400d0adc3..139866c2db 100644--- a/saleor/static/dashboard-next/home/types/Home.ts+++ b/saleor/static/dashboard-next/home/types/Home.ts@@ -59,7 +59,7 @@ export interface Home_productTopToday_edges_node_attributes_value {export interface Home_productTopToday_edges_node_attributes {__typename: "SelectedAttribute";- value: Home_productTopToday_edges_node_attributes_value;+ value: Home_productTopToday_edges_node_attributes_value | null;}export interface Home_productTopToday_edges_node_product_thumbnail {diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsxdeleted file mode 100644index e275ed5c81..0000000000--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsx+++ /dev/null@@ -1,99 +0,0 @@-import Button from "@material-ui/core/Button";-import Dialog from "@material-ui/core/Dialog";-import DialogActions from "@material-ui/core/DialogActions";-import DialogContent from "@material-ui/core/DialogContent";-import DialogTitle from "@material-ui/core/DialogTitle";-import TextField from "@material-ui/core/TextField";-import React from "react";--import Form from "@saleor/components/Form";-import { FormSpacer } from "@saleor/components/FormSpacer";-import ListField from "@saleor/components/ListField";-import i18n from "../../../i18n";--export interface FormData {- name: string;- values: Array<{- label: string;- value: string;- }>;-}--export interface ProductTypeAttributeEditDialogProps {- disabled: boolean;- errors: Array<{- field: string;- message: string;- }>;- name: string;- opened: boolean;- title: string;- values: Array<{- label: string;- value: string;- }>;- onClose: () => void;- onConfirm: (data: FormData) => void;-}--const ProductTypeAttributeEditDialog: React.StatelessComponent<- ProductTypeAttributeEditDialogProps-> = ({ disabled, errors, name, opened, title, values, onClose, onConfirm }) => {- const initialForm: FormData = {- name: name || "",- values: values || []- };- return (- <Dialog onClose={onClose} open={opened}>- <Form errors={errors} initial={initialForm} onSubmit={onConfirm}>- {({ change, data, errors: formErrors }) => (- <>- <DialogTitle>{title}</DialogTitle>- <DialogContent>- <TextField- disabled={disabled}- error={!!formErrors.name}- fullWidth- label={i18n.t("Attribute name")}- helperText={formErrors.name}- name="name"- value={data.name}- onChange={change}- />- <FormSpacer />- <ListField- autoComplete="off"- disabled={disabled}- error={- !!formErrors.values ||- !!formErrors.addValues ||- !!formErrors.removeValues- }- fullWidth- name="values"- label={i18n.t("Attribute values")}- helperText={- formErrors.values ||- formErrors.addValues ||- formErrors.removeValues- }- values={data.values}- onChange={change}- />- </DialogContent>- <DialogActions>- <Button onClick={onClose}>- {i18n.t("Cancel", { context: "button" })}- </Button>- <Button color="primary" variant="contained" type="submit">- {i18n.t("Save", { context: "button" })}- </Button>- </DialogActions>- </>- )}- </Form>- </Dialog>- );-};-ProductTypeAttributeEditDialog.displayName = "ProductTypeAttributeEditDialog";-export default ProductTypeAttributeEditDialog;diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/index.tsdeleted file mode 100644index 6344b380f1..0000000000--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { default } from "./ProductTypeAttributeEditDialog";-export * from "./ProductTypeAttributeEditDialog";diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeUnassignDialog/ProductTypeAttributeUnassignDialog.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeUnassignDialog/ProductTypeAttributeUnassignDialog.tsxnew file mode 100644index 0000000000..a8637158eb--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeUnassignDialog/ProductTypeAttributeUnassignDialog.tsx@@ -0,0 +1,49 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import * as React from "react";++import ActionDialog from "@saleor/components/ActionDialog";+import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";+import i18n from "@saleor/i18n";++export interface ProductTypeAttributeUnassignDialogProps {+ attributeName: string;+ confirmButtonState: ConfirmButtonTransitionState;+ open: boolean;+ productTypeName: string;+ onClose: () => void;+ onConfirm: () => void;+}++const ProductTypeAttributeUnassignDialog: React.FC<+ ProductTypeAttributeUnassignDialogProps+> = ({+ attributeName,+ confirmButtonState,+ open,+ productTypeName,+ onClose,+ onConfirm+}) => (+ <ActionDialog+ confirmButtonState={confirmButtonState}+ open={open}+ onClose={onClose}+ onConfirm={onConfirm}+ title={i18n.t("Unassign attribute from product type")}+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to unassign <strong>{{ attributeName }}</strong> from <strong>{{ productTypeName }}</strong>?",+ {+ attributeName,+ productTypeName+ }+ )+ }}+ />+ </ActionDialog>+);+ProductTypeAttributeUnassignDialog.displayName =+ "ProductTypeAttributeUnassignDialog";+export default ProductTypeAttributeUnassignDialog;diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeUnassignDialog/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeUnassignDialog/index.tsnew file mode 100644index 0000000000..dc8bd0a038--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeUnassignDialog/index.ts@@ -0,0 +1,2 @@+export { default } from './ProductTypeAttributeUnassignDialog';+export * from './ProductTypeAttributeUnassignDialog';\ No newline at end of filediff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsxindex 1b219b00b5..f22beb810c 100644--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx@@ -10,15 +10,18 @@ import {import Table from "@material-ui/core/Table";import TableBody from "@material-ui/core/TableBody";import TableCell from "@material-ui/core/TableCell";-import TableHead from "@material-ui/core/TableHead";import TableRow from "@material-ui/core/TableRow";import DeleteIcon from "@material-ui/icons/Delete";import React from "react";import CardTitle from "@saleor/components/CardTitle";+import Checkbox from "@saleor/components/Checkbox";import Skeleton from "@saleor/components/Skeleton";-import i18n from "../../../i18n";-import { maybe, renderCollection } from "../../../misc";+import TableHead from "@saleor/components/TableHead";+import i18n from "@saleor/i18n";+import { maybe, renderCollection, stopPropagation } from "@saleor/misc";+import { ListActions } from "@saleor/types";+import { AttributeTypeEnum } from "@saleor/types/globalTypes";import {ProductTypeDetails_productType_productAttributes,ProductTypeDetails_productType_variantAttributes@@ -40,14 +43,15 @@ const styles = (theme: Theme) =>}});-interface ProductTypeAttributesProps extends WithStyles<typeof styles> {+interface ProductTypeAttributesProps extends ListActions {attributes:| ProductTypeDetails_productType_productAttributes[]| ProductTypeDetails_productType_variantAttributes[];+ disabled: boolean;type: string;- onAttributeAdd: (type: string) => void;- onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;- onAttributeUpdate: (id: string) => void;+ onAttributeAssign: (type: AttributeTypeEnum) => void;+ onAttributeClick: (id: string) => void;+ onAttributeUnassign: (id: string) => void;}const ProductTypeAttributes = withStyles(styles, {@@ -56,15 +60,21 @@ const ProductTypeAttributes = withStyles(styles, {({attributes,classes,+ disabled,+ isChecked,+ selected,+ toggle,+ toggleAll,+ toolbar,type,- onAttributeAdd,- onAttributeDelete,- onAttributeUpdate- }: ProductTypeAttributesProps) => (+ onAttributeAssign,+ onAttributeClick,+ onAttributeUnassign+ }: ProductTypeAttributesProps & WithStyles<typeof styles>) => (<Card><CardTitletitle={- type === "PRODUCT"+ type === AttributeTypeEnum.PRODUCT? i18n.t("Product Attributes"): i18n.t("Variant Attributes")}@@ -72,55 +82,67 @@ const ProductTypeAttributes = withStyles(styles, {<Buttoncolor="primary"variant="text"- onClick={() => onAttributeAdd(type)}+ onClick={() => onAttributeAssign(AttributeTypeEnum[type])}>- {i18n.t("Add attribute", { context: "button" })}+ {i18n.t("Assign attribute", { context: "button" })}</Button>}/><Table>- <TableHead>- <TableRow>- <TableCell>{i18n.t("Attribute name")}</TableCell>- <TableCell className={classes.textLeft}>- {i18n.t("Values")}- </TableCell>- <TableCell />- </TableRow>+ <TableHead+ disabled={disabled}+ selected={selected}+ items={attributes}+ toggleAll={toggleAll}+ toolbar={toolbar}+ >+ <TableCell>{i18n.t("Attribute name")}</TableCell>+ <TableCell /></TableHead><TableBody>{renderCollection(attributes,- attribute => (- <TableRow- className={!!attribute ? classes.link : undefined}- hover={!!attribute}- onClick={- !!attribute- ? () => onAttributeUpdate(attribute.id)- : undefined- }- key={maybe(() => attribute.id)}- >- <TableCell>- {maybe(() => attribute.name) ? attribute.name : <Skeleton />}- </TableCell>- <TableCell className={classes.textLeft}>- {maybe(() => attribute.values) !== undefined ? (- attribute.values.map(value => value.name).join(", ")- ) : (- <Skeleton />- )}- </TableCell>- <TableCell className={classes.iconCell}>- <IconButton- onClick={event => onAttributeDelete(attribute.id, event)}- >- <DeleteIcon color="primary" />- </IconButton>- </TableCell>- </TableRow>- ),+ attribute => {+ const isSelected = attribute ? isChecked(attribute.id) : false;++ return (+ <TableRow+ selected={isSelected}+ className={!!attribute ? classes.link : undefined}+ hover={!!attribute}+ onClick={+ !!attribute+ ? () => onAttributeClick(attribute.id)+ : undefined+ }+ key={maybe(() => attribute.id)}+ >+ <TableCell padding="checkbox">+ <Checkbox+ checked={isSelected}+ disabled={disabled}+ onChange={() => toggle(attribute.id)}+ />+ </TableCell>+ <TableCell>+ {maybe(() => attribute.name) ? (+ attribute.name+ ) : (+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.iconCell}>+ <IconButton+ onClick={stopPropagation(() =>+ onAttributeUnassign(attribute.id)+ )}+ >+ <DeleteIcon color="primary" />+ </IconButton>+ </TableCell>+ </TableRow>+ );+ },() => (<TableRow><TableCell colSpan={2}>diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeBulkAttributeUnassignDialog/ProductTypeBulkAttributeUnassignDialog.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeBulkAttributeUnassignDialog/ProductTypeBulkAttributeUnassignDialog.tsxnew file mode 100644index 0000000000..dc7f1ee836--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeBulkAttributeUnassignDialog/ProductTypeBulkAttributeUnassignDialog.tsx@@ -0,0 +1,49 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import * as React from "react";++import ActionDialog from "@saleor/components/ActionDialog";+import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";+import i18n from "@saleor/i18n";++export interface ProductTypeBulkAttributeUnassignDialogProps {+ attributeQuantity: string;+ confirmButtonState: ConfirmButtonTransitionState;+ open: boolean;+ productTypeName: string;+ onClose: () => void;+ onConfirm: () => void;+}++const ProductTypeBulkAttributeUnassignDialog: React.FC<+ ProductTypeBulkAttributeUnassignDialogProps+> = ({+ attributeQuantity,+ confirmButtonState,+ open,+ productTypeName,+ onClose,+ onConfirm+}) => (+ <ActionDialog+ confirmButtonState={confirmButtonState}+ open={open}+ onClose={onClose}+ onConfirm={onConfirm}+ title={i18n.t("Unassign attribute from product type")}+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to unassign <strong>{{ attributeQuantity }}</strong> attributes from <strong>{{ productTypeName }}</strong>?",+ {+ attributeQuantity,+ productTypeName+ }+ )+ }}+ />+ </ActionDialog>+);+ProductTypeBulkAttributeUnassignDialog.displayName =+ "ProductTypeBulkAttributeUnassignDialog";+export default ProductTypeBulkAttributeUnassignDialog;diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeBulkAttributeUnassignDialog/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeBulkAttributeUnassignDialog/index.tsnew file mode 100644index 0000000000..e6df37e86a--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeBulkAttributeUnassignDialog/index.ts@@ -0,0 +1,2 @@+export { default } from './ProductTypeBulkAttributeUnassignDialog';+export * from './ProductTypeBulkAttributeUnassignDialog';\ No newline at end of filediff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDeleteDialog/ProductTypeDeleteDialog.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDeleteDialog/ProductTypeDeleteDialog.tsxnew file mode 100644index 0000000000..dad9ed934c--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDeleteDialog/ProductTypeDeleteDialog.tsx@@ -0,0 +1,43 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import * as React from "react";++import ActionDialog from "@saleor/components/ActionDialog";+import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";+import i18n from "@saleor/i18n";++export interface ProductTypeDeleteDialogProps {+ confirmButtonState: ConfirmButtonTransitionState;+ open: boolean;+ name: string;+ onClose: () => void;+ onConfirm: () => void;+}++const ProductTypeDeleteDialog: React.FC<ProductTypeDeleteDialogProps> = ({+ confirmButtonState,+ open,+ name,+ onClose,+ onConfirm+}) => (+ <ActionDialog+ confirmButtonState={confirmButtonState}+ open={open}+ onClose={onClose}+ onConfirm={onConfirm}+ title={i18n.t("Remove product type")}+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ name }}</strong>?",+ {+ name+ }+ )+ }}+ />+ </ActionDialog>+);+ProductTypeDeleteDialog.displayName = "ProductTypeDeleteDialog";+export default ProductTypeDeleteDialog;diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDeleteDialog/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeDeleteDialog/index.tsnew file mode 100644index 0000000000..4c9e6f92dc--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDeleteDialog/index.ts@@ -0,0 +1,2 @@+export { default } from './ProductTypeDeleteDialog';+export * from './ProductTypeDeleteDialog';\ No newline at end of filediff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsxindex cfb7a72a4f..b7c48214f2 100644--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx@@ -9,9 +9,10 @@ import Form from "@saleor/components/Form";import Grid from "@saleor/components/Grid";import PageHeader from "@saleor/components/PageHeader";import SaveButtonBar from "@saleor/components/SaveButtonBar";-import i18n from "../../../i18n";-import { maybe } from "../../../misc";-import { WeightUnitsEnum } from "../../../types/globalTypes";+import i18n from "@saleor/i18n";+import { maybe } from "@saleor/misc";+import { ListActions, UserError } from "@saleor/types";+import { AttributeTypeEnum, WeightUnitsEnum } from "@saleor/types/globalTypes";import {ProductTypeDetails_productType,ProductTypeDetails_taxTypes@@ -40,19 +41,18 @@ export interface ProductTypeForm {}export interface ProductTypeDetailsPageProps {- errors: Array<{- field: string;- message: string;- }>;+ errors: UserError[];productType: ProductTypeDetails_productType;defaultWeightUnit: WeightUnitsEnum;disabled: boolean;pageTitle: string;+ productAttributeList: ListActions;saveButtonBarState: ConfirmButtonTransitionState;taxTypes: ProductTypeDetails_taxTypes[];- onAttributeAdd: (type: string) => void;- onAttributeDelete: (id: string, event: React.MouseEvent<any>) => void;- onAttributeUpdate: (id: string) => void;+ variantAttributeList: ListActions;+ onAttributeAdd: (type: AttributeTypeEnum) => void;+ onAttributeClick: (id: string) => void;+ onAttributeUnassign: (id: string) => void;onBack: () => void;onDelete: () => void;onSubmit: (data: ProductTypeForm) => void;@@ -66,11 +66,13 @@ const ProductTypeDetailsPage: React.StatelessComponent<errors,pageTitle,productType,+ productAttributeList,saveButtonBarState,taxTypes,+ variantAttributeList,onAttributeAdd,- onAttributeDelete,- onAttributeUpdate,+ onAttributeUnassign,+ onAttributeClick,onBack,onDelete,onSubmit@@ -139,10 +141,12 @@ const ProductTypeDetailsPage: React.StatelessComponent<<CardSpacer /><ProductTypeAttributesattributes={maybe(() => productType.productAttributes)}- type="PRODUCT"- onAttributeAdd={onAttributeAdd}- onAttributeDelete={onAttributeDelete}- onAttributeUpdate={onAttributeUpdate}+ disabled={disabled}+ type={AttributeTypeEnum.PRODUCT}+ onAttributeAssign={onAttributeAdd}+ onAttributeClick={onAttributeClick}+ onAttributeUnassign={onAttributeUnassign}+ {...productAttributeList}/><CardSpacer /><ControlledCheckbox@@ -157,10 +161,12 @@ const ProductTypeDetailsPage: React.StatelessComponent<<CardSpacer /><ProductTypeAttributesattributes={maybe(() => productType.variantAttributes)}- type="VARIANT"- onAttributeAdd={onAttributeAdd}- onAttributeDelete={onAttributeDelete}- onAttributeUpdate={onAttributeUpdate}+ disabled={disabled}+ type={AttributeTypeEnum.VARIANT}+ onAttributeAssign={onAttributeAdd}+ onAttributeClick={onAttributeClick}+ onAttributeUnassign={onAttributeUnassign}+ {...variantAttributeList}/></>)}diff --git a/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx b/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsxindex ce34e26602..4b419204f5 100644--- a/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx+++ b/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx@@ -3,24 +3,15 @@ import React from "react";import { getMutationProviderData } from "../../misc";import { PartialMutationProviderOutput } from "../../types";import {- TypedAttributeCreateMutation,- TypedAttributeDeleteMutation,- TypedAttributeUpdateMutation,+ TypedAssignAttributeMutation,TypedProductTypeDeleteMutation,- TypedProductTypeUpdateMutation+ TypedProductTypeUpdateMutation,+ TypedUnassignAttributeMutation} from "../mutations";import {- AttributeCreate,- AttributeCreateVariables-} from "../types/AttributeCreate";-import {- AttributeDelete,- AttributeDeleteVariables-} from "../types/AttributeDelete";-import {- AttributeUpdate,- AttributeUpdateVariables-} from "../types/AttributeUpdate";+ AssignAttribute,+ AssignAttributeVariables+} from "../types/AssignAttribute";import {ProductTypeDelete,ProductTypeDeleteVariables@@ -29,35 +20,32 @@ import {ProductTypeUpdate,ProductTypeUpdateVariables} from "../types/ProductTypeUpdate";+import {+ UnassignAttribute,+ UnassignAttributeVariables+} from "../types/UnassignAttribute";interface ProductTypeOperationsProps {- children: (- props: {- attributeCreate: PartialMutationProviderOutput<- AttributeCreate,- AttributeCreateVariables- >;- deleteAttribute: PartialMutationProviderOutput<- AttributeDelete,- AttributeDeleteVariables- >;- deleteProductType: PartialMutationProviderOutput<- ProductTypeDelete,- ProductTypeDeleteVariables- >;- updateAttribute: PartialMutationProviderOutput<- AttributeUpdate,- AttributeUpdateVariables- >;- updateProductType: PartialMutationProviderOutput<- ProductTypeUpdate,- ProductTypeUpdateVariables- >;- }- ) => React.ReactNode;- onAttributeCreate: (data: AttributeCreate) => void;- onAttributeDelete: (data: AttributeDelete) => void;- onAttributeUpdate: (data: AttributeUpdate) => void;+ children: (props: {+ assignAttribute: PartialMutationProviderOutput<+ AssignAttribute,+ AssignAttributeVariables+ >;+ unassignAttribute: PartialMutationProviderOutput<+ UnassignAttribute,+ UnassignAttributeVariables+ >;+ deleteProductType: PartialMutationProviderOutput<+ ProductTypeDelete,+ ProductTypeDeleteVariables+ >;+ updateProductType: PartialMutationProviderOutput<+ ProductTypeUpdate,+ ProductTypeUpdateVariables+ >;+ }) => React.ReactNode;+ onAssignAttribute: (data: AssignAttribute) => void;+ onUnassignAttribute: (data: UnassignAttribute) => void;onProductTypeDelete: (data: ProductTypeDelete) => void;onProductTypeUpdate: (data: ProductTypeUpdate) => void;}@@ -66,9 +54,8 @@ const ProductTypeOperations: React.StatelessComponent<ProductTypeOperationsProps> = ({children,- onAttributeCreate,- onAttributeDelete,- onAttributeUpdate,+ onAssignAttribute,+ onUnassignAttribute,onProductTypeDelete,onProductTypeUpdate}) => {@@ -77,37 +64,30 @@ const ProductTypeOperations: React.StatelessComponent<{(...deleteProductType) => (<TypedProductTypeUpdateMutation onCompleted={onProductTypeUpdate}>{(...updateProductType) => (- <TypedAttributeCreateMutation onCompleted={onAttributeCreate}>- {(...createAttribute) => (- <TypedAttributeDeleteMutation onCompleted={onAttributeDelete}>- {(...deleteAttribute) => (- <TypedAttributeUpdateMutation- onCompleted={onAttributeUpdate}- >- {(...updateAttribute) =>- children({- attributeCreate: getMutationProviderData(- ...createAttribute- ),- deleteAttribute: getMutationProviderData(- ...deleteAttribute- ),- deleteProductType: getMutationProviderData(- ...deleteProductType- ),- updateAttribute: getMutationProviderData(- ...updateAttribute- ),- updateProductType: getMutationProviderData(- ...updateProductType- )- })- }- </TypedAttributeUpdateMutation>- )}- </TypedAttributeDeleteMutation>+ <TypedAssignAttributeMutation onCompleted={onAssignAttribute}>+ {(...assignAttribute) => (+ <TypedUnassignAttributeMutation+ onCompleted={onUnassignAttribute}+ >+ {(...unassignAttribute) =>+ children({+ assignAttribute: getMutationProviderData(+ ...assignAttribute+ ),+ deleteProductType: getMutationProviderData(+ ...deleteProductType+ ),+ unassignAttribute: getMutationProviderData(+ ...unassignAttribute+ ),+ updateProductType: getMutationProviderData(+ ...updateProductType+ )+ })+ }+ </TypedUnassignAttributeMutation>)}- </TypedAttributeCreateMutation>+ </TypedAssignAttributeMutation>)}</TypedProductTypeUpdateMutation>)}diff --git a/saleor/static/dashboard-next/productTypes/fixtures.ts b/saleor/static/dashboard-next/productTypes/fixtures.tsindex 83d512b039..9718befc76 100644--- a/saleor/static/dashboard-next/productTypes/fixtures.ts+++ b/saleor/static/dashboard-next/productTypes/fixtures.ts@@ -532,61 +532,19 @@ export const productType: ProductTypeDetails_productType = {__typename: "Attribute" as "Attribute",id: "UHJvZHVjdEF0dHJpYnV0ZTo5",name: "Author",- slug: "author",- values: [- {- __typename: "AttributeValue" as "AttributeValue",- id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI0",- name: "John Doe",- slug: "john-doe"- },- {- __typename: "AttributeValue" as "AttributeValue",- id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI1",- name: "Milionare Pirate",- slug: "milionare-pirate"- }- ]+ slug: "author"},{__typename: "Attribute" as "Attribute",id: "UHJvZHVjdEF0dHJpYnV0ZToxMQ==",name: "Language",- slug: "language",- values: [- {- __typename: "AttributeValue" as "AttributeValue",- id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI4",- name: "English",- slug: "english"- },- {- __typename: "AttributeValue" as "AttributeValue",- id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI5",- name: "Pirate",- slug: "pirate"- }- ]+ slug: "language"},{__typename: "Attribute" as "Attribute",id: "UHJvZHVjdEF0dHJpYnV0ZToxMA==",name: "Publisher",- slug: "publisher",- values: [- {- __typename: "AttributeValue" as "AttributeValue",- id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI2",- name: "Mirumee Press",- slug: "mirumee-press"- },- {- __typename: "AttributeValue" as "AttributeValue",- id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI3",- name: "Saleor Publishing",- slug: "saleor-publishing"- }- ]+ slug: "publisher"}],taxType: {diff --git a/saleor/static/dashboard-next/productTypes/mutations.ts b/saleor/static/dashboard-next/productTypes/mutations.tsindex 9898e0644d..d176a81905 100644--- a/saleor/static/dashboard-next/productTypes/mutations.ts+++ b/saleor/static/dashboard-next/productTypes/mutations.ts@@ -2,6 +2,10 @@ import gql from "graphql-tag";import { TypedMutation } from "../mutations";import { productTypeDetailsFragment } from "./queries";+import {+ AssignAttribute,+ AssignAttributeVariables+} from "./types/AssignAttribute";import {ProductTypeBulkDelete,ProductTypeBulkDeleteVariables@@ -18,6 +22,10 @@ import {ProductTypeUpdate,ProductTypeUpdateVariables} from "./types/ProductTypeUpdate";+import {+ UnassignAttribute,+ UnassignAttributeVariables+} from "./types/UnassignAttribute";export const productTypeDeleteMutation = gql`mutation ProductTypeDelete($id: ID!) {@@ -71,6 +79,44 @@ export const TypedProductTypeUpdateMutation = TypedMutation<ProductTypeUpdateVariables>(productTypeUpdateMutation);+export const assignAttributeMutation = gql`+ ${productTypeDetailsFragment}+ mutation AssignAttribute($id: ID!, $operations: [AttributeAssignInput!]!) {+ attributeAssign(productTypeId: $id, operations: $operations) {+ errors {+ field+ message+ }+ productType {+ ...ProductTypeDetailsFragment+ }+ }+ }+`;+export const TypedAssignAttributeMutation = TypedMutation<+ AssignAttribute,+ AssignAttributeVariables+>(assignAttributeMutation);++export const unassignAttributeMutation = gql`+ ${productTypeDetailsFragment}+ mutation UnassignAttribute($id: ID!, $ids: [ID]!) {+ attributeUnassign(productTypeId: $id, attributeIds: $ids) {+ errors {+ field+ message+ }+ productType {+ ...ProductTypeDetailsFragment+ }+ }+ }+`;+export const TypedUnassignAttributeMutation = TypedMutation<+ UnassignAttribute,+ UnassignAttributeVariables+>(unassignAttributeMutation);+export const productTypeCreateMutation = gql`${productTypeDetailsFragment}mutation ProductTypeCreate($input: ProductTypeInput!) {diff --git a/saleor/static/dashboard-next/productTypes/queries.ts b/saleor/static/dashboard-next/productTypes/queries.tsindex 92fb755be1..9b34f532df 100644--- a/saleor/static/dashboard-next/productTypes/queries.ts+++ b/saleor/static/dashboard-next/productTypes/queries.ts@@ -1,5 +1,6 @@import gql from "graphql-tag";+import { attributeFragment } from "@saleor/attributes/queries";import { TypedQuery } from "../queries";import { ProductTypeCreateData } from "./types/ProductTypeCreateData";import {@@ -11,18 +12,6 @@ import {ProductTypeListVariables} from "./types/ProductTypeList";-export const attributeFragment = gql`- fragment AttributeFragment on Attribute {- id- name- slug- values {- id- name- slug- }- }-`;export const productTypeFragment = gql`fragment ProductTypeFragment on ProductType {iddiff --git a/saleor/static/dashboard-next/productTypes/types/AssignAttribute.ts b/saleor/static/dashboard-next/productTypes/types/AssignAttribute.tsnew file mode 100644index 0000000000..b334788382--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/types/AssignAttribute.ts@@ -0,0 +1,68 @@+/* tslint:disable */+/* eslint-disable */+// This file was automatically generated and should not be edited.++import { AttributeAssignInput } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: AssignAttribute+// ====================================================++export interface AssignAttribute_attributeAssign_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface AssignAttribute_attributeAssign_productType_taxType {+ __typename: "TaxType";+ description: string | null;+ taxCode: string | null;+}++export interface AssignAttribute_attributeAssign_productType_productAttributes {+ __typename: "Attribute";+ id: string;+ name: string | null;+ slug: string | null;+}++export interface AssignAttribute_attributeAssign_productType_variantAttributes {+ __typename: "Attribute";+ id: string;+ name: string | null;+ slug: string | null;+}++export interface AssignAttribute_attributeAssign_productType_weight {+ __typename: "Weight";+ unit: string;+ value: number;+}++export interface AssignAttribute_attributeAssign_productType {+ __typename: "ProductType";+ id: string;+ name: string;+ hasVariants: boolean;+ isShippingRequired: boolean;+ taxType: AssignAttribute_attributeAssign_productType_taxType | null;+ productAttributes: (AssignAttribute_attributeAssign_productType_productAttributes | null)[] | null;+ variantAttributes: (AssignAttribute_attributeAssign_productType_variantAttributes | null)[] | null;+ weight: AssignAttribute_attributeAssign_productType_weight | null;+}++export interface AssignAttribute_attributeAssign {+ __typename: "AttributeAssign";+ errors: AssignAttribute_attributeAssign_errors[] | null;+ productType: AssignAttribute_attributeAssign_productType | null;+}++export interface AssignAttribute {+ attributeAssign: AssignAttribute_attributeAssign | null;+}++export interface AssignAttributeVariables {+ id: string;+ operations: AttributeAssignInput[];+}diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.tsindex e6dfb6c0ac..2df733f768 100644--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts@@ -20,26 +20,11 @@ export interface ProductTypeCreate_productTypeCreate_productType_taxType {taxCode: string | null;}-export interface ProductTypeCreate_productTypeCreate_productType_productAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;-}-export interface ProductTypeCreate_productTypeCreate_productType_productAttributes {__typename: "Attribute";id: string;name: string | null;slug: string | null;- values: (ProductTypeCreate_productTypeCreate_productType_productAttributes_values | null)[] | null;-}--export interface ProductTypeCreate_productTypeCreate_productType_variantAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;}export interface ProductTypeCreate_productTypeCreate_productType_variantAttributes {@@ -47,7 +32,6 @@ export interface ProductTypeCreate_productTypeCreate_productType_variantAttributid: string;name: string | null;slug: string | null;- values: (ProductTypeCreate_productTypeCreate_productType_variantAttributes_values | null)[] | null;}export interface ProductTypeCreate_productTypeCreate_productType_weight {diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.tsindex 3c1a8e0a84..b5c993b360 100644--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts@@ -14,26 +14,11 @@ export interface ProductTypeDetails_productType_taxType {taxCode: string | null;}-export interface ProductTypeDetails_productType_productAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;-}-export interface ProductTypeDetails_productType_productAttributes {__typename: "Attribute";id: string;name: string | null;slug: string | null;- values: (ProductTypeDetails_productType_productAttributes_values | null)[] | null;-}--export interface ProductTypeDetails_productType_variantAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;}export interface ProductTypeDetails_productType_variantAttributes {@@ -41,7 +26,6 @@ export interface ProductTypeDetails_productType_variantAttributes {id: string;name: string | null;slug: string | null;- values: (ProductTypeDetails_productType_variantAttributes_values | null)[] | null;}export interface ProductTypeDetails_productType_weight {diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.tsindex 4b7466e9c1..f8684acff3 100644--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts@@ -12,26 +12,11 @@ export interface ProductTypeDetailsFragment_taxType {taxCode: string | null;}-export interface ProductTypeDetailsFragment_productAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;-}-export interface ProductTypeDetailsFragment_productAttributes {__typename: "Attribute";id: string;name: string | null;slug: string | null;- values: (ProductTypeDetailsFragment_productAttributes_values | null)[] | null;-}--export interface ProductTypeDetailsFragment_variantAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;}export interface ProductTypeDetailsFragment_variantAttributes {@@ -39,7 +24,6 @@ export interface ProductTypeDetailsFragment_variantAttributes {id: string;name: string | null;slug: string | null;- values: (ProductTypeDetailsFragment_variantAttributes_values | null)[] | null;}export interface ProductTypeDetailsFragment_weight {diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.tsindex 87433c0b1e..84a8706c18 100644--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts@@ -20,26 +20,11 @@ export interface ProductTypeUpdate_productTypeUpdate_productType_taxType {taxCode: string | null;}-export interface ProductTypeUpdate_productTypeUpdate_productType_productAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;-}-export interface ProductTypeUpdate_productTypeUpdate_productType_productAttributes {__typename: "Attribute";id: string;name: string | null;slug: string | null;- values: (ProductTypeUpdate_productTypeUpdate_productType_productAttributes_values | null)[] | null;-}--export interface ProductTypeUpdate_productTypeUpdate_productType_variantAttributes_values {- __typename: "AttributeValue";- id: string;- name: string | null;- slug: string | null;}export interface ProductTypeUpdate_productTypeUpdate_productType_variantAttributes {@@ -47,7 +32,6 @@ export interface ProductTypeUpdate_productTypeUpdate_productType_variantAttributid: string;name: string | null;slug: string | null;- values: (ProductTypeUpdate_productTypeUpdate_productType_variantAttributes_values | null)[] | null;}export interface ProductTypeUpdate_productTypeUpdate_productType_weight {diff --git a/saleor/static/dashboard-next/productTypes/types/UnassignAttribute.ts b/saleor/static/dashboard-next/productTypes/types/UnassignAttribute.tsnew file mode 100644index 0000000000..a345c0e654--- /dev/null+++ b/saleor/static/dashboard-next/productTypes/types/UnassignAttribute.ts@@ -0,0 +1,66 @@+/* tslint:disable */+/* eslint-disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL mutation operation: UnassignAttribute+// ====================================================++export interface UnassignAttribute_attributeUnassign_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface UnassignAttribute_attributeUnassign_productType_taxType {+ __typename: "TaxType";+ description: string | null;+ taxCode: string | null;+}++export interface UnassignAttribute_attributeUnassign_productType_productAttributes {+ __typename: "Attribute";+ id: string;+ name: string | null;+ slug: string | null;+}++export interface UnassignAttribute_attributeUnassign_productType_variantAttributes {+ __typename: "Attribute";+ id: string;+ name: string | null;+ slug: string | null;+}++export interface UnassignAttribute_attributeUnassign_productType_weight {+ __typename: "Weight";+ unit: string;+ value: number;+}++export interface UnassignAttribute_attributeUnassign_productType {+ __typename: "ProductType";+ id: string;+ name: string;+ hasVariants: boolean;+ isShippingRequired: boolean;+ taxType: UnassignAttribute_attributeUnassign_productType_taxType | null;+ productAttributes: (UnassignAttribute_attributeUnassign_productType_productAttributes | null)[] | null;+ variantAttributes: (UnassignAttribute_attributeUnassign_productType_variantAttributes | null)[] | null;+ weight: UnassignAttribute_attributeUnassign_productType_weight | null;+}++export interface UnassignAttribute_attributeUnassign {+ __typename: "AttributeUnassign";+ errors: UnassignAttribute_attributeUnassign_errors[] | null;+ productType: UnassignAttribute_attributeUnassign_productType | null;+}++export interface UnassignAttribute {+ attributeUnassign: UnassignAttribute_attributeUnassign | null;+}++export interface UnassignAttributeVariables {+ id: string;+ ids: (string | null)[];+}diff --git a/saleor/static/dashboard-next/productTypes/urls.ts b/saleor/static/dashboard-next/productTypes/urls.tsindex 8e7c8e6290..86251789d7 100644--- a/saleor/static/dashboard-next/productTypes/urls.ts+++ b/saleor/static/dashboard-next/productTypes/urls.ts@@ -18,10 +18,12 @@ export const productTypeAddUrl = productTypeAddPath;export const productTypePath = (id: string) => urlJoin(productTypeSection, id);export type ProductTypeUrlDialog =- | "add-attribute"- | "edit-attribute"+ | "assign-attribute"+ | "unassign-attribute"+ | "unassign-attributes"| "remove";-export type ProductTypeUrlQueryParams = Dialog<ProductTypeUrlDialog> &+export type ProductTypeUrlQueryParams = BulkAction &+ Dialog<ProductTypeUrlDialog> &SingleAction & {type?: string;};diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsxindex 474102a594..6dddba387d 100644--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx@@ -1,24 +1,27 @@-import DialogContentText from "@material-ui/core/DialogContentText";+import Button from "@material-ui/core/Button";import React from "react";-import ActionDialog from "@saleor/components/ActionDialog";+import { attributeUrl } from "@saleor/attributes/urls";+import AssignAttributeDialog from "@saleor/components/AssignAttributeDialog";import { WindowTitle } from "@saleor/components/WindowTitle";+import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";+import SearchAttributes from "@saleor/containers/SearchAttributes";+import useBulkActions from "@saleor/hooks/useBulkActions";import useNavigator from "@saleor/hooks/useNavigator";import useNotifier from "@saleor/hooks/useNotifier";-import i18n from "../../../i18n";-import { getMutationState, maybe } from "../../../misc";-import { AttributeTypeEnum } from "../../../types/globalTypes";-import ProductTypeAttributeEditDialog, {- FormData as AttributeForm-} from "../../components/ProductTypeAttributeEditDialog";+import i18n from "@saleor/i18n";+import { getMutationState, maybe, stopPropagation } from "@saleor/misc";+import ProductTypeAttributeUnassignDialog from "@saleor/productTypes/components/ProductTypeAttributeUnassignDialog";+import ProductTypeBulkAttributeUnassignDialog from "@saleor/productTypes/components/ProductTypeBulkAttributeUnassignDialog";+import ProductTypeDeleteDialog from "@saleor/productTypes/components/ProductTypeDeleteDialog";+import { AssignAttribute } from "@saleor/productTypes/types/AssignAttribute";+import { UnassignAttribute } from "@saleor/productTypes/types/UnassignAttribute";+import { AttributeTypeEnum } from "@saleor/types/globalTypes";import ProductTypeDetailsPage, {ProductTypeForm} from "../../components/ProductTypeDetailsPage";import ProductTypeOperations from "../../containers/ProductTypeOperations";import { TypedProductTypeDetailsQuery } from "../../queries";-import { AttributeCreate } from "../../types/AttributeCreate";-import { AttributeDelete } from "../../types/AttributeDelete";-import { AttributeUpdate } from "../../types/AttributeUpdate";import { ProductTypeDelete } from "../../types/ProductTypeDelete";import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../../types/ProductTypeUpdate";import {@@ -33,11 +36,14 @@ interface ProductTypeUpdateProps {params: ProductTypeUrlQueryParams;}-export const ProductTypeUpdate: React.StatelessComponent<- ProductTypeUpdateProps-> = ({ id, params }) => {+export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({+ id,+ params+}) => {const navigate = useNavigator();const notify = useNotifier();+ const productAttributeListActions = useBulkActions();+ const variantAttributeListActions = useBulkActions();return (<ProductTypeUpdateErrors>@@ -48,48 +54,32 @@ export const ProductTypeUpdate: React.StatelessComponent<require={["productType"]}>{({ data, loading: dataLoading }) => {- const closeModal = () => {- navigate(productTypeUrl(id), true);- setErrors.addAttributeErrors([]);- setErrors.editAttributeErrors([]);- };- const handleAttributeCreateSuccess = (data: AttributeCreate) => {- if (data.attributeCreate.errors.length === 0) {+ const closeModal = () => navigate(productTypeUrl(id), true);++ const handleAttributeAssignSuccess = (data: AssignAttribute) => {+ if (data.attributeAssign.errors.length === 0) {notify({- text: i18n.t("Attribute created", {+ text: i18n.t("Attributes assigned", {context: "notification"})});closeModal();} else if (- data.attributeCreate.errors !== null &&- data.attributeCreate.errors.length > 0+ data.attributeAssign.errors !== null &&+ data.attributeAssign.errors.length > 0) {- setErrors.addAttributeErrors(data.attributeCreate.errors);- }- };- const handleAttributeDeleteSuccess = (data: AttributeDelete) => {- if (!data.attributeDelete.errors) {- notify({- text: i18n.t("Attribute deleted", {- context: "notification"- })- });+ setErrors.addAttributeErrors(data.attributeAssign.errors);}};- const handleAttributeUpdateSuccess = (data: AttributeUpdate) => {- if (data.attributeUpdate.errors.length === 0) {+ const handleAttributeUnassignSuccess = (+ data: UnassignAttribute+ ) => {+ if (!data.attributeUnassign.errors) {notify({- text: i18n.t("Attribute updated", {+ text: i18n.t("Attribute unassigned", {context: "notification"})});- closeModal();- } else if (- data.attributeUpdate.errors !== null &&- data.attributeUpdate.errors.length > 0- ) {- setErrors.editAttributeErrors(data.attributeUpdate.errors);}};const handleProductTypeDeleteSuccess = (@@ -126,17 +116,15 @@ export const ProductTypeUpdate: React.StatelessComponent<return (<ProductTypeOperations- onAttributeCreate={handleAttributeCreateSuccess}- onAttributeDelete={handleAttributeDeleteSuccess}- onAttributeUpdate={handleAttributeUpdateSuccess}+ onAssignAttribute={handleAttributeAssignSuccess}+ onUnassignAttribute={handleAttributeUnassignSuccess}onProductTypeDelete={handleProductTypeDeleteSuccess}onProductTypeUpdate={handleProductTypeUpdateSuccess}>{({- attributeCreate,- deleteAttribute,+ assignAttribute,deleteProductType,- updateAttribute,+ unassignAttribute,updateProductType}) => {const handleProductTypeDelete = () =>@@ -161,60 +149,45 @@ export const ProductTypeUpdate: React.StatelessComponent<}});};- const handleAttributeCreate = (- data: AttributeForm,- type: AttributeTypeEnum- ) =>- attributeCreate.mutate({+ const handleAssignAttribute = () =>+ assignAttribute.mutate({id,- input: {- name: data.name,- values: data.values.map(value => ({- name: value.label- }))- },- type+ operations: params.ids.map(id => ({+ attributeId: id,+ attributeType: AttributeTypeEnum[params.type]+ }))});- const handleAttributeDelete = (- id: string,- event: React.MouseEvent<any>- ) => {- event.stopPropagation();- deleteAttribute.mutate({ id });- };- const handleAttributeUpdate = (- id: string,- formData: AttributeForm- ) => {- const attribute = data.productType.variantAttributes- .concat(data.productType.productAttributes)- .filter(attribute => attribute.id === id)[0];- updateAttribute.mutate({++ const handleAttributeUnassign = () =>+ unassignAttribute.mutate({id,- input: {- addValues: formData.values- .filter(- value =>- !attribute.values- .map(value => value.id)- .includes(value.value)- )- .map(value => ({- name: value.label- })),- name: formData.name,- removeValues: attribute.values- .filter(- value =>- !formData.values- .map(value => value.value)- .includes(value.id)- )- .map(value => value.id)- }+ ids: [params.id]});- };++ const handleBulkAttributeUnassign = () =>+ unassignAttribute.mutate({+ id,+ ids: params.ids+ });+const loading = updateProductType.opts.loading || dataLoading;++ const assignTransactionState = getMutationState(+ assignAttribute.opts.called,+ assignAttribute.opts.loading,+ maybe(+ () => assignAttribute.opts.data.attributeAssign.errors+ )+ );++ const unassignTransactionState = getMutationState(+ unassignAttribute.opts.called,+ unassignAttribute.opts.loading,+ maybe(+ () => unassignAttribute.opts.data.attributeUnassign.errors+ )+ );+const deleteTransactionState = getMutationState(deleteProductType.opts.called,deleteProductType.opts.loading,@@ -231,12 +204,6 @@ export const ProductTypeUpdate: React.StatelessComponent<));- const attribute = maybe(() =>- data.productType.productAttributes- .concat(data.productType.variantAttributes)- .find(attribute => attribute.id === params.id)- );-return (<><WindowTitle title={maybe(() => data.productType.name)} />@@ -253,16 +220,18 @@ export const ProductTypeUpdate: React.StatelessComponent<onAttributeAdd={type =>navigate(productTypeUrl(id, {- action: "add-attribute",+ action: "assign-attribute",type}))}- onAttributeDelete={handleAttributeDelete}- onAttributeUpdate={attributeId =>+ onAttributeClick={attributeId =>+ navigate(attributeUrl(attributeId))+ }+ onAttributeUnassign={attributeId =>navigate(productTypeUrl(id, {- action: "edit-attribute",+ action: "unassign-attribute",id: attributeId}))@@ -276,75 +245,141 @@ export const ProductTypeUpdate: React.StatelessComponent<)}onSubmit={handleProductTypeUpdate}- />- {!dataLoading && (- <>- {Object.keys(AttributeTypeEnum).map(key => (- <ProductTypeAttributeEditDialog- disabled={attributeCreate.opts.loading}- errors={errors.addAttributeErrors}- name=""- values={[]}- onClose={closeModal}- onConfirm={data =>- handleAttributeCreate(- data,- AttributeTypeEnum[key]+ productAttributeList={{+ isChecked: productAttributeListActions.isSelected,+ selected:+ productAttributeListActions.listElements.length,+ toggle: productAttributeListActions.toggle,+ toggleAll: productAttributeListActions.toggleAll,+ toolbar: (+ <Button+ color="primary"+ onClick={() =>+ navigate(+ productTypeUrl(id, {+ action: "unassign-attributes",+ ids:+ productAttributeListActions.listElements+ }))}- opened={- params.action === "add-attribute" &&- params.type === AttributeTypeEnum[key]+ >+ {i18n.t("Unassign", {+ context: "unassign attribute from product type"+ })}+ </Button>+ )+ }}+ variantAttributeList={{+ isChecked: variantAttributeListActions.isSelected,+ selected:+ variantAttributeListActions.listElements.length,+ toggle: variantAttributeListActions.toggle,+ toggleAll: variantAttributeListActions.toggleAll,+ toolbar: (+ <Button+ color="primary"+ onClick={() =>+ navigate(+ productTypeUrl(id, {+ action: "unassign-attributes",+ ids:+ variantAttributeListActions.listElements+ })+ )}- title={i18n.t("Add Attribute", {- context: "modal title"+ >+ {i18n.t("Unassign", {+ context: "unassign attribute from product type"})}- key={key}- />- ))}- <ProductTypeAttributeEditDialog- disabled={updateAttribute.opts.loading}- errors={errors.editAttributeErrors}- name={maybe(() => attribute.name)}- values={maybe(() =>- attribute.values.map(value => ({- label: value.name,- value: value.id- }))- )}- onClose={closeModal}- onConfirm={data =>- handleAttributeUpdate(params.id, data)- }- opened={params.action === "edit-attribute"}- title={i18n.t("Edit Attribute", {- context: "modal title"- })}- />- <ActionDialog- confirmButtonState={deleteTransactionState}- open={params.action === "remove"}- onClose={() => navigate(productTypeUrl(id))}- onConfirm={handleProductTypeDelete}- title={i18n.t("Remove product type")}- variant="delete"- >- <DialogContentText- dangerouslySetInnerHTML={{- __html: i18n.t(- "Are you sure you want to remove <strong>{{ name }}</strong>?",- {- name: maybe(- () => data.productType.name,- "..."+ </Button>+ )+ }}+ />+ {!dataLoading && (+ <SearchAttributes+ variables={DEFAULT_INITIAL_SEARCH_DATA}+ >+ {({ search, result }) => (+ <>+ {Object.keys(AttributeTypeEnum).map(key => (+ <AssignAttributeDialog+ attributes={maybe(() =>+ result.data.attributes.edges.map(+ edge => edge.node)+ )}+ confirmButtonState={assignTransactionState}+ loading={result.loading}+ onClose={closeModal}+ onSubmit={handleAssignAttribute}+ onFetch={search}+ open={+ params.action === "assign-attribute" &&+ params.type === AttributeTypeEnum[key]}- )- }}- />- </ActionDialog>- </>+ selected={maybe(() => params.ids, [])}+ onToggle={attributeId => {+ const ids = maybe(() => params.ids, []);+ navigate(+ productTypeUrl(id, {+ ...params,+ ids: ids.includes(id)+ ? params.ids.filter(+ selectedId =>+ selectedId !== attributeId+ )+ : [...ids, attributeId]+ })+ );+ }}+ key={key}+ />+ ))}+ </>+ )}+ </SearchAttributes>)}+ <ProductTypeDeleteDialog+ confirmButtonState={deleteTransactionState}+ name={maybe(() => data.productType.name, "...")}+ open={params.action === "remove"}+ onClose={() => navigate(productTypeUrl(id))}+ onConfirm={handleProductTypeDelete}+ />+ <ProductTypeBulkAttributeUnassignDialog+ attributeQuantity={maybe(+ () => params.ids.length.toString(),+ "..."+ )}+ confirmButtonState={unassignTransactionState}+ onClose={closeModal}+ onConfirm={handleAttributeUnassign}+ open={params.action === "unassign-attributes"}+ productTypeName={maybe(+ () => data.productType.name,+ "..."+ )}+ />+ <ProductTypeAttributeUnassignDialog+ attributeName={maybe(+ () =>+ [+ ...data.productType.productAttributes,+ ...data.productType.variantAttributes+ ].find(attribute => attribute.id === params.id)+ .name,+ "..."+ )}+ confirmButtonState={unassignTransactionState}+ onClose={closeModal}+ onConfirm={handleBulkAttributeUnassign}+ open={params.action === "unassign-attribute"}+ productTypeName={maybe(+ () => data.productType.name,+ "..."+ )}+ /></>);}}diff --git a/saleor/static/dashboard-next/products/types/Product.ts b/saleor/static/dashboard-next/products/types/Product.tsindex 2396b200b2..5a7fb789df 100644--- a/saleor/static/dashboard-next/products/types/Product.ts+++ b/saleor/static/dashboard-next/products/types/Product.ts@@ -72,7 +72,7 @@ export interface Product_attributes_value {export interface Product_attributes {__typename: "SelectedAttribute";attribute: Product_attributes_attribute;- value: Product_attributes_value;+ value: Product_attributes_value | null;}export interface Product_pricing_priceRange_start_net {diff --git a/saleor/static/dashboard-next/products/types/ProductCreate.ts b/saleor/static/dashboard-next/products/types/ProductCreate.tsindex 5688b7287e..afa3fc2b14 100644--- a/saleor/static/dashboard-next/products/types/ProductCreate.ts+++ b/saleor/static/dashboard-next/products/types/ProductCreate.ts@@ -80,7 +80,7 @@ export interface ProductCreate_productCreate_product_attributes_value {export interface ProductCreate_productCreate_product_attributes {__typename: "SelectedAttribute";attribute: ProductCreate_productCreate_product_attributes_attribute;- value: ProductCreate_productCreate_product_attributes_value;+ value: ProductCreate_productCreate_product_attributes_value | null;}export interface ProductCreate_productCreate_product_pricing_priceRange_start_net {diff --git a/saleor/static/dashboard-next/products/types/ProductDetails.ts b/saleor/static/dashboard-next/products/types/ProductDetails.tsindex 4e0326d16a..de8697966e 100644--- a/saleor/static/dashboard-next/products/types/ProductDetails.ts+++ b/saleor/static/dashboard-next/products/types/ProductDetails.ts@@ -72,7 +72,7 @@ export interface ProductDetails_product_attributes_value {export interface ProductDetails_product_attributes {__typename: "SelectedAttribute";attribute: ProductDetails_product_attributes_attribute;- value: ProductDetails_product_attributes_value;+ value: ProductDetails_product_attributes_value | null;}export interface ProductDetails_product_pricing_priceRange_start_net {diff --git a/saleor/static/dashboard-next/products/types/ProductImageCreate.ts b/saleor/static/dashboard-next/products/types/ProductImageCreate.tsindex 1e4baa7298..04e8c39d8e 100644--- a/saleor/static/dashboard-next/products/types/ProductImageCreate.ts+++ b/saleor/static/dashboard-next/products/types/ProductImageCreate.ts@@ -78,7 +78,7 @@ export interface ProductImageCreate_productImageCreate_product_attributes_valueexport interface ProductImageCreate_productImageCreate_product_attributes {__typename: "SelectedAttribute";attribute: ProductImageCreate_productImageCreate_product_attributes_attribute;- value: ProductImageCreate_productImageCreate_product_attributes_value;+ value: ProductImageCreate_productImageCreate_product_attributes_value | null;}export interface ProductImageCreate_productImageCreate_product_pricing_priceRange_start_net {diff --git a/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts b/saleor/static/dashboard-next/products/types/ProductImageUpdate.tsindex bd2a9d1787..1db5000cc0 100644--- a/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts+++ b/saleor/static/dashboard-next/products/types/ProductImageUpdate.ts@@ -78,7 +78,7 @@ export interface ProductImageUpdate_productImageUpdate_product_attributes_valueexport interface ProductImageUpdate_productImageUpdate_product_attributes {__typename: "SelectedAttribute";attribute: ProductImageUpdate_productImageUpdate_product_attributes_attribute;- value: ProductImageUpdate_productImageUpdate_product_attributes_value;+ value: ProductImageUpdate_productImageUpdate_product_attributes_value | null;}export interface ProductImageUpdate_productImageUpdate_product_pricing_priceRange_start_net {diff --git a/saleor/static/dashboard-next/products/types/ProductUpdate.ts b/saleor/static/dashboard-next/products/types/ProductUpdate.tsindex b991242e01..b11f789925 100644--- a/saleor/static/dashboard-next/products/types/ProductUpdate.ts+++ b/saleor/static/dashboard-next/products/types/ProductUpdate.ts@@ -80,7 +80,7 @@ export interface ProductUpdate_productUpdate_product_attributes_value {export interface ProductUpdate_productUpdate_product_attributes {__typename: "SelectedAttribute";attribute: ProductUpdate_productUpdate_product_attributes_attribute;- value: ProductUpdate_productUpdate_product_attributes_value;+ value: ProductUpdate_productUpdate_product_attributes_value | null;}export interface ProductUpdate_productUpdate_product_pricing_priceRange_start_net {diff --git a/saleor/static/dashboard-next/products/types/ProductVariant.ts b/saleor/static/dashboard-next/products/types/ProductVariant.tsindex 86239a5995..ce379e15a8 100644--- a/saleor/static/dashboard-next/products/types/ProductVariant.ts+++ b/saleor/static/dashboard-next/products/types/ProductVariant.ts@@ -31,7 +31,7 @@ export interface ProductVariant_attributes_value {export interface ProductVariant_attributes {__typename: "SelectedAttribute";attribute: ProductVariant_attributes_attribute;- value: ProductVariant_attributes_value;+ value: ProductVariant_attributes_value | null;}export interface ProductVariant_costPrice {diff --git a/saleor/static/dashboard-next/products/types/ProductVariantDetails.ts b/saleor/static/dashboard-next/products/types/ProductVariantDetails.tsindex d7337cbac7..793fee6605 100644--- a/saleor/static/dashboard-next/products/types/ProductVariantDetails.ts+++ b/saleor/static/dashboard-next/products/types/ProductVariantDetails.ts@@ -31,7 +31,7 @@ export interface ProductVariantDetails_productVariant_attributes_value {export interface ProductVariantDetails_productVariant_attributes {__typename: "SelectedAttribute";attribute: ProductVariantDetails_productVariant_attributes_attribute;- value: ProductVariantDetails_productVariant_attributes_value;+ value: ProductVariantDetails_productVariant_attributes_value | null;}export interface ProductVariantDetails_productVariant_costPrice {diff --git a/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts b/saleor/static/dashboard-next/products/types/SimpleProductUpdate.tsindex 5b0b3d69b7..389f64694c 100644--- a/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts+++ b/saleor/static/dashboard-next/products/types/SimpleProductUpdate.ts@@ -80,7 +80,7 @@ export interface SimpleProductUpdate_productUpdate_product_attributes_value {export interface SimpleProductUpdate_productUpdate_product_attributes {__typename: "SelectedAttribute";attribute: SimpleProductUpdate_productUpdate_product_attributes_attribute;- value: SimpleProductUpdate_productUpdate_product_attributes_value;+ value: SimpleProductUpdate_productUpdate_product_attributes_value | null;}export interface SimpleProductUpdate_productUpdate_product_pricing_priceRange_start_net {@@ -210,7 +210,7 @@ export interface SimpleProductUpdate_productVariantUpdate_productVariant_attribuexport interface SimpleProductUpdate_productVariantUpdate_productVariant_attributes {__typename: "SelectedAttribute";attribute: SimpleProductUpdate_productVariantUpdate_productVariant_attributes_attribute;- value: SimpleProductUpdate_productVariantUpdate_productVariant_attributes_value;+ value: SimpleProductUpdate_productVariantUpdate_productVariant_attributes_value | null;}export interface SimpleProductUpdate_productVariantUpdate_productVariant_costPrice {diff --git a/saleor/static/dashboard-next/products/types/VariantCreate.ts b/saleor/static/dashboard-next/products/types/VariantCreate.tsindex 3c8d9f64c1..c763a11aa6 100644--- a/saleor/static/dashboard-next/products/types/VariantCreate.ts+++ b/saleor/static/dashboard-next/products/types/VariantCreate.ts@@ -39,7 +39,7 @@ export interface VariantCreate_productVariantCreate_productVariant_attributes_vaexport interface VariantCreate_productVariantCreate_productVariant_attributes {__typename: "SelectedAttribute";attribute: VariantCreate_productVariantCreate_productVariant_attributes_attribute;- value: VariantCreate_productVariantCreate_productVariant_attributes_value;+ value: VariantCreate_productVariantCreate_productVariant_attributes_value | null;}export interface VariantCreate_productVariantCreate_productVariant_costPrice {diff --git a/saleor/static/dashboard-next/products/types/VariantImageAssign.ts b/saleor/static/dashboard-next/products/types/VariantImageAssign.tsindex dfc6bf05c3..560d08e0b9 100644--- a/saleor/static/dashboard-next/products/types/VariantImageAssign.ts+++ b/saleor/static/dashboard-next/products/types/VariantImageAssign.ts@@ -37,7 +37,7 @@ export interface VariantImageAssign_variantImageAssign_productVariant_attributesexport interface VariantImageAssign_variantImageAssign_productVariant_attributes {__typename: "SelectedAttribute";attribute: VariantImageAssign_variantImageAssign_productVariant_attributes_attribute;- value: VariantImageAssign_variantImageAssign_productVariant_attributes_value;+ value: VariantImageAssign_variantImageAssign_productVariant_attributes_value | null;}export interface VariantImageAssign_variantImageAssign_productVariant_costPrice {diff --git a/saleor/static/dashboard-next/products/types/VariantImageUnassign.ts b/saleor/static/dashboard-next/products/types/VariantImageUnassign.tsindex 420d03223a..3a63b52e8b 100644--- a/saleor/static/dashboard-next/products/types/VariantImageUnassign.ts+++ b/saleor/static/dashboard-next/products/types/VariantImageUnassign.ts@@ -37,7 +37,7 @@ export interface VariantImageUnassign_variantImageUnassign_productVariant_attribexport interface VariantImageUnassign_variantImageUnassign_productVariant_attributes {__typename: "SelectedAttribute";attribute: VariantImageUnassign_variantImageUnassign_productVariant_attributes_attribute;- value: VariantImageUnassign_variantImageUnassign_productVariant_attributes_value;+ value: VariantImageUnassign_variantImageUnassign_productVariant_attributes_value | null;}export interface VariantImageUnassign_variantImageUnassign_productVariant_costPrice {diff --git a/saleor/static/dashboard-next/products/types/VariantUpdate.ts b/saleor/static/dashboard-next/products/types/VariantUpdate.tsindex e979e4edfb..0f723a4352 100644--- a/saleor/static/dashboard-next/products/types/VariantUpdate.ts+++ b/saleor/static/dashboard-next/products/types/VariantUpdate.ts@@ -39,7 +39,7 @@ export interface VariantUpdate_productVariantUpdate_productVariant_attributes_vaexport interface VariantUpdate_productVariantUpdate_productVariant_attributes {__typename: "SelectedAttribute";attribute: VariantUpdate_productVariantUpdate_productVariant_attributes_attribute;- value: VariantUpdate_productVariantUpdate_productVariant_attributes_value;+ value: VariantUpdate_productVariantUpdate_productVariant_attributes_value | null;}export interface VariantUpdate_productVariantUpdate_productVariant_costPrice {diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.jsindex dffb7d3a85..9a050f083d 100644--- a/saleor/static/dashboard-next/storybook/config.js+++ b/saleor/static/dashboard-next/storybook/config.js@@ -6,6 +6,7 @@ function loadStories() {require("./stories/components/ActionDialog");require("./stories/components/AddressEdit");require("./stories/components/AddressFormatter");+ require("./stories/components/AssignAttributeDialog");require("./stories/components/AutocompleteSelectMenu");require("./stories/components/CardMenu");require("./stories/components/Checkbox");@@ -131,8 +132,10 @@ function loadStories() {require("./stories/orders/OrderShippingMethodEditDialog");// Product types- require("./stories/productTypes/ProductTypeAttributeEditDialog");+ require("./stories/productTypes/ProductTypeAttributeUnassignDialog");+ require("./stories/productTypes/ProductTypeBulkAttributeUnassignDialog");require("./stories/productTypes/ProductTypeCreatePage");+ require("./stories/productTypes/ProductTypeDeleteDialog");require("./stories/productTypes/ProductTypeDetailsPage");require("./stories/productTypes/ProductTypeListPage");diff --git a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsxnew file mode 100644index 0000000000..b52f8177fe--- /dev/null+++ b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx@@ -0,0 +1,27 @@+import { storiesOf } from "@storybook/react";+import * as React from "react";++import { attributes } from "@saleor/attributes/fixtures";+import AssignAttributeDialog, {+ AssignAttributeDialogProps+} from "../../../components/AssignAttributeDialog";+import Decorator from "../../Decorator";++const props: AssignAttributeDialogProps = {+ attributes: attributes.slice(0, 5),+ confirmButtonState: "default",+ loading: false,+ onClose: () => undefined,+ onFetch: () => undefined,+ onSubmit: () => undefined,+ onToggle: () => undefined,+ open: true,+ selected: [attributes[0].id, attributes[3].id]+};++storiesOf("Generics / Assign attributes dialog", module)+ .addDecorator(Decorator)+ .add("default", () => <AssignAttributeDialog {...props} />)+ .add("loading", () => (+ <AssignAttributeDialog {...props} attributes={undefined} loading={true} />+ ));diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeAttributeEditDialog.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeAttributeEditDialog.tsxdeleted file mode 100644index 9b091cc9b3..0000000000--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeAttributeEditDialog.tsx+++ /dev/null@@ -1,41 +0,0 @@-import { storiesOf } from "@storybook/react";-import React from "react";--import ProductTypeAttributeEditDialog, {- ProductTypeAttributeEditDialogProps-} from "../../../productTypes/components/ProductTypeAttributeEditDialog";-import { attributes } from "../../../productTypes/fixtures";-import Decorator from "../../Decorator";--const attribute = attributes[0];--const props: ProductTypeAttributeEditDialogProps = {- disabled: false,- errors: [],- name: attribute.name,- onClose: () => undefined,- onConfirm: () => undefined,- opened: true,- title: "Add Attribute",- values: attribute.values.map(value => ({- label: value.name,- value: value.id- }))-};--storiesOf("Product types / Edit attribute", module)- .addDecorator(Decorator)- .add("default", () => <ProductTypeAttributeEditDialog {...props} />)- .add("loading", () => (- <ProductTypeAttributeEditDialog {...props} disabled={true} />- ))- .add("form errors", () => (- <ProductTypeAttributeEditDialog- {...props}- // errors={["name", "values"].map(field => formError(field))}- errors={["name", "values"].map(field => ({- field,- message: "Generic error"- }))}- />- ));diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeAttributeUnassignDialog.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeAttributeUnassignDialog.tsxnew file mode 100644index 0000000000..125c2fadfd--- /dev/null+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeAttributeUnassignDialog.tsx@@ -0,0 +1,20 @@+import { storiesOf } from "@storybook/react";+import * as React from "react";++import ProductTypeAttributeUnassignDialog, {+ ProductTypeAttributeUnassignDialogProps+} from "../../../productTypes/components/ProductTypeAttributeUnassignDialog";+import Decorator from "../../Decorator";++const props: ProductTypeAttributeUnassignDialogProps = {+ attributeName: "Size",+ confirmButtonState: "default",+ onClose: () => undefined,+ onConfirm: () => undefined,+ open: true,+ productTypeName: "Shoes"+};++storiesOf("Views / Product types / Unassign attribute", module)+ .addDecorator(Decorator)+ .add("default", () => <ProductTypeAttributeUnassignDialog {...props} />);diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeBulkAttributeUnassignDialog.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeBulkAttributeUnassignDialog.tsxnew file mode 100644index 0000000000..d4ab11ef4e--- /dev/null+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeBulkAttributeUnassignDialog.tsx@@ -0,0 +1,20 @@+import { storiesOf } from "@storybook/react";+import * as React from "react";++import ProductTypeBulkAttributeUnassignDialog, {+ ProductTypeBulkAttributeUnassignDialogProps+} from "../../../productTypes/components/ProductTypeBulkAttributeUnassignDialog";+import Decorator from "../../Decorator";++const props: ProductTypeBulkAttributeUnassignDialogProps = {+ attributeQuantity: "4",+ confirmButtonState: "default",+ onClose: () => undefined,+ onConfirm: () => undefined,+ open: true,+ productTypeName: "Shoes"+};++storiesOf("Views / Product types / Unassign multiple attributes", module)+ .addDecorator(Decorator)+ .add("default", () => <ProductTypeBulkAttributeUnassignDialog {...props} />);diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDeleteDialog.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDeleteDialog.tsxnew file mode 100644index 0000000000..4370816a99--- /dev/null+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDeleteDialog.tsx@@ -0,0 +1,19 @@+import { storiesOf } from "@storybook/react";+import * as React from "react";++import ProductTypeDeleteDialog, {+ ProductTypeDeleteDialogProps+} from "../../../productTypes/components/ProductTypeDeleteDialog";+import Decorator from "../../Decorator";++const props: ProductTypeDeleteDialogProps = {+ confirmButtonState: "default",+ name: "Shoes",+ onClose: () => undefined,+ onConfirm: () => undefined,+ open: true+};++storiesOf("Product types / ProductTypeDeleteDialog", module)+ .addDecorator(Decorator)+ .add("default", () => <ProductTypeDeleteDialog {...props} />);diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsxindex 15a3973fbd..5e8badd77b 100644--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx@@ -2,6 +2,7 @@ import { Omit } from "@material-ui/core";import { storiesOf } from "@storybook/react";import React from "react";+import { listActionsProps } from "@saleor/fixtures";import ProductTypeDetailsPage, {ProductTypeDetailsPageProps} from "../../../productTypes/components/ProductTypeDetailsPage";@@ -20,9 +21,11 @@ const props: Omit<ProductTypeDetailsPageProps, "classes"> = {onDelete: () => undefined,onSubmit: () => undefined,pageTitle: productType.name,+ productAttributeList: listActionsProps,productType,saveButtonBarState: "default",- taxTypes: []+ taxTypes: [],+ variantAttributeList: listActionsProps};storiesOf("Views / Product types / Product type details", module)diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex 0ac477a5e8..7733f2744e 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -16,6 +16,11 @@ export enum AttributeInputTypeEnum {MULTISELECT = "MULTISELECT",}+export enum AttributeTypeEnum {+ PRODUCT = "PRODUCT",+ VARIANT = "VARIANT",+}+export enum AttributeValueType {COLOR = "COLOR",GRADIENT = "GRADIENT",@@ -244,6 +249,11 @@ export interface AddressInput {phone?: string | null;}+export interface AttributeAssignInput {+ id: string;+ type: AttributeTypeEnum;+}+export interface AttributeCreateInput {inputType?: AttributeInputTypeEnum | null;name: string;