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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix/dashboard filter order and toast stack (#14907)
Damian Legawiec04760bf28c44
diff --git a/.changeset/filter-value-order.md b/.changeset/filter-value-order.mdnew file mode 100644index 0000000000..db170cfa19--- /dev/null+++ b/.changeset/filter-value-order.md@@ -0,0 +1,5 @@+---+"@spree/dashboard-core": patch+---++Ticking or unticking a value in the "Add filter" panel no longer reorders the list. Values selected when the panel opens are still shown first.diff --git a/.changeset/resource-combobox-selection.md b/.changeset/resource-combobox-selection.mdnew file mode 100644index 0000000000..6319b3611a--- /dev/null+++ b/.changeset/resource-combobox-selection.md@@ -0,0 +1,6 @@+---+"@spree/dashboard-core": patch+"@spree/dashboard-ui": patch+---++Search pickers keep the option you pick instead of flickering and switching to another value while results load.diff --git a/.changeset/stacked-toasts.md b/.changeset/stacked-toasts.mdnew file mode 100644index 0000000000..ef578477c7--- /dev/null+++ b/.changeset/stacked-toasts.md@@ -0,0 +1,5 @@+---+"@spree/dashboard-ui": patch+---++Toasts now stack behind each other and fan out on hover, matching the shadcn toast.diff --git a/packages/dashboard-core/src/components/resource-combobox.tsx b/packages/dashboard-core/src/components/resource-combobox.tsxindex 76ea532bc2..80056204ad 100644--- a/packages/dashboard-core/src/components/resource-combobox.tsx+++ b/packages/dashboard-core/src/components/resource-combobox.tsx@@ -109,6 +109,11 @@ export function ResourceCombobox<T extends ComboboxOption>({// elsewhere (a customer created on another page) never invalidates it.// Every search refetches; cached rows for a repeated term still paint first.staleTime: 0,+ // Keeps the last results on screen while the next query loads, so the+ // list does not blank on every keystroke. Only within one tenant: the+ // second argument is the query those results came from.+ placeholderData: (previous, previousQuery) =>+ previousQuery?.queryKey[1] === tenantId ? previous : undefined,})// Hydrate the currently selected ID into a record so the trigger showsdiff --git a/packages/dashboard-core/src/components/table-toolbar.tsx b/packages/dashboard-core/src/components/table-toolbar.tsxindex 9198575392..1f4cdd5004 100644--- a/packages/dashboard-core/src/components/table-toolbar.tsx+++ b/packages/dashboard-core/src/components/table-toolbar.tsx@@ -1177,17 +1177,19 @@ function InlineValueList({}))}, [isCurrency, currencies, isTags, tags.data, resources.data, column.filterResource, query])- // Selected values ride at the top so a choice made before searching does not- // disappear the moment the query stops matching it.+ // Values already selected when the list opens ride at the top, so an active+ // filter is visible without scrolling. The set is frozen at mount: ticking a+ // box must not move rows under the pointer.+ const [pinned] = useState(() => selected)const ordered = useMemo(() => {- const chosen = options.filter((option) => selected.includes(option.value))- const rest = options.filter((option) => !selected.includes(option.value))+ const chosen = options.filter((option) => pinned.includes(option.value))+ const rest = options.filter((option) => !pinned.includes(option.value))// Not truncated: a list cut at ten looks like a list of ten, and a// vocabulary of forty tags would silently lose thirty with nothing on// screen to say so. The container scrolls instead, so the scrollbar// reports how much more there is — and searching narrows it.return [...chosen, ...rest]- }, [options, selected])+ }, [options, pinned])if (!isCurrency && (tags.isLoading || resources.isLoading)) {return (@@ -1507,6 +1509,7 @@ function FilterPanel({behind the panel is already showing the result. */}{field && multi && column && (<InlineValueList+ key={column.key}column={column}tenantId={tenantId}query={query}diff --git a/packages/dashboard-ui/src/spree/resource-combobox.tsx b/packages/dashboard-ui/src/spree/resource-combobox.tsxindex 12c46bd3c0..c62472300f 100644--- a/packages/dashboard-ui/src/spree/resource-combobox.tsx+++ b/packages/dashboard-ui/src/spree/resource-combobox.tsx@@ -1,4 +1,4 @@-import type { ReactNode } from 'react'+import { type ReactNode, useState } from 'react'import {Combobox,ComboboxContent,@@ -84,14 +84,30 @@ export function ResourceCombobox<T extends ComboboxOption>({disabled,id,}: ResourceComboboxProps<T>) {- const selected = items.find((r) => r.id === value) ?? null+ // The picked record is remembered so it stays selected while `items` is+ // between fetches. Without it, the selection drops out of the list for a+ // moment, Base UI reads that as the value being cleared, empties the input,+ // and the field flickers between labels until the queries settle.+ const [picked, setPicked] = useState<T | null>(null)+ const selected =+ items.find((r) => r.id === value) ?? (picked && picked.id === value ? picked : null)return (<Comboboxitems={items}value={selected}- onValueChange={(record: T | null) => onChange(record?.id, record)}- onInputValueChange={onInputChange}+ // Compared by id: a refetch hands back equal records as new objects.+ isItemEqualToValue={(item: T, current: T) => item.id === current.id}+ onValueChange={(record: T | null) => {+ setPicked(record)+ onChange(record?.id, record)+ }}+ // Picking an option writes its label into the input. That is not a+ // search, so the query goes back to the empty list instead of searching+ // for the full label of what was just chosen.+ onInputValueChange={(next, details) =>+ onInputChange?.(details.reason === 'item-press' ? '' : next)+ }itemToStringLabel={(record: T | null) => (record ? getOptionLabel(record) : '')}itemToStringValue={(record: T | null) => record?.id ?? ''}// Filtering is server-side: the caller's `onInputChange` already narrowsdiff --git a/packages/dashboard-ui/src/ui/toast.tsx b/packages/dashboard-ui/src/ui/toast.tsxindex bf22889d56..8ea71e5434 100644--- a/packages/dashboard-ui/src/ui/toast.tsx+++ b/packages/dashboard-ui/src/ui/toast.tsx@@ -12,6 +12,7 @@ import {TriangleAlertIcon,XIcon,} from '../spree/icons'+import { Button } from './button'/*** App-wide toast manager. Created outside React so a toast can be raised from@@ -26,18 +27,89 @@ import {export const toastManager = ToastPrimitive.createToastManager()const ICONS: Record<string, React.ReactNode> = {- success: <CircleCheckIcon className="size-4 text-emerald-600 dark:text-emerald-400" />,- error: <OctagonXIcon className="size-4 text-destructive" />,- warning: <TriangleAlertIcon className="size-4 text-amber-600 dark:text-amber-400" />,- info: <InfoIcon className="size-4 text-muted-foreground" />,- loading: <Loader2Icon className="size-4 animate-spin text-muted-foreground" />,+ success: <CircleCheckIcon className="text-emerald-600 dark:text-emerald-400" />,+ error: <OctagonXIcon className="text-destructive" />,+ warning: <TriangleAlertIcon className="text-amber-600 dark:text-amber-400" />,+ info: <InfoIcon className="text-muted-foreground" />,+ loading: <Loader2Icon className="animate-spin text-muted-foreground" />,+}++function ToastViewport({ className, ...props }: ToastPrimitive.Viewport.Props) {+ return (+ <ToastPrimitive.Viewport+ data-slot="toast-viewport"+ className={cn(+ // `z-40`, below the overlay layer (`z-50`) rather than above+ // everything: the stack sits bottom-right, which is exactly where a+ // side sheet's footer buttons are, and a toast drifting over Save is+ // both unclickable and a click the merchant did not intend.+ 'pointer-events-none fixed inset-x-4 bottom-[max(1rem,env(safe-area-inset-bottom))] z-40 mx-auto w-auto max-w-sm outline-none sm:right-4 sm:left-auto sm:mx-0 sm:w-full',+ className,+ )}+ {...props}+ />+ )+}++function Toast({ className, ...props }: ToastPrimitive.Root.Props) {+ return (+ <ToastPrimitive.Root+ data-slot="toast"+ className={cn(+ 'group/toast pointer-events-auto absolute right-0 bottom-0 z-[calc(1000-var(--toast-index))] w-full origin-bottom rounded-2xl border bg-popover text-popover-foreground shadow-lg will-change-transform outline-none select-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50',+ '[--gap:0.75rem] [--height:var(--toast-frontmost-height,var(--toast-height))] [--offset-y:calc(var(--toast-offset-y)*-1+calc(var(--toast-index)*var(--gap)*-1)+var(--toast-swipe-movement-y))] [--peek:0.75rem] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))]',+ 'h-(--height) [transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--peek))-(var(--shrink)*var(--height))))_scale(var(--scale))] [transition:transform_500ms_cubic-bezier(0.22,1,0.36,1),opacity_500ms,height_150ms]',+ "after:absolute after:top-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-['']",+ 'data-expanded:h-(--toast-height) data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(var(--offset-y))]',+ 'data-limited:opacity-0 data-starting-style:[transform:translateY(150%)]',+ '[&[data-ending-style]:not([data-limited]):not([data-swipe-direction])]:[transform:translateY(150%)]',+ 'data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))]',+ 'data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))]',+ 'data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))]',+ 'data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))]',+ 'data-expanded:data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))]',+ 'data-expanded:data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))]',+ 'data-expanded:data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))]',+ 'data-expanded:data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))]',+ className,+ )}+ {...props}+ />+ )+}++function ToastContent({ className, ...props }: ToastPrimitive.Content.Props) {+ return (+ <ToastPrimitive.Content+ data-slot="toast-content"+ className={cn(+ 'flex items-center gap-3 overflow-hidden p-4 transition-opacity duration-250 ease-[cubic-bezier(0.22,1,0.36,1)] data-behind:opacity-0 data-expanded:opacity-100',+ className,+ )}+ {...props}+ />+ )+}++function ToastIcon({ type }: { type: string | undefined }) {+ const icon = type ? ICONS[type] : null+ if (!icon) return null++ return (+ <span+ data-slot="toast-icon"+ className="shrink-0 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4"+ >+ {icon}+ </span>+ )}function ToastList() {const { toasts } = ToastPrimitive.useToastManager()return toasts.map((toast) => (- <ToastPrimitive.Root+ <Toastkey={toast.id}toast={toast}// Base UI types a toast as `dialog`, which puts every transient@@ -45,37 +117,31 @@ function ToastList() {// lookup, ours or a screen reader user's, matches whatever toast happens// to be on screen. `status` is what a passive notification should expose.role={toast.type === 'error' ? 'alert' : 'status'}- // `--toast-index` / `--toast-offset-y` drive the stacked-card effect:- // toasts behind the front one scale down and sit slightly higher.- className={cn(- // Normal flow inside a bottom-anchored column, not absolute- // positioning: a zero-height viewport gives an absolutely-positioned- // child nothing to sit on, and it renders below the fold.- 'pointer-events-auto w-full',- 'rounded-xl border border-border bg-popover p-4 text-popover-foreground shadow-lg',- 'transition-all duration-200 ease-out',- 'data-[starting-style]:translate-y-2 data-[starting-style]:opacity-0',- 'data-[ending-style]:translate-y-2 data-[ending-style]:opacity-0',- )}>- <div className="flex items-start gap-3">- {toast.type && ICONS[toast.type] && (- <span className="mt-0.5 shrink-0">{ICONS[toast.type]}</span>- )}+ <ToastContent>+ <ToastIcon type={toast.type} /><div className="flex min-w-0 flex-1 flex-col gap-1">- <ToastPrimitive.Title className="font-medium text-sm leading-snug" />- <ToastPrimitive.Description className="text-muted-foreground text-sm leading-snug" />+ <ToastPrimitive.Title data-slot="toast-title" className="font-medium text-sm" />+ <ToastPrimitive.Description+ data-slot="toast-description"+ className="text-muted-foreground text-sm"+ /></div>+ <ToastPrimitive.Action+ data-slot="toast-action"+ render={<Button variant="outline" size="sm" />}+ className="shrink-0"+ /><ToastPrimitive.Close- // 44px tap target on touch, compact for a pointer — the same rule the- // rest of the app follows for icon-only controls.- className="-mt-1 -mr-1 inline-flex size-7 shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"+ data-slot="toast-close"aria-label={i18n.t('admin.actions.close')}+ render={<Button variant="ghost" size="icon-sm" />}+ className="relative shrink-0 text-muted-foreground after:absolute after:-inset-2 after:content-[''] hover:text-foreground">- <XIcon className="size-4" />+ <XIcon aria-hidden="true" /></ToastPrimitive.Close>- </div>- </ToastPrimitive.Root>+ </ToastContent>+ </Toast>))}@@ -90,22 +156,10 @@ export function Toaster({ children }: { children?: React.ReactNode }) {return (<ToastPrimitive.Provider toastManager={toastManager}>{children}- <ToastPrimitive.Portal>- <ToastPrimitive.Viewport- className={cn(- // Below the overlay layer (`z-50`) rather than above everything:- // the stack sits bottom-right, which is exactly where a side- // sheet's footer buttons are, and a toast drifting over Save is- // both unclickable and a click the merchant did not intend.- 'fixed right-4 z-40 flex w-[min(22rem,calc(100vw-2rem))] flex-col gap-2',- // `pointer-events-none` on the column so the empty space above the- // stack never blocks the page; each toast takes them back.- 'pointer-events-none',- 'bottom-[max(1rem,env(safe-area-inset-bottom))]',- )}- >+ <ToastPrimitive.Portal data-slot="toast-portal">+ <ToastViewport><ToastList />- </ToastPrimitive.Viewport>+ </ToastViewport></ToastPrimitive.Portal></ToastPrimitive.Provider>)