Sprint Backlog
A sprint backlog you prioritize by dragging rows, with a capacity line that moves as you reorder, column order from a drag-and-drop view menu, handles that switch off while filtering, and move to top / bottom, status and remove actions.
Built only from Niko Table pieces and shadcn/ui components. Install it, then swap the sample data for your own.
Installation
pnpm dlx shadcn@latest add @niko-table/backlog-tablePreview
"use client"
import * as React from "react"import { DataTableRoot } from "@/components/niko-table/core/data-table-root"import { DataTable } from "@/components/niko-table/core/data-table"import { DataTableEmptyBody, DataTableHeader,} from "@/components/niko-table/core/data-table-structure"import { DataTableDndBody } from "@/components/niko-table/core/data-table-row-dnd-structure"import { useDataTable } from "@/components/niko-table/core/data-table-context"import { DataTableColumnHeader } from "@/components/niko-table/components/data-table-column-header"import { DataTableColumnTitle } from "@/components/niko-table/components/data-table-column-title"import { DataTableToolbarSection } from "@/components/niko-table/components/data-table-toolbar-section"import { DataTableSearchFilter } from "@/components/niko-table/components/data-table-search-filter"import { DataTableFacetedFilter } from "@/components/niko-table/components/data-table-faceted-filter"import { DataTableClearFilter } from "@/components/niko-table/components/data-table-clear-filter"import { DataTableViewDndMenu } from "@/components/niko-table/components/data-table-view-dnd-menu"import { DataTableRowDndProvider } from "@/components/niko-table/components/data-table-row-dnd"import { DataTableEmptyDescription, DataTableEmptyFilteredMessage, DataTableEmptyIcon, DataTableEmptyMessage, DataTableEmptyTitle,} from "@/components/niko-table/components/data-table-empty-state"import { DataTableRowMenuScope, RowMenuItem, RowMenuSeparator, RowMenuSub, RowMenuSubContent, RowMenuSubTrigger, useDataTableRow,} from "@/components/niko-table/components/data-table-row-menu"import { DataTableRowContextMenuSlot } from "@/components/niko-table/components/data-table-row-context-menu-slot"import type { DataTableColumnDef } from "@/components/niko-table/types"import { Button } from "@/components/niko-table/primitives/button"import { Progress } from "@/components/ui/progress"import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger,} from "@/components/niko-table/primitives/dropdown-menu"import { ListChecks, MoreHorizontal, SearchX } from "lucide-react"import { cn } from "@/lib/utils"import { CAPACITY, issues as sampleIssues, statusOptions, typeOptions, type Issue, type IssueStatus,} from "./backlog-data"import { belowTheLine } from "./backlog-format"import { AssigneeCell, EstimateCell, IssueCell, LabelsCell, LineContext, RankCell, ReorderHandle, StatusCell, TypeCell,} from "./backlog-cells"
type Actions = { moveTo: (issue: Issue, edge: "top" | "bottom") => void setStatus: (issue: Issue, status: IssueStatus) => void remove: (issue: Issue) => void}
/* * Row actions: one small piece per action, each reading its row from context. * `BacklogTable` composes them into ONE fragment that both the "⋯" dropdown * and the right-click menu render. */function MoveToTopItem({ moveTo }: Pick<Actions, "moveTo">) { const issue = useDataTableRow<Issue>() const { top } = React.useContext(LineContext) return ( <RowMenuItem disabled={issue.key === top} onClick={() => moveTo(issue, "top")} > Move to top </RowMenuItem> )}
function MoveToBottomItem({ moveTo }: Pick<Actions, "moveTo">) { const issue = useDataTableRow<Issue>() const { bottom } = React.useContext(LineContext) return ( <RowMenuItem disabled={issue.key === bottom} onClick={() => moveTo(issue, "bottom")} > Move to bottom </RowMenuItem> )}
function StatusSubmenu({ setStatus }: Pick<Actions, "setStatus">) { const issue = useDataTableRow<Issue>() return ( <RowMenuSub> <RowMenuSubTrigger>Status</RowMenuSubTrigger> <RowMenuSubContent> {statusOptions.map(option => ( <RowMenuItem key={option.value} disabled={option.value === issue.status} onClick={() => setStatus(issue, option.value as IssueStatus)} > {option.label} </RowMenuItem> ))} </RowMenuSubContent> </RowMenuSub> )}
function RemoveItem({ remove }: Pick<Actions, "remove">) { const issue = useDataTableRow<Issue>() return ( <RowMenuItem variant="destructive" onClick={() => remove(issue)}> Remove from sprint </RowMenuItem> )}
function columnHeader(title: string) { return ( <DataTableColumnHeader> <DataTableColumnTitle title={title} /> </DataTableColumnHeader> )}
function useIssueColumns(rowMenu: React.ReactNode) { return React.useMemo<DataTableColumnDef<Issue>[]>( () => [ { id: "drag-handle", size: 48, header: () => null, cell: ({ row }) => <ReorderHandle row={row} />, enableSorting: false, enableHiding: false, enableResizing: false, }, { id: "rank", size: 56, meta: { label: "Rank" }, header: () => columnHeader("#"), cell: ({ row }) => <RankCell row={row} />, enableSorting: false, enableHiding: false, }, { id: "issue", // Key and title, so search finds either. accessorFn: issue => `${issue.key} ${issue.title}`, size: 320, meta: { label: "Issue" }, header: () => columnHeader("Issue"), cell: ({ row }) => <IssueCell issue={row.original} />, enableSorting: false, enableHiding: false, }, { accessorKey: "type", size: 120, meta: { label: "Type", options: typeOptions }, header: () => columnHeader("Type"), enableColumnFilter: true, enableSorting: false, cell: ({ row }) => <TypeCell issue={row.original} />, }, { accessorKey: "estimate", size: 90, meta: { label: "Points" }, header: () => columnHeader("Pts"), enableSorting: false, cell: ({ row }) => <EstimateCell issue={row.original} />, }, { accessorKey: "assignee", size: 120, meta: { label: "Assignee" }, header: () => columnHeader("Assignee"), enableSorting: false, cell: ({ row }) => <AssigneeCell issue={row.original} />, }, { accessorKey: "status", size: 130, meta: { label: "Status", options: statusOptions }, header: () => columnHeader("Status"), enableColumnFilter: true, enableSorting: false, cell: ({ row }) => <StatusCell issue={row.original} />, }, { accessorKey: "labels", size: 190, meta: { label: "Labels" }, header: () => columnHeader("Labels"), enableSorting: false, cell: ({ row }) => <LabelsCell issue={row.original} />, }, { id: "actions", size: 56, enableSorting: false, enableHiding: false, cell: ({ row }) => ( <div className="flex justify-end"> <DropdownMenu> <DropdownMenuTrigger asChild> <Button variant="ghost" size="icon" className="size-8" aria-label={`Open actions for ${row.original.key}`} > <MoreHorizontal className="size-4" /> </Button> </DropdownMenuTrigger> <DropdownMenuContent align="end"> <DataTableRowMenuScope row={row.original} surface="dropdown"> {rowMenu} </DataTableRowMenuScope> </DropdownMenuContent> </DropdownMenu> </div> ), }, ], [rowMenu], )}
function BacklogHeader() { const { table } = useDataTable<Issue>() const { keys } = React.useContext(LineContext) const rows = table.getCoreRowModel().rows.map(row => row.original) const total = rows.reduce((sum, issue) => sum + issue.estimate, 0) const done = rows .filter(issue => issue.status === "done") .reduce((sum, issue) => sum + issue.estimate, 0) const committed = rows .filter(issue => !keys.has(issue.key)) .reduce((sum, issue) => sum + issue.estimate, 0) const below = keys.size return ( <div className="flex flex-col gap-3"> <div className="flex flex-col gap-0.5"> <h2 className="text-base font-semibold">Sprint backlog</h2> <p className="text-sm text-muted-foreground"> {rows.length} {rows.length === 1 ? "issue" : "issues"} · {total}{" "} points · {done} points done </p> </div> <div className="flex flex-col gap-1.5"> <div className="flex flex-wrap items-center justify-between gap-2 text-sm"> <span> <span className="font-medium tabular-nums">{committed}</span> of{" "} {CAPACITY} points fit this sprint </span> <span className={cn("text-muted-foreground", below > 0 && "text-warning")} > {below} below the line </span> </div> <Progress value={Math.min(100, (committed / CAPACITY) * 100)} aria-label={`${committed} of ${CAPACITY} points fit this sprint`} // The indicator is the only direct child, so no slot name is needed. className={cn( "h-1.5 bg-muted", committed > CAPACITY && "[&>*]:bg-warning", )} /> </div> </div> )}
const defaultColumnOrder = [ "drag-handle", "rank", "issue", "type", "estimate", "assignee", "status", "labels", "actions",]
export default function BacklogTable() { const [issues, setIssues] = React.useState(sampleIssues) const [columnOrder, setColumnOrder] = React.useState(defaultColumnOrder) const [lastAction, setLastAction] = React.useState("")
// Mirror of the rows so stable callbacks can read the latest order. const issuesRef = React.useRef(issues) React.useEffect(() => { issuesRef.current = issues }, [issues])
const line = React.useMemo( () => ({ ...belowTheLine(issues), top: issues[0]?.key ?? null, bottom: issues[issues.length - 1]?.key ?? null, }), [issues], )
const reorder = React.useCallback( (next: Issue[], move: { activeId: string | number }) => { const key = String(move.activeId) setIssues(next) setLastAction( `${key} moved to position ${next.findIndex(issue => issue.key === key) + 1}`, ) }, [], )
const actions = React.useMemo<Actions>( () => ({ moveTo: (issue, edge) => { setIssues(rows => { const rest = rows.filter(row => row.key !== issue.key) return edge === "top" ? [issue, ...rest] : [...rest, issue] }) setLastAction( `${issue.key} moved to position ${ edge === "top" ? 1 : issuesRef.current.length }`, ) }, setStatus: (issue, status) => { setIssues(rows => rows.map(row => (row.key === issue.key ? { ...row, status } : row)), ) setLastAction(`${issue.key} is now ${status.replace("-", " ")}`) }, remove: issue => { setIssues(rows => rows.filter(row => row.key !== issue.key)) setLastAction(`${issue.key} removed from the sprint`) }, }), [], )
// The row actions, composed ONCE and mounted in both the "⋯" dropdown and // the right-click menu. const rowMenu = React.useMemo( () => ( <> <MoveToTopItem moveTo={actions.moveTo} /> <MoveToBottomItem moveTo={actions.moveTo} /> <StatusSubmenu setStatus={actions.setStatus} /> <RowMenuSeparator /> <RemoveItem remove={actions.remove} /> </> ), [actions], ) const columns = useIssueColumns(rowMenu)
return ( <div className="w-full rounded-xl border bg-card p-4 text-card-foreground shadow-sm"> <LineContext.Provider value={line}> <DataTableRoot data={issues} columns={columns} getRowId={issue => issue.key} state={{ columnOrder }} onColumnOrderChange={setColumnOrder} > <div className="flex flex-col gap-4"> <BacklogHeader /> <DataTableToolbarSection className="flex-wrap px-0"> <DataTableSearchFilter placeholder="Search issues..." className="min-w-48 flex-none sm:w-64" /> <DataTableFacetedFilter accessorKey="type" multiple /> <DataTableFacetedFilter accessorKey="status" multiple /> <DataTableClearFilter /> <div className="ml-auto"> <DataTableViewDndMenu columnOrder={columnOrder} onColumnOrderChange={setColumnOrder} onReset={() => setColumnOrder(defaultColumnOrder)} /> </div> </DataTableToolbarSection> {/* Manual order is the order, so there is no sorting here. */} <DataTableRowDndProvider data={issues} onReorder={reorder}> <DataTable> <DataTableHeader /> <DataTableDndBody> <DataTableRowContextMenuSlot> {rowMenu} </DataTableRowContextMenuSlot> <DataTableEmptyBody> <DataTableEmptyMessage> <DataTableEmptyIcon> <ListChecks className="size-12" /> </DataTableEmptyIcon> <DataTableEmptyTitle> The sprint is empty </DataTableEmptyTitle> <DataTableEmptyDescription> Every issue was removed from the sprint. </DataTableEmptyDescription> </DataTableEmptyMessage> <DataTableEmptyFilteredMessage> <DataTableEmptyIcon> <SearchX className="size-12" /> </DataTableEmptyIcon> <DataTableEmptyTitle> No matching issues </DataTableEmptyTitle> <DataTableEmptyDescription> Try another search, or clear the filters. </DataTableEmptyDescription> </DataTableEmptyFilteredMessage> </DataTableEmptyBody> </DataTableDndBody> </DataTable> </DataTableRowDndProvider> <p className="text-xs text-muted-foreground" aria-live="polite"> {lastAction || "Drag the handle, or focus it and press Space, to reorder."} </p> </div> </DataTableRoot> </LineContext.Provider> </div> )}"use client"
import * as React from "react"import { useDataTable } from "@/components/niko-table/core/data-table-context"import { DataTableRowDragHandle } from "@/components/niko-table/components/data-table-row-dnd"import type { DataTableRow } from "@/components/niko-table/types"import { Avatar, AvatarFallback } from "@/components/ui/avatar"import { Badge } from "@/components/ui/badge"import { Button } from "@/components/niko-table/primitives/button"import { Bug, GripVertical, Sparkles, Wrench } from "lucide-react"import { cn } from "@/lib/utils"import type { Issue, IssueStatus, IssueType } from "./backlog-data"import { initials, statusLabel, typeLabel } from "./backlog-format"
/** Which issues sit below the sprint line, for the current order. */export const LineContext = React.createContext<{ keys: Set<string> first: string | null /** Keys of the first and last issue in the full list. */ top: string | null bottom: string | null}>({ keys: new Set(), first: null, top: null, bottom: null })
/** Mutes the content of a row that sits below the line. */export function Dim({ issue, className, children,}: { issue: Issue className?: string children: React.ReactNode}) { const { keys } = React.useContext(LineContext) return ( <div className={cn(keys.has(issue.key) && "opacity-60", className)}> {children} </div> )}
/** Dragging is only safe on the full list, so filters switch the handle off. */export function ReorderHandle({ row }: { row: DataTableRow<Issue> }) { const { table } = useDataTable<Issue>() const filtering = Boolean(table.state.globalFilter) || table.state.columnFilters.length > 0 if (!filtering) return <DataTableRowDragHandle rowId={row.id} /> const reason = "Clear the search and filters to reorder" return ( <span title={reason}> <Button variant="ghost" size="icon" className="size-8" disabled aria-label={`Reordering ${row.original.key} is off. ${reason}`} > <GripVertical className="size-4 text-muted-foreground" /> </Button> </span> )}
export function RankCell({ row }: { row: DataTableRow<Issue> }) { const { keys } = React.useContext(LineContext) return ( <Dim issue={row.original} className="text-muted-foreground tabular-nums"> {row.index + 1} {keys.has(row.original.key) && ( <span className="sr-only">, below the line</span> )} </Dim> )}
export function IssueCell({ issue }: { issue: Issue }) { const { first } = React.useContext(LineContext) return ( <div className="flex min-w-0 flex-col gap-0.5"> {first === issue.key && ( <span className="text-xs font-medium tracking-wide text-warning uppercase"> Below the line </span> )} <Dim issue={issue} className="flex min-w-0 flex-col"> <span className="font-mono text-xs text-muted-foreground"> {issue.key} </span> <span className="truncate font-medium">{issue.title}</span> </Dim> </div> )}
const typeIcon: Record<IssueType, React.ReactNode> = { feature: <Sparkles className="size-4 text-primary" aria-hidden="true" />, bug: <Bug className="size-4 text-destructive" aria-hidden="true" />, chore: <Wrench className="size-4 text-muted-foreground" aria-hidden="true" />,}
export function TypeCell({ issue }: { issue: Issue }) { return ( <Dim issue={issue} className="flex items-center gap-2"> {typeIcon[issue.type]} {typeLabel[issue.type]} </Dim> )}
export function EstimateCell({ issue }: { issue: Issue }) { return ( <Dim issue={issue} className="text-right tabular-nums"> {issue.estimate} <span className="sr-only"> points</span> </Dim> )}
export function AssigneeCell({ issue }: { issue: Issue }) { return ( <Dim issue={issue}> {issue.assignee ? ( <Avatar className="size-7" title={issue.assignee}> <AvatarFallback className="text-xs"> {initials(issue.assignee)} </AvatarFallback> <span className="sr-only">{issue.assignee}</span> </Avatar> ) : ( <span className="text-sm text-muted-foreground italic">Unassigned</span> )} </Dim> )}
const statusStyle: Record<IssueStatus, string> = { todo: "text-muted-foreground", "in-progress": "border-primary text-primary", "in-review": "border-warning text-warning", done: "border-success text-success",}
export function StatusCell({ issue }: { issue: Issue }) { return ( <Dim issue={issue}> <Badge variant="outline" className={statusStyle[issue.status]}> {statusLabel[issue.status]} </Badge> </Dim> )}
export function LabelsCell({ issue }: { issue: Issue }) { return ( <Dim issue={issue} className="flex gap-1"> {issue.labels.map(label => ( <Badge key={label} variant="secondary"> {label} </Badge> ))} </Dim> )}import { CAPACITY, type Issue, type IssueStatus, type IssueType,} from "./backlog-data"
/** * Keys of the issues that do not fit in the sprint, given the current order. * An issue is below the line once the points up to and including it pass the * capacity. The first such key is returned too, so the divider can sit there. */export function belowTheLine(issues: Issue[], capacity = CAPACITY) { let total = 0 const keys = new Set<string>() let first: string | null = null for (const issue of issues) { total += issue.estimate if (total > capacity) { keys.add(issue.key) first ??= issue.key } } return { keys, first }}
export function initials(name: string) { return name .split(" ") .filter(Boolean) .map(part => part[0]?.toUpperCase()) .slice(0, 2) .join("")}
export const typeLabel: Record<IssueType, string> = { feature: "Feature", bug: "Bug", chore: "Chore",}
export const statusLabel: Record<IssueStatus, string> = { todo: "To do", "in-progress": "In progress", "in-review": "In review", done: "Done",}export type IssueType = "feature" | "bug" | "chore"export type IssueStatus = "todo" | "in-progress" | "in-review" | "done"
export type Issue = { /** Also the table row id. */ key: string title: string type: IssueType /** Story points. */ estimate: number /** Null while unassigned. */ assignee: string | null status: IssueStatus labels: string[]}
/** Points the team can take on this sprint. */export const CAPACITY = 40
export const typeOptions = [ { label: "Feature", value: "feature" }, { label: "Bug", value: "bug" }, { label: "Chore", value: "chore" },]
export const statusOptions = [ { label: "To do", value: "todo" }, { label: "In progress", value: "in-progress" }, { label: "In review", value: "in-review" }, { label: "Done", value: "done" },]
const labelPool = ["frontend", "backend", "api", "design", "infra"]
/** * Sample data, generated rather than hand-written. A seeded PRNG (mulberry32) * keeps it random-looking but identical on every render. Swap `issues` for * your own rows, listed in priority order. */function seededRandom(seed: number) { let a = seed return () => { a = (a + 0x6d2b79f5) | 0 let t = Math.imul(a ^ (a >>> 15), 1 | a) t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t return ((t ^ (t >>> 14)) >>> 0) / 4294967296 }}
const people = [ "Alma Ferreira", "Ben Okafor", "Carmen Lam", "Dmitri Bauer", "Esi Mensah", "Felix Park",]
// Fixed titles so each reads like real work; order is the starting priority.const titles: [IssueType, string][] = [ ["bug", "Cart total ignores discount codes"], ["feature", "Saved filters on the reports page"], ["chore", "Upgrade the build runner image"], ["feature", "Export a report as CSV"], ["bug", "Date picker closes on first click"], ["feature", "Email digest for weekly activity"], ["bug", "Search returns stale results"], ["chore", "Remove unused feature flags"], ["feature", "Bulk archive for old projects"], ["feature", "Dark mode for the settings page"], ["bug", "Avatar upload fails on large files"], ["chore", "Add retries to the webhook worker"], ["feature", "Keyboard shortcuts for navigation"], ["bug", "Wrong timezone in activity feed"], ["feature", "Invite links that expire"], ["chore", "Move image resizing to the queue"], ["feature", "Comment threads on tasks"], ["chore", "Write the on-call runbook"],]
// Fixed positions so every status is guaranteed; the rest mostly wait.const statuses: IssueStatus[] = [ "done", "done", "in-review", "in-progress", "in-progress", "in-review", "in-progress", "todo", "todo", "todo", "todo", "todo", "todo", "todo", "todo", "todo", "todo", "todo",]
function generateIssues(seed: number): Issue[] { const random = seededRandom(seed) const estimates = [1, 2, 3, 3, 5, 5, 8] return titles.map(([type, title], i) => { const status = statuses[i] ?? "todo" const labelCount = Math.floor(random() * 3) const labels = [...labelPool] .sort(() => random() - 0.5) .slice(0, labelCount) .sort() const assigneeRoll = random() return { key: `ENG-${412 + i * 3}`, title, type, estimate: estimates[Math.floor(random() * estimates.length)] ?? 3, // A few unassigned, never one already in progress. assignee: status === "todo" && assigneeRoll < 0.3 ? null : (people[Math.floor(random() * people.length)] ?? null), status, labels, } })}
export const issues = generateIssues(2291)Usage
The files land in components/backlog-table/. Render the block anywhere:
import SprintBacklog from "@/components/backlog-table/backlog-table"
export default function Page() { return <SprintBacklog />}Then replace the generated rows in backlog-data.ts with your own data, or load it from your API and pass it in.