@umituz/web-dashboard 8.7.0 → 8.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/package.json +1 -1
- package/src/domains/calendar/calendar.css +186 -8
- package/src/domains/calendar/components/CalendarResourceTimeline.test.tsx +93 -0
- package/src/domains/calendar/components/CalendarResourceTimeline.tsx +164 -0
- package/src/domains/calendar/components/CalendarTimeGrid.test.tsx +27 -0
- package/src/domains/calendar/components/CalendarTimeGrid.tsx +46 -8
- package/src/domains/calendar/components/index.ts +5 -0
- package/src/domains/calendar/types/view.types.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
.udb-cal-dot--primary,
|
|
69
69
|
.udb-cal-chip--primary,
|
|
70
70
|
.udb-cal-event--primary,
|
|
71
|
-
.udb-cal-agenda-item--primary
|
|
71
|
+
.udb-cal-agenda-item--primary,
|
|
72
|
+
.udb-cal-res-block--primary {
|
|
72
73
|
background: color-mix(in srgb, var(--color-primary, #2563eb) 12%, transparent);
|
|
73
74
|
color: var(--color-primary, #2563eb);
|
|
74
75
|
}
|
|
@@ -76,7 +77,8 @@
|
|
|
76
77
|
.udb-cal-dot--success,
|
|
77
78
|
.udb-cal-chip--success,
|
|
78
79
|
.udb-cal-event--success,
|
|
79
|
-
.udb-cal-agenda-item--success
|
|
80
|
+
.udb-cal-agenda-item--success,
|
|
81
|
+
.udb-cal-res-block--success {
|
|
80
82
|
background: color-mix(in srgb, var(--color-success, #16a34a) 12%, transparent);
|
|
81
83
|
color: var(--color-success, #16a34a);
|
|
82
84
|
}
|
|
@@ -84,7 +86,8 @@
|
|
|
84
86
|
.udb-cal-dot--warning,
|
|
85
87
|
.udb-cal-chip--warning,
|
|
86
88
|
.udb-cal-event--warning,
|
|
87
|
-
.udb-cal-agenda-item--warning
|
|
89
|
+
.udb-cal-agenda-item--warning,
|
|
90
|
+
.udb-cal-res-block--warning {
|
|
88
91
|
background: color-mix(in srgb, var(--color-warning, #d97706) 16%, transparent);
|
|
89
92
|
color: var(--color-warning, #d97706);
|
|
90
93
|
}
|
|
@@ -92,7 +95,8 @@
|
|
|
92
95
|
.udb-cal-dot--danger,
|
|
93
96
|
.udb-cal-chip--danger,
|
|
94
97
|
.udb-cal-event--danger,
|
|
95
|
-
.udb-cal-agenda-item--danger
|
|
98
|
+
.udb-cal-agenda-item--danger,
|
|
99
|
+
.udb-cal-res-block--danger {
|
|
96
100
|
background: color-mix(in srgb, var(--color-destructive, #dc2626) 12%, transparent);
|
|
97
101
|
color: var(--color-destructive, #dc2626);
|
|
98
102
|
}
|
|
@@ -100,7 +104,8 @@
|
|
|
100
104
|
.udb-cal-dot--info,
|
|
101
105
|
.udb-cal-chip--info,
|
|
102
106
|
.udb-cal-event--info,
|
|
103
|
-
.udb-cal-agenda-item--info
|
|
107
|
+
.udb-cal-agenda-item--info,
|
|
108
|
+
.udb-cal-res-block--info {
|
|
104
109
|
background: color-mix(in srgb, var(--color-info, #0891b2) 12%, transparent);
|
|
105
110
|
color: var(--color-info, #0891b2);
|
|
106
111
|
}
|
|
@@ -108,7 +113,8 @@
|
|
|
108
113
|
.udb-cal-dot--accent,
|
|
109
114
|
.udb-cal-chip--accent,
|
|
110
115
|
.udb-cal-event--accent,
|
|
111
|
-
.udb-cal-agenda-item--accent
|
|
116
|
+
.udb-cal-agenda-item--accent,
|
|
117
|
+
.udb-cal-res-block--accent {
|
|
112
118
|
background: color-mix(in srgb, var(--color-accent, #7c3aed) 12%, transparent);
|
|
113
119
|
color: var(--color-accent, #7c3aed);
|
|
114
120
|
}
|
|
@@ -119,7 +125,8 @@
|
|
|
119
125
|
|
|
120
126
|
.udb-cal-chip--neutral,
|
|
121
127
|
.udb-cal-event--neutral,
|
|
122
|
-
.udb-cal-agenda-item--neutral
|
|
128
|
+
.udb-cal-agenda-item--neutral,
|
|
129
|
+
.udb-cal-res-block--neutral {
|
|
123
130
|
background: var(--color-secondary, #f1f5f9);
|
|
124
131
|
color: var(--color-secondary-foreground, #334155);
|
|
125
132
|
}
|
|
@@ -249,6 +256,55 @@
|
|
|
249
256
|
grid-template-columns: 3.5rem repeat(var(--udb-cal-days, 1), minmax(0, 1fr));
|
|
250
257
|
}
|
|
251
258
|
|
|
259
|
+
.udb-cal-days {
|
|
260
|
+
grid-column: 1 / -1;
|
|
261
|
+
display: grid;
|
|
262
|
+
grid-template-columns: 3.5rem repeat(var(--udb-cal-days, 1), minmax(0, 1fr));
|
|
263
|
+
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.udb-cal-days-corner {
|
|
267
|
+
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.udb-cal-days .udb-cal-day-head + .udb-cal-day-head {
|
|
271
|
+
border-left: 1px solid var(--color-border, #e2e8f0);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.udb-cal-allday {
|
|
275
|
+
grid-column: 1 / -1;
|
|
276
|
+
display: grid;
|
|
277
|
+
grid-template-columns: 3.5rem repeat(var(--udb-cal-days, 1), minmax(0, 1fr));
|
|
278
|
+
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
279
|
+
background: color-mix(in srgb, var(--color-muted, #f8fafc) 45%, transparent);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.udb-cal-allday-corner {
|
|
283
|
+
display: flex;
|
|
284
|
+
align-items: center;
|
|
285
|
+
justify-content: flex-end;
|
|
286
|
+
padding-right: 8px;
|
|
287
|
+
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
288
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
289
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.udb-cal-allday-cell {
|
|
293
|
+
display: flex;
|
|
294
|
+
flex-wrap: wrap;
|
|
295
|
+
align-content: center;
|
|
296
|
+
gap: 3px;
|
|
297
|
+
padding: 4px 6px;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.udb-cal-allday-cell + .udb-cal-allday-cell {
|
|
301
|
+
border-left: 1px solid var(--color-border, #eef2f7);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.udb-cal-allday-cell .udb-cal-chip {
|
|
305
|
+
max-width: 100%;
|
|
306
|
+
}
|
|
307
|
+
|
|
252
308
|
.udb-cal-gutter {
|
|
253
309
|
position: relative;
|
|
254
310
|
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
@@ -273,7 +329,6 @@
|
|
|
273
329
|
justify-content: center;
|
|
274
330
|
gap: 6px;
|
|
275
331
|
padding: 8px 4px;
|
|
276
|
-
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
277
332
|
}
|
|
278
333
|
|
|
279
334
|
.udb-cal-day-head.is-today .udb-cal-daynum {
|
|
@@ -470,3 +525,126 @@
|
|
|
470
525
|
margin: 0;
|
|
471
526
|
color: var(--color-muted-foreground, #94a3b8);
|
|
472
527
|
}
|
|
528
|
+
|
|
529
|
+
.udb-cal-res {
|
|
530
|
+
border: 1px solid var(--color-border, #e2e8f0);
|
|
531
|
+
border-radius: 12px;
|
|
532
|
+
background: var(--color-card, #ffffff);
|
|
533
|
+
color: var(--color-foreground, #0f172a);
|
|
534
|
+
overflow: hidden;
|
|
535
|
+
font-size: var(--udb-font-size-sm, 12px);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.udb-cal-res-axis {
|
|
539
|
+
position: relative;
|
|
540
|
+
height: 26px;
|
|
541
|
+
margin-left: var(--udb-cal-res-label-width, 11rem);
|
|
542
|
+
border-bottom: 1px solid var(--color-border, #e2e8f0);
|
|
543
|
+
background: color-mix(in srgb, var(--color-muted, #f8fafc) 60%, transparent);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
.udb-cal-res-axis-label {
|
|
547
|
+
position: absolute;
|
|
548
|
+
top: 6px;
|
|
549
|
+
transform: translateX(-50%);
|
|
550
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
551
|
+
font-size: 10px;
|
|
552
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
.udb-cal-res-row {
|
|
556
|
+
display: grid;
|
|
557
|
+
grid-template-columns: var(--udb-cal-res-label-width, 11rem) minmax(0, 1fr);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
.udb-cal-res-row + .udb-cal-res-row {
|
|
561
|
+
border-top: 1px solid var(--color-border, #e2e8f0);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.udb-cal-res-label {
|
|
565
|
+
display: flex;
|
|
566
|
+
flex-direction: column;
|
|
567
|
+
justify-content: center;
|
|
568
|
+
gap: 1px;
|
|
569
|
+
min-width: 0;
|
|
570
|
+
padding: 6px 12px;
|
|
571
|
+
border-right: 1px solid var(--color-border, #e2e8f0);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.udb-cal-res-name {
|
|
575
|
+
overflow: hidden;
|
|
576
|
+
text-overflow: ellipsis;
|
|
577
|
+
white-space: nowrap;
|
|
578
|
+
font-weight: 600;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.udb-cal-res-meta {
|
|
582
|
+
overflow: hidden;
|
|
583
|
+
text-overflow: ellipsis;
|
|
584
|
+
white-space: nowrap;
|
|
585
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
586
|
+
color: var(--color-muted-foreground, #64748b);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
.udb-cal-res-lane {
|
|
590
|
+
position: relative;
|
|
591
|
+
min-height: 56px;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
.udb-cal-res-hour {
|
|
595
|
+
position: absolute;
|
|
596
|
+
top: 0;
|
|
597
|
+
bottom: 0;
|
|
598
|
+
border-left: 1px solid var(--color-border, #eef2f7);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.udb-cal-res-block {
|
|
602
|
+
position: absolute;
|
|
603
|
+
top: 5px;
|
|
604
|
+
bottom: 5px;
|
|
605
|
+
display: flex;
|
|
606
|
+
flex-direction: column;
|
|
607
|
+
gap: 1px;
|
|
608
|
+
padding: 2px 6px;
|
|
609
|
+
border: none;
|
|
610
|
+
border-left: 3px solid currentColor;
|
|
611
|
+
border-radius: 5px;
|
|
612
|
+
overflow: hidden;
|
|
613
|
+
text-align: left;
|
|
614
|
+
font-size: var(--udb-font-size-xs, 11px);
|
|
615
|
+
font-weight: 500;
|
|
616
|
+
cursor: pointer;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
.udb-cal-res-block:focus-visible {
|
|
620
|
+
outline: 2px solid var(--color-ring, #2563eb);
|
|
621
|
+
outline-offset: 1px;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.udb-cal-res-block.is-muted {
|
|
625
|
+
opacity: 0.45;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
.udb-cal-res-block-time {
|
|
629
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
630
|
+
font-size: 10px;
|
|
631
|
+
opacity: 0.8;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
.udb-cal-res-block-title {
|
|
635
|
+
overflow: hidden;
|
|
636
|
+
text-overflow: ellipsis;
|
|
637
|
+
white-space: nowrap;
|
|
638
|
+
font-weight: 600;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
.udb-cal-res-empty {
|
|
642
|
+
display: grid;
|
|
643
|
+
place-items: center;
|
|
644
|
+
padding: 48px 16px;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.udb-cal-res-empty-text {
|
|
648
|
+
margin: 0;
|
|
649
|
+
color: var(--color-muted-foreground, #94a3b8);
|
|
650
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
};
|
|
@@ -69,4 +69,31 @@ describe('CalendarTimeGrid', () => {
|
|
|
69
69
|
expect.objectContaining({ id: 'Consult' }),
|
|
70
70
|
);
|
|
71
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
|
+
});
|
|
72
99
|
});
|
|
@@ -54,7 +54,10 @@ export const CalendarTimeGrid = ({
|
|
|
54
54
|
}, [dayStartMin, dayEndMin]);
|
|
55
55
|
|
|
56
56
|
const timed = useMemo(() => items.filter((item) => item.startMin !== undefined), [items]);
|
|
57
|
-
const
|
|
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);
|
|
58
61
|
|
|
59
62
|
const positionOf = (minute: number): string =>
|
|
60
63
|
`${((minute - dayStartMin) / total) * 100}%`;
|
|
@@ -74,6 +77,44 @@ export const CalendarTimeGrid = ({
|
|
|
74
77
|
className="udb-cal-grid"
|
|
75
78
|
style={{ ['--udb-cal-days' as string]: days.length } as CSSProperties}
|
|
76
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
|
+
|
|
77
118
|
<div className="udb-cal-gutter" aria-hidden="true">
|
|
78
119
|
{hours.map((minute) => (
|
|
79
120
|
<div className="udb-cal-hour-label" style={{ top: positionOf(minute) }} key={minute}>
|
|
@@ -83,13 +124,10 @@ export const CalendarTimeGrid = ({
|
|
|
83
124
|
</div>
|
|
84
125
|
|
|
85
126
|
{days.map((dayKey) => {
|
|
86
|
-
const
|
|
127
|
+
const laneItems = timedByDay.get(dayKey) ?? [];
|
|
128
|
+
const dayCount = laneItems.length + (untimedByDay.get(dayKey)?.length ?? 0);
|
|
87
129
|
return (
|
|
88
130
|
<section className="udb-cal-day" aria-label={dayKey} key={dayKey}>
|
|
89
|
-
<header className={dayKey === today ? 'udb-cal-day-head is-today' : 'udb-cal-day-head'}>
|
|
90
|
-
<span className="udb-cal-weekday">{formatWeekdayShort(dayKey, locale)}</span>
|
|
91
|
-
<span className="udb-cal-daynum">{formatDayNumber(dayKey)}</span>
|
|
92
|
-
</header>
|
|
93
131
|
<div
|
|
94
132
|
className="udb-cal-lane"
|
|
95
133
|
role="grid"
|
|
@@ -103,7 +141,7 @@ export const CalendarTimeGrid = ({
|
|
|
103
141
|
key={minute}
|
|
104
142
|
/>
|
|
105
143
|
))}
|
|
106
|
-
{layoutColumns(
|
|
144
|
+
{layoutColumns(laneItems).map(({ item, column, columns }) => {
|
|
107
145
|
const geometry = eventGeometry(item, dayStartMin, dayEndMin);
|
|
108
146
|
return (
|
|
109
147
|
<button
|
|
@@ -133,7 +171,7 @@ export const CalendarTimeGrid = ({
|
|
|
133
171
|
</button>
|
|
134
172
|
);
|
|
135
173
|
})}
|
|
136
|
-
{days.length === 1 &&
|
|
174
|
+
{days.length === 1 && dayCount === 0 &&
|
|
137
175
|
(emptyState ?? <p className="udb-cal-empty">{text.emptyDay}</p>)}
|
|
138
176
|
</div>
|
|
139
177
|
</section>
|
|
@@ -6,3 +6,8 @@ export { CalendarMonth } from './CalendarMonth';
|
|
|
6
6
|
export type { CalendarMonthProps } from './CalendarMonth';
|
|
7
7
|
export { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
8
8
|
export type { CalendarTimeGridProps } from './CalendarTimeGrid';
|
|
9
|
+
export { CalendarResourceTimeline } from './CalendarResourceTimeline';
|
|
10
|
+
export type {
|
|
11
|
+
CalendarResource,
|
|
12
|
+
CalendarResourceTimelineProps,
|
|
13
|
+
} from './CalendarResourceTimeline';
|
|
@@ -16,6 +16,7 @@ export interface CalendarItem {
|
|
|
16
16
|
kind?: string;
|
|
17
17
|
muted?: boolean;
|
|
18
18
|
payload?: unknown;
|
|
19
|
+
resourceId?: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export interface CalendarLegendEntry {
|
|
@@ -31,6 +32,7 @@ export interface CalendarLabels {
|
|
|
31
32
|
week: string;
|
|
32
33
|
day: string;
|
|
33
34
|
agenda: string;
|
|
35
|
+
allDay: string;
|
|
34
36
|
more: string;
|
|
35
37
|
emptyDay: string;
|
|
36
38
|
}
|
|
@@ -43,6 +45,7 @@ export const DEFAULT_CALENDAR_LABELS: CalendarLabels = {
|
|
|
43
45
|
week: 'Week',
|
|
44
46
|
day: 'Day',
|
|
45
47
|
agenda: 'Agenda',
|
|
48
|
+
allDay: 'All day',
|
|
46
49
|
more: '+{count} more',
|
|
47
50
|
emptyDay: 'Nothing scheduled',
|
|
48
51
|
};
|