Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save appinteractive/f686827f78dfcf1c64b7a4a8a4cb233a to your computer and use it in GitHub Desktop.

Select an option

Save appinteractive/f686827f78dfcf1c64b7a4a8a4cb233a to your computer and use it in GitHub Desktop.
Patch - Fix medusa image removal bug
```patch
diff --git a/dist/product-media-MROYO2YQ.mjs b/dist/product-media-MROYO2YQ.mjs
index 44a3115645b8eb2fb9ceb24da80ef924825c009d..6a0ebcd3c3ea92742ddad24efe999222d17d54c8 100644
--- a/dist/product-media-MROYO2YQ.mjs
+++ b/dist/product-media-MROYO2YQ.mjs
@@ -431,7 +431,7 @@ var ProductMediaGallery = ({ product }) => {
[isPending]
);
const handleDownloadCurrent = () => {
- if (isPending) {
+ if (isPending || !media[curr]) {
return;
}
const a = document.createElement("a");
@@ -441,6 +441,7 @@ var ProductMediaGallery = ({ product }) => {
a.click();
};
const handleDeleteCurrent = async () => {
+ if (!media[curr]) return;
const current = media[curr];
const res = await prompt({
title: t("general.areYouSure"),
@@ -453,7 +454,7 @@ var ProductMediaGallery = ({ product }) => {
}
const mediaToKeep = product.images?.filter((i) => i.id !== current.id).map((i) => ({ id: i.id, url: i.url })) || [];
if (curr === media.length - 1) {
- setCurr((prev2) => prev2 - 1);
+ setCurr((prev2) => Math.max(0, prev2 - 1));
}
await mutateAsync({
images: mediaToKeep,
@@ -539,7 +540,8 @@ var Canvas = ({ media, curr }) => {
/* @__PURE__ */ jsx2(Button2, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx2(Link2, { to: "?view=edit", children: t("products.media.emptyState.action") }) })
] });
}
- return /* @__PURE__ */ jsx2("div", { className: "bg-ui-bg-subtle relative size-full overflow-hidden", children: /* @__PURE__ */ jsx2("div", { className: "flex size-full items-center justify-center p-6", children: /* @__PURE__ */ jsxs2("div", { className: "relative inline-block max-h-full max-w-full", children: [
+ if (!media[curr]) { return null; }
+ return /* @__PURE__ */ jsx2("div", { className: "bg-ui-bg-subtle relative size-full overflow-hidden", children: /* @__PURE__ */ jsx2("div", { className: "flex size-full items-center justify-center p-6", children: /* @__PURE__ */ jsxs2("div", { className: "relative inline-block max-h-full max-w-full", children: [
media[curr].isThumbnail && /* @__PURE__ */ jsx2("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx2(Tooltip2, { content: t("products.media.thumbnailTooltip"), children: /* @__PURE__ */ jsx2(ThumbnailBadge2, {}) }) }),
/* @__PURE__ */ jsx2(
"img",
@@ -589,7 +591,7 @@ var Preview = ({
}
),
/* @__PURE__ */ jsx2("div", { className: "flex items-center gap-x-2", children: visibleItems.map((item) => {
- const isCurrentImage = item.id === media[curr].id;
+ const isCurrentImage = media[curr] ? item.id === media[curr].id : false;
const originalIndex = media.findIndex((i) => i.id === item.id);
return /* @__PURE__ */ jsx2(
"button",
diff --git a/src/routes/products/product-media/components/product-media-gallery/product-media-gallery.tsx b/src/routes/products/product-media/components/product-media-gallery/product-media-gallery.tsx
index 98d20dceb5acc6e69bbe3b91a2e350e3b074df93..d8c14ab65b884e6da93267114bec63e7d228d69c 100644
--- a/src/routes/products/product-media/components/product-media-gallery/product-media-gallery.tsx
+++ b/src/routes/products/product-media/components/product-media-gallery/product-media-gallery.tsx
@@ -56,7 +56,7 @@ export const ProductMediaGallery = ({ product }: ProductMediaGalleryProps) => {
)
const handleDownloadCurrent = () => {
- if (isPending) {
+ if (isPending || !media[curr]) {
return
}
@@ -72,6 +72,7 @@ export const ProductMediaGallery = ({ product }: ProductMediaGalleryProps) => {
}
const handleDeleteCurrent = async () => {
+ if (!media[curr]) return
const current = media[curr]
const res = await prompt({
@@ -93,7 +94,7 @@ export const ProductMediaGallery = ({ product }: ProductMediaGalleryProps) => {
.map((i) => ({ id: i.id, url: i.url })) || []
if (curr === media.length - 1) {
- setCurr((prev) => prev - 1)
+ setCurr((prev) => Math.max(0, prev - 1))
}
await mutateAsync({
@@ -193,6 +194,10 @@ const Canvas = ({ media, curr }: { media: Media[]; curr: number }) => {
)
}
+ if (!media[curr]) {
+ return null
+ }
+
return (
<div className="bg-ui-bg-subtle relative size-full overflow-hidden">
<div className="flex size-full items-center justify-center p-6">
@@ -265,7 +270,7 @@ const Preview = ({
</IconButton>
<div className="flex items-center gap-x-2">
{visibleItems.map((item) => {
- const isCurrentImage = item.id === media[curr].id
+ const isCurrentImage = media[curr] ? item.id === media[curr].id : false
const originalIndex = media.findIndex((i) => i.id === item.id)
return (
```
```package.json
{
"pnpm": {
"patchedDependencies": {
"@medusajs/dashboard@2.13.4": "patches/@medusajs__dashboard@2.13.4.patch"
},
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment