The list page with a Display menu
The list's display option
The display option of docs/screen-list.md: copy the file below whole in place of that recipe's file (same path, same frame). It is written short: it keeps the search and the row's menu, and leaves out the status filter, the stepper and the peek — put back any of them exactly as docs/screen-list.md writes them. It draws ListPage arrangement="filtered"; the chooser (agent/layout-chooser.md) names the others, the same slots.
display: a Display menu that reshapes the table
A Display button at the heading's end (secondaryActions) opens a DropdownMenu of four groups, each changing the table as it is picked, the menu staying open (onSelect keeps it): Columns, a DropdownMenuCheckboxItem per column that can go (the row's name never does); Group by, a DropdownMenuRadioGroup (none, status, priority, assignee), each group a TableGroup whose value names the key too, so each grouping keeps its own folds; Sort by, another (priority, title, estimate), ordering the rows inside each group; Density, a third (comfortable, compact), the Table's density.
`tsx display // src/screens/issues.tsx: the list page with a Display menu import { type ReactNode, useState } from 'react'; import { ListPage } from '@/components/goop/patterns/list-page'; import { Button, ButtonIcon, ButtonLabel } from '@/components/ui/goop/button'; import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/goop/dropdown-menu'; import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from '@/components/ui/goop/empty'; import { IconButton, IconButtonIcon } from '@/components/ui/goop/icon-button'; import { PageHeader, PageHeaderTitle } from '@/components/ui/goop/page-header'; import { PriorityMark } from '@/components/ui/goop/priority-mark'; import { SearchInput } from '@/components/ui/goop/search-input'; import { StatusMark } from '@/components/ui/goop/status-mark'; import { Table, TableBody, type TableColumn, TableGroup, TableHead, TableHeader, TableRow, } from '@/components/ui/goop/table'; import { TableCell, TableCellLabel, TableCellPerson } from '@/components/ui/goop/table-cell'; import { ScreenFrame, ScreenTopBar } from './frame';
// ---- the sample data: swap it for yours type Status = 'todo' | 'in-progress' | 'in-review' | 'done'; const STATUS_WORDS: Record<Status, string> = { todo: 'To do', 'in-progress': 'In progress', 'in-review': 'In review', done: 'Done', }; const STATUSES = Object.keys(STATUS_WORDS) as Status[]; type Priority = 'urgent' | 'high' | 'medium' | 'low'; const PRIORITY_WORDS: Record<Priority, string> = { urgent: 'Urgent', high: 'High', medium: 'Medium', low: 'Low' }; const PRIORITIES = Object.keys(PRIORITY_WORDS) as Priority[]; interface Issue { id: string; title: string; status: Status; priority: Priority; assignee: string; /** Points; null for not estimated. */ estimate: number | null; } const ME = 'Teodora Valk'; const ISSUES: Issue[] = [ { id: 'FW-121', title: 'Tags vanish on sync', status: 'in-review', priority: 'urgent', assignee: 'Bilal Rashed', estimate: 3, }, { id: 'FW-117', title: 'Recruit 8 participants', status: 'todo', priority: 'high', assignee: 'Dagny Holm', estimate: 5, }, { id: 'FW-110', title: 'Help page on tags', status: 'in-progress', priority: 'low', assignee: 'Teodora Valk', estimate: 1, }, { id: 'FW-108', title: 'Waveform stutters', status: 'done', priority: 'medium', assignee: 'Ngozi Ilori', estimate: 2, }, ];
// ---- what the Display menu offers type Column = 'status' | 'priority' | 'assignee' | 'estimate'; const COLUMNS: Record<Column, { name: string; track: string | TableColumn }> = { status: { name: 'Status', track: '128px' }, priority: { name: 'Priority', track: { track: '96px', hide: 'narrow' } }, assignee: { name: 'Assignee', track: { track: '176px', hide: 'narrow' } }, estimate: { name: 'Estimate', track: { track: '96px', hide: 'narrow' } }, }; const COLUMN_KEYS = Object.keys(COLUMNS) as Column[]; type GroupBy = 'none' | 'status' | 'priority' | 'assignee'; const GROUP_WORDS: Record<GroupBy, string> = { none: 'No grouping', status: 'Status', priority: 'Priority', assignee: 'Assignee', }; type SortBy = 'priority' | 'title' | 'estimate'; const SORT_WORDS: Record<SortBy, string> = { priority: 'Priority', title: 'Title', estimate: 'Estimate' }; type Density = 'comfortable' | 'compact'; const DENSITY_WORDS: Record<Density, string> = { comfortable: 'Comfortable', compact: 'Compact' };
/** The rows in the order picked: the most urgent first, by title, or the largest estimate first. */ function sorted(issues: Issue[], by: SortBy): Issue[] { return [...issues].sort((a, b) => by === 'title' ? a.title.localeCompare(b.title) : by === 'estimate' ? (b.estimate ?? -1) - (a.estimate ?? -1) : PRIORITIES.indexOf(a.priority) - PRIORITIES.indexOf(b.priority), ); }
/** The groups of a grouping, in its key's own order, each with its rows; empty groups left out. */ function groupsOf(issues: Issue[], by: Exclude<GroupBy, 'none'>) { const keys: string[] = by === 'status' ? STATUSES : by === 'priority' ? PRIORITIES : [...new Set(issues.map((issue) => issue.assignee))].sort(); return keys.flatMap((key) => { const rows = issues.filter((issue) => issue[by] === key); if (rows.length === 0) return []; const title = by === 'status' ? STATUS_WORDS[key as Status] : by === 'priority' ? PRIORITY_WORDS[key as Priority] : key; const mark: ReactNode = by === 'status' ? ( <StatusMark status={key as Status} /> ) : by === 'priority' ? ( <PriorityMark priority={key as Priority} /> ) : null; return [{ key, title, mark, rows }]; }); }
/** A menu choice that changes the table at once and leaves the menu open for the next. */ const keepOpen = (event: Event) => event.preventDefault();
export default function IssuesScreen() { const [issues, setIssues] = useState(ISSUES); const [query, setQuery] = useState(''); const [shown, setShown] = useState<Column[]>(COLUMN_KEYS); const [groupBy, setGroupBy] = useState<GroupBy>('status'); const [sortBy, setSortBy] = useState<SortBy>('priority'); const [density, setDensity] = useState<Density>('comfortable'); const found = sorted( issues.filter((issue) => ${issue.id} ${issue.title}.toLowerCase().includes(query.trim().toLowerCase())), sortBy, ); const change = (id: string, next: Partial<Issue>) => setIssues((all) => all.map((issue) => (issue.id === id ? { ...issue, ...next } : issue))); const show = (column: Column, on: boolean) => setShown((now) => COLUMN_KEYS.filter((key) => (key === column ? on : now.includes(key)))); const cellOf = (column: Column, issue: Issue) => column === 'status' ? ( <TableCell key={column}> <StatusMark status={issue.status} label={STATUS_WORDS[issue.status]} /> </TableCell> ) : column === 'priority' ? ( <TableCell key={column}> <PriorityMark priority={issue.priority} label /> </TableCell> ) : column === 'assignee' ? ( <TableCell key={column}> <TableCellPerson name={issue.assignee} /> </TableCell> ) : ( <TableCell key={column} numeric> <TableCellLabel>{issue.estimate ?? '–'}</TableCellLabel> </TableCell> ); const rowOf = (issue: Issue) => ( <TableRow key={issue.id}> <TableCell> <TableCellLabel primary>{issue.title}</TableCellLabel> </TableCell> {shown.map((column) => cellOf(column, issue))} <TableCell align="end"> <DropdownMenu> <DropdownMenuTrigger asChild> <IconButton variant="ghost" size="sm" aria-label={Actions for ${issue.id}}> <IconButtonIcon icon="dots" /> </IconButton> </DropdownMenuTrigger> <DropdownMenuContent align="end" aria-label={Actions for ${issue.id}}> <DropdownMenuItem disabled={issue.assignee === ME} onSelect={() => change(issue.id, { assignee: ME })}> Assign to me </DropdownMenuItem> <DropdownMenuItem disabled={issue.status === 'done'} onSelect={() => change(issue.id, { status: 'done' })}> Mark as done </DropdownMenuItem> </DropdownMenuContent> </DropdownMenu> </TableCell> </TableRow> ); return ( <ScreenFrame current="/issues"> <ListPage arrangement="filtered" header={<ScreenTopBar title="Issues" />} heading={ <PageHeader> <PageHeaderTitle asChild> <h1>Issues</h1> </PageHeaderTitle> </PageHeader> } secondaryActions={ <DropdownMenu> <DropdownMenuTrigger asChild> <Button variant="outline"> <ButtonIcon icon="adjustments-horizontal" /> <ButtonLabel>Display</ButtonLabel> </Button> </DropdownMenuTrigger> <DropdownMenuContent align="end" aria-label="Display"> <DropdownMenuGroup> <DropdownMenuLabel>Columns</DropdownMenuLabel> {COLUMN_KEYS.map((column) => ( <DropdownMenuCheckboxItem key={column} checked={shown.includes(column)} onCheckedChange={(on) => show(column, on === true)} onSelect={keepOpen} > {COLUMNS[column].name} </DropdownMenuCheckboxItem> ))} </DropdownMenuGroup> <DropdownMenuSeparator /> <DropdownMenuGroup> <DropdownMenuLabel>Group by</DropdownMenuLabel> <DropdownMenuRadioGroup value={groupBy} onValueChange={(value) => setGroupBy(value as GroupBy)}> {(Object.keys(GROUP_WORDS) as GroupBy[]).map((value) => ( <DropdownMenuRadioItem key={value} value={value} onSelect={keepOpen}> {GROUP_WORDS[value]} </DropdownMenuRadioItem> ))} </DropdownMenuRadioGroup> </DropdownMenuGroup> <DropdownMenuSeparator /> <DropdownMenuGroup> <DropdownMenuLabel>Sort by</DropdownMenuLabel> <DropdownMenuRadioGroup value={sortBy} onValueChange={(value) => setSortBy(value as SortBy)}> {(Object.keys(SORT_WORDS) as SortBy[]).map((value) => ( <DropdownMenuRadioItem key={value} value={value} onSelect={keepOpen}> {SORT_WORDS[value]} </DropdownMenuRadioItem> ))} </DropdownMenuRadioGroup> </DropdownMenuGroup> <DropdownMenuSeparator /> <DropdownMenuGroup> <DropdownMenuLabel>Density</DropdownMenuLabel> <DropdownMenuRadioGroup value={density} onValueChange={(value) => setDensity(value as Density)}> {(Object.keys(DENSITY_WORDS) as Density[]).map((value) => ( <DropdownMenuRadioItem key={value} value={value} onSelect={keepOpen}> {DENSITY_WORDS[value]} </DropdownMenuRadioItem> ))} </DropdownMenuRadioGroup> </DropdownMenuGroup> </DropdownMenuContent> </DropdownMenu> } filters={ <SearchInput label="Search issues" placeholder="Search issues" value={query} onChange={(event) => setQuery(event.currentTarget.value)} /> } collection={ found.length === 0 ? ( <Empty variant="outline"> <EmptyHeader> <EmptyTitle>No issue matches the search.</EmptyTitle> <EmptyDescription>Try other words.</EmptyDescription> </EmptyHeader> </Empty> ) : ( <Table aria-label="Issues" gutter="page" density={density} columns={['minmax(160px, 1fr)', ...shown.map((column) => COLUMNS[column].track), '40px']} > <TableHeader> <TableRow> <TableHead> <TableCellLabel>Issue</TableCellLabel> </TableHead> {shown.map((column) => ( <TableHead key={column} numeric={column === 'estimate'}> <TableCellLabel>{COLUMNS[column].name}</TableCellLabel> </TableHead> ))} <TableHead align="end" aria-label="Actions" /> </TableRow> </TableHeader> <TableBody> {groupBy === 'none' ? found.map(rowOf) : groupsOf(found, groupBy).map((group) => ( <TableGroup key={${groupBy}:${group.key}} value={${groupBy}:${group.key}} title={group.title} count={group.rows.length} mark={group.mark} > {group.rows.map(rowOf)} </TableGroup> ))} </TableBody> </Table> ) } /> </ScreenFrame> ); }