Product Gallery, Delete and Preview Features
Storefront gallery arrows, admin product delete with undo, the deleted-products view with restore, list filters, and the customer preview.
Audience: Product owners, QA, frontend, admin and backend developers Scope: What shipped across the storefront, the admin panel and the backend, and the rules each surface follows
Product Gallery, Delete and Preview
1. Feature Overview
One feature, three repos. The backend change is small and is a prerequisite for the admin work; the storefront change is independent.
| Repo | What shipped |
|---|---|
Storefront (nano-store-frontend) | Previous/next arrows and keyboard navigation on the product gallery; product video URLs are rewritten to embeddable form (toEmbedUrl); the out-of-stock screen-reader note appears only on option rows that have a sold-out value; the Facebook sign-in button is disabled with an explanatory toast |
Admin (Happy-shop-admin) | Delete with Undo, a Deleted products view with restore, restore for soft-deleted categories, brands and brand series, On sale and Featured list filters, a deleted banner on the detail page, controls hidden for deleted products, and a storefront-faithful "View as customer" preview |
Backend (Nano-store-backend) | Restore refuses (409) when the product's category, brand or series is soft-deleted; timestamps.deletedAt on the admin product response |
Deploy order: backend first. The admin tolerates an older backend that omits deletedAt (see Backend).
2. Surface Matrix
| Surface | Prefix / location | Auth |
|---|---|---|
| Storefront gallery | src/app/products/[slug]/_components/ | Public |
| Admin product screens | /dashboard/products, /dashboard/products/:productId, .../edit, .../preview | Admin session plus Products_* permission codes |
| Backend admin API | /api/admin/products | JWT + role, @Permissions("Products_*") |
3. Storefront Gallery
-
Previous and next arrows appear when the gallery has more than one slide. Navigation wraps in both directions, so the arrows are never disabled.
-
ArrowLeftandArrowRightstep the gallery. The handler ignores the key when Alt, Ctrl, Meta or Shift is held, when the focus is in an input or acontenteditableelement, when the active slide is a video, and when there is a single slide. -
A polite live region announces the position (for example "Image 2 of 3"). It stays silent until the visitor has navigated and resets when the slide set changes (variant change).
-
The thumbnail rail scrolls to follow the active slide.
-
Video URLs. The backend allowlists only the host of a product video URL, so a
watch?v=URL is stored as entered, and YouTube refuses to be framed on that page.toEmbedUrl(src/lib/catalog/embed-url.ts) rewrites the URL before it reaches the gallery. The host allowlist and the CSP are unchanged.Stored URL Result YouTube /watch?v=ID/embed/IDon the same host.torstartofNorNsis kept as?start=N; other values (1m30s) and other params are droppedYouTube /shorts/ID/embed/IDYouTube /embed/IDPasses through unchanged Vimeo player.vimeo.com/video/<digits>Passes through unchanged Anything else (other hosts, youtu.be,http, other paths, unparseable)The slide is dropped A YouTube id must be exactly 11 characters (
[A-Za-z0-9_-]) on watch, shorts and embed, or the slide is dropped. An operator-saved/embed/URL with a shorter id therefore no longer shows. -
Out-of-stock note. The screen-reader-only "Currently out of stock" note in
product-option-axis-row.tsxrenders only when some value in that option row is out of stock. It isaria-hiddenand referenced byaria-describedbyfrom the sold-out radios, so it is never read as a product-level statement. Before, every option row carried it, even for a fully in-stock product. -
The gallery is split into five files:
product-gallery.tsx,use-gallery-navigation.ts,gallery-arrows.tsx,gallery-slide-view.tsx,gallery-thumbnail-rail.tsx. -
The Facebook button in
auth-social-buttons.tsxisaria-disabled="true"(not natively disabled, so it stays focusable and clickable). Clicking it shows the toast "Facebook sign-in isn't enabled yet." and sends no request.
4. Admin: Delete, Undo and Restore
4.1 Delete
- The Delete control appears on the product detail page for users with
Products_DELETEand opens a confirmation dialog. The dialog cannot be dismissed while the delete is pending. - The delete is a soft delete. The dialog copy says the product is hidden from the store and moved to Deleted products, where it can be restored.
- On success the admin shows
Deleted "{name}"and returns to the list. An Undo action appears on that toast only when the user also hasProducts_RESTORE. - Undo restores the product and moves to its detail page, but only if the user is still on
/dashboard/productswhen the result arrives. Otherwise it only shows a toast.
| Backend response | Admin outcome | Toast |
|---|---|---|
200 | deleted | Deleted "{name}" |
409 PRODUCT_ALREADY_DELETED | already_deleted | "This product was already deleted" |
404 PRODUCT_NOT_FOUND | not_found | "This product no longer exists" |
| Other 4xx | Error | The described backend error; dialog stays open |
| 5xx, timeout, non-API error | Error | "Could not confirm the delete. Try again — if it already went through, retrying will confirm it." |
4.2 Deleted products view
- The product list has a filter whose default option is "Active products" and whose only other option is "Deleted products" (URL
?deleted=true). - In the deleted view the bulk-selection column and bulk bar are hidden, and each row shows a Restore button for users with
Products_RESTORE. Users with onlyProducts_READsee the list read-only. - An empty deleted view shows "No deleted products." in preference to the other empty states.
- Restoring a
publishedorunlistedproduct asks for confirmation first;draftandarchivedproducts restore directly. If the restored row was the only row on page N greater than 1, the URL steps back to page N-1. - "Clear filters" returns to the active view.
4.3 Restore outcomes
| Backend response | Admin result | Copy |
|---|---|---|
200 | restored | Row Restore: "Restored {name}". Undo: "Product restored" |
409 PRODUCT_NOT_DELETED | already_active (counts as success) | Row Restore: "Already restored". Undo: "Product restored" |
409 PRODUCT_CATEGORY_DELETED | Error | "Can't restore: its category is deleted. Restore that first." |
409 PRODUCT_BRAND_DELETED | Error | "Can't restore: its brand is deleted. Restore that first." |
409 PRODUCT_SERIES_DELETED | Error | "Can't restore: its series is deleted. Restore that first." |
409 RESOURCE_ALREADY_EXISTS | Error | "Can't restore: another active product now uses this product's SKU or slug. Change that product's SKU first." |
404 PRODUCT_NOT_FOUND | Error | "This product no longer exists" |
"Restore that first." has a destination: the category, brand and series restore screens in section 4.5. Restore the referent there, then retry the product.
4.4 Detail page for a deleted product
- A deleted banner and a Restore button replace the edit and delete controls. Create, update and delete permissions are forced off for the page.
- The stock section is read-only: it shows
"Stock status: {label}"and omits the adjustment, overselling and "Open inventory" pointers. - The edit page redirects a deleted product back to its detail page.
- The page makes no variants or options list calls for a deleted product. The backend answers those with 404 anyway (see Backend).
- The Variants section shows "Variants are not shown for deleted products. Restore the product to see and edit them." A live product with no variants still shows the data-error warning.
- Upload fields are disabled.
MediaUploadFieldmounts no dropzone and no file input whendisabled; it renders a disabled fieldset instead. This covers the thumbnail and the SEO image fields, and applies to any read-only user. - A missing product now renders the 404 page through
unstable_rethrow; the earlierdigest === "NEXT_NOT_FOUND"check never matched on Next 16. deletedAtundefined(older backend) andnullboth mean the product is not deleted.
4.5 Catalog restore: categories, brands and series
Routes: /dashboard/catalog/categories, /categories/[categoryId], /brands, /brands/[brandId]. All three entities share one CatalogRestoreButton, which renders nothing without the permission.
| Entity | Permission | How deleted rows appear (?deleted=true) |
|---|---|---|
| Category | Categories_RESTORE | Filter option "Deleted categories" shows a flat list of deleted categories for the current level (root, or the open [categoryId]). No drill-in link, visibility switch, edit or delete. "New category" is hidden. Empty state: "No deleted categories." |
| Brand | Brands_RESTORE | Filter option "Active and deleted" shows live plus deleted rows. Deleted rows carry a "Deleted" badge and only a Restore action; edit, delete and the visibility switch are hidden |
| Brand series | BrandSeries_RESTORE | Same as brands, with a new "Deleted" badge |
A restore writes to the backend, then calls invalidateStorefrontCache (category.changed, brand.changed, brand-series.changed), then revalidatePath. The cache call never throws, so a committed restore is never reported as a failure.
Restore errors branch on errorCode (describeCatalogError in catalog-action-error.ts):
| Entity | errorCode | Copy |
|---|---|---|
| Category | CATEGORY_NOT_DELETED | "That category is not deleted, so it cannot be restored." |
| Category | CATEGORY_RESTORE_MAX_DEPTH_EXCEEDED | "Restoring here would nest the category too deep. Move its parent first." |
| Category | CATEGORY_PARENT_DELETED | "The parent category is deleted. Restore the parent first, or choose a different parent when creating or moving." |
| Category | CATEGORY_NOT_FOUND | "That category no longer exists. Refresh the list." |
| Brand | BRAND_NOT_DELETED | "That brand is not deleted, so there is nothing to restore. Refresh the list." |
| Brand | BRAND_NOT_FOUND | "That brand no longer exists. Refresh the list." |
| Series | BRAND_SERIES_NOT_DELETED | "That series is not deleted, so there is nothing to restore. Refresh the list." |
| Series | BRAND_SERIES_BRAND_DELETED | "Its brand is deleted. Restore the brand first." |
| Series | BRAND_SERIES_NOT_FOUND | "That series no longer exists. Refresh the list." |
The create, update, visibility and delete actions in the same catalog modules still show raw server text. This is not changed here.
5. Admin: List Filters
The list has two new selects, On sale (On sale / Not on sale) and Featured (Featured / Not featured), each defaulting to "Any". parseProductListParams forwards onSale and featured only for the literal strings true and false. Any other value is dropped, because the backend would coerce a stray string to false and silently filter the list.
6. Admin: View as Customer Preview
Route: /dashboard/products/:productId/preview, linked from the detail page header as "View as customer". The link is visible to every user who can read the page.
- The preview renders a copy of the storefront product page body (a snapshot of the storefront at a recorded commit, tracked in
_storefront/SOURCE.mdand_storefront/source.ts), fed from admin API data through an adapter. It works for drafts, which the storefront never serves. - It is inert: commerce controls do nothing and the copied code makes no customer requests. A static test fails on
fetch(,"use server",@/lib/mobile-api,@/lib/author_actions/inside the copy. - A banner outside the preview root shows the lifecycle through label maps, a count of images in private storage, a degraded-data warning when the variants or options list failed, and "Deleted — not visible to customers" for a deleted product.
- Swatch URLs are accepted only when they are on the asset origin under
/public/; signed, private or foreign URLs become no swatch. - Variant availability is an approximation, because the admin variant DTO carries no per-variant inventory.
- Video embeds render in an
iframewithsandbox="allow-scripts allow-same-origin allow-presentation". - The Phosphor icon package
@phosphor-icons/reactwas added as a dependency.
7. Error UX Mapping
| Condition | What the user sees |
|---|---|
| Restore blocked by a deleted category, brand or series | Error toast naming the referent to restore first (section 4.3) |
| Session expired during delete | "Your session may have expired — reload and sign in again"; dialog stays open |
| Facebook sign-in clicked | Toast "Facebook sign-in isn't enabled yet." |
| Preview of an unknown product | Not-found page |
| Restore of a category, brand or series that is not deleted, or no longer exists | Mapped toast (section 4.5) |
| Product video URL that cannot be embedded | The slide is dropped (section 3) |
8. Known Gaps
- Category restore requires a live parent. The backend answers
CATEGORY_PARENT_DELETED(409) when the parent is deleted or missing, and the admin shows the "restore the parent first" copy. deletedOnlylists one tree level. A deleted subcategory under a live parent appears in that parent's Deleted view; one under a deleted parent appears only after the parent is restored.- Restore, delete and visibility actions on the catalog screens were not driven in a browser.
See Also
Variant Pricing, Admin and Storefront Behaviour
Prices are a variant rollup; how the admin edits variants and how the storefront renders them.
Product Gallery, Delete and Preview Backend Architecture
Backend changes for the feature — the restore referent guard, the admin-only deletedAt timestamp, and their error contract.