Skip to content

feat: Dataview.Timeline component#844

Open
rohanchkrabrty wants to merge 5 commits into
mainfrom
worktree-timeline
Open

feat: Dataview.Timeline component#844
rohanchkrabrty wants to merge 5 commits into
mainfrom
worktree-timeline

Conversation

@rohanchkrabrty

@rohanchkrabrty rohanchkrabrty commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds DataView.Timeline, a renderer that positions the shared DataView row model as cards on a continuous, horizontally scrollable time axis — the card interior is fully consumer-owned via renderCard(row, context), while the Timeline owns the time scale, lane packing, sticky two-tier axis (ticks, month/year bands, today + custom markers, gridlines), and native x/y scrolling with drag-to-pan, momentum glide, and a snapped hover cursor.
  • Supports range-window data loading: explicit range for a stable coordinate space, onVisibleRangeChange (rAF-throttled, deduped by ms window), and time-anchored scrolling so the content never jumps when the domain shifts; imperative navigation ships via actionsRef (scrollTo, getVisibleRange).
  • Performance: memoized card wrapper so per-frame cursor/viewport state never re-renders card interiors, and binary-search horizontal culling behind virtualized.
  • Fixes from review: scroll position is restored when a gated view is re-activated, and point-marker lanes pack with estimatedPointWidth so content-sized cards don't overlap; rowHeight is renamed to estimatedRowHeight to match DataView.List.
  • Includes docs (guide + props tables), playground demos, an order-desk example page, and 52 unit tests covering geometry, axis, panning, culling, and the imperative handle.

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Jul 20, 2026 8:06pm

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a reusable DataView.Timeline component with typed configuration, time-scale and lane-packing utilities, axis rendering, virtualization, panning, cursor tracking, momentum scrolling, and visible-range callbacks. Exposes the API through DataView exports, adds comprehensive timeline tests, and introduces demos, documentation, and an order-management example with incremental loading, synchronized timeline/list views, filtering, status indicators, and order details dialogs.

Sequence Diagram(s)

sequenceDiagram
  participant Page
  participant DataViewTimeline
  participant OrdersAPI
  participant DetailsDialog
  Page->>DataViewTimeline: Render orders for visible range
  DataViewTimeline->>Page: Emit visible date bounds
  Page->>OrdersAPI: Fetch missing month buckets
  OrdersAPI-->>Page: Return generated orders
  Page->>DataViewTimeline: Render accumulated orders
  DataViewTimeline->>DetailsDialog: Open selected order
Loading

Suggested reviewers: paansinghcoder, rohilsurana, shreyag02

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided, so there is no meaningful description to evaluate. Add a brief description of the timeline component, its API, and the main UI/docs changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: adding the DataView.Timeline component.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rohanchkrabrty
rohanchkrabrty marked this pull request as ready for review July 14, 2026 09:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (1)
apps/www/src/app/examples/timeline/page.tsx (1)

531-562: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Guard loadWindow's async callback against unmount.

fetchOrdersApi(...).then(...) calls setOrders/setIsLoading unconditionally. If the page unmounts while the simulated 500ms latency is in flight, these fire post-unmount. Harmless in React 18+ (silently no-ops), but worth the idiomatic guard since this page is a public usage example other engineers will copy.

♻️ Suggested guard
+  const mountedRef = useRef(true);
+  useEffect(() => () => { mountedRef.current = false; }, []);
+
   const loadWindow = useCallback((fromMs: number, toMs: number) => {
     const clampedFrom = Math.max(fromMs, Date.parse(RANGE[0]));
     const clampedTo = Math.min(toMs, Date.parse(RANGE[1]));
     if (clampedFrom >= clampedTo) return;
     const missing = monthKeysBetween(clampedFrom, clampedTo).filter(
       key => !requestedRef.current.has(key)
     );
     if (missing.length === 0) return;
     for (const key of missing) requestedRef.current.add(key);
     inflightRef.current += 1;
     setIsLoading(true);
     fetchOrdersApi(missing).then(rows => {
+      if (!mountedRef.current) return;
       setOrders(prev => [...prev, ...rows]);
       inflightRef.current -= 1;
       if (inflightRef.current === 0) setIsLoading(false);
     });
   }, []);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/www/src/app/examples/timeline/page.tsx` around lines 531 - 562, Guard
the async callback in loadWindow with a mounted-state ref that is set false
during component cleanup, and skip setOrders/setIsLoading after unmount while
preserving inflight bookkeeping as appropriate. Apply the guard specifically to
the fetchOrdersApi(...).then(...) path and initialize the ref within Page.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/raystack/components/data-view/__tests__/timeline.test.tsx`:
- Around line 654-667: Update the `fires onVisibleRangeChange with the visible
time window` test to assert that `to.getTime()` also equals the Jan 1, 2025
timestamp, matching the existing comment that both viewport edges resolve to t0;
leave the existing `from` assertion unchanged.

