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.

Improve the Reporting UI

Damian Legawiecd730e81aabfa
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.ts
index 15bb93ba09..415fc1ec31 100644
--- a/packages/dashboard-ui/src/index.ts
+++ b/packages/dashboard-ui/src/index.ts
@@ -116,6 +116,7 @@ export * from './ui/popover'
export * from './ui/progress'
export * from './ui/radio-group'
export * from './ui/rich-text-editor'
+export * from './ui/scroll-area'
export * from './ui/select'
export * from './ui/separator'
export * from './ui/sheet'
diff --git a/packages/dashboard-ui/src/ui/data-table.tsx b/packages/dashboard-ui/src/ui/data-table.tsx
index 3fd5b2b670..c365c4dbc8 100644
--- a/packages/dashboard-ui/src/ui/data-table.tsx
+++ b/packages/dashboard-ui/src/ui/data-table.tsx
@@ -33,6 +33,13 @@ interface TableProps extends React.ComponentProps<'table'> {
* own radius.
*/
roundedBottom?: boolean
+ /**
+ * Rounds the header's outer corners, for a table that starts a card. The
+ * header's own square corners otherwise sit on top of the card's radius and
+ * clip it — the mirror of the `roundedBottom` case, and unset by default
+ * because a table usually has a card header or some content above it.
+ */
+ roundedTop?: boolean
/**
* Scrolls sideways at every width, not just on narrow viewports. For a table
* in a bounded container — a card, a sheet, a dialog — where the default
@@ -70,6 +77,7 @@ function Table({
children,
stickyHeader = false,
roundedBottom,
+ roundedTop,
scrollX = false,
...props
}: TableProps) {
@@ -101,7 +109,12 @@ function Table({
'last:[&_tbody_tr:last-child_td:first-child]:rounded-bl-xl last:[&_tbody_tr:last-child_td:last-child]:rounded-br-xl last:[&_tbody_tr:last-child_td:only-child]:rounded-b-xl'
// `true`/`false` decide on the table itself; unset defers to the wrapper's
// own position among its siblings.
- const tableRoundedClasses = roundedBottom === true ? alwaysRounded : undefined
+ // `thead` cells carry the header's background, so the radius belongs on the
+ // cells rather than the row — a rounded row still shows square cell corners.
+ const topRounded = roundedTop
+ ? '[&_thead_tr:first-child_th:first-child]:rounded-tl-xl [&_thead_tr:first-child_th:last-child]:rounded-tr-xl [&_thead_tr:first-child_th:only-child]:rounded-t-xl'
+ : undefined
+ const tableRoundedClasses = cn(roundedBottom === true ? alwaysRounded : undefined, topRounded)
const wrapperRoundedClasses = roundedBottom === undefined ? roundedWhenLast : undefined
const kids = Children.toArray(children)
@@ -281,7 +294,7 @@ function TableHead({ className, ...props }: React.ComponentProps<'th'>) {
return (
<th
className={cn(
- 'text-left text-sm font-normal text-muted-foreground bg-card px-3 py-2.5 h-9 sm:p-2 whitespace-nowrap first:pl-4 last:pr-4',
+ 'text-left text-sm font-normal text-muted-foreground bg-muted px-3 py-2.5 h-9 sm:p-2 whitespace-nowrap first:pl-4 last:pr-4',
'shadow-[inset_0_-1px_0_0_var(--border-subtle)]',
className,
)}
diff --git a/packages/dashboard-ui/src/ui/scroll-area.tsx b/packages/dashboard-ui/src/ui/scroll-area.tsx
new file mode 100644
index 0000000000..8eb508d48c
--- /dev/null
+++ b/packages/dashboard-ui/src/ui/scroll-area.tsx
@@ -0,0 +1,65 @@
+import { ScrollArea as ScrollAreaPrimitive } from '@base-ui/react/scroll-area'
+import type * as React from 'react'
+import { cn } from '../lib/utils'
+
+/**
+ * shadcn's scroll-area, on Base UI rather than Radix — the registry ships the
+ * Radix build for this project's style, and nothing else here imports Radix.
+ * Same parts and the same slot names; the scrollbar fades in on hover or
+ * scroll, which is Base UI's own behaviour rather than a Radix `type` prop.
+ *
+ * Height belongs to the caller: set it here, or let a flex parent size it.
+ */
+function ScrollArea({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
+ return (
+ <ScrollAreaPrimitive.Root
+ data-slot="scroll-area"
+ className={cn('relative', className)}
+ {...props}
+ >
+ <ScrollAreaPrimitive.Viewport
+ data-slot="scroll-area-viewport"
+ className="size-full overscroll-contain rounded-[inherit] outline-none transition-[color,box-shadow] focus-visible:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_15%,transparent)]"
+ >
+ {children}
+ </ScrollAreaPrimitive.Viewport>
+ <ScrollBar />
+ <ScrollAreaPrimitive.Corner />
+ </ScrollAreaPrimitive.Root>
+ )
+}
+
+function ScrollBar({
+ className,
+ orientation = 'vertical',
+ ...props
+}: React.ComponentProps<typeof ScrollAreaPrimitive.Scrollbar>) {
+ return (
+ <ScrollAreaPrimitive.Scrollbar
+ data-slot="scroll-area-scrollbar"
+ orientation={orientation}
+ className={cn(
+ 'flex touch-none select-none p-px',
+ 'data-[orientation=horizontal]:h-2.5 data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-col data-[orientation=horizontal]:border-t data-[orientation=horizontal]:border-t-transparent',
+ 'data-[orientation=vertical]:h-full data-[orientation=vertical]:w-2.5 data-[orientation=vertical]:border-l data-[orientation=vertical]:border-l-transparent',
+ // Base UI marks the bar while it is scrolled or hovered, so it can
+ // stay out of the way of a short list until it is wanted.
+ 'opacity-0 transition-opacity duration-150 ease-out data-[hovering]:opacity-100 data-[scrolling]:opacity-100',
+ 'motion-reduce:transition-none',
+ className,
+ )}
+ {...props}
+ >
+ <ScrollAreaPrimitive.Thumb
+ data-slot="scroll-area-thumb"
+ className="relative flex-1 rounded-full bg-border-control"
+ />
+ </ScrollAreaPrimitive.Scrollbar>
+ )
+}
+
+export { ScrollArea, ScrollBar }
diff --git a/packages/dashboard-ui/src/ui/tabs.tsx b/packages/dashboard-ui/src/ui/tabs.tsx
index 7f3e99bd98..f422abd305 100644
--- a/packages/dashboard-ui/src/ui/tabs.tsx
+++ b/packages/dashboard-ui/src/ui/tabs.tsx
@@ -21,7 +21,11 @@ function Tabs({
}
/** The track a set of tabs sits in, recessed so the selected tab reads as raised. */
-function TabsList({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.List>) {
+function TabsList({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<typeof TabsPrimitive.List>) {
return (
<TabsPrimitive.List
data-slot="tabs-list"
@@ -31,7 +35,9 @@ function TabsList({ className, ...props }: React.ComponentProps<typeof TabsPrimi
className,
)}
{...props}
- />
+ >
+ {children}
+ </TabsPrimitive.List>
)
}
@@ -43,14 +49,15 @@ function TabsTrigger({ className, ...props }: React.ComponentProps<typeof TabsPr
// min-h-7 + py-1 keeps the hit area past the 24px WCAG target size at
// every text size; the old h-[calc(100%-1px)] left it to the parent.
'inline-flex min-h-7 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md px-2.5 py-1 text-sm font-medium whitespace-nowrap',
- 'transition-[color,background-color,box-shadow] duration-100 ease-out outline-none',
+ 'transition-[color,background-color,box-shadow] duration-150 ease-out outline-none motion-reduce:transition-none',
'group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start',
// Unselected tabs recede so the selected one reads as chosen; hover
// promotes to full foreground rather than only shifting the surface,
// which is the part a colour-blind or low-vision reader can see.
'text-muted-foreground hover:text-foreground',
- // The pair --track-recessed / --nested-raised is defined to hold this
- // step in both themes: +3% lightness in light, +5% in dark.
+ // The raised surface lives on the tab itself, as it did before the
+ // indicator: it is the thing that makes the selection legible, and it
+ // must not depend on a separate element rendering correctly behind it.
'data-[active]:bg-nested-raised data-[active]:text-foreground data-[active]:shadow-xs',
// Same focus treatment as Button, so a keyboard user sees one
// consistent indicator across the dashboard.
diff --git a/packages/dashboard/src/components/spree/reporting/report-view.tsx b/packages/dashboard/src/components/spree/reporting/report-view.tsx
index 126f42eb38..d121a8474c 100644
--- a/packages/dashboard/src/components/spree/reporting/report-view.tsx
+++ b/packages/dashboard/src/components/spree/reporting/report-view.tsx
@@ -438,7 +438,7 @@ function ResultTable({
return (
<Card>
<CardContent className="p-0">
- <Table data-testid="report-table" roundedBottom>
+ <Table data-testid="report-table" roundedBottom roundedTop>
<TableHeader>
<TableHeaderRow>
{ranked && <TableHead className="w-10">#</TableHead>}
diff --git a/packages/dashboard/src/hooks/use-saved-reports.ts b/packages/dashboard/src/hooks/use-saved-reports.ts
index e59ff92baa..6592fa2857 100644
--- a/packages/dashboard/src/hooks/use-saved-reports.ts
+++ b/packages/dashboard/src/hooks/use-saved-reports.ts
@@ -20,6 +20,22 @@ export function useSavedReport(id: string | undefined) {
})
}
+/**
+ * A seeded report looked up by its exact name, so a surface that knows which
+ * built-in it is showing can link straight to it. Reports are addressed by id
+ * and names are translated, so the name is the only stable handle a caller
+ * has without hardcoding ids per store.
+ */
+export function useSavedReportByName(name: string | undefined) {
+ const query = useQuery({
+ queryKey: useResourceKey('saved-reports', { name_eq: name ?? '' }),
+ queryFn: () => adminClient.reporting.savedReports.list({ name_eq: name, limit: 1 }),
+ enabled: !!name,
+ })
+
+ return { ...query, report: query.data?.data?.[0] }
+}
+
export function useCreateSavedReport() {
return useResourceMutation<SavedReport, Error, SavedReportCreateParams>({
mutationFn: (params) => adminClient.reporting.savedReports.create(params),
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 82a4efdba5..6db4d95199 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -3228,7 +3228,14 @@
"units_count_few": "{{count}} وحدات",
"units_count_many": "{{count}} وحدة",
"units_count_other": "{{count}} وحدة",
- "empty": "لا توجد بيانات لهذه الفترة بعد."
+ "empty": "لا توجد بيانات لهذه الفترة بعد.",
+ "view_report": "عرض التقرير",
+ "report_names": {
+ "seller_payouts": "مدفوعات البائعين",
+ "top_categories": "أفضل الفئات",
+ "top_companies": "أفضل الشركات",
+ "top_customers": "أفضل العملاء"
+ }
},
"unavailable": {
"title": "التقارير غير متاحة لدورك",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 8006480866..7c5a489208 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -3203,7 +3203,14 @@
"orders_count_other": "{{count}} Bestellungen",
"units_count_one": "{{count}} Stück",
"units_count_other": "{{count}} Stück",
- "empty": "Noch keine Daten für diesen Zeitraum."
+ "empty": "Noch keine Daten für diesen Zeitraum.",
+ "view_report": "Bericht ansehen",
+ "report_names": {
+ "seller_payouts": "Verkäuferauszahlungen",
+ "top_categories": "Top-Kategorien",
+ "top_companies": "Top-Firmen",
+ "top_customers": "Top-Kunden"
+ }
},
"unavailable": {
"title": "Berichte sind für Ihre Rolle nicht verfügbar",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index e88e5165c2..6f4f5a594d 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -3203,7 +3203,14 @@
"orders_count_other": "{{count}} orders",
"units_count_one": "{{count}} unit",
"units_count_other": "{{count}} units",
- "empty": "No data for this period yet."
+ "empty": "No data for this period yet.",
+ "view_report": "View report",
+ "report_names": {
+ "seller_payouts": "Seller payouts",
+ "top_categories": "Top categories",
+ "top_companies": "Top companies",
+ "top_customers": "Top customers"
+ }
},
"unavailable": {
"title": "Reports are unavailable for your role",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index ccfa2d47dd..e09b09c567 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -3203,7 +3203,14 @@
"orders_count_other": "{{count}} commandes",
"units_count_one": "{{count}} unité",
"units_count_other": "{{count}} unités",
- "empty": "Pas encore de données pour cette période."
+ "empty": "Pas encore de données pour cette période.",
+ "view_report": "Voir le rapport",
+ "report_names": {
+ "seller_payouts": "Versements aux vendeurs",
+ "top_categories": "Meilleures catégories",
+ "top_companies": "Meilleures entreprises",
+ "top_customers": "Meilleurs clients"
+ }
},
"unavailable": {
"title": "Les rapports ne sont pas disponibles pour votre rôle",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 5662756013..b20bbd64a9 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -3239,7 +3239,14 @@
"units_count_few": "{{count}} sztuki",
"units_count_many": "{{count}} sztuk",
"units_count_other": "{{count}} sztuki",
- "empty": "Brak danych dla tego okresu."
+ "empty": "Brak danych dla tego okresu.",
+ "view_report": "Zobacz raport",
+ "report_names": {
+ "seller_payouts": "Wypłaty dla sprzedawców",
+ "top_categories": "Najlepsze kategorie",
+ "top_companies": "Najlepsze firmy",
+ "top_customers": "Najlepsi klienci"
+ }
},
"unavailable": {
"title": "Raporty są niedostępne dla Twojej roli",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 959d831332..8636ce01db 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -3193,7 +3193,14 @@
},
"orders_count_other": "{{count}} 笔订单",
"units_count_other": "{{count}} 件",
- "empty": "该时间段暂无数据。"
+ "empty": "该时间段暂无数据。",
+ "view_report": "查看报告",
+ "report_names": {
+ "seller_payouts": "卖家结算",
+ "top_categories": "热门类别",
+ "top_companies": "热门公司",
+ "top_customers": "热门客户"
+ }
},
"unavailable": {
"title": "您的角色无法查看报表",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/index.tsx
index 29eaa73b25..aedc212d09 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/index.tsx
@@ -1,4 +1,4 @@
-import type { DashboardOperations, ReportingDimensionValue, ReportingQuery } from '@spree/admin-sdk'
+import type { DashboardOperations, ReportingQuery } from '@spree/admin-sdk'
import { SpreeError } from '@spree/admin-sdk'
import {
adminClient,
@@ -10,9 +10,11 @@ import {
useStore,
} from '@spree/dashboard-core'
import {
+ Button,
Card,
CardContent,
CardDescription,
+ CardFooter,
CardHeader,
CardTitle,
cn,
@@ -24,6 +26,7 @@ import {
EmptyMedia,
EmptyTitle,
Progress,
+ ScrollArea,
Skeleton,
Table,
TableBody,
@@ -47,8 +50,9 @@ import {
TruckIcon,
} from '@spree/dashboard-ui/icons'
import { useQuery } from '@tanstack/react-query'
-import { createFileRoute, Link } from '@tanstack/react-router'
+import { createFileRoute, Link, type LinkProps } from '@tanstack/react-router'
import { format, parseISO } from 'date-fns'
+import type { CSSProperties } from 'react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { ALL_CHANNELS, ChannelSelect } from '../../../components/spree/channel-select'
@@ -66,6 +70,7 @@ import {
useReportingQuery,
useReportingSchema,
} from '../../../hooks/use-reporting'
+import { useSavedReportByName } from '../../../hooks/use-saved-reports'
export const Route = createFileRoute('/_authenticated/$storeId/')({
component: DashboardPage,
@@ -215,7 +220,8 @@ function DashboardPage() {
)
}
-const OPERATIONS_ROW_CLASS = 'flex items-center gap-3 border-b px-4 py-3 last:border-0'
+const OPERATIONS_ROW_CLASS =
+ 'flex items-center gap-3 border-b border-border-subtle px-4 py-3 last:border-0'
type OperationsFilter = { id: string; field: string; operator: string; value: string }
@@ -353,6 +359,10 @@ function OperationsCard({
type RankingTab = 'customers' | 'categories' | 'companies' | 'sellers'
// Each tab is one contract query; the revenue metric doubles as the share bar.
+/** One row's height. The rows, the five-row container and the loading
+ * skeleton all derive from it, so they cannot drift apart. */
+const RANKING_ROW_HEIGHT = '5.25rem'
+
const RANKING_QUERIES: Record<
RankingTab,
{
@@ -362,6 +372,12 @@ const RANKING_QUERIES: Record<
}
revenueMetric: string
countMetric: string
+ /** Where a row points. The route travels with the query that produced the
+ * row, so a new tab cannot forget one. */
+ rowLink: (storeId: string, id: string) => LinkProps
+ /** The seeded report this ranking is the top five of; the card links to it
+ * by name, since a report is addressed by id and names are translated. */
+ reportKey: string
}
> = {
customers: {
@@ -373,6 +389,11 @@ const RANKING_QUERIES: Record<
},
revenueMetric: 'total_sales',
countMetric: 'orders',
+ rowLink: (storeId, customerId) => ({
+ to: '/$storeId/customers/$customerId',
+ params: { storeId, customerId },
+ }),
+ reportKey: 'top_customers',
},
categories: {
query: {
@@ -383,6 +404,11 @@ const RANKING_QUERIES: Record<
},
revenueMetric: 'net_sales',
countMetric: 'units_sold',
+ rowLink: (storeId, categoryId) => ({
+ to: '/$storeId/products/categories/$categoryId',
+ params: { storeId, categoryId },
+ }),
+ reportKey: 'top_categories',
},
companies: {
query: {
@@ -393,6 +419,11 @@ const RANKING_QUERIES: Record<
},
revenueMetric: 'total_sales',
countMetric: 'orders',
+ rowLink: (storeId, companyId) => ({
+ to: '/$storeId/companies/$companyId',
+ params: { storeId, companyId },
+ }),
+ reportKey: 'top_companies',
},
// What each seller sold, on the line items that were theirs.
sellers: {
@@ -404,6 +435,11 @@ const RANKING_QUERIES: Record<
},
revenueMetric: 'net_sales',
countMetric: 'units_sold',
+ rowLink: (storeId, sellerId) => ({
+ to: '/$storeId/sellers/$sellerId',
+ params: { storeId, sellerId },
+ }),
+ reportKey: 'seller_payouts',
},
}
@@ -419,7 +455,10 @@ function RankingsCard({
const { storeId } = Route.useParams()
const [tab, setTab] = useState<RankingTab>(tabs[0])
- const { query, revenueMetric, countMetric } = RANKING_QUERIES[tab]
+ const { query, revenueMetric, countMetric, rowLink, reportKey } = RANKING_QUERIES[tab]
+ // The seeded report's own name, from the same keys the seeder writes it with.
+ const reportName = t(`admin.pages.home.rankings.report_names.${reportKey}`)
+ const { report } = useSavedReportByName(reportName)
// Read from the query rather than stored beside it: two copies can disagree,
// and a row asked for a dimension it was not grouped by renders unnamed.
const [dimensionName] = query.dimensions
@@ -465,112 +504,112 @@ function RankingsCard({
</TabsList>
</Tabs>
</CardHeader>
- <CardContent className="p-0">
+ {/* Five rows tall whatever the tab holds — rows, a skeleton, an empty
+ note or an error all live at this height, so the page below never
+ moves as tabs are switched or data arrives. */}
+ <CardContent
+ className="h-[calc(var(--ranking-row)*5)] p-0"
+ style={{ '--ranking-row': RANKING_ROW_HEIGHT } as CSSProperties}
+ >
{rows === undefined ? (
error ? (
- <p className="px-4 pb-6 pt-2 text-sm text-muted-foreground">
- {t('admin.errors.generic')}
- </p>
+ <p className="px-4 pt-4 text-sm text-muted-foreground">{t('admin.errors.generic')}</p>
) : (
<RankingRowsSkeleton />
)
) : rows.length === 0 ? (
- <p className="px-4 pb-6 pt-2 text-sm text-muted-foreground">
+ <p className="px-4 pt-4 text-sm text-muted-foreground">
{t('admin.pages.home.rankings.empty')}
</p>
) : (
- <div className="flex flex-col">
- {rows.map((row, index) => (
- <div key={`${tab}-${row.key ?? index}`} className="border-b px-4 py-3 last:border-0">
- <div className="flex items-baseline justify-between gap-3">
- <span className="flex min-w-0 items-baseline gap-2 text-sm">
- <span className="w-5 shrink-0 text-muted-foreground tabular-nums">
- {index + 1}.
- </span>
- <RankingName tab={tab} storeId={storeId} dimension={row.dimension} />
- </span>
- <span className="shrink-0 text-right">
- <span className="block text-sm font-medium tabular-nums">{row.display}</span>
- <span className="block text-xs text-muted-foreground">{row.meta}</span>
- </span>
- </div>
- <Progress className="mt-2" value={sharePercent(row.amount, maxAmount)} />
- </div>
- ))}
- </div>
+ // Five rows tall, whatever the tab returns: the card keeps one height
+ // so the page below it does not jump as tabs are switched, and a
+ // longer ranking scrolls rather than stretching the layout.
+ <ScrollArea className="h-full">
+ <div className="flex flex-col">
+ {rows.map((row, index) => {
+ const body = (
+ <>
+ <div className="flex items-baseline justify-between gap-3">
+ <span className="flex min-w-0 items-baseline gap-2 text-sm">
+ <span className="w-5 shrink-0 text-muted-foreground tabular-nums">
+ {index + 1}.
+ </span>
+ <DimensionLabel dimension={row.dimension} />
+ </span>
+ <span className="shrink-0 text-right">
+ <span className="block text-sm font-medium tabular-nums">
+ {row.display}
+ </span>
+ <span className="block text-xs text-muted-foreground">{row.meta}</span>
+ </span>
+ </div>
+ <Progress className="mt-2 pl-7" value={sharePercent(row.amount, maxAmount)} />
+ </>
+ )
+ const rowKey = `${tab}-${row.key ?? index}`
+ // A fixed row height: only customer rows carry a sub-line, so
+ // without it the list is a different height on every tab and
+ // the card resizes as they are switched.
+ const rowClass =
+ 'flex h-(--ranking-row) flex-col justify-center border-b px-4 text-foreground no-underline last:border-0'
+
+ // The whole row is the target rather than just the name: a
+ // ranking row is one thing, and a link the width of a name is a
+ // small target beside the figures it belongs to. A row whose key
+ // has no record behind it ("Unassigned") stays inert.
+ return row.dimension.id ? (
+ <Link
+ key={rowKey}
+ {...rowLink(storeId, row.dimension.id)}
+ className={cn(rowClass, 'transition-colors hover:bg-accent/60')}
+ >
+ {body}
+ </Link>
+ ) : (
+ <div key={rowKey} className={rowClass}>
+ {body}
+ </div>
+ )
+ })}
+ </div>
+ </ScrollArea>
)}
</CardContent>
+ {/* Five rows is the top of a longer report; the footer is the way to the
+ rest of it, below the rows rather than competing with the tabs. */}
+ <Can I="read" a={Subject.SavedReport}>
+ <CardFooter className="justify-end">
+ <Button asChild variant="ghost" size="sm" disabled={!report}>
+ {report ? (
+ <Link to="/$storeId/reports/$reportId" params={{ storeId, reportId: report.id }}>
+ {t('admin.pages.home.rankings.view_report')}
+ <ChevronRightIcon className="size-4" />
+ </Link>
+ ) : (
+ // The report is looked up by name, so until it resolves — or if
+ // a merchant deleted that built-in — the list is the honest
+ // destination rather than a link to nothing.
+ <Link to="/$storeId/reports" params={{ storeId }} search={{ search: reportName }}>
+ {t('admin.pages.home.rankings.view_report')}
+ <ChevronRightIcon className="size-4" />
+ </Link>
+ )}
+ </Button>
+ </CardFooter>
+ </Can>
</Card>
)
}
-function RankingName({
- tab,
- storeId,
- dimension,
-}: {
- tab: RankingTab
- storeId: string
- dimension: ReportingDimensionValue
-}) {
- const label = <DimensionLabel dimension={dimension} />
-
- if (!dimension.id) {
- return label
- }
-
- if (tab === 'customers') {
- return (
- <Link
- to="/$storeId/customers/$customerId"
- params={{ storeId, customerId: dimension.id }}
- className="min-w-0 hover:underline"
- >
- {label}
- </Link>
- )
- }
-
- if (tab === 'companies') {
- return (
- <Link
- to="/$storeId/companies/$companyId"
- params={{ storeId, companyId: dimension.id }}
- className="min-w-0 hover:underline"
- >
- {label}
- </Link>
- )
- }
-
- if (tab === 'sellers') {
- return (
- <Link
- to="/$storeId/sellers/$sellerId"
- params={{ storeId, sellerId: dimension.id }}
- className="min-w-0 hover:underline"
- >
- {label}
- </Link>
- )
- }
-
- return (
- <Link
- to="/$storeId/products/categories/$categoryId"
- params={{ storeId, categoryId: dimension.id }}
- className="min-w-0 hover:underline"
- >
- {label}
- </Link>
- )
-}
-
function RankingRowsSkeleton() {
return (
<div className="flex flex-col">
{['rank-1', 'rank-2', 'rank-3', 'rank-4', 'rank-5'].map((key) => (
- <div key={key} className="border-b px-4 py-3 last:border-0">
+ <div
+ key={key}
+ className="flex h-(--ranking-row) flex-col justify-center border-b px-4 last:border-0"
+ >
<div className="flex items-center justify-between gap-3">
<Skeleton className="h-4 w-40" />
<Skeleton className="h-4 w-16" />
@@ -681,7 +720,10 @@ function DashboardSkeleton() {
<CardContent className="p-0">
<div className="flex flex-col">
{['op-1', 'op-2', 'op-3', 'op-4', 'op-5'].map((key) => (
- <div key={key} className="flex items-center gap-3 border-b px-4 py-3 last:border-0">
+ <div
+ key={key}
+ className="flex items-center gap-3 border-b border-border-subtle px-4 py-3 last:border-0"
+ >
<Skeleton className="size-8 rounded-md" />
<Skeleton className="h-4 w-32 flex-1" />
<Skeleton className="h-4 w-8" />
diff --git a/spree/core/app/services/spree/seeds/saved_reports.rb b/spree/core/app/services/spree/seeds/saved_reports.rb
index 4c12f18051..3e4c6cd75c 100644
--- a/spree/core/app/services/spree/seeds/saved_reports.rb
+++ b/spree/core/app/services/spree/seeds/saved_reports.rb
@@ -29,6 +29,9 @@ module Spree
{ key: 'top_categories',
query: { 'metrics' => %w[net_sales units_sold], 'dimensions' => %w[category],
'time_range' => { 'preset' => 'last_4_weeks' }, 'sort' => '-net_sales', 'limit' => 20 } },
+ { key: 'top_companies',
+ query: { 'metrics' => %w[total_sales orders], 'dimensions' => %w[company],
+ 'time_range' => { 'preset' => 'last_4_weeks' }, 'sort' => '-total_sales', 'limit' => 20 } },
{ key: 'top_customers',
query: { 'metrics' => %w[total_sales orders], 'dimensions' => %w[customer],
'time_range' => { 'preset' => 'last_4_weeks' }, 'sort' => '-total_sales', 'limit' => 20 } },
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 50061d3c69..39cfcca692 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -1918,6 +1918,9 @@ en:
top_categories:
description: Best-selling categories by net sales over the last four weeks.
name: Top categories
+ top_companies:
+ description: Organisations ranked by spend over the last four weeks.
+ name: Top companies
top_customers:
description: Customers ranked by spend over the last four weeks.
name: Top customers