Skip to content

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

Add types to react-sortable-hoc

dominik-zeglen97adcf007774
diff --git a/package.json b/package.json
index 3104fb60e1..a6e4c8fe70 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
"@types/react-dropzone": "^4.2.2",
"@types/react-helmet": "^5.0.8",
"@types/react-infinite-scroller": "^1.2.1",
+ "@types/react-sortable-hoc": "^0.6.5",
"@types/react-sortable-tree": "^0.3.6",
"@types/storybook__addon-storyshots": "^3.4.9",
"@types/string-similarity": "^1.2.1",
diff --git a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
index a4727eca59..4446fb57ab 100644
--- a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
@@ -12,6 +12,7 @@ import {
import CardTitle from "@saleor/components/CardTitle";
import ImageTile from "@saleor/components/ImageTile";
import ImageUpload from "@saleor/components/ImageUpload";
+import { ReorderEvent } from "@saleor/types";
import React from "react";
import { SortableContainer, SortableElement } from "react-sortable-hoc";
import i18n from "../../../i18n";
@@ -113,17 +114,21 @@ interface ProductImagesProps extends WithStyles<typeof styles> {
loading?: boolean;
onImageDelete: (id: string) => () => void;
onImageEdit: (id: string) => () => void;
+ onImageReorder?: ReorderEvent;
onImageUpload(file: File);
- onImageReorder?(event: { oldIndex: number; newIndex: number });
}
-interface ImageListContainerProps extends WithStyles<typeof styles> {
- items: any;
- onImageDelete: (id: string) => () => void;
- onImageEdit: (id: string) => () => void;
+interface SortableImageProps {
+ image: {
+ id: string;
+ alt?: string;
+ url: string;
+ };
+ onImageEdit: (id: string) => void;
+ onImageDelete: () => void;
}
-const SortableImage = SortableElement(
+const SortableImage = SortableElement<SortableImageProps>(
({ image, onImageEdit, onImageDelete }) => (
<ImageTile
image={image}
@@ -133,7 +138,14 @@ const SortableImage = SortableElement(
)
);
-const ImageListContainer = SortableContainer(
+interface ImageListContainerProps {
+ className: string;
+ items: any;
+ onImageDelete: (id: string) => () => void;
+ onImageEdit: (id: string) => () => void;
+}
+
+const ImageListContainer = SortableContainer<ImageListContainerProps>(
withStyles(styles, { name: "ImageListContainer" })(
({
classes,
@@ -141,7 +153,7 @@ const ImageListContainer = SortableContainer(
onImageDelete,
onImageEdit,
...props
- }: ImageListContainerProps) => {
+ }: ImageListContainerProps & WithStyles<typeof styles>) => {
return (
<div {...props}>
{items.map((image, index) => (
diff --git a/saleor/static/dashboard-next/types.ts b/saleor/static/dashboard-next/types.ts
index 16f830d83a..83bc133414 100644
--- a/saleor/static/dashboard-next/types.ts
+++ b/saleor/static/dashboard-next/types.ts
@@ -109,3 +109,8 @@ export type SingleAction = Partial<{
export type BulkAction = Partial<{
ids: string[];
}>;
+
+export type ReorderEvent = (event: {
+ oldIndex: number;
+ newIndex: number;
+}) => void;