Skip to content

Commit ce1bdc1

Browse files
Copilothuangyiirene
andcommitted
Address code review feedback: extract helpers and remove empty cn() call
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 22ca625 commit ce1bdc1

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

packages/components/src/renderers/complex/timeline.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ import {
2020
} from '@/ui';
2121
import { renderChildren } from '../../lib/utils';
2222

23+
// Constants
24+
const MILLISECONDS_PER_WEEK = 7 * 24 * 60 * 60 * 1000;
25+
26+
// Helper function to calculate date range from items
27+
function calculateDateRange(items: any[]): { minDate: string; maxDate: string } {
28+
const allDates = items.flatMap((row: any) =>
29+
(row.items || []).flatMap((item: any) => [item.startDate, item.endDate])
30+
);
31+
32+
const minTimestamp = Math.min(...allDates.map((d: string) => new Date(d).getTime()));
33+
const maxTimestamp = Math.max(...allDates.map((d: string) => new Date(d).getTime()));
34+
35+
return {
36+
minDate: new Date(minTimestamp).toISOString().split('T')[0],
37+
maxDate: new Date(maxTimestamp).toISOString().split('T')[0],
38+
};
39+
}
40+
2341
// Helper function to calculate bar position and width based on dates
2442
function calculateBarDimensions(
2543
startDate: string,
@@ -132,19 +150,9 @@ ComponentRegistry.register(
132150
// Gantt/Airtable-style Timeline
133151
if (variant === 'gantt') {
134152
// Calculate date range from all items
135-
const allDates = items.flatMap((row: any) =>
136-
(row.items || []).flatMap((item: any) => [item.startDate, item.endDate])
137-
);
138-
const minDate =
139-
schema.minDate ||
140-
new Date(Math.min(...allDates.map((d: string) => new Date(d).getTime())))
141-
.toISOString()
142-
.split('T')[0];
143-
const maxDate =
144-
schema.maxDate ||
145-
new Date(Math.max(...allDates.map((d: string) => new Date(d).getTime())))
146-
.toISOString()
147-
.split('T')[0];
153+
const dateRange = calculateDateRange(items);
154+
const minDate = schema.minDate || dateRange.minDate;
155+
const maxDate = schema.maxDate || dateRange.maxDate;
148156

149157
// Generate time scale headers (months, weeks, etc.)
150158
const timeScale = schema.timeScale || 'month';
@@ -169,7 +177,7 @@ ComponentRegistry.register(
169177
while (current <= end) {
170178
headers.push(
171179
`Week ${Math.ceil(
172-
(current.getTime() - start.getTime()) / (7 * 24 * 60 * 60 * 1000)
180+
(current.getTime() - start.getTime()) / MILLISECONDS_PER_WEEK
173181
) + 1}`
174182
);
175183
current.setDate(current.getDate() + 7);

packages/components/src/ui/timeline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const TimelineContent = React.forwardRef<
5959
>(({ className, ...props }, ref) => (
6060
<div
6161
ref={ref}
62-
className={cn("", className)}
62+
className={className}
6363
{...props}
6464
/>
6565
))

0 commit comments

Comments
 (0)