Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Make a whole variant line the link, and link delivery lines too

Damian Legawiec07209c2a4765
diff --git a/packages/admin-sdk/src/types/generated/StockReceiptItem.ts b/packages/admin-sdk/src/types/generated/StockReceiptItem.ts
index e076429603..567c6e89eb 100644
--- a/packages/admin-sdk/src/types/generated/StockReceiptItem.ts
+++ b/packages/admin-sdk/src/types/generated/StockReceiptItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest b4870bd5d1822eccaa6f169921ad5d69
+// Typelizer digest 8327d2e44ffd63ce99f8bba067077b3c
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -11,6 +11,7 @@ interface StockReceiptItem {
line_type: 'purchase_order_item' | 'stock_transfer_item';
line_id: string | null;
variant_id: string | null;
+ product_id: string | null;
variant_name: string | null;
variant_sku: string | null;
thumbnail_url: string | null;
diff --git a/packages/dashboard/src/components/spree/stock-receipts-card.tsx b/packages/dashboard/src/components/spree/stock-receipts-card.tsx
index 3da447d85f..d777e82619 100644
--- a/packages/dashboard/src/components/spree/stock-receipts-card.tsx
+++ b/packages/dashboard/src/components/spree/stock-receipts-card.tsx
@@ -75,8 +75,8 @@ function StockReceiptPanel({ receipt }: { receipt: StockReceipt }) {
const items = receipt.items ?? []
return (
- <Card variant="nested">
- <CardHeader>
+ <Card variant="nested" className="px-0 rounded-xl">
+ <CardHeader className="px-3!">
<CardTitle className="min-w-0 font-normal text-sm">
<span className="font-medium tabular-nums">{receipt.number}</span>
<span className="text-muted-foreground text-xs">
@@ -88,7 +88,7 @@ function StockReceiptPanel({ receipt }: { receipt: StockReceipt }) {
</CardTitle>
</CardHeader>
- <CardContent className="flex items-center justify-between border-b border-border-subtle py-3 text-sm">
+ <CardContent className="flex items-center justify-between border-b border-border-subtle p-3! text-sm">
<span className="text-muted-foreground">
{t('admin.stock_receipts.summary', {
accepted: receipt.quantity_accepted_total,
@@ -98,44 +98,51 @@ function StockReceiptPanel({ receipt }: { receipt: StockReceipt }) {
{receipt.notes && <span className="truncate text-muted-foreground">{receipt.notes}</span>}
</CardContent>
- {items.length > 0 && (
- <Table scrollX roundedBottom>
- <TableHeader>
- <TableRow>
- <TableHead>{t('admin.inventory_lines.columns.variant')}</TableHead>
- <TableHead className="text-right">
- {t('admin.stock_receipts.columns.accepted')}
- </TableHead>
- <TableHead className="text-right">
- {t('admin.stock_receipts.columns.rejected')}
- </TableHead>
- <TableHead>{t('admin.stock_receipts.columns.reason')}</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {items.map((item) => (
- <TableRow key={item.id}>
- <TableCell>
- <VariantLink
- name={item.variant_name}
- sku={item.variant_sku}
- thumbnailUrl={item.thumbnail_url}
- />
- </TableCell>
- <TableCell className="text-right tabular-nums">{item.quantity_accepted}</TableCell>
- <TableCell className="text-right tabular-nums">{item.quantity_rejected}</TableCell>
- <TableCell>
- {item.rejection_reason
- ? t(`admin.stock_receipts.rejection_reasons.${item.rejection_reason}`, {
- defaultValue: item.rejection_reason,
- })
- : '—'}
- </TableCell>
+ <CardContent className="p-0">
+ {items.length > 0 && (
+ <Table scrollX roundedBottom>
+ <TableHeader>
+ <TableRow>
+ <TableHead>{t('admin.inventory_lines.columns.variant')}</TableHead>
+ <TableHead className="text-right">
+ {t('admin.stock_receipts.columns.accepted')}
+ </TableHead>
+ <TableHead className="text-right">
+ {t('admin.stock_receipts.columns.rejected')}
+ </TableHead>
+ <TableHead>{t('admin.stock_receipts.columns.reason')}</TableHead>
</TableRow>
- ))}
- </TableBody>
- </Table>
- )}
+ </TableHeader>
+ <TableBody>
+ {items.map((item) => (
+ <TableRow key={item.id}>
+ <TableCell>
+ <VariantLink
+ productId={item.product_id}
+ name={item.variant_name}
+ sku={item.variant_sku}
+ thumbnailUrl={item.thumbnail_url}
+ />
+ </TableCell>
+ <TableCell className="text-right tabular-nums">
+ {item.quantity_accepted}
+ </TableCell>
+ <TableCell className="text-right tabular-nums">
+ {item.quantity_rejected}
+ </TableCell>
+ <TableCell>
+ {item.rejection_reason
+ ? t(`admin.stock_receipts.rejection_reasons.${item.rejection_reason}`, {
+ defaultValue: item.rejection_reason,
+ })
+ : '—'}
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ )}
+ </CardContent>
</Card>
)
}
diff --git a/packages/dashboard/src/components/spree/variant-link.tsx b/packages/dashboard/src/components/spree/variant-link.tsx
index c7406b9b38..a72ec3c6a1 100644
--- a/packages/dashboard/src/components/spree/variant-link.tsx
+++ b/packages/dashboard/src/components/spree/variant-link.tsx
@@ -4,8 +4,9 @@ import { PackageIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
/**
- * A document line's variant — its image, its name linked to the product that
- * owns it, and optionally its SKU underneath.
+ * A document line's variant — its image, its name and optionally its SKU —
+ * the whole of it linked to the product that owns it, so a merchant can aim
+ * at the picture as readily as the name.
*
* Renders plain text when the line names no product. A line outlives the
* variant it names — the same way the movement ledger outlives the level it
@@ -24,25 +25,26 @@ export function VariantLink({
thumbnailUrl?: string | null
}) {
const { storeId } = useStore()
- const label = name ?? '—'
- return (
- <div className="flex items-center gap-3">
+ const body = (
+ <>
<Thumbnail src={thumbnailUrl} fallback={<PackageIcon />} />
<div className="min-w-0">
- {productId ? (
- <Link
- to="/$storeId/products/$productId"
- params={{ storeId, productId }}
- className="font-medium hover:underline"
- >
- {label}
- </Link>
- ) : (
- <span className="font-medium">{label}</span>
- )}
+ <span className="font-medium group-hover:underline">{name ?? '—'}</span>
{sku && <span className="block text-muted-foreground text-xs">{sku}</span>}
</div>
- </div>
+ </>
+ )
+
+ if (!productId) return <div className="flex items-center gap-3">{body}</div>
+
+ return (
+ <Link
+ to="/$storeId/products/$productId"
+ params={{ storeId, productId }}
+ className="group flex items-center gap-3"
+ >
+ {body}
+ </Link>
)
}
diff --git a/spree/api/app/serializers/spree/api/v3/admin/stock_receipt_item_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/stock_receipt_item_serializer.rb
index 71d0f832fb..57838baff9 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/stock_receipt_item_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/stock_receipt_item_serializer.rb
@@ -11,6 +11,7 @@ module Spree
notes: 'string | null',
line_type: [:string, enum: %w[purchase_order_item stock_transfer_item]],
line_id: 'string | null',
+ product_id: 'string | null',
variant_id: 'string | null',
variant_name: 'string | null',
variant_sku: 'string | null',
@@ -32,6 +33,12 @@ module Spree
item.variant&.prefixed_id
end
+ # The product the line's variant belongs to, so a delivery's line
+ # can link to the screen where that SKU's stock lives.
+ attribute :product_id do |item|
+ item.variant&.product&.prefixed_id
+ end
+
attribute :variant_name do |item|
item.variant&.product&.name
end