Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(prompts): keep the prompts table header and Prompt column pinned while scrolling (#1007)
Cihane80b0835e669
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsxindex e069593ea..c41903591 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx@@ -2238,7 +2238,7 @@ function AllPromptsTab({</div></CardHeader><CardContent className="p-0">- <Table>+ <Table stickyHeader stickyFirstColumn><TableHeader><TableRow><TableHead className="pl-6">Prompt</TableHead>diff --git a/web/src/components/ui/table.test.ts b/web/src/components/ui/table.test.tsnew file mode 100644index 000000000..2acbb7b77--- /dev/null+++ b/web/src/components/ui/table.test.ts@@ -0,0 +1,42 @@+/**+ * table.test.ts+ *+ * Tests the sticky header / first column classes exported from table.tsx.+ */++import { describe, expect, test } from 'vitest';+import { stickyTableClasses } from './table';++describe('stickyTableClasses', () => {+ test('a plain table only scrolls sideways and adds no sticky classes', () => {+ const c = stickyTableClasses({});+ expect(c.sticky).toBe(false);+ expect(c.container).toBe('overflow-x-auto');+ expect(c.table).toBe('');+ });++ test('stickyHeader caps the height, scrolls inside, and pins header cells', () => {+ const c = stickyTableClasses({ stickyHeader: true });+ expect(c.sticky).toBe(true);+ expect(c.container).toContain('overflow-auto');+ expect(c.container).toContain('max-h-');+ expect(c.table).toContain('[&_thead_th]:sticky');+ expect(c.table).toContain('[&_thead_th]:top-0');+ expect(c.table).toContain('[&_thead_th]:bg-card');+ expect(c.table).not.toContain('[&_tr>*:first-child]:sticky');+ });++ test('stickyFirstColumn pins the first cell of every row to the left', () => {+ const c = stickyTableClasses({ stickyFirstColumn: true });+ expect(c.sticky).toBe(true);+ expect(c.container).toContain('overflow-auto');+ expect(c.table).toContain('[&_tr>*:first-child]:sticky');+ expect(c.table).toContain('[&_tr>*:first-child]:left-0');+ expect(c.table).not.toContain('[&_thead_th]:sticky');+ });++ test('with both, the top-left header cell sits above the other sticky cells', () => {+ const c = stickyTableClasses({ stickyHeader: true, stickyFirstColumn: true });+ expect(c.table).toContain('[&_thead_th:first-child]:z-20');+ });+});diff --git a/web/src/components/ui/table.tsx b/web/src/components/ui/table.tsxindex 722f7e4ae..bc8850537 100644--- a/web/src/components/ui/table.tsx+++ b/web/src/components/ui/table.tsx@@ -4,12 +4,62 @@ import * as React from 'react';import { cn } from '@/lib/utils';-function Table({ className, ...props }: React.ComponentProps<'table'>) {+interface TableProps extends React.ComponentProps<'table'> {+ /** Pin the header row while the rows scroll underneath it. */+ stickyHeader?: boolean;+ /** Pin the first column while the table scrolls sideways. */+ stickyFirstColumn?: boolean;+}++/**+ * Container and table classes for the sticky options. A sticky cell pins to its+ * nearest scrolling ancestor, so a sticky table scrolls inside its own+ * height-capped container: that keeps both the header (vertical) and the first+ * column (horizontal) pinned. Sticky cells need an opaque background so rows+ * don't show through, and the first column repaints the row hover tint itself.+ */+export function stickyTableClasses({+ stickyHeader = false,+ stickyFirstColumn = false,+}: Pick<TableProps, 'stickyHeader' | 'stickyFirstColumn'>) {+ const sticky = stickyHeader || stickyFirstColumn;+ return {+ sticky,+ container: sticky ? 'max-h-[calc(100dvh-12rem)] overflow-auto' : 'overflow-x-auto',+ table: cn(+ stickyHeader &&+ '[&_thead_th]:sticky [&_thead_th]:top-0 [&_thead_th]:z-10 [&_thead_th]:bg-card [&_thead_th]:shadow-[inset_0_-1px_0_var(--border)] data-[scrolled-y]:[&_thead_th]:shadow-[inset_0_-1px_0_var(--border),0_2px_4px_-2px_rgb(0_0_0/0.12)]',+ stickyFirstColumn &&+ '[&_tr>*:first-child]:sticky [&_tr>*:first-child]:left-0 [&_tr>*:first-child]:z-[5] [&_tr>*:first-child]:bg-card [&_tbody_tr:hover>*:first-child]:bg-[color-mix(in_oklab,var(--muted)_50%,var(--card))] data-[scrolled-x]:[&_tbody_tr>*:first-child]:shadow-[inset_-1px_0_0_var(--border)]',+ stickyHeader && stickyFirstColumn && '[&_thead_th:first-child]:z-20',+ ),+ };+}++function Table({ className, stickyHeader, stickyFirstColumn, ...props }: TableProps) {+ const classes = stickyTableClasses({ stickyHeader, stickyFirstColumn });+ // Only shows the edge shadows once the table has actually scrolled.+ const [scrolled, setScrolled] = React.useState({ y: false, x: false });+return (- <div data-slot="table-container" className="relative w-full overflow-x-auto">+ <div+ data-slot="table-container"+ className={cn('relative w-full', classes.container)}+ onScroll={+ classes.sticky+ ? (e) => {+ const y = e.currentTarget.scrollTop > 0;+ const x = e.currentTarget.scrollLeft > 0;+ setScrolled((s) => (s.y === y && s.x === x ? s : { y, x }));+ }+ : undefined+ }+ ><tabledata-slot="table"- className={cn('w-full caption-bottom text-sm', className)}+ data-scrolled-y={scrolled.y || undefined}+ data-scrolled-x={scrolled.x || undefined}+ className={cn('w-full caption-bottom text-sm', classes.table, className)}{...props}/></div>