Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Moves from four to three columns on home (#43804)

Saxon Fletcher73112440c34a
diff --git a/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx b/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx
index 4d686b16c62..6ce5ccaa87d 100644
--- a/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx
+++ b/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx
@@ -95,7 +95,7 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
</div>
) : errorLints.length > 0 ? (
<>
- <Row columns={[3, 2, 1]}>
+ <Row maxColumns={4} minWidth={280}>
{errorLints.map((lint) => {
return (
<Card
diff --git a/apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx b/apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx
index 540250376f2..3764084ce00 100644
--- a/apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx
+++ b/apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx
@@ -405,7 +405,8 @@ export function CustomReportSection() {
strategy={rectSortingStrategy}
>
<Row
- columns={[3, 2, 1]}
+ maxColumns={4}
+ minWidth={280}
onDrop={handleDrop}
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
diff --git a/apps/studio/components/interfaces/ProjectHome/ProjectUsageSection.tsx b/apps/studio/components/interfaces/ProjectHome/ProjectUsageSection.tsx
index d642ce60f5a..469c9971a80 100644
--- a/apps/studio/components/interfaces/ProjectHome/ProjectUsageSection.tsx
+++ b/apps/studio/components/interfaces/ProjectHome/ProjectUsageSection.tsx
@@ -219,7 +219,7 @@ export const ProjectUsageSection = () => {
tooltipSide="left"
/>
</div>
- <Row columns={[3, 2, 1]}>
+ <Row maxColumns={4} minWidth={280}>
{enabledServices.map((s) => (
<Card key={s.key} className="mb-0 md:mb-0 h-full flex flex-col h-64">
<CardHeader className="flex flex-row items-end justify-between gap-2 space-y-0 pb-0 border-b-0">
diff --git a/packages/ui-patterns/src/Row/index.test.ts b/packages/ui-patterns/src/Row/index.test.ts
new file mode 100644
index 00000000000..ff0a089544b
--- /dev/null
+++ b/packages/ui-patterns/src/Row/index.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest'
+
+import { resolveColumnsForWidth } from './index'
+
+describe('resolveColumnsForWidth', () => {
+ it('caps the visible count by maxColumns', () => {
+ expect(resolveColumnsForWidth({ width: 1600, maxColumns: 4, minWidth: 280, gap: 16 })).toBe(4)
+ })
+
+ it('reduces visible items as the container narrows', () => {
+ expect(resolveColumnsForWidth({ width: 1200, maxColumns: 4, minWidth: 280, gap: 16 })).toBe(4)
+ expect(resolveColumnsForWidth({ width: 900, maxColumns: 4, minWidth: 280, gap: 16 })).toBe(3)
+ expect(resolveColumnsForWidth({ width: 700, maxColumns: 4, minWidth: 280, gap: 16 })).toBe(2)
+ expect(resolveColumnsForWidth({ width: 500, maxColumns: 4, minWidth: 280, gap: 16 })).toBe(1)
+ })
+
+ it('always returns at least one visible slot', () => {
+ expect(resolveColumnsForWidth({ width: 0, maxColumns: 4, minWidth: 280, gap: 16 })).toBe(1)
+ })
+
+ it('returns a safe value when minWidth and gap are both zero', () => {
+ expect(resolveColumnsForWidth({ width: 1600, maxColumns: 4, minWidth: 0, gap: 0 })).toBe(4)
+ })
+})
diff --git a/packages/ui-patterns/src/Row/index.tsx b/packages/ui-patterns/src/Row/index.tsx
index 3802aa6aa50..781ec0c8fbc 100644
--- a/packages/ui-patterns/src/Row/index.tsx
+++ b/packages/ui-patterns/src/Row/index.tsx
@@ -9,8 +9,10 @@ import { Button, cn } from 'ui'
import { useMeasuredWidth } from './Row.utils'
interface RowProps extends React.HTMLAttributes<HTMLDivElement> {
- // columns can be a fixed number or an array [lg, md, sm]
- columns: number | [number, number, number]
+ // Maximum number of columns visible in the row at once
+ maxColumns: number
+ // Minimum width in pixels for each item before the row reduces the visible count
+ minWidth: number
children: ReactNode
className?: string
/** gap between items in pixels */
@@ -21,8 +23,35 @@ interface RowProps extends React.HTMLAttributes<HTMLDivElement> {
scrollBehavior?: ScrollBehavior
}
+export const resolveColumnsForWidth = ({
+ width,
+ maxColumns,
+ minWidth,
+ gap,
+}: {
+ width: number
+ maxColumns: number
+ minWidth: number
+ gap: number
+}) => {
+ const denominator = minWidth + gap
+ if (denominator <= 0) return Math.max(1, maxColumns)
+ const fittedColumns = Math.floor((width + gap) / denominator)
+
+ return Math.max(1, Math.min(maxColumns, fittedColumns))
+}
+
export const Row = forwardRef<HTMLDivElement, RowProps>(function Row(
- { columns, children, className, gap = 16, showArrows = true, scrollBehavior = 'smooth', ...rest },
+ {
+ maxColumns,
+ minWidth,
+ children,
+ className,
+ gap = 16,
+ showArrows = true,
+ scrollBehavior = 'smooth',
+ ...rest
+ },
ref
) {
const containerRef = useRef<HTMLDivElement>(null)
@@ -32,18 +61,15 @@ export const Row = forwardRef<HTMLDivElement, RowProps>(function Row(
const [scrollPosition, setScrollPosition] = useState(0)
const measuredWidth = useMeasuredWidth(containerRef)
- const resolveColumnsForWidth = (width: number): number => {
- if (!Array.isArray(columns)) return columns
- // Interpret as [lg, md, sm]
- const [lgCols, mdCols, smCols] = columns
- if (width >= 1024) return lgCols
- if (width >= 768) return mdCols
- return smCols
- }
-
const numberOfColumns = useMemo(
- () => resolveColumnsForWidth(measuredWidth ?? 0),
- [measuredWidth, columns]
+ () =>
+ resolveColumnsForWidth({
+ width: measuredWidth ?? 0,
+ maxColumns,
+ minWidth,
+ gap,
+ }),
+ [gap, maxColumns, measuredWidth, minWidth]
)
const scrollByStep = (direction: -1 | 1) => {