Skip to content

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

Update callbacks and stories

dominik-zeglene4a4193fe936
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsx
index 539cfc9f23..ead9ea1686 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog.tsx
@@ -12,7 +12,7 @@ import { FormSpacer } from "../../../components/FormSpacer";
import ListField from "../../../components/ListField/ListField";
import i18n from "../../../i18n";
-interface FormData {
+export interface FormData {
name: string;
values: string[];
}
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
index d9b833d2ac..112a4ff18f 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
@@ -1,3 +1,4 @@
+import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import { withStyles } from "@material-ui/core/styles";
import Table from "@material-ui/core/Table";
@@ -16,13 +17,20 @@ import {
ProductTypeDetails_productType_productAttributes_edges_node,
ProductTypeDetails_productType_variantAttributes_edges_node
} from "../../types/ProductTypeDetails";
-import ProductTypeAttributeEditDialog from "../ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog";
+import ProductTypeAttributeEditDialog, {
+ FormData as ProductTypeAttributeEditDialogFormData
+} from "../ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog";
interface ProductTypeAttributesProps {
attributes:
| ProductTypeDetails_productType_productAttributes_edges_node[]
| ProductTypeDetails_productType_variantAttributes_edges_node[];
title: string;
+ onAttributeAdd: (data: ProductTypeAttributeEditDialogFormData) => void;
+ onAttributeUpdate: (
+ id: string,
+ data: ProductTypeAttributeEditDialogFormData
+ ) => void;
}
const decorate = withStyles({
@@ -34,74 +42,103 @@ const decorate = withStyles({
}
});
const ProductTypeAttributes = decorate<ProductTypeAttributesProps>(
- ({ attributes, classes, title }) => (
- <Card>
- <CardTitle title={title} />
- <Table>
- <TableHead>
- <TableRow>
- <TableCell>{i18n.t("Attribute name")}</TableCell>
- <TableCell className={classes.textLeft}>
- {i18n.t("Values")}
- </TableCell>
- </TableRow>
- </TableHead>
- <TableBody>
- {renderCollection(
- attributes,
- attribute => (
- <Toggle key={maybe(() => attribute.id)}>
- {(
- openedAttributeEditDialog,
- { toggle: toggleAttributeEditDialog }
- ) => (
- <>
- <TableRow
- className={!!attribute ? classes.link : undefined}
- hover={!!attribute}
- onClick={toggleAttributeEditDialog}
- 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 />
- )}
+ ({ attributes, classes, title, onAttributeAdd, onAttributeUpdate }) => (
+ <Toggle>
+ {(openedAttributeAddDialog, { toggle: toggleAttributeAddDialog }) => (
+ <>
+ <Card>
+ <CardTitle
+ title={title}
+ toolbar={
+ <Button
+ color="secondary"
+ variant="flat"
+ onClick={toggleAttributeAddDialog}
+ >
+ {i18n.t("Add attribute", { context: "button" })}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell>{i18n.t("Attribute name")}</TableCell>
+ <TableCell className={classes.textLeft}>
+ {i18n.t("Values")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ attributes,
+ attribute => (
+ <Toggle key={maybe(() => attribute.id)}>
+ {(
+ openedAttributeEditDialog,
+ { toggle: toggleAttributeEditDialog }
+ ) => (
+ <>
+ <TableRow
+ className={!!attribute ? classes.link : undefined}
+ hover={!!attribute}
+ onClick={toggleAttributeEditDialog}
+ 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>
+ </TableRow>
+ <ProductTypeAttributeEditDialog
+ name={maybe(() => attribute.name)}
+ opened={openedAttributeEditDialog}
+ title={i18n.t("Edit attribute")}
+ values={maybe(() =>
+ attribute.values.map(value => value.name)
+ )}
+ onClose={toggleAttributeEditDialog}
+ onConfirm={data =>
+ onAttributeUpdate(attribute.id, data)
+ }
+ />
+ </>
+ )}
+ </Toggle>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("No attributes found")}
</TableCell>
</TableRow>
- <ProductTypeAttributeEditDialog
- name={maybe(() => attribute.name)}
- opened={openedAttributeEditDialog}
- title={i18n.t("Edit attribute")}
- values={maybe(() =>
- attribute.values.map(value => value.name)
- )}
- onClose={toggleAttributeEditDialog}
- onConfirm={undefined}
- />
- </>
+ )
)}
- </Toggle>
- ),
- () => (
- <TableRow>
- <TableCell colSpan={2}>
- {i18n.t("No attributes found")}
- </TableCell>
- </TableRow>
- )
- )}
- </TableBody>
- </Table>
- </Card>
+ </TableBody>
+ </Table>
+ </Card>
+ <ProductTypeAttributeEditDialog
+ opened={openedAttributeAddDialog}
+ title={i18n.t("Add attribute")}
+ name=""
+ values={[]}
+ onClose={toggleAttributeAddDialog}
+ onConfirm={onAttributeAdd}
+ />
+ </>
+ )}
+ </Toggle>
)
);
ProductTypeAttributes.displayName = "ProductTypeAttributes";
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index b22fc1cba2..f7a2a3afad 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -15,6 +15,7 @@ import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { TaxRateType, WeightUnitsEnum } from "../../../types/globalTypes";
import { ProductTypeDetails_productType } from "../../types/ProductTypeDetails";
+import { FormData as ProductTypeAttributeEditDialogFormData } from "../ProductTypeAttributeEditDialog/ProductTypeAttributeEditDialog";
import ProductTypeAttributes from "../ProductTypeAttributes/ProductTypeAttributes";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
@@ -44,12 +45,11 @@ interface ProductTypeDetailsPageProps {
disabled: boolean;
pageTitle: string;
saveButtonBarState: SaveButtonBarState;
- searchLoading: boolean;
- searchResults: Array<{
- id: string;
- name: string;
- }>;
- onAttributeSearch: (name: string) => void;
+ onAttributeAdd: (data: ProductTypeAttributeEditDialogFormData) => void;
+ onAttributeUpdate: (
+ id: string,
+ data: ProductTypeAttributeEditDialogFormData
+ ) => void;
onBack: () => void;
onDelete?: () => void;
onSubmit: (data: ProductTypeForm) => void;
@@ -74,6 +74,8 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
pageTitle,
productType,
saveButtonBarState,
+ onAttributeAdd,
+ onAttributeUpdate,
onBack,
onDelete,
onSubmit
@@ -137,6 +139,8 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
)
)}
title={i18n.t("Product Attributes")}
+ onAttributeAdd={onAttributeAdd}
+ onAttributeUpdate={onAttributeUpdate}
/>
</div>
<div className={classes.cardContainer}>
@@ -157,6 +161,8 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
)
)}
title={i18n.t("Variant Attributes")}
+ onAttributeAdd={onAttributeAdd}
+ onAttributeUpdate={onAttributeUpdate}
/>
</div>
)}
diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
index 6adf3b72a1..30c2b72a20 100644
--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
@@ -2,7 +2,7 @@ import { storiesOf } from "@storybook/react";
import * as React from "react";
import ProductTypeDetailsPage from "../../../productTypes/components/ProductTypeDetailsPage";
-import { attributes, productType } from "../../../productTypes/fixtures";
+import { productType } from "../../../productTypes/fixtures";
import { WeightUnitsEnum } from "../../../types/globalTypes";
import Decorator from "../../Decorator";
@@ -10,15 +10,14 @@ const props = {
defaultWeightUnit: "kg" as WeightUnitsEnum,
disabled: false,
errors: [],
- onAttributeSearch: () => undefined,
+ onAttributeAdd: () => undefined,
+ onAttributeUpdate: () => undefined,
onBack: () => undefined,
onDelete: () => undefined,
onSubmit: () => undefined,
pageTitle: productType.name,
productType,
- saveButtonBarState: "default",
- searchLoading: false,
- searchResults: attributes
+ saveButtonBarState: "default"
};
storiesOf("Views / Product types / Product type details", module)