@umituz/web-dashboard 11.6.1 → 11.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/package.json +3 -3
- package/src/domains/calendar/calendar.css +0 -649
- package/src/domains/calendar/components/index.ts +12 -10
- package/src/domains/calendar/types/view.types.ts +8 -51
- package/src/domains/calendar/utils/index.ts +30 -49
- package/src/domains/calendar/utils/layout.ts +31 -221
- package/src/domains/calendar/components/Calendar.test.tsx +0 -106
- package/src/domains/calendar/components/Calendar.tsx +0 -211
- package/src/domains/calendar/components/CalendarAgenda.test.tsx +0 -73
- package/src/domains/calendar/components/CalendarAgenda.tsx +0 -105
- package/src/domains/calendar/components/CalendarMonth.test.tsx +0 -59
- package/src/domains/calendar/components/CalendarMonth.tsx +0 -109
- package/src/domains/calendar/components/CalendarResourceTimeline.test.tsx +0 -93
- package/src/domains/calendar/components/CalendarResourceTimeline.tsx +0 -164
- package/src/domains/calendar/components/CalendarTimeGrid.test.tsx +0 -99
- package/src/domains/calendar/components/CalendarTimeGrid.tsx +0 -182
- package/src/domains/calendar/utils/layout.test.ts +0 -144
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import type { CSSProperties, MouseEvent, ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_CALENDAR_LABELS,
|
|
5
|
-
type CalendarItem,
|
|
6
|
-
type CalendarLabels,
|
|
7
|
-
} from '../types/view.types';
|
|
8
|
-
import {
|
|
9
|
-
DEFAULT_DAY_END_MIN,
|
|
10
|
-
DEFAULT_DAY_START_MIN,
|
|
11
|
-
SLOT_QUANTUM_MIN,
|
|
12
|
-
itemSpan,
|
|
13
|
-
layoutColumns,
|
|
14
|
-
minutesToLabel,
|
|
15
|
-
} from '../utils/layout';
|
|
16
|
-
|
|
17
|
-
export interface CalendarResource {
|
|
18
|
-
id: string;
|
|
19
|
-
label: ReactNode;
|
|
20
|
-
meta?: ReactNode;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface CalendarResourceTimelineProps {
|
|
24
|
-
resources: readonly CalendarResource[];
|
|
25
|
-
items: readonly CalendarItem[];
|
|
26
|
-
dayStartMin?: number;
|
|
27
|
-
dayEndMin?: number;
|
|
28
|
-
labels?: Partial<CalendarLabels>;
|
|
29
|
-
emptyState?: ReactNode;
|
|
30
|
-
onSelectItem?: (item: CalendarItem) => void;
|
|
31
|
-
onSlotClick?: (resourceId: string, minutes: number) => void;
|
|
32
|
-
className?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const CalendarResourceTimeline = ({
|
|
36
|
-
resources,
|
|
37
|
-
items,
|
|
38
|
-
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
39
|
-
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
40
|
-
labels,
|
|
41
|
-
emptyState,
|
|
42
|
-
onSelectItem,
|
|
43
|
-
onSlotClick,
|
|
44
|
-
className,
|
|
45
|
-
}: CalendarResourceTimelineProps) => {
|
|
46
|
-
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
47
|
-
const total = Math.max(dayEndMin - dayStartMin, 60);
|
|
48
|
-
|
|
49
|
-
const hours = useMemo(() => {
|
|
50
|
-
const first = Math.ceil(dayStartMin / 60) * 60;
|
|
51
|
-
const list: number[] = [];
|
|
52
|
-
for (let minute = first; minute < dayEndMin; minute += 60) list.push(minute);
|
|
53
|
-
return list;
|
|
54
|
-
}, [dayStartMin, dayEndMin]);
|
|
55
|
-
|
|
56
|
-
const byResource = useMemo(() => {
|
|
57
|
-
const known = new Set(resources.map((resource) => resource.id));
|
|
58
|
-
const map = new Map<string, CalendarItem[]>();
|
|
59
|
-
for (const item of items) {
|
|
60
|
-
if (!item.resourceId || !known.has(item.resourceId) || item.startMin === undefined) continue;
|
|
61
|
-
const bucket = map.get(item.resourceId);
|
|
62
|
-
if (bucket) bucket.push(item);
|
|
63
|
-
else map.set(item.resourceId, [item]);
|
|
64
|
-
}
|
|
65
|
-
return map;
|
|
66
|
-
}, [items, resources]);
|
|
67
|
-
|
|
68
|
-
const scheduled = useMemo(
|
|
69
|
-
() => [...byResource.values()].reduce((sum, bucket) => sum + bucket.length, 0),
|
|
70
|
-
[byResource],
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const fractionOf = (minute: number): number =>
|
|
74
|
-
Math.max((minute - dayStartMin) / total, 0);
|
|
75
|
-
|
|
76
|
-
const handleLaneClick = (resourceId: string, event: MouseEvent<HTMLDivElement>) => {
|
|
77
|
-
if (!onSlotClick) return;
|
|
78
|
-
const bounds = event.currentTarget.getBoundingClientRect();
|
|
79
|
-
if (bounds.width <= 0) return;
|
|
80
|
-
const ratio = (event.clientX - bounds.left) / bounds.width;
|
|
81
|
-
const raw = dayStartMin + ratio * total;
|
|
82
|
-
const quantized = Math.floor(raw / SLOT_QUANTUM_MIN) * SLOT_QUANTUM_MIN;
|
|
83
|
-
if (quantized >= dayStartMin && quantized < dayEndMin) onSlotClick(resourceId, quantized);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const axisStyle = (minute: number): CSSProperties => ({ left: `${fractionOf(minute) * 100}%` });
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<div className={className ? `udb-cal-res ${className}` : 'udb-cal-res'}>
|
|
90
|
-
{resources.length > 0 && scheduled > 0 && (
|
|
91
|
-
<>
|
|
92
|
-
<div className="udb-cal-res-axis" aria-hidden="true">
|
|
93
|
-
{hours.map((minute) => (
|
|
94
|
-
<span className="udb-cal-res-axis-label" style={axisStyle(minute)} key={minute}>
|
|
95
|
-
{minutesToLabel(minute)}
|
|
96
|
-
</span>
|
|
97
|
-
))}
|
|
98
|
-
</div>
|
|
99
|
-
<div className="udb-cal-res-body">
|
|
100
|
-
{resources.map((resource) => {
|
|
101
|
-
const rowItems = byResource.get(resource.id) ?? [];
|
|
102
|
-
return (
|
|
103
|
-
<div className="udb-cal-res-row" key={resource.id}>
|
|
104
|
-
<div className="udb-cal-res-label">
|
|
105
|
-
<span className="udb-cal-res-name">{resource.label}</span>
|
|
106
|
-
{resource.meta && <span className="udb-cal-res-meta">{resource.meta}</span>}
|
|
107
|
-
</div>
|
|
108
|
-
<div
|
|
109
|
-
className="udb-cal-res-lane"
|
|
110
|
-
onClick={(event) => handleLaneClick(resource.id, event)}
|
|
111
|
-
>
|
|
112
|
-
{hours.map((minute) => (
|
|
113
|
-
<span className="udb-cal-res-hour" style={axisStyle(minute)} key={minute} />
|
|
114
|
-
))}
|
|
115
|
-
{layoutColumns(rowItems).map(({ item, column, columns }) => {
|
|
116
|
-
const span = itemSpan(item);
|
|
117
|
-
const start = fractionOf(Math.max(span.startMin, dayStartMin)) * 100;
|
|
118
|
-
const width =
|
|
119
|
-
Math.max(
|
|
120
|
-
(Math.min(span.endMin, dayEndMin) - Math.max(span.startMin, dayStartMin)) /
|
|
121
|
-
total,
|
|
122
|
-
0.04,
|
|
123
|
-
) * 100;
|
|
124
|
-
return (
|
|
125
|
-
<button
|
|
126
|
-
type="button"
|
|
127
|
-
key={item.id}
|
|
128
|
-
className={
|
|
129
|
-
item.muted
|
|
130
|
-
? `udb-cal-res-block udb-cal-res-block--${item.tone ?? 'primary'} is-muted`
|
|
131
|
-
: `udb-cal-res-block udb-cal-res-block--${item.tone ?? 'primary'}`
|
|
132
|
-
}
|
|
133
|
-
style={{
|
|
134
|
-
left: `calc(${start + width * (column / columns)}% + 2px)`,
|
|
135
|
-
width: `calc(${width / columns}% - 4px)`,
|
|
136
|
-
}}
|
|
137
|
-
onClick={(click) => {
|
|
138
|
-
click.stopPropagation();
|
|
139
|
-
onSelectItem?.(item);
|
|
140
|
-
}}
|
|
141
|
-
>
|
|
142
|
-
<span className="udb-cal-res-block-time">
|
|
143
|
-
{minutesToLabel(span.startMin)}
|
|
144
|
-
</span>
|
|
145
|
-
<span className="udb-cal-res-block-title">{item.title}</span>
|
|
146
|
-
{item.meta}
|
|
147
|
-
</button>
|
|
148
|
-
);
|
|
149
|
-
})}
|
|
150
|
-
</div>
|
|
151
|
-
</div>
|
|
152
|
-
);
|
|
153
|
-
})}
|
|
154
|
-
</div>
|
|
155
|
-
</>
|
|
156
|
-
)}
|
|
157
|
-
{(resources.length === 0 || scheduled === 0) && (
|
|
158
|
-
<div className="udb-cal-res-empty">
|
|
159
|
-
{emptyState ?? <p className="udb-cal-res-empty-text">{text.emptyDay}</p>}
|
|
160
|
-
</div>
|
|
161
|
-
)}
|
|
162
|
-
</div>
|
|
163
|
-
);
|
|
164
|
-
};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
4
|
-
import type { CalendarItem } from '../types/view.types';
|
|
5
|
-
|
|
6
|
-
const item = (id: string, dayKey: string, startMin: number, endMin: number): CalendarItem => ({
|
|
7
|
-
id,
|
|
8
|
-
dayKey,
|
|
9
|
-
startMin,
|
|
10
|
-
endMin,
|
|
11
|
-
title: id,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const mount = (props: Partial<Parameters<typeof CalendarTimeGrid>[0]> = {}) =>
|
|
15
|
-
render(<CalendarTimeGrid items={[]} days={['2026-03-15']} {...props} />);
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
vi.restoreAllMocks();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('CalendarTimeGrid', () => {
|
|
22
|
-
it('positions timed events inside their day lane', () => {
|
|
23
|
-
mount({ items: [item('Consult', '2026-03-15', 600, 660)] });
|
|
24
|
-
const block = screen.getByText('Consult').closest('button') as HTMLElement;
|
|
25
|
-
expect(block.className).toContain('udb-cal-event');
|
|
26
|
-
expect(parseFloat(block.style.top)).toBeCloseTo(21.4286, 3);
|
|
27
|
-
expect(parseFloat(block.style.height)).toBeCloseTo(7.1429, 3);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('splits overlapping events into columns', () => {
|
|
31
|
-
mount({
|
|
32
|
-
items: [item('first', '2026-03-15', 600, 660), item('second', '2026-03-15', 630, 690)],
|
|
33
|
-
});
|
|
34
|
-
const first = screen.getByText('first').closest('button') as HTMLElement;
|
|
35
|
-
const second = screen.getByText('second').closest('button') as HTMLElement;
|
|
36
|
-
expect(first.style.width).toBe('calc(50% - 4px)');
|
|
37
|
-
expect(second.style.width).toBe('calc(50% - 4px)');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('reports empty single days', () => {
|
|
41
|
-
mount();
|
|
42
|
-
expect(screen.getByText('Nothing scheduled')).toBeTruthy();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('quantizes empty-lane clicks to slot boundaries', () => {
|
|
46
|
-
const onSlotClick = vi.fn();
|
|
47
|
-
const { container } = mount({ onSlotClick });
|
|
48
|
-
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
|
|
49
|
-
top: 0,
|
|
50
|
-
height: 400,
|
|
51
|
-
bottom: 400,
|
|
52
|
-
left: 0,
|
|
53
|
-
right: 100,
|
|
54
|
-
width: 100,
|
|
55
|
-
x: 0,
|
|
56
|
-
y: 0,
|
|
57
|
-
toJSON: () => ({}),
|
|
58
|
-
} as DOMRect);
|
|
59
|
-
const lane = container.querySelector('.udb-cal-lane') as HTMLElement;
|
|
60
|
-
fireEvent.click(lane, { clientY: 100 });
|
|
61
|
-
expect(onSlotClick).toHaveBeenCalledWith('2026-03-15', 630);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('reports item selection from an event block', () => {
|
|
65
|
-
const onSelectItem = vi.fn();
|
|
66
|
-
mount({ items: [item('Consult', '2026-03-15', 600, 660)], onSelectItem });
|
|
67
|
-
fireEvent.click(screen.getByText('Consult'));
|
|
68
|
-
expect(onSelectItem).toHaveBeenCalledWith(
|
|
69
|
-
expect.objectContaining({ id: 'Consult' }),
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('keeps untimed items in the all-day strip instead of dropping them', () => {
|
|
74
|
-
const { container } = mount({
|
|
75
|
-
days: ['2026-03-15', '2026-03-16'],
|
|
76
|
-
items: [
|
|
77
|
-
item('Consult', '2026-03-15', 600, 660),
|
|
78
|
-
{ id: 'Permit expiry', dayKey: '2026-03-16', title: 'Permit expiry', tone: 'danger' },
|
|
79
|
-
],
|
|
80
|
-
});
|
|
81
|
-
const strip = container.querySelector('.udb-cal-allday');
|
|
82
|
-
expect(strip).toBeTruthy();
|
|
83
|
-
expect(screen.getByText('All day')).toBeTruthy();
|
|
84
|
-
expect(strip?.textContent).toContain('Permit expiry');
|
|
85
|
-
expect(strip?.textContent).not.toContain('Consult');
|
|
86
|
-
expect(container.querySelectorAll('.udb-cal-event')).toHaveLength(1);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('does not flag a single day as empty when it only holds all-day items', () => {
|
|
90
|
-
mount({ items: [{ id: 'Expiry', dayKey: '2026-03-15', title: 'Expiry' }] });
|
|
91
|
-
expect(screen.queryByText('Nothing scheduled')).toBeNull();
|
|
92
|
-
expect(screen.getByText('All day')).toBeTruthy();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('omits the all-day strip when every item is timed', () => {
|
|
96
|
-
const { container } = mount({ items: [item('Consult', '2026-03-15', 600, 660)] });
|
|
97
|
-
expect(container.querySelector('.udb-cal-allday')).toBeNull();
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import type { CSSProperties, MouseEvent, ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_CALENDAR_LABELS,
|
|
5
|
-
type CalendarItem,
|
|
6
|
-
type CalendarLabels,
|
|
7
|
-
} from '../types/view.types';
|
|
8
|
-
import {
|
|
9
|
-
DEFAULT_DAY_END_MIN,
|
|
10
|
-
DEFAULT_DAY_START_MIN,
|
|
11
|
-
SLOT_QUANTUM_MIN,
|
|
12
|
-
eventGeometry,
|
|
13
|
-
formatDayNumber,
|
|
14
|
-
formatWeekdayShort,
|
|
15
|
-
groupByDayKey,
|
|
16
|
-
itemSpan,
|
|
17
|
-
layoutColumns,
|
|
18
|
-
minutesToLabel,
|
|
19
|
-
todayKey,
|
|
20
|
-
} from '../utils/layout';
|
|
21
|
-
|
|
22
|
-
export interface CalendarTimeGridProps {
|
|
23
|
-
items: readonly CalendarItem[];
|
|
24
|
-
days: readonly string[];
|
|
25
|
-
dayStartMin?: number;
|
|
26
|
-
dayEndMin?: number;
|
|
27
|
-
locale?: string;
|
|
28
|
-
labels?: Partial<CalendarLabels>;
|
|
29
|
-
emptyState?: ReactNode;
|
|
30
|
-
onSelectItem?: (item: CalendarItem) => void;
|
|
31
|
-
onSlotClick?: (dayKey: string, minutes: number) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const CalendarTimeGrid = ({
|
|
35
|
-
items,
|
|
36
|
-
days,
|
|
37
|
-
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
38
|
-
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
39
|
-
locale = 'en-US',
|
|
40
|
-
labels,
|
|
41
|
-
emptyState,
|
|
42
|
-
onSelectItem,
|
|
43
|
-
onSlotClick,
|
|
44
|
-
}: CalendarTimeGridProps) => {
|
|
45
|
-
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
46
|
-
const today = todayKey();
|
|
47
|
-
const total = Math.max(dayEndMin - dayStartMin, 60);
|
|
48
|
-
|
|
49
|
-
const hours = useMemo(() => {
|
|
50
|
-
const first = Math.ceil(dayStartMin / 60) * 60;
|
|
51
|
-
const list: number[] = [];
|
|
52
|
-
for (let minute = first; minute < dayEndMin; minute += 60) list.push(minute);
|
|
53
|
-
return list;
|
|
54
|
-
}, [dayStartMin, dayEndMin]);
|
|
55
|
-
|
|
56
|
-
const timed = useMemo(() => items.filter((item) => item.startMin !== undefined), [items]);
|
|
57
|
-
const untimed = useMemo(() => items.filter((item) => item.startMin === undefined), [items]);
|
|
58
|
-
const timedByDay = useMemo(() => groupByDayKey(timed), [timed]);
|
|
59
|
-
const untimedByDay = useMemo(() => groupByDayKey(untimed), [untimed]);
|
|
60
|
-
const hasAllDay = days.some((dayKey) => (untimedByDay.get(dayKey)?.length ?? 0) > 0);
|
|
61
|
-
|
|
62
|
-
const positionOf = (minute: number): string =>
|
|
63
|
-
`${((minute - dayStartMin) / total) * 100}%`;
|
|
64
|
-
|
|
65
|
-
const handleLaneClick = (dayKey: string, event: MouseEvent<HTMLDivElement>) => {
|
|
66
|
-
if (!onSlotClick) return;
|
|
67
|
-
const bounds = event.currentTarget.getBoundingClientRect();
|
|
68
|
-
if (bounds.height <= 0) return;
|
|
69
|
-
const ratio = (event.clientY - bounds.top) / bounds.height;
|
|
70
|
-
const raw = dayStartMin + ratio * total;
|
|
71
|
-
const quantized = Math.floor(raw / SLOT_QUANTUM_MIN) * SLOT_QUANTUM_MIN;
|
|
72
|
-
if (quantized >= dayStartMin && quantized < dayEndMin) onSlotClick(dayKey, quantized);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<div
|
|
77
|
-
className="udb-cal-grid"
|
|
78
|
-
style={{ ['--udb-cal-days' as string]: days.length } as CSSProperties}
|
|
79
|
-
>
|
|
80
|
-
<div className="udb-cal-days">
|
|
81
|
-
<span className="udb-cal-days-corner" />
|
|
82
|
-
{days.map((dayKey) => (
|
|
83
|
-
<div
|
|
84
|
-
className={dayKey === today ? 'udb-cal-day-head is-today' : 'udb-cal-day-head'}
|
|
85
|
-
key={dayKey}
|
|
86
|
-
>
|
|
87
|
-
<span className="udb-cal-weekday">{formatWeekdayShort(dayKey, locale)}</span>
|
|
88
|
-
<span className="udb-cal-daynum">{formatDayNumber(dayKey)}</span>
|
|
89
|
-
</div>
|
|
90
|
-
))}
|
|
91
|
-
</div>
|
|
92
|
-
|
|
93
|
-
{hasAllDay && (
|
|
94
|
-
<div className="udb-cal-allday">
|
|
95
|
-
<span className="udb-cal-allday-corner">{text.allDay}</span>
|
|
96
|
-
{days.map((dayKey) => (
|
|
97
|
-
<div className="udb-cal-allday-cell" key={dayKey}>
|
|
98
|
-
{(untimedByDay.get(dayKey) ?? []).map((item) => (
|
|
99
|
-
<button
|
|
100
|
-
type="button"
|
|
101
|
-
key={item.id}
|
|
102
|
-
className={
|
|
103
|
-
item.muted
|
|
104
|
-
? `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'} is-muted`
|
|
105
|
-
: `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'}`
|
|
106
|
-
}
|
|
107
|
-
onClick={() => onSelectItem?.(item)}
|
|
108
|
-
>
|
|
109
|
-
{item.icon}
|
|
110
|
-
<span className="udb-cal-chip-title">{item.title}</span>
|
|
111
|
-
</button>
|
|
112
|
-
))}
|
|
113
|
-
</div>
|
|
114
|
-
))}
|
|
115
|
-
</div>
|
|
116
|
-
)}
|
|
117
|
-
|
|
118
|
-
<div className="udb-cal-gutter" aria-hidden="true">
|
|
119
|
-
{hours.map((minute) => (
|
|
120
|
-
<div className="udb-cal-hour-label" style={{ top: positionOf(minute) }} key={minute}>
|
|
121
|
-
{minutesToLabel(minute)}
|
|
122
|
-
</div>
|
|
123
|
-
))}
|
|
124
|
-
</div>
|
|
125
|
-
|
|
126
|
-
{days.map((dayKey) => {
|
|
127
|
-
const laneItems = timedByDay.get(dayKey) ?? [];
|
|
128
|
-
const dayCount = laneItems.length + (untimedByDay.get(dayKey)?.length ?? 0);
|
|
129
|
-
return (
|
|
130
|
-
<section className="udb-cal-day" aria-label={dayKey} key={dayKey}>
|
|
131
|
-
<div
|
|
132
|
-
className="udb-cal-lane"
|
|
133
|
-
role="grid"
|
|
134
|
-
aria-label={dayKey}
|
|
135
|
-
onClick={(event) => handleLaneClick(dayKey, event)}
|
|
136
|
-
>
|
|
137
|
-
{hours.map((minute) => (
|
|
138
|
-
<div
|
|
139
|
-
className="udb-cal-hour-line"
|
|
140
|
-
style={{ top: positionOf(minute) }}
|
|
141
|
-
key={minute}
|
|
142
|
-
/>
|
|
143
|
-
))}
|
|
144
|
-
{layoutColumns(laneItems).map(({ item, column, columns }) => {
|
|
145
|
-
const geometry = eventGeometry(item, dayStartMin, dayEndMin);
|
|
146
|
-
return (
|
|
147
|
-
<button
|
|
148
|
-
type="button"
|
|
149
|
-
key={item.id}
|
|
150
|
-
className={
|
|
151
|
-
item.muted
|
|
152
|
-
? `udb-cal-event udb-cal-event--${item.tone ?? 'primary'} is-muted`
|
|
153
|
-
: `udb-cal-event udb-cal-event--${item.tone ?? 'primary'}`
|
|
154
|
-
}
|
|
155
|
-
style={{
|
|
156
|
-
top: `${geometry.top}%`,
|
|
157
|
-
height: `${geometry.height}%`,
|
|
158
|
-
left: `calc(${(column / columns) * 100}% + 2px)`,
|
|
159
|
-
width: `calc(${100 / columns}% - 4px)`,
|
|
160
|
-
}}
|
|
161
|
-
onClick={(click) => {
|
|
162
|
-
click.stopPropagation();
|
|
163
|
-
onSelectItem?.(item);
|
|
164
|
-
}}
|
|
165
|
-
>
|
|
166
|
-
<span className="udb-cal-event-time">
|
|
167
|
-
{minutesToLabel(itemSpan(item).startMin)}
|
|
168
|
-
</span>
|
|
169
|
-
<span className="udb-cal-event-title">{item.title}</span>
|
|
170
|
-
{item.meta}
|
|
171
|
-
</button>
|
|
172
|
-
);
|
|
173
|
-
})}
|
|
174
|
-
{days.length === 1 && dayCount === 0 &&
|
|
175
|
-
(emptyState ?? <p className="udb-cal-empty">{text.emptyDay}</p>)}
|
|
176
|
-
</div>
|
|
177
|
-
</section>
|
|
178
|
-
);
|
|
179
|
-
})}
|
|
180
|
-
</div>
|
|
181
|
-
);
|
|
182
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
addDaysKey,
|
|
4
|
-
addMonthsKey,
|
|
5
|
-
eventGeometry,
|
|
6
|
-
findConflicts,
|
|
7
|
-
generateDaySlots,
|
|
8
|
-
groupByDayKey,
|
|
9
|
-
itemSpan,
|
|
10
|
-
layoutColumns,
|
|
11
|
-
minutesToLabel,
|
|
12
|
-
monthMatrix,
|
|
13
|
-
spansOverlap,
|
|
14
|
-
startOfWeekKey,
|
|
15
|
-
weekDays,
|
|
16
|
-
} from './layout';
|
|
17
|
-
import type { CalendarItem } from '../types/view.types';
|
|
18
|
-
|
|
19
|
-
const item = (id: string, dayKey: string, startMin?: number, endMin?: number): CalendarItem => ({
|
|
20
|
-
id,
|
|
21
|
-
dayKey,
|
|
22
|
-
startMin,
|
|
23
|
-
endMin,
|
|
24
|
-
title: id,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('day keys', () => {
|
|
28
|
-
it('builds monday-based weeks', () => {
|
|
29
|
-
expect(weekDays('2026-03-10')).toEqual([
|
|
30
|
-
'2026-03-09',
|
|
31
|
-
'2026-03-10',
|
|
32
|
-
'2026-03-11',
|
|
33
|
-
'2026-03-12',
|
|
34
|
-
'2026-03-13',
|
|
35
|
-
'2026-03-14',
|
|
36
|
-
'2026-03-15',
|
|
37
|
-
]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('honors sunday-based weeks', () => {
|
|
41
|
-
expect(startOfWeekKey('2026-03-10', 0)).toBe('2026-03-08');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('builds a six-row month matrix', () => {
|
|
45
|
-
const matrix = monthMatrix('2026-03-10');
|
|
46
|
-
expect(matrix).toHaveLength(42);
|
|
47
|
-
expect(matrix[0]).toBe('2026-02-23');
|
|
48
|
-
expect(matrix[41]).toBe('2026-04-05');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('clamps month shifts to month ends', () => {
|
|
52
|
-
expect(addMonthsKey('2026-03-31', -1)).toBe('2026-02-28');
|
|
53
|
-
expect(addDaysKey('2026-03-01', -1)).toBe('2026-02-28');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('formats minute-of-day labels', () => {
|
|
57
|
-
expect(minutesToLabel(630)).toBe('10:30');
|
|
58
|
-
expect(minutesToLabel(25 * 60 + 15)).toBe('01:15');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('spans', () => {
|
|
63
|
-
it('treats touching edges as non-overlapping', () => {
|
|
64
|
-
expect(spansOverlap({ startMin: 60, endMin: 120 }, { startMin: 120, endMin: 180 })).toBe(false);
|
|
65
|
-
expect(spansOverlap({ startMin: 60, endMin: 121 }, { startMin: 120, endMin: 180 })).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('defaults open spans to one hour', () => {
|
|
69
|
-
expect(itemSpan(item('a', '2026-03-10', 600))).toEqual({ startMin: 600, endMin: 660 });
|
|
70
|
-
expect(itemSpan(item('b', '2026-03-10'))).toEqual({ startMin: 0, endMin: 60 });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('flags only items overlapping another', () => {
|
|
74
|
-
const items = [
|
|
75
|
-
item('a', '2026-03-10', 60, 120),
|
|
76
|
-
item('b', '2026-03-10', 90, 150),
|
|
77
|
-
item('c', '2026-03-10', 200, 260),
|
|
78
|
-
];
|
|
79
|
-
expect(findConflicts(items).map((entry) => entry.id).sort()).toEqual(['a', 'b']);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('layoutColumns', () => {
|
|
84
|
-
it('gives overlapping events side-by-side columns', () => {
|
|
85
|
-
const placed = layoutColumns([
|
|
86
|
-
item('x', '2026-03-10', 60, 120),
|
|
87
|
-
item('y', '2026-03-10', 90, 150),
|
|
88
|
-
]);
|
|
89
|
-
const byId = new Map(placed.map((entry) => [entry.item.id, entry]));
|
|
90
|
-
expect(byId.get('x')?.columns).toBe(2);
|
|
91
|
-
expect(byId.get('y')?.columns).toBe(2);
|
|
92
|
-
expect(new Set(placed.map((entry) => entry.column))).toEqual(new Set([0, 1]));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('splits clusters when events only touch', () => {
|
|
96
|
-
const placed = layoutColumns([
|
|
97
|
-
item('x', '2026-03-10', 60, 120),
|
|
98
|
-
item('z', '2026-03-10', 120, 180),
|
|
99
|
-
]);
|
|
100
|
-
expect(placed.every((entry) => entry.columns === 1)).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('eventGeometry', () => {
|
|
105
|
-
it('positions events as percentages of the day range', () => {
|
|
106
|
-
const geometry = eventGeometry(item('a', '2026-03-10', 600, 660), 420, 1260);
|
|
107
|
-
expect(geometry.top).toBeCloseTo(21.43, 1);
|
|
108
|
-
expect(geometry.height).toBeCloseTo(7.14, 1);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('clamps events spilling outside the range', () => {
|
|
112
|
-
const geometry = eventGeometry(item('a', '2026-03-10', 300, 1300), 420, 1260);
|
|
113
|
-
expect(geometry.top).toBe(0);
|
|
114
|
-
expect(geometry.height).toBe(100);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('generateDaySlots', () => {
|
|
119
|
-
it('marks slots intersecting booked spans as taken', () => {
|
|
120
|
-
const slots = generateDaySlots(
|
|
121
|
-
{ startMin: 420, endMin: 720, durationMin: 60 },
|
|
122
|
-
[{ startMin: 480, endMin: 540 }],
|
|
123
|
-
);
|
|
124
|
-
expect(slots.map((slot) => slot.startMin)).toEqual([420, 480, 540, 600, 660]);
|
|
125
|
-
expect(slots.map((slot) => slot.taken)).toEqual([false, true, false, false, false]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('supports a step smaller than the duration', () => {
|
|
129
|
-
const slots = generateDaySlots({ startMin: 420, endMin: 540, durationMin: 60, stepMin: 30 });
|
|
130
|
-
expect(slots.map((slot) => slot.startMin)).toEqual([420, 450, 480]);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('groupByDayKey', () => {
|
|
135
|
-
it('buckets by day and sorts by start minute', () => {
|
|
136
|
-
const grouped = groupByDayKey([
|
|
137
|
-
item('late', '2026-03-10', 900, 960),
|
|
138
|
-
item('early', '2026-03-10', 540, 600),
|
|
139
|
-
item('other-day', '2026-03-11', 600, 660),
|
|
140
|
-
]);
|
|
141
|
-
expect(grouped.get('2026-03-10')?.map((entry) => entry.id)).toEqual(['early', 'late']);
|
|
142
|
-
expect(grouped.get('2026-03-11')?.map((entry) => entry.id)).toEqual(['other-day']);
|
|
143
|
-
});
|
|
144
|
-
});
|