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 | 50x 32x 32x 5x 32x 32x 32x 32x 64x 32x 32x 37x 5x 5x 37x 37x 192x 32x 32x 32x 32x 32x 128x 96x 96x 5x 32x 32x 32x 64x 32x 32x 37x 5x 32x 160x 32x 32x 32x 64x 160x 5x 32x 32x 32x 32x 32x 64x 64x 192x 32x 32x 32x 32x 128x 96x 192x 32x 5x 37x 32x 37x 64x 160x 96x | import { ArrowUpRight, Trash2 } from "lucide-react";
import { Button } from "@/ahuora-design-system/ui/button";
import { Input } from "@/ahuora-design-system/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/ahuora-design-system/ui/select";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import type {
CompositeScheduleRuleDraft,
ScheduleScenarioOption,
} from "@/api/apiStore.gen";
import { DAY_GROUPS } from "./scheduleEditorModel";
export function CompositeScheduleRuleRow({
rule,
index,
canEdit,
options,
sourceNavigationDisabled,
onChange,
onDraftChange,
onCommit,
onRemove,
onOpenSource,
}: {
rule: CompositeScheduleRuleDraft;
index: number;
canEdit: boolean;
options: ScheduleScenarioOption[];
sourceNavigationDisabled: boolean;
onChange: (patch: Partial<CompositeScheduleRuleDraft>) => void;
onDraftChange: (patch: Partial<CompositeScheduleRuleDraft>) => void;
onCommit: (patch: Partial<CompositeScheduleRuleDraft>) => void;
onRemove: () => void;
onOpenSource: () => void;
}) {
const sourceNavigationHelp = sourceNavigationDisabled
? "Wait for the composite schedule to finish saving."
: "Open source scenario";
return (
<div
className="grid gap-2 rounded-md border bg-muted/10 p-2 md:grid-cols-[minmax(8rem,1fr)_minmax(8rem,1fr)_7rem_minmax(8rem,1fr)_auto]"
aria-label={`Composite schedule rule ${index + 1}`}
>
<div className="space-y-1">
<label className="text-xs font-medium text-muted-foreground">
Source
</label>
<div className="flex gap-1">
<Select
value={rule.source_scenario ? String(rule.source_scenario) : ""}
disabled={!canEdit}
onValueChange={(value) =>
onChange({ source_scenario: Number(value) })
}
>
<SelectTrigger aria-label={`Source scenario for rule ${index + 1}`}>
<SelectValue placeholder="Select source" />
</SelectTrigger>
<SelectContent>
{options.map((option) => (
<SelectItem key={option.id} value={String(option.id)}>
{option.name}
</SelectItem>
))}
</SelectContent>
</Select>
<ToolTipCover asChild content={sourceNavigationHelp} delay={0}>
<Button
type="button"
variant="ghost"
size="icon"
aria-label={`Open source scenario for rule ${index + 1}`}
disabled={!rule.source_scenario || sourceNavigationDisabled}
onClick={onOpenSource}
>
<ArrowUpRight className="size-4" />
</Button>
</ToolTipCover>
</div>
</div>
<div className="space-y-1">
<label className="text-xs font-medium text-muted-foreground">
Days
</label>
<Select
value={String(rule.days_mask)}
disabled={!canEdit}
onValueChange={(value) => onChange({ days_mask: Number(value) })}
>
<SelectTrigger aria-label={`Days for rule ${index + 1}`}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{DAY_GROUPS.map((group) => (
<SelectItem key={group.value} value={String(group.value)}>
{group.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<TimeInput
label="Start"
ariaLabel={`Start time for rule ${index + 1}`}
value={rule.start_time}
disabled={!canEdit}
onChange={(start_time) => onChange({ start_time })}
/>
<div className="flex items-end gap-2">
<div className="min-w-0 flex-1 space-y-1">
<label className="text-xs font-medium text-muted-foreground">
Label
</label>
<Input
value={rule.label ?? ""}
disabled={!canEdit}
maxLength={128}
aria-label={`Label for rule ${index + 1}`}
onChange={(event) =>
onDraftChange({ label: event.currentTarget.value })
}
onBlur={(event) => onCommit({ label: event.currentTarget.value })}
onKeyDown={(event) => {
Iif (event.key !== "Enter") return;
event.preventDefault();
event.currentTarget.blur();
}}
/>
</div>
<ToolTipCover asChild content="Remove rule" delay={0}>
<Button
type="button"
variant="ghost"
size="icon"
aria-label={`Remove composite schedule rule ${index + 1}`}
disabled={!canEdit}
onClick={onRemove}
>
<Trash2 className="size-4" />
</Button>
</ToolTipCover>
</div>
</div>
);
}
function TimeInput({
label,
ariaLabel,
value,
disabled,
onChange,
}: {
label: string;
ariaLabel: string;
value: string;
disabled: boolean;
onChange: (value: string) => void;
}) {
return (
<div className="space-y-1">
<label className="text-xs font-medium text-muted-foreground">
{label}
</label>
<Input
type="time"
value={value.slice(0, 5)}
disabled={disabled}
aria-label={ariaLabel}
className="dark:[color-scheme:dark]"
onChange={(event) => onChange(event.currentTarget.value)}
/>
</div>
);
}
|