Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | 8x 12x 6x 2x 4x 2x 4x 6x 10x 1x 1x 5x 5x 5x 11x 5x 5x 2x 5x 5x 35x 742x 35x 80x 10x 10x 5x 4x 5x 9x 9x 20x 105x 42x 105x 147x 80x 80x 80x 160x 80x 80x 44x 44x 80x 44x 80x 80x 168x 123x 44x 168x 168x 256x 168x | import { Badge } from "@/ahuora-design-system/ui/badge";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import type { CompositeSchedulePlanPayload } from "@/api/apiStore.gen";
import {
ScheduleTimelineSourceKind,
ScheduleValidationStatus,
} from "@/api/apiStore.gen";
import {
DAY_LABELS,
paletteForBlock,
SOURCE_PALETTE,
TIMETABLE_AXIS_LABELS,
type TimetableDisplayBlock,
timeRangeLabel,
timeToHours,
timetableBlocks,
} from "./scheduleFormatting";
export function CompositeScheduleDiagnostics({
plan,
fallbackError,
}: {
plan?: CompositeSchedulePlanPayload;
fallbackError: string;
}) {
const diagnostics = plan?.diagnostics ?? [];
Iif (!fallbackError && diagnostics.length === 0) return null;
return (
<div className="grid gap-1 text-sm" aria-live="polite">
{fallbackError && (
<span className="text-destructive">{fallbackError}</span>
)}
{diagnostics.map((diagnostic, index) => (
<span
key={`${diagnostic.code}-${index}`}
className={
diagnostic.severity === "error"
? "text-destructive"
: "text-muted-foreground"
}
>
{diagnostic.message}
</span>
))}
</div>
);
}
export function CompositeScheduleTimetable({
plan,
}: {
plan?: CompositeSchedulePlanPayload;
}) {
if (!plan) {
return (
<div className="rounded-md border bg-muted/10 p-3 text-sm text-muted-foreground">
Update the composite schedule to see the weekly timetable.
</div>
);
}
return (
<div className="rounded-md border">
<div className="flex flex-wrap items-center justify-between gap-2 border-b px-3 py-2">
<div className="text-sm font-medium">Timetable preview</div>
<Badge
variant={
plan.status === ScheduleValidationStatus.Valid
? "success"
: "secondary"
}
size="xs"
borderRadius="round"
>
{plan.status === ScheduleValidationStatus.Valid
? "Valid"
: "Needs attention"}
</Badge>
</div>
<div className="px-3 py-3" aria-label="Weekly schedule timetable viewer">
<div className="grid grid-cols-[3.25rem_minmax(0,1fr)] gap-x-3 gap-y-1.5">
<div />
<div className="relative h-5 text-[11px] text-muted-foreground">
{TIMETABLE_AXIS_LABELS.map((label, index) => (
<span
key={label}
className="absolute top-0 -translate-x-1/2 tabular-nums"
style={{
left: `${
(index / (TIMETABLE_AXIS_LABELS.length - 1)) * 100
}%`,
}}
>
{label}
</span>
))}
</div>
{DAY_LABELS.map((label, dayIndex) => {
const daySteps = plan.timeline.filter(
(step) => Number(step.day) === dayIndex,
);
const blocks = timetableBlocks(daySteps);
return (
<div key={label} className="contents">
<div className="flex h-8 items-center text-sm font-medium text-muted-foreground">
{label}
</div>
<div
className="relative h-8 overflow-hidden rounded-sm bg-muted/10"
aria-label={`${label} timetable`}
>
<TimelineTick leftPercent={25} />
<TimelineTick leftPercent={50} />
<TimelineTick leftPercent={75} />
{blocks.length ? (
blocks.map((block) => (
<TimetableBlock
key={block.key}
block={block}
palette={paletteForBlock(plan, block)}
/>
))
) : (
<span className="flex h-full items-center px-2 text-xs text-muted-foreground">
Off
</span>
)}
</div>
</div>
);
})}
</div>
</div>
<div className="flex flex-wrap gap-x-3 gap-y-1 border-t px-3 py-2 text-xs text-muted-foreground">
<span className="inline-flex items-center gap-1.5">
<span className="size-2.5 rounded-sm bg-muted-foreground/40" />
Off period
</span>
{plan.sources.map((source, index) => {
const palette = SOURCE_PALETTE[index % SOURCE_PALETTE.length];
return (
<span
key={source.id}
className="inline-flex min-w-0 items-center gap-1.5"
>
<span
className={`size-2.5 shrink-0 rounded-sm ${palette.swatch}`}
/>
<span className="truncate">{source.name}</span>
</span>
);
})}
</div>
</div>
);
}
function TimelineTick({ leftPercent }: { leftPercent: number }) {
return (
<div
className="pointer-events-none absolute inset-y-0 w-px bg-muted-foreground/10"
style={{ left: `${leftPercent}%` }}
/>
);
}
function TimetableBlock({
block,
palette,
}: {
block: TimetableDisplayBlock;
palette: (typeof SOURCE_PALETTE)[number];
}) {
const scheduled =
block.source_kind === ScheduleTimelineSourceKind.ScheduledSource;
const label = scheduled
? block.source_rule_label || block.source_scenario_name || "Scheduled"
: "Off";
const range = timeRangeLabel(block);
const compact = scheduled && block.duration_hours < 5;
const title = scheduled
? `${range} ${label}, ${block.source_row_count} source row${
block.source_row_count === 1 ? "" : "s"
}`
: `${range} Off period`;
return (
<ToolTipCover asChild content={title} delay={0}>
<span
aria-label={title}
className={`absolute inset-y-0 flex items-center overflow-hidden rounded-sm px-2 text-xs ${
scheduled ? palette.block : "bg-transparent text-muted-foreground"
}`}
style={{
left: `${(timeToHours(block.start_time) / 24) * 100}%`,
width: `${(block.duration_hours / 24) * 100}%`,
}}
>
<span className="flex min-w-0 items-center gap-1.5">
<span className="truncate font-medium">{label}</span>
{!compact ? (
<span className="hidden shrink-0 tabular-nums opacity-75 sm:inline">
{range}
</span>
) : null}
</span>
</span>
</ToolTipCover>
);
}
|