Skip to content

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

Wrap fields with maybe()

Krzysztof Bialoglowicz4a19083bcb87
diff --git a/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx b/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
index d168c1ee3b..57d49bca95 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
@@ -19,7 +19,7 @@ import Skeleton from "../../../components/Skeleton";
import TableCellAvatar from "../../../components/TableCellAvatar";
import TablePagination from "../../../components/TablePagination";
import i18n from "../../../i18n";
-import { renderCollection } from "../../../misc";
+import { renderCollection, maybe } from "../../../misc";
const styles = (theme: Theme) =>
createStyles({
@@ -97,7 +97,9 @@ export const ProductList = withStyles(styles, { name: "ProductList" })(
products,
product => (
<TableRow key={product ? product.id : "skeleton"}>
- <TableCellAvatar thumbnail={product && product.thumbnail.url} />
+ <TableCellAvatar
+ thumbnail={product && maybe(() => product.thumbnail.url)}
+ />
<TableCell className={classes.textLeft}>
{product ? (
<span
diff --git a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
index c0ea20a4a4..72b6ad692e 100644
--- a/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
+++ b/saleor/static/dashboard-next/components/AssignProductDialog/AssignProductDialog.tsx
@@ -22,6 +22,7 @@ import TableCellAvatar from "../../components/TableCellAvatar";
import { SearchProducts_products_edges_node } from "../../containers/SearchProducts/types/SearchProducts";
import i18n from "../../i18n";
import Checkbox from "../Checkbox";
+import { maybe } from "../../misc";
export interface FormData {
products: SearchProducts_products_edges_node[];
@@ -119,7 +120,7 @@ const AssignProductDialog = withStyles(styles, {
<TableRow key={product.id}>
<TableCellAvatar
className={classes.avatar}
- thumbnail={product.thumbnail.url}
+ thumbnail={maybe(() => product.thumbnail.url)}
/>
<TableCell className={classes.wideCell}>
{product.name}
diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
index aaa2f024ba..8d8f36cfd9 100644
--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
@@ -152,8 +152,7 @@ export const ProductList = withStyles(styles, { name: "ProductList" })(
)}
</TableCell>
<TableCell className={classes.colPublished}>
- {product &&
- product.isAvailable !== undefined ? (
+ {product && maybe(() => product.isAvailable !== undefined) ? (
<StatusLabel
label={
product.isAvailable
@@ -170,9 +169,9 @@ export const ProductList = withStyles(styles, { name: "ProductList" })(
</TableCell>
<TableCell className={classes.colPrice}>
{product &&
- product.basePrice &&
- product.basePrice.amount !== undefined &&
- product.basePrice.currency !== undefined ? (
+ maybe(() => product.basePrice) &&
+ maybe(() => product.basePrice.amount) !== undefined &&
+ maybe(() => product.basePrice.currency) !== undefined ? (
<Money money={product.basePrice} />
) : (
<Skeleton />
diff --git a/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx
index 2b6019efeb..5299670456 100644
--- a/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx
@@ -121,7 +121,7 @@ const OrderFulfillmentDialog = withStyles(styles, {
product.quantity - product.quantityFulfilled;
return (
<TableRow key={product.id}>
- <TableCellAvatar thumbnail={product.thumbnail.url} />
+ <TableCellAvatar thumbnail={maybe(() => product.thumbnail.url} />
<TableCell>{product.productName}</TableCell>
<TableCell>{product.productSku}</TableCell>
<TableCell className={classes.quantityInputContainer}>
diff --git a/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
index d2c7b91938..05e838c24b 100644
--- a/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
@@ -75,7 +75,7 @@ const OrderUnfulfilledItems = withStyles(styles, {
hover={!!line}
key={maybe(() => line.id)}
>
- <TableCellAvatar thumbnail={line.thumbnail.url} />
+ <TableCellAvatar thumbnail={maybe(() => line.thumbnail.url} />
<TableCell>
{maybe(() => line.productName) || <Skeleton />}
</TableCell>