In `@packages/raystack/components/data-view/components/timeline.tsx`:
- Around line 275-287: The lane-packing input in the useMemo block must not
treat auto-width point cards as MIN_RENDER_WIDTH intervals when endField is
absent. Provide measurable fixed-width geometry for point cards or constrain
their wrapper before calling packLanes, ensuring packed items cannot overlap
later cards on the same lane.
- Around line 567-573: Update the visible-range useEffect callback to first
verify that the timeline is the active view before invoking
onVisibleRangeChange. Preserve the existing viewport and callback guards and
date-range calculation, but prevent retained viewport changes from triggering
callbacks while the timeline is hidden.
- Around line 175-186: Make the initial day anchor deterministic across SSR and
hydration: update todayTime’s today === true path and the fallback anchor below
to use a fixed server snapshot or defer timezone-dependent date calculation
until after hydration. Preserve the existing today === false behavior and
explicit today timestamp handling.
- Around line 752-765: The timeline card wrapper in the render path around
renderCard must be keyboard-activatable whenever onRowClick is provided. Add
appropriate focusability and Enter/Space key handling that invokes onRowClick
with item.row.original, while preserving non-clickable behavior and ensuring
nested controls remain usable.
- Around line 135-142: Update the row extraction in the timeline component to
use rowModel.flatRows instead of rowModel.rows before filtering leaf rows.
Preserve the existing subRows-based filter so group headers remain excluded
while nested leaf rows are included.

---

Nitpick comments:
In `@apps/www/src/app/examples/timeline/page.tsx`:
- Around line 531-562: Guard the async callback in loadWindow with a
mounted-state ref that is set false during component cleanup, and skip
setOrders/setIsLoading after unmount while preserving inflight bookkeeping as
appropriate. Apply the guard specifically to the fetchOrdersApi(...).then(...)
path and initialize the ref within Page.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8fb8ac3a-c71b-4a24-927b-7cd65bf0eab9

📥 Commits

Reviewing files that changed from the base of the PR and between 75c5cc1 and 35a0c24.

📒 Files selected for processing (10)
  • apps/www/src/app/examples/timeline/page.tsx
  • packages/raystack/components/data-view/__tests__/timeline.test.tsx
  • packages/raystack/components/data-view/components/timeline.tsx
  • packages/raystack/components/data-view/data-view.module.css
  • packages/raystack/components/data-view/data-view.tsx
  • packages/raystack/components/data-view/data-view.types.tsx
  • packages/raystack/components/data-view/index.ts
  • packages/raystack/components/data-view/utils/pack-lanes.tsx
  • packages/raystack/components/data-view/utils/time-scale.tsx
  • packages/raystack/index.tsx

