Skip to content

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

Refactor ImageTile component

dominik-zeglen104a99b61891
diff --git a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
index 4bbba5da30..f4b4b78d5d 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
@@ -40,11 +40,6 @@ const decorate = withStyles(theme => ({
width: "100%"
},
imageContainer: {
- "&:hover, &.dragged": {
- "& $imageOverlay": {
- display: "block" as "block"
- }
- },
background: "#ffffff",
border: "1px solid #eaeaea",
borderRadius: theme.spacing.unit,
@@ -53,7 +48,6 @@ const decorate = withStyles(theme => ({
overflow: "hidden" as "hidden",
padding: theme.spacing.unit * 2,
position: "relative" as "relative",
- margin: "auto",
width: 148
}
}));
diff --git a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx
index 31f9e888e5..b817368ca0 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx
@@ -1,7 +1,7 @@
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
-import Image from "../../../components/Image";
+import ImageTile from "../../../components/ImageTile";
import Toggle from "../../../components/Toggle";
import CategoryDeleteImage from "../CategoryDeleteImage";
@@ -19,7 +19,7 @@ const CategoryBackgroundImage = decorate<CategoryBackgroundImageProps>(
<Toggle>
{(opened, { toggle }) => (
<>
- <Image
+ <ImageTile
tile={backgroundImage}
onImageDelete={toggle}
deleteIcon={true}
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
index 65f4e9eec3..dc5418c5c9 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
@@ -204,8 +204,7 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(
onDelete={onDelete}
onSave={submit}
labels={{
- delete: i18n.t("Delete category"),
- save: i18n.t("Save category")
+ delete: i18n.t("Delete category")
}}
state={saveButtonBarState}
disabled={disabled || !hasChanged}
diff --git a/saleor/static/dashboard-next/components/Image/index.ts b/saleor/static/dashboard-next/components/Image/index.ts
deleted file mode 100644
index 6baa126180..0000000000
--- a/saleor/static/dashboard-next/components/Image/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./Image";
-export * from "./Image";
diff --git a/saleor/static/dashboard-next/components/Image/Image.tsx b/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
similarity index 83%
rename from saleor/static/dashboard-next/components/Image/Image.tsx
rename to saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
index 259cdad773..05c111f147 100644
--- a/saleor/static/dashboard-next/components/Image/Image.tsx
+++ b/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
@@ -21,7 +21,6 @@ const decorate = withStyles(theme => ({
background: "#ffffff",
border: "1px solid #eaeaea",
borderRadius: theme.spacing.unit,
- margin: "auto",
height: 148,
overflow: "hidden" as "hidden",
padding: theme.spacing.unit * 2,
@@ -34,21 +33,17 @@ const decorate = withStyles(theme => ({
display: "none" as "none",
height: 148,
left: 0,
- padding: theme.spacing.unit * 2,
position: "absolute" as "absolute",
top: 0,
width: 148
},
imageOverlayToolbar: {
- alignContent: "flex-end",
display: "flex" as "flex",
- position: "relative" as "relative",
- right: -theme.spacing.unit * 4,
- top: -theme.spacing.unit * 2
+ justifyContent: "flex-end"
}
}));
-interface ImageProps {
+interface ImageTileProps {
tile?: {
id?: string;
alt?: string;
@@ -62,21 +57,21 @@ interface ImageProps {
index?: string;
}
-const Image = decorate<ImageProps>(
+const ImageTile = decorate<ImageTileProps>(
({ classes, onImageDelete, onImageEdit, tile, editIcon, deleteIcon }) => (
<div className={classes.imageContainer}>
<div className={classes.imageOverlay}>
<div className={classes.imageOverlayToolbar}>
- {editIcon ? (
+ {editIcon && (
<IconButton color="secondary" onClick={onImageEdit}>
<EditIcon />
</IconButton>
- ) : null}
- {deleteIcon ? (
+ )}
+ {deleteIcon && (
<IconButton color="secondary" onClick={onImageDelete}>
<DeleteIcon />
</IconButton>
- ) : null}
+ )}
</div>
</div>
<img className={classes.image} src={tile.url} alt={tile.alt} />
@@ -84,4 +79,4 @@ const Image = decorate<ImageProps>(
)
);
-export default Image;
+export default ImageTile;
diff --git a/saleor/static/dashboard-next/components/ImageTile/index.ts b/saleor/static/dashboard-next/components/ImageTile/index.ts
new file mode 100644
index 0000000000..56297f8849
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ImageTile/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ImageTile";
+export * from "./ImageTile";
diff --git a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
index 1fee3a5105..7b2574ddb9 100644
--- a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
@@ -10,7 +10,7 @@ import * as React from "react";
import { SortableContainer, SortableElement } from "react-sortable-hoc";
import ActionDialog from "../../../components/ActionDialog";
import CardTitle from "../../../components/CardTitle";
-import Image from "../../../components/Image";
+import ImageTile from "../../../components/ImageTile";
import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
@@ -118,7 +118,7 @@ const decorate = withStyles(theme => ({
const SortableImage = SortableElement(
({ image, onImageEdit, toggle, tile }) => (
- <Image
+ <ImageTile
tile={tile}
deleteIcon={true}
editIcon={true}
diff --git a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
index 1598bf3d25..b0ef8821f9 100644
--- a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
@@ -40,17 +40,10 @@ const updateProps: CategoryUpdatePageProps = {
storiesOf("Views / Categories / Update category", module)
.addDecorator(Decorator)
.add("default", () => <CategoryUpdatePage {...updateProps} />)
- .add("default without background", () => (
+ .add("no background", () => (
<CategoryUpdatePage {...updateProps} backgroundImage={{}} />
))
- .add("When in root", () => (
- <CategoryUpdatePage
- {...updateProps}
- products={undefined}
- category={undefined}
- />
- ))
- .add("When loading", () => (
+ .add("loading", () => (
<CategoryUpdatePage
{...updateProps}
subcategories={undefined}