@umituz/web-dashboard 11.6.0 → 11.7.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/layout.ts +31 -221
- package/src/styles/chrome.css +37 -32
- 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,211 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
4
|
-
import { Button, IconButton } from '@umituz/web-design-system/atoms';
|
|
5
|
-
import { Segmented } from '@umituz/web-design-system/molecules';
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_CALENDAR_LABELS,
|
|
8
|
-
type CalendarItem,
|
|
9
|
-
type CalendarLabels,
|
|
10
|
-
type CalendarLegendEntry,
|
|
11
|
-
type CalendarScreenView,
|
|
12
|
-
} from '../types/view.types';
|
|
13
|
-
import {
|
|
14
|
-
DEFAULT_DAY_END_MIN,
|
|
15
|
-
DEFAULT_DAY_START_MIN,
|
|
16
|
-
DEFAULT_MAX_PER_DAY,
|
|
17
|
-
addDaysKey,
|
|
18
|
-
addMonthsKey,
|
|
19
|
-
formatAgendaTitle,
|
|
20
|
-
formatDayTitle,
|
|
21
|
-
formatMonthTitle,
|
|
22
|
-
formatWeekTitle,
|
|
23
|
-
todayKey,
|
|
24
|
-
weekDays,
|
|
25
|
-
} from '../utils/layout';
|
|
26
|
-
import { CalendarAgenda } from './CalendarAgenda';
|
|
27
|
-
import { CalendarMonth } from './CalendarMonth';
|
|
28
|
-
import { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
29
|
-
|
|
30
|
-
export interface CalendarProps {
|
|
31
|
-
items: readonly CalendarItem[];
|
|
32
|
-
view?: CalendarScreenView;
|
|
33
|
-
onViewChange?: (view: CalendarScreenView) => void;
|
|
34
|
-
cursor?: string;
|
|
35
|
-
initialCursor?: string;
|
|
36
|
-
onCursorChange?: (dayKey: string) => void;
|
|
37
|
-
views?: readonly CalendarScreenView[];
|
|
38
|
-
weekStartsOn?: 0 | 1;
|
|
39
|
-
dayStartMin?: number;
|
|
40
|
-
dayEndMin?: number;
|
|
41
|
-
maxPerDay?: number;
|
|
42
|
-
agendaDays?: number;
|
|
43
|
-
locale?: string;
|
|
44
|
-
labels?: Partial<CalendarLabels>;
|
|
45
|
-
legend?: readonly CalendarLegendEntry[];
|
|
46
|
-
toolbarExtra?: ReactNode;
|
|
47
|
-
emptyState?: ReactNode;
|
|
48
|
-
onSelectItem?: (item: CalendarItem) => void;
|
|
49
|
-
onSelectDay?: (dayKey: string) => void;
|
|
50
|
-
onSlotClick?: (dayKey: string, minutes: number) => void;
|
|
51
|
-
className?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const Calendar = ({
|
|
55
|
-
items,
|
|
56
|
-
view,
|
|
57
|
-
onViewChange,
|
|
58
|
-
cursor,
|
|
59
|
-
initialCursor,
|
|
60
|
-
onCursorChange,
|
|
61
|
-
views = ['month', 'week', 'day'],
|
|
62
|
-
weekStartsOn = 1,
|
|
63
|
-
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
64
|
-
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
65
|
-
maxPerDay = DEFAULT_MAX_PER_DAY,
|
|
66
|
-
agendaDays = 30,
|
|
67
|
-
locale = 'en-US',
|
|
68
|
-
labels,
|
|
69
|
-
legend,
|
|
70
|
-
toolbarExtra,
|
|
71
|
-
emptyState,
|
|
72
|
-
onSelectItem,
|
|
73
|
-
onSelectDay,
|
|
74
|
-
onSlotClick,
|
|
75
|
-
className,
|
|
76
|
-
}: CalendarProps) => {
|
|
77
|
-
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
78
|
-
const [innerView, setInnerView] = useState<CalendarScreenView>(views[0] ?? 'month');
|
|
79
|
-
const [innerCursor, setInnerCursor] = useState(() => cursor ?? initialCursor ?? todayKey());
|
|
80
|
-
const activeView = view ?? innerView;
|
|
81
|
-
const activeCursor = cursor ?? innerCursor;
|
|
82
|
-
|
|
83
|
-
const applyView = (next: CalendarScreenView) => {
|
|
84
|
-
setInnerView(next);
|
|
85
|
-
onViewChange?.(next);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const applyCursor = (next: string) => {
|
|
89
|
-
setInnerCursor(next);
|
|
90
|
-
onCursorChange?.(next);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const shift = (direction: number) => {
|
|
94
|
-
if (activeView === 'month') applyCursor(addMonthsKey(activeCursor, direction));
|
|
95
|
-
else if (activeView === 'week') applyCursor(addDaysKey(activeCursor, direction * 7));
|
|
96
|
-
else if (activeView === 'agenda') applyCursor(addDaysKey(activeCursor, direction * agendaDays));
|
|
97
|
-
else applyCursor(addDaysKey(activeCursor, direction));
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const title = useMemo(() => {
|
|
101
|
-
if (activeView === 'day') return formatDayTitle(activeCursor, locale);
|
|
102
|
-
if (activeView === 'week') return formatWeekTitle(activeCursor, locale);
|
|
103
|
-
if (activeView === 'agenda') return formatAgendaTitle(activeCursor, agendaDays, locale);
|
|
104
|
-
return formatMonthTitle(activeCursor, locale);
|
|
105
|
-
}, [activeView, activeCursor, agendaDays, locale]);
|
|
106
|
-
|
|
107
|
-
const handleSelectDay = (dayKey: string) => {
|
|
108
|
-
applyCursor(dayKey);
|
|
109
|
-
if (activeView !== 'day' && views.includes('day')) applyView('day');
|
|
110
|
-
onSelectDay?.(dayKey);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<div className={className ? `udb-cal ${className}` : 'udb-cal'}>
|
|
115
|
-
<div className="udb-cal-toolbar">
|
|
116
|
-
<div className="udb-cal-toolbar-nav">
|
|
117
|
-
<IconButton
|
|
118
|
-
icon={<ChevronLeft size={16} />}
|
|
119
|
-
label={text.previous}
|
|
120
|
-
size="sm"
|
|
121
|
-
variant="outline"
|
|
122
|
-
onClick={() => shift(-1)}
|
|
123
|
-
/>
|
|
124
|
-
<IconButton
|
|
125
|
-
icon={<ChevronRight size={16} />}
|
|
126
|
-
label={text.next}
|
|
127
|
-
size="sm"
|
|
128
|
-
variant="outline"
|
|
129
|
-
onClick={() => shift(1)}
|
|
130
|
-
/>
|
|
131
|
-
<span className="udb-cal-title">{title}</span>
|
|
132
|
-
<Button variant="ghost" size="sm" onClick={() => applyCursor(todayKey())}>
|
|
133
|
-
{text.today}
|
|
134
|
-
</Button>
|
|
135
|
-
</div>
|
|
136
|
-
<div className="udb-cal-toolbar-side">
|
|
137
|
-
{toolbarExtra && <div className="udb-cal-extra">{toolbarExtra}</div>}
|
|
138
|
-
{legend && legend.length > 0 && (
|
|
139
|
-
<div className="udb-cal-legend">
|
|
140
|
-
{legend.map((entry) => (
|
|
141
|
-
<span className="udb-cal-legend-entry" key={entry.tone + entry.label}>
|
|
142
|
-
<span className={`udb-cal-legend-dot udb-cal-dot--${entry.tone}`} />
|
|
143
|
-
{entry.label}
|
|
144
|
-
</span>
|
|
145
|
-
))}
|
|
146
|
-
</div>
|
|
147
|
-
)}
|
|
148
|
-
<Segmented
|
|
149
|
-
options={views.map((option) => ({ value: option, label: text[option] }))}
|
|
150
|
-
value={activeView}
|
|
151
|
-
onChange={(next) => applyView(next)}
|
|
152
|
-
aria-label={text.month}
|
|
153
|
-
/>
|
|
154
|
-
</div>
|
|
155
|
-
</div>
|
|
156
|
-
|
|
157
|
-
{activeView === 'month' && (
|
|
158
|
-
<CalendarMonth
|
|
159
|
-
items={items}
|
|
160
|
-
anchorKey={activeCursor}
|
|
161
|
-
weekStartsOn={weekStartsOn}
|
|
162
|
-
locale={locale}
|
|
163
|
-
maxPerDay={maxPerDay}
|
|
164
|
-
labels={labels}
|
|
165
|
-
onSelectDay={handleSelectDay}
|
|
166
|
-
onSelectItem={onSelectItem}
|
|
167
|
-
/>
|
|
168
|
-
)}
|
|
169
|
-
|
|
170
|
-
{activeView === 'week' && (
|
|
171
|
-
<CalendarTimeGrid
|
|
172
|
-
items={items}
|
|
173
|
-
days={weekDays(activeCursor, weekStartsOn)}
|
|
174
|
-
dayStartMin={dayStartMin}
|
|
175
|
-
dayEndMin={dayEndMin}
|
|
176
|
-
locale={locale}
|
|
177
|
-
labels={labels}
|
|
178
|
-
emptyState={emptyState}
|
|
179
|
-
onSelectItem={onSelectItem}
|
|
180
|
-
onSlotClick={onSlotClick}
|
|
181
|
-
/>
|
|
182
|
-
)}
|
|
183
|
-
|
|
184
|
-
{activeView === 'day' && (
|
|
185
|
-
<CalendarTimeGrid
|
|
186
|
-
items={items}
|
|
187
|
-
days={[activeCursor]}
|
|
188
|
-
dayStartMin={dayStartMin}
|
|
189
|
-
dayEndMin={dayEndMin}
|
|
190
|
-
locale={locale}
|
|
191
|
-
labels={labels}
|
|
192
|
-
emptyState={emptyState}
|
|
193
|
-
onSelectItem={onSelectItem}
|
|
194
|
-
onSlotClick={onSlotClick}
|
|
195
|
-
/>
|
|
196
|
-
)}
|
|
197
|
-
|
|
198
|
-
{activeView === 'agenda' && (
|
|
199
|
-
<CalendarAgenda
|
|
200
|
-
items={items}
|
|
201
|
-
anchorKey={activeCursor}
|
|
202
|
-
agendaDays={agendaDays}
|
|
203
|
-
locale={locale}
|
|
204
|
-
labels={labels}
|
|
205
|
-
emptyState={emptyState}
|
|
206
|
-
onSelectItem={onSelectItem}
|
|
207
|
-
/>
|
|
208
|
-
)}
|
|
209
|
-
</div>
|
|
210
|
-
);
|
|
211
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { CalendarAgenda } from './CalendarAgenda';
|
|
4
|
-
import type { CalendarItem } from '../types/view.types';
|
|
5
|
-
import { todayKey } from '../utils/layout';
|
|
6
|
-
|
|
7
|
-
const item = (id: string, dayKey: string, startMin?: number, endMin?: number): CalendarItem => ({
|
|
8
|
-
id,
|
|
9
|
-
dayKey,
|
|
10
|
-
startMin,
|
|
11
|
-
endMin,
|
|
12
|
-
title: id,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('CalendarAgenda', () => {
|
|
16
|
-
it('groups only days with items inside the window', () => {
|
|
17
|
-
render(
|
|
18
|
-
<CalendarAgenda
|
|
19
|
-
items={[
|
|
20
|
-
item('Kickoff', '2026-03-15', 600, 660),
|
|
21
|
-
item('Beyond', '2026-04-20', 900),
|
|
22
|
-
]}
|
|
23
|
-
anchorKey="2026-03-10"
|
|
24
|
-
agendaDays={30}
|
|
25
|
-
/>,
|
|
26
|
-
);
|
|
27
|
-
expect(screen.getByText('Sunday, March 15, 2026')).toBeTruthy();
|
|
28
|
-
expect(screen.queryByText(/April 20/)).toBeNull();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('marks the today group and counts its items', () => {
|
|
32
|
-
const today = todayKey();
|
|
33
|
-
render(
|
|
34
|
-
<CalendarAgenda
|
|
35
|
-
items={[item('First', today, 540, 600), item('Second', today, 720)]}
|
|
36
|
-
anchorKey={today}
|
|
37
|
-
/>,
|
|
38
|
-
);
|
|
39
|
-
expect(screen.getByText('Today')).toBeTruthy();
|
|
40
|
-
expect(screen.getByText('2')).toBeTruthy();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('fires onSelectItem with the payload-carrying item', () => {
|
|
44
|
-
const onSelectItem = vi.fn();
|
|
45
|
-
render(
|
|
46
|
-
<CalendarAgenda
|
|
47
|
-
items={[item('Kickoff', '2026-03-15', 600, 660)]}
|
|
48
|
-
anchorKey="2026-03-15"
|
|
49
|
-
onSelectItem={onSelectItem}
|
|
50
|
-
/>,
|
|
51
|
-
);
|
|
52
|
-
fireEvent.click(screen.getByRole('button', { name: /Kickoff/ }));
|
|
53
|
-
expect(onSelectItem).toHaveBeenCalledWith(
|
|
54
|
-
expect.objectContaining({ id: 'Kickoff', dayKey: '2026-03-15' }),
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('renders a custom empty state when the window has no items', () => {
|
|
59
|
-
render(
|
|
60
|
-
<CalendarAgenda
|
|
61
|
-
items={[]}
|
|
62
|
-
anchorKey="2026-03-10"
|
|
63
|
-
emptyState={<button type="button">Book a shoot day</button>}
|
|
64
|
-
/>,
|
|
65
|
-
);
|
|
66
|
-
expect(screen.getByText('Book a shoot day')).toBeTruthy();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('falls back to the default empty label', () => {
|
|
70
|
-
render(<CalendarAgenda items={[]} anchorKey="2026-03-10" />);
|
|
71
|
-
expect(screen.getByText('Nothing scheduled')).toBeTruthy();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_CALENDAR_LABELS,
|
|
5
|
-
type CalendarItem,
|
|
6
|
-
type CalendarLabels,
|
|
7
|
-
} from '../types/view.types';
|
|
8
|
-
import {
|
|
9
|
-
addDaysKey,
|
|
10
|
-
formatDayTitle,
|
|
11
|
-
groupByDayKey,
|
|
12
|
-
minutesToLabel,
|
|
13
|
-
todayKey,
|
|
14
|
-
} from '../utils/layout';
|
|
15
|
-
|
|
16
|
-
export interface CalendarAgendaProps {
|
|
17
|
-
items: readonly CalendarItem[];
|
|
18
|
-
anchorKey: string;
|
|
19
|
-
agendaDays?: number;
|
|
20
|
-
locale?: string;
|
|
21
|
-
labels?: Partial<CalendarLabels>;
|
|
22
|
-
emptyState?: ReactNode;
|
|
23
|
-
onSelectItem?: (item: CalendarItem) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const CalendarAgenda = ({
|
|
27
|
-
items,
|
|
28
|
-
anchorKey,
|
|
29
|
-
agendaDays = 30,
|
|
30
|
-
locale = 'en-US',
|
|
31
|
-
labels,
|
|
32
|
-
emptyState,
|
|
33
|
-
onSelectItem,
|
|
34
|
-
}: CalendarAgendaProps) => {
|
|
35
|
-
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
36
|
-
const today = todayKey();
|
|
37
|
-
const windowDays = Math.max(agendaDays, 1);
|
|
38
|
-
|
|
39
|
-
const groups = useMemo(() => {
|
|
40
|
-
const byDay = groupByDayKey(items);
|
|
41
|
-
const window: { dayKey: string; dayItems: CalendarItem[] }[] = [];
|
|
42
|
-
for (let offset = 0; offset < windowDays; offset += 1) {
|
|
43
|
-
const dayKey = addDaysKey(anchorKey, offset);
|
|
44
|
-
const dayItems = byDay.get(dayKey);
|
|
45
|
-
if (dayItems && dayItems.length > 0) window.push({ dayKey, dayItems });
|
|
46
|
-
}
|
|
47
|
-
return window;
|
|
48
|
-
}, [items, anchorKey, windowDays]);
|
|
49
|
-
|
|
50
|
-
if (groups.length === 0) {
|
|
51
|
-
return (
|
|
52
|
-
<div className="udb-cal-agenda-empty">
|
|
53
|
-
{emptyState ?? <p className="udb-cal-agenda-empty-text">{text.emptyDay}</p>}
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<div className="udb-cal-agenda">
|
|
60
|
-
{groups.map(({ dayKey, dayItems }) => (
|
|
61
|
-
<section
|
|
62
|
-
className={
|
|
63
|
-
dayKey === today ? 'udb-cal-agenda-group is-today' : 'udb-cal-agenda-group'
|
|
64
|
-
}
|
|
65
|
-
key={dayKey}
|
|
66
|
-
>
|
|
67
|
-
<header className="udb-cal-agenda-head">
|
|
68
|
-
<span className="udb-cal-agenda-date">{formatDayTitle(dayKey, locale)}</span>
|
|
69
|
-
{dayKey === today && <span className="udb-cal-agenda-today">{text.today}</span>}
|
|
70
|
-
<span className="udb-cal-agenda-count">{dayItems.length}</span>
|
|
71
|
-
</header>
|
|
72
|
-
<div className="udb-cal-agenda-rows">
|
|
73
|
-
{dayItems.map((item) => (
|
|
74
|
-
<button
|
|
75
|
-
type="button"
|
|
76
|
-
key={item.id}
|
|
77
|
-
className={
|
|
78
|
-
item.muted
|
|
79
|
-
? `udb-cal-agenda-item udb-cal-agenda-item--${item.tone ?? 'primary'} is-muted`
|
|
80
|
-
: `udb-cal-agenda-item udb-cal-agenda-item--${item.tone ?? 'primary'}`
|
|
81
|
-
}
|
|
82
|
-
onClick={() => onSelectItem?.(item)}
|
|
83
|
-
>
|
|
84
|
-
<span className="udb-cal-agenda-time">
|
|
85
|
-
{item.startMin !== undefined && minutesToLabel(item.startMin)}
|
|
86
|
-
{item.endMin !== undefined && (
|
|
87
|
-
<span className="udb-cal-agenda-time-end">– {minutesToLabel(item.endMin)}</span>
|
|
88
|
-
)}
|
|
89
|
-
</span>
|
|
90
|
-
<span className={`udb-cal-dot udb-cal-dot--${item.tone ?? 'primary'}`} />
|
|
91
|
-
<span className="udb-cal-agenda-body">
|
|
92
|
-
<span className="udb-cal-agenda-title">
|
|
93
|
-
{item.icon}
|
|
94
|
-
{item.title}
|
|
95
|
-
</span>
|
|
96
|
-
{item.meta && <span className="udb-cal-agenda-meta">{item.meta}</span>}
|
|
97
|
-
</span>
|
|
98
|
-
</button>
|
|
99
|
-
))}
|
|
100
|
-
</div>
|
|
101
|
-
</section>
|
|
102
|
-
))}
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { CalendarMonth } from './CalendarMonth';
|
|
4
|
-
import type { CalendarItem } from '../types/view.types';
|
|
5
|
-
|
|
6
|
-
const item = (id: string, dayKey: string, startMin?: number): CalendarItem => ({
|
|
7
|
-
id,
|
|
8
|
-
dayKey,
|
|
9
|
-
startMin,
|
|
10
|
-
title: id,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const mount = (props: Partial<Parameters<typeof CalendarMonth>[0]> = {}) =>
|
|
14
|
-
render(<CalendarMonth items={[]} anchorKey="2026-03-10" {...props} />);
|
|
15
|
-
|
|
16
|
-
describe('CalendarMonth', () => {
|
|
17
|
-
it('renders a six-by-seven matrix', () => {
|
|
18
|
-
const { container } = mount();
|
|
19
|
-
expect(container.querySelectorAll('[role="gridcell"]')).toHaveLength(42);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('places items on their day and reports selections', () => {
|
|
23
|
-
const onSelectItem = vi.fn();
|
|
24
|
-
mount({ items: [item('Kickoff', '2026-03-15', 600)], onSelectItem });
|
|
25
|
-
fireEvent.click(screen.getByText('Kickoff'));
|
|
26
|
-
expect(onSelectItem).toHaveBeenCalledTimes(1);
|
|
27
|
-
expect(onSelectItem.mock.calls[0]![0].id).toBe('Kickoff');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('caps chips per cell and overflows through the more label', () => {
|
|
31
|
-
const onSelectDay = vi.fn();
|
|
32
|
-
const items = [
|
|
33
|
-
item('one', '2026-03-15', 540),
|
|
34
|
-
item('two', '2026-03-15', 600),
|
|
35
|
-
item('three', '2026-03-15', 660),
|
|
36
|
-
item('four', '2026-03-15', 720),
|
|
37
|
-
];
|
|
38
|
-
mount({ items, maxPerDay: 2, onSelectDay });
|
|
39
|
-
expect(screen.getByText('one')).toBeTruthy();
|
|
40
|
-
expect(screen.getByText('two')).toBeTruthy();
|
|
41
|
-
expect(screen.queryByText('three')).toBeNull();
|
|
42
|
-
expect(screen.getByText('+2 more')).toBeTruthy();
|
|
43
|
-
fireEvent.click(screen.getByText('+2 more'));
|
|
44
|
-
expect(onSelectDay).toHaveBeenCalledWith('2026-03-15');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('supports label overrides for the overflow chip', () => {
|
|
48
|
-
const items = [item('one', '2026-03-15'), item('two', '2026-03-15'), item('three', '2026-03-15')];
|
|
49
|
-
mount({ items, maxPerDay: 1, labels: { more: '+{count} tane' } });
|
|
50
|
-
expect(screen.getByText('+2 tane')).toBeTruthy();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('fires day selection from the day number button', () => {
|
|
54
|
-
const onSelectDay = vi.fn();
|
|
55
|
-
mount({ onSelectDay });
|
|
56
|
-
fireEvent.click(screen.getByRole('button', { name: '2026-03-15' }));
|
|
57
|
-
expect(onSelectDay).toHaveBeenCalledWith('2026-03-15');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_CALENDAR_LABELS,
|
|
4
|
-
type CalendarItem,
|
|
5
|
-
type CalendarLabels,
|
|
6
|
-
} from '../types/view.types';
|
|
7
|
-
import {
|
|
8
|
-
formatDayNumber,
|
|
9
|
-
formatWeekdayShort,
|
|
10
|
-
groupByDayKey,
|
|
11
|
-
minutesToLabel,
|
|
12
|
-
monthMatrix,
|
|
13
|
-
sameMonth,
|
|
14
|
-
todayKey,
|
|
15
|
-
weekDays,
|
|
16
|
-
} from '../utils/layout';
|
|
17
|
-
|
|
18
|
-
export interface CalendarMonthProps {
|
|
19
|
-
items: readonly CalendarItem[];
|
|
20
|
-
anchorKey: string;
|
|
21
|
-
weekStartsOn?: 0 | 1;
|
|
22
|
-
locale?: string;
|
|
23
|
-
maxPerDay?: number;
|
|
24
|
-
labels?: Partial<CalendarLabels>;
|
|
25
|
-
onSelectDay?: (dayKey: string) => void;
|
|
26
|
-
onSelectItem?: (item: CalendarItem) => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const CalendarMonth = ({
|
|
30
|
-
items,
|
|
31
|
-
anchorKey,
|
|
32
|
-
weekStartsOn = 1,
|
|
33
|
-
locale = 'en-US',
|
|
34
|
-
maxPerDay = 3,
|
|
35
|
-
labels,
|
|
36
|
-
onSelectDay,
|
|
37
|
-
onSelectItem,
|
|
38
|
-
}: CalendarMonthProps) => {
|
|
39
|
-
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
40
|
-
const today = todayKey();
|
|
41
|
-
const cells = useMemo(() => monthMatrix(anchorKey, weekStartsOn), [anchorKey, weekStartsOn]);
|
|
42
|
-
const byDay = useMemo(() => groupByDayKey(items), [items]);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<div className="udb-cal-month" role="grid">
|
|
46
|
-
<div className="udb-cal-month-head" role="row">
|
|
47
|
-
{weekDays(anchorKey, weekStartsOn).map((dayKey) => (
|
|
48
|
-
<div className="udb-cal-month-weekday" role="columnheader" key={dayKey}>
|
|
49
|
-
{formatWeekdayShort(dayKey, locale)}
|
|
50
|
-
</div>
|
|
51
|
-
))}
|
|
52
|
-
</div>
|
|
53
|
-
<div className="udb-cal-month-body">
|
|
54
|
-
{cells.map((dayKey) => {
|
|
55
|
-
const dayItems = byDay.get(dayKey) ?? [];
|
|
56
|
-
const visible = dayItems.slice(0, maxPerDay);
|
|
57
|
-
const overflow = dayItems.length - visible.length;
|
|
58
|
-
return (
|
|
59
|
-
<div
|
|
60
|
-
className={
|
|
61
|
-
sameMonth(dayKey, anchorKey) ? 'udb-cal-month-cell' : 'udb-cal-month-cell is-outside'
|
|
62
|
-
}
|
|
63
|
-
role="gridcell"
|
|
64
|
-
key={dayKey}
|
|
65
|
-
>
|
|
66
|
-
<button
|
|
67
|
-
type="button"
|
|
68
|
-
className={dayKey === today ? 'udb-cal-month-daynum is-today' : 'udb-cal-month-daynum'}
|
|
69
|
-
onClick={() => onSelectDay?.(dayKey)}
|
|
70
|
-
aria-label={dayKey}
|
|
71
|
-
>
|
|
72
|
-
{formatDayNumber(dayKey)}
|
|
73
|
-
</button>
|
|
74
|
-
<div className="udb-cal-month-chips">
|
|
75
|
-
{visible.map((item) => (
|
|
76
|
-
<button
|
|
77
|
-
type="button"
|
|
78
|
-
key={item.id}
|
|
79
|
-
className={
|
|
80
|
-
item.muted
|
|
81
|
-
? `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'} is-muted`
|
|
82
|
-
: `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'}`
|
|
83
|
-
}
|
|
84
|
-
onClick={() => onSelectItem?.(item)}
|
|
85
|
-
>
|
|
86
|
-
{item.icon}
|
|
87
|
-
{item.startMin !== undefined && (
|
|
88
|
-
<span className="udb-cal-chip-time">{minutesToLabel(item.startMin)}</span>
|
|
89
|
-
)}
|
|
90
|
-
<span className="udb-cal-chip-title">{item.title}</span>
|
|
91
|
-
</button>
|
|
92
|
-
))}
|
|
93
|
-
{overflow > 0 && (
|
|
94
|
-
<button
|
|
95
|
-
type="button"
|
|
96
|
-
className="udb-cal-chip-more"
|
|
97
|
-
onClick={() => onSelectDay?.(dayKey)}
|
|
98
|
-
>
|
|
99
|
-
{text.more.replace('{count}', String(overflow))}
|
|
100
|
-
</button>
|
|
101
|
-
)}
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
})}
|
|
106
|
-
</div>
|
|
107
|
-
</div>
|
|
108
|
-
);
|
|
109
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { CalendarResourceTimeline } from './CalendarResourceTimeline';
|
|
4
|
-
import type { CalendarItem } from '../types/view.types';
|
|
5
|
-
|
|
6
|
-
const item = (id: string, resourceId: string, startMin: number, endMin: number): CalendarItem => ({
|
|
7
|
-
id,
|
|
8
|
-
dayKey: '2026-03-15',
|
|
9
|
-
resourceId,
|
|
10
|
-
startMin,
|
|
11
|
-
endMin,
|
|
12
|
-
title: id,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const resources = [
|
|
16
|
-
{ id: 'room-1', label: 'Salle Lumière' },
|
|
17
|
-
{ id: 'room-2', label: 'Salle Méliès' },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
const mount = (props: Partial<Parameters<typeof CalendarResourceTimeline>[0]> = {}) =>
|
|
21
|
-
render(<CalendarResourceTimeline resources={resources} items={[]} {...props} />);
|
|
22
|
-
|
|
23
|
-
const numberIn = (value: string): number => parseFloat(value.replace(/^calc\(/, ''));
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
vi.restoreAllMocks();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('CalendarResourceTimeline', () => {
|
|
30
|
-
it('renders one row per resource and drops items without a matching resource', () => {
|
|
31
|
-
const { container } = mount({
|
|
32
|
-
items: [item('Screening', 'room-1', 600, 660), item('Orphan', 'room-9', 660, 720)],
|
|
33
|
-
});
|
|
34
|
-
const rows = container.querySelectorAll('.udb-cal-res-row');
|
|
35
|
-
expect(rows).toHaveLength(2);
|
|
36
|
-
expect(screen.getByText('Salle Lumière')).toBeTruthy();
|
|
37
|
-
expect(screen.queryByText('Orphan')).toBeNull();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('positions blocks along the horizontal minute axis', () => {
|
|
41
|
-
mount({ items: [item('Screening', 'room-1', 600, 660)] });
|
|
42
|
-
const block = screen.getByText('Screening').closest('button') as HTMLElement;
|
|
43
|
-
expect(numberIn(block.style.left)).toBeCloseTo(21.4286, 3);
|
|
44
|
-
expect(numberIn(block.style.width)).toBeCloseTo(7.1429, 3);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('splits overlapping blocks on the same resource into columns', () => {
|
|
48
|
-
mount({ items: [item('first', 'room-1', 600, 660), item('second', 'room-1', 630, 690)] });
|
|
49
|
-
const first = screen.getByText('first').closest('button') as HTMLElement;
|
|
50
|
-
const second = screen.getByText('second').closest('button') as HTMLElement;
|
|
51
|
-
expect(numberIn(first.style.width)).toBeCloseTo(3.5714, 3);
|
|
52
|
-
expect(numberIn(second.style.width)).toBeCloseTo(3.5714, 3);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('quantizes lane clicks to slot boundaries', () => {
|
|
56
|
-
const onSlotClick = vi.fn();
|
|
57
|
-
const { container } = mount({
|
|
58
|
-
items: [item('Screening', 'room-1', 600, 660)],
|
|
59
|
-
onSlotClick,
|
|
60
|
-
});
|
|
61
|
-
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
|
|
62
|
-
top: 0,
|
|
63
|
-
height: 56,
|
|
64
|
-
bottom: 56,
|
|
65
|
-
left: 0,
|
|
66
|
-
right: 400,
|
|
67
|
-
width: 400,
|
|
68
|
-
x: 0,
|
|
69
|
-
y: 0,
|
|
70
|
-
toJSON: () => ({}),
|
|
71
|
-
} as DOMRect);
|
|
72
|
-
const lane = container.querySelector('.udb-cal-res-lane') as HTMLElement;
|
|
73
|
-
fireEvent.click(lane, { clientX: 100 });
|
|
74
|
-
expect(onSlotClick).toHaveBeenCalledWith('room-1', 630);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('reports item selection with the payload round-trip', () => {
|
|
78
|
-
const onSelectItem = vi.fn();
|
|
79
|
-
mount({
|
|
80
|
-
items: [{ ...item('Screening', 'room-1', 600, 660), payload: { screeningId: 42 } }],
|
|
81
|
-
onSelectItem,
|
|
82
|
-
});
|
|
83
|
-
fireEvent.click(screen.getByText('Screening'));
|
|
84
|
-
expect(onSelectItem).toHaveBeenCalledWith(
|
|
85
|
-
expect.objectContaining({ id: 'Screening', payload: { screeningId: 42 } }),
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('falls back to the default empty label when nothing is scheduled', () => {
|
|
90
|
-
mount();
|
|
91
|
-
expect(screen.getByText('Nothing scheduled')).toBeTruthy();
|
|
92
|
-
});
|
|
93
|
-
});
|