Comment on lines +654 to +667
it('fires onVisibleRangeChange with the visible time window', async () => {
const onVisibleRangeChange = vi.fn();
renderTimeline({ onVisibleRangeChange });
await act(async () => {
await new Promise(resolve => setTimeout(resolve, 0));
});
expect(onVisibleRangeChange).toHaveBeenCalled();
const calls = onVisibleRangeChange.mock.calls;
const [from, to] = calls[calls.length - 1][0];
expect(from).toBeInstanceOf(Date);
expect(to).toBeInstanceOf(Date);
// jsdom viewport is 0-wide at scrollLeft 0 → both edges sit at t0 (Jan 1).
expect(from.getTime()).toBe(dayjs('2025-01-01').valueOf());
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert to as well, per the test's own comment.

The comment states "both edges sit at t0 (Jan 1)" but only from.getTime() is checked; to.getTime() is left unverified despite being just as cheap to assert.

✅ Suggested addition
     expect(from.getTime()).toBe(dayjs('2025-01-01').valueOf());
+    expect(to.getTime()).toBe(dayjs('2025-01-01').valueOf());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('fires onVisibleRangeChange with the visible time window', async () => {
const onVisibleRangeChange = vi.fn();
renderTimeline({ onVisibleRangeChange });
await act(async () => {
await new Promise(resolve => setTimeout(resolve, 0));
});
expect(onVisibleRangeChange).toHaveBeenCalled();
const calls = onVisibleRangeChange.mock.calls;
const [from, to] = calls[calls.length - 1][0];
expect(from).toBeInstanceOf(Date);
expect(to).toBeInstanceOf(Date);
// jsdom viewport is 0-wide at scrollLeft 0 → both edges sit at t0 (Jan 1).
expect(from.getTime()).toBe(dayjs('2025-01-01').valueOf());
});
it('fires onVisibleRangeChange with the visible time window', async () => {
const onVisibleRangeChange = vi.fn();
renderTimeline({ onVisibleRangeChange });
await act(async () => {
await new Promise(resolve => setTimeout(resolve, 0));
});
expect(onVisibleRangeChange).toHaveBeenCalled();
const calls = onVisibleRangeChange.mock.calls;
const [from, to] = calls[calls.length - 1][0];
expect(from).toBeInstanceOf(Date);
expect(to).toBeInstanceOf(Date);
// jsdom viewport is 0-wide at scrollLeft 0 → both edges sit at t0 (Jan 1).
expect(from.getTime()).toBe(dayjs('2025-01-01').valueOf());
expect(to.getTime()).toBe(dayjs('2025-01-01').valueOf());
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/raystack/components/data-view/__tests__/timeline.test.tsx` around
lines 654 - 667, Update the `fires onVisibleRangeChange with the visible time
window` test to assert that `to.getTime()` also equals the Jan 1, 2025
timestamp, matching the existing comment that both viewport edges resolve to t0;
leave the existing `from` assertion unchanged.

Comment on lines +135 to +142
const rowModel = table?.getRowModel();
const { rows = [] } = rowModel || {};

// Timeline bypasses group headers (RFC §Grouping) — position leaf rows only.
const leafRows = useMemo(
() => rows.filter(row => !(row.subRows && row.subRows.length > 0)),
[rows]
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the target file and inspect the relevant section.
git ls-files 'packages/raystack/components/data-view/components/timeline.tsx'
wc -l packages/raystack/components/data-view/components/timeline.tsx
sed -n '1,240p' packages/raystack/components/data-view/components/timeline.tsx

# Search for row-model usage and TanStack table version hints.
rg -n "flatRows|getRowModel|subRows|grouped" packages/raystack/components -S
rg -n "tanstack|`@tanstack/react-table`|`@tanstack/table-core`" package.json packages -S

Repository: raystack/apsara

Length of output: 23245


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- timeline.tsx around row selection ---'
sed -n '120,220p' packages/raystack/components/data-view/components/timeline.tsx

echo '--- data-view.tsx table setup ---'
sed -n '120,260p' packages/raystack/components/data-view/data-view.tsx

echo '--- utils row-count comment and helpers ---'
sed -n '290,340p' packages/raystack/components/data-view/utils/index.tsx

echo '--- any explicit use of filterFromLeafRows / getExpandedRowModel / grouping setup ---'
rg -n "filterFromLeafRows|getExpandedRowModel|getGroupedRowModel|getFilteredRowModel|getPaginationRowModel|manualGrouping|grouping:" packages/raystack/components/data-view packages/raystack/components/data-table -S

Repository: raystack/apsara

Length of output: 11308


Use rowModel.flatRows here packages/raystack/components/data-view/components/timeline.tsx:135-142
rowModel.rows only contains the top-level grouped rows, so filtering it drops nested leaf rows and grouped timelines can render nothing. flatRows keeps the leaves while still letting you skip group headers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/raystack/components/data-view/components/timeline.tsx` around lines
135 - 142, Update the row extraction in the timeline component to use
rowModel.flatRows instead of rowModel.rows before filtering leaf rows. Preserve
the existing subRows-based filter so group headers remain excluded while nested
leaf rows are included.

Comment thread packages/raystack/components/data-view/components/timeline.tsx
Comment thread packages/raystack/components/data-view/components/timeline.tsx
Comment on lines +567 to +573
useEffect(() => {
if (!onVisibleRangeChange || !viewport) return;
onVisibleRangeChange([
new Date(timeScale.timeAt(viewport.left)),
new Date(timeScale.timeAt(viewport.left + viewport.width))
]);
}, [onVisibleRangeChange, viewport, timeScale]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Gate visible-range callbacks on the active view.

After a timeline has been active, its retained viewport can trigger callbacks while hidden whenever its scale or callback identity changes—potentially initiating pagination for an inactive view.

Proposed fix
   useEffect(() => {
-    if (!onVisibleRangeChange || !viewport) return;
+    if (!isActive || !onVisibleRangeChange || !viewport) return;
     onVisibleRangeChange([
       new Date(timeScale.timeAt(viewport.left)),
       new Date(timeScale.timeAt(viewport.left + viewport.width))
     ]);
-  }, [onVisibleRangeChange, viewport, timeScale]);
+  }, [isActive, onVisibleRangeChange, viewport, timeScale]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
if (!onVisibleRangeChange || !viewport) return;
onVisibleRangeChange([
new Date(timeScale.timeAt(viewport.left)),
new Date(timeScale.timeAt(viewport.left + viewport.width))
]);
}, [onVisibleRangeChange, viewport, timeScale]);
useEffect(() => {
if (!isActive || !onVisibleRangeChange || !viewport) return;
onVisibleRangeChange([
new Date(timeScale.timeAt(viewport.left)),
new Date(timeScale.timeAt(viewport.left + viewport.width))
]);
}, [isActive, onVisibleRangeChange, viewport, timeScale]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/raystack/components/data-view/components/timeline.tsx` around lines
567 - 573, Update the visible-range useEffect callback to first verify that the
timeline is the active view before invoking onVisibleRangeChange. Preserve the
existing viewport and callback guards and date-range calculation, but prevent
retained viewport changes from triggering callbacks while the timeline is
hidden.

Comment on lines +752 to +765
return (
<div
role='listitem'
key={item.row.id}
className={cx(
styles.timelineCard,
onRowClick && styles.clickable,
classNames.card
)}
style={style}
data-collapsed={context.collapsed || undefined}
onClick={() => onRowClick?.(item.row.original)}
>
{renderCard(item.row, context)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant file structure first
ast-grep outline packages/raystack/components/data-view/components/timeline.tsx --view expanded

# Show the target area with line numbers
sed -n '700,830p' packages/raystack/components/data-view/components/timeline.tsx

# Search for any keyboard handlers or interactive wrappers in this file
rg -n "onKeyDown|onKeyUp|tabIndex|role='button'|role=\"button\"|button" packages/raystack/components/data-view/components/timeline.tsx

Repository: raystack/apsara

Length of output: 3638


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the click/interaction context around the timeline cards
sed -n '430,475p' packages/raystack/components/data-view/components/timeline.tsx

# Find the prop types / callback definition for onRowClick and renderCard
rg -n "onRowClick|renderCard|TimelineCardContext|clickable" packages/raystack/components/data-view/components/timeline.tsx

Repository: raystack/apsara

Length of output: 2238


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the relevant lines around the interaction helpers
sed -n '430,475p' packages/raystack/components/data-view/components/timeline.tsx

# Locate the component's interaction-related identifiers
rg -n "onRowClick|renderCard|TimelineCardContext|clickable" packages/raystack/components/data-view/components/timeline.tsx

Repository: raystack/apsara

Length of output: 2238


Add keyboard activation to clickable cards

When onRowClick is set, this wrapper is still a plain div, so the card is mouse-only and unreachable by keyboard. Add focusability plus Enter/Space handling, or switch to an interactive element that preserves nested controls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/raystack/components/data-view/components/timeline.tsx` around lines
752 - 765, The timeline card wrapper in the render path around renderCard must
be keyboard-activatable whenever onRowClick is provided. Add appropriate
focusability and Enter/Space key handling that invokes onRowClick with
item.row.original, while preserving non-clickable behavior and ensuring nested
controls remain usable.

@rohanchkrabrty rohanchkrabrty self-assigned this Jul 19, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/www/src/content/docs/components/dataview/props.ts`:
- Line 197: Update the documentation for renderCard in the props definition to
identify its first argument as the TanStack Row wrapper (Row<TData>), not the
raw T value, while preserving the existing callback signature behavior and
context parameter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9bda2ade-fdf0-4794-87cf-6bfe995b854b

📥 Commits

Reviewing files that changed from the base of the PR and between 35a0c24 and ce88ac6.

📒 Files selected for processing (12)
  • apps/www/src/app/examples/timeline/page.tsx
  • apps/www/src/components/dataview-demo.tsx
  • apps/www/src/components/demo/demo.tsx
  • apps/www/src/content/docs/components/dataview/demo.ts
  • apps/www/src/content/docs/components/dataview/index.mdx
  • apps/www/src/content/docs/components/dataview/props.ts
  • packages/raystack/components/data-view/__tests__/timeline.test.tsx
  • packages/raystack/components/data-view/components/timeline.tsx
  • packages/raystack/components/data-view/data-view.types.tsx
  • packages/raystack/components/data-view/index.ts
  • packages/raystack/components/data-view/utils/time-scale.tsx
  • packages/raystack/index.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/raystack/components/data-view/index.ts
  • packages/raystack/index.tsx
  • packages/raystack/components/data-view/data-view.types.tsx
  • packages/raystack/components/data-view/utils/time-scale.tsx
  • packages/raystack/components/data-view/components/timeline.tsx

Comment thread apps/www/src/content/docs/components/dataview/props.ts
- restore scroll position when a gated timeline view is re-activated
- pack point-marker lanes with estimatedPointWidth so wide chips don't overlap
- memoize card wrapper so cursor/viewport frames don't re-render renderCard
- binary-search horizontal culling; dedupe onVisibleRangeChange by ms window
- rename rowHeight -> estimatedRowHeight to match DataView.List

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant