fix(web): disable recurrence controls on the alternate-schedules default row
The last row in the alternate-schedules editor is the catch-all default: ReplacePlayoutAlternateScheduleItemsHandler excludes the highest-index item from the saved rows entirely and only keeps its ProgramScheduleId as the playout's default schedule, so any recurrence edits made to that row (days of week/month, months, date range) were silently discarded on save. Disable the recurrence controls (chips, selects, limit-to-date-range checkbox) whenever the selected row is the default, and show an inline note explaining why. The Templates editor is unaffected — its handler saves every row's recurrence fields as-is, so RecurrenceFields there keeps full editing.
This commit is contained in:
@@ -162,6 +162,32 @@ describe('PlayoutAlternateSchedulesScreen', () => {
|
||||
expect(await screen.findByText('Start day')).toBeInTheDocument();
|
||||
expect(screen.getByText('End day')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables recurrence controls and shows a note when the default (last) row is selected', async () => {
|
||||
mockAltApi();
|
||||
render(<PlayoutAlternateSchedulesScreen playoutId={5} />);
|
||||
|
||||
fireEvent.click(await screen.findByText('Beta'));
|
||||
|
||||
expect(await screen.findByText('Edit schedule')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('The default entry always matches every day; reorder it above another entry to scope it.')
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByRole('checkbox')).toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
|
||||
it('leaves recurrence controls enabled for a non-default row', async () => {
|
||||
mockAltApi();
|
||||
render(<PlayoutAlternateSchedulesScreen playoutId={5} />);
|
||||
|
||||
fireEvent.click(await screen.findByText('Alpha'));
|
||||
|
||||
expect(await screen.findByText('Edit schedule')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText('The default entry always matches every day; reorder it above another entry to scope it.')
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('checkbox')).toHaveAttribute('aria-disabled', 'false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PlayoutTemplatesEditorScreen', () => {
|
||||
|
||||
@@ -208,12 +208,14 @@ function ChipRow({
|
||||
values,
|
||||
options,
|
||||
onToggle,
|
||||
formatValue
|
||||
formatValue,
|
||||
disabled = false
|
||||
}: {
|
||||
values: number[] | DayOfWeek[];
|
||||
options: Array<number | DayOfWeek>;
|
||||
onToggle: (value: never) => void;
|
||||
formatValue: (value: never) => string;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||
@@ -222,6 +224,7 @@ function ChipRow({
|
||||
return (
|
||||
<button
|
||||
className={`ctv-chip-toggle${active ? ' ctv-chip-toggle-active' : ''}`}
|
||||
disabled={disabled}
|
||||
key={String(option)}
|
||||
onClick={() => onToggle(option as never)}
|
||||
type="button"
|
||||
@@ -236,19 +239,33 @@ function ChipRow({
|
||||
|
||||
function RecurrenceFields({
|
||||
draft,
|
||||
onChange
|
||||
onChange,
|
||||
disabled = false,
|
||||
disabledNote
|
||||
}: {
|
||||
draft: RecurrenceDraft;
|
||||
onChange: (patch: Partial<RecurrenceDraft>) => void;
|
||||
disabled?: boolean;
|
||||
disabledNote?: string;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{disabled && disabledNote && (
|
||||
<div className="ctv-channels-error" role="note" style={{ background: 'transparent', border: 'none' }}>
|
||||
<span>{disabledNote}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="ctv-settings-row">
|
||||
<div className="ctv-settings-row-main">
|
||||
<div className="ctv-settings-row-label">Limit to date range</div>
|
||||
</div>
|
||||
<div className="ctv-settings-row-control">
|
||||
<Checkbox checked={draft.limitToDateRange} onChange={(next) => onChange({ limitToDateRange: next })} />
|
||||
<Checkbox
|
||||
checked={draft.limitToDateRange}
|
||||
disabled={disabled}
|
||||
onChange={(next) => onChange({ limitToDateRange: next })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -260,16 +277,19 @@ function RecurrenceFields({
|
||||
</div>
|
||||
<div className="ctv-settings-row-control" style={{ display: 'flex', gap: 8 }}>
|
||||
<Select
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange({ startMonth: Number(event.target.value) })}
|
||||
options={MONTH_OPTIONS}
|
||||
value={String(draft.startMonth)}
|
||||
/>
|
||||
<Select
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange({ startDay: Number(event.target.value) })}
|
||||
options={DAY_OF_MONTH_OPTIONS}
|
||||
value={String(draft.startDay)}
|
||||
/>
|
||||
<Select
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange({ startYear: event.target.value ? Number(event.target.value) : null })}
|
||||
options={YEAR_OPTIONS}
|
||||
value={draft.startYear === null ? '' : String(draft.startYear)}
|
||||
@@ -282,16 +302,19 @@ function RecurrenceFields({
|
||||
</div>
|
||||
<div className="ctv-settings-row-control" style={{ display: 'flex', gap: 8 }}>
|
||||
<Select
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange({ endMonth: Number(event.target.value) })}
|
||||
options={MONTH_OPTIONS}
|
||||
value={String(draft.endMonth)}
|
||||
/>
|
||||
<Select
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange({ endDay: Number(event.target.value) })}
|
||||
options={DAY_OF_MONTH_OPTIONS}
|
||||
value={String(draft.endDay)}
|
||||
/>
|
||||
<Select
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange({ endYear: event.target.value ? Number(event.target.value) : null })}
|
||||
options={YEAR_OPTIONS}
|
||||
value={draft.endYear === null ? '' : String(draft.endYear)}
|
||||
@@ -307,16 +330,17 @@ function RecurrenceFields({
|
||||
</div>
|
||||
<div className="ctv-settings-row-control" style={{ flexDirection: 'column', alignItems: 'stretch', gap: 8 }}>
|
||||
<ChipRow
|
||||
disabled={disabled}
|
||||
formatValue={(day) => shortDayName(day)}
|
||||
onToggle={(day) => onChange({ daysOfWeek: toggle(draft.daysOfWeek, day) })}
|
||||
options={DAYS_OF_WEEK}
|
||||
values={draft.daysOfWeek}
|
||||
/>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<Button onClick={() => onChange({ daysOfWeek: [...WEEKDAYS] })} size="sm" variant="ghost">
|
||||
<Button disabled={disabled} onClick={() => onChange({ daysOfWeek: [...WEEKDAYS] })} size="sm" variant="ghost">
|
||||
Weekdays
|
||||
</Button>
|
||||
<Button onClick={() => onChange({ daysOfWeek: [...WEEKENDS] })} size="sm" variant="ghost">
|
||||
<Button disabled={disabled} onClick={() => onChange({ daysOfWeek: [...WEEKENDS] })} size="sm" variant="ghost">
|
||||
Weekends
|
||||
</Button>
|
||||
</div>
|
||||
@@ -329,6 +353,7 @@ function RecurrenceFields({
|
||||
</div>
|
||||
<div className="ctv-settings-row-control">
|
||||
<ChipRow
|
||||
disabled={disabled}
|
||||
formatValue={(day) => String(day)}
|
||||
onToggle={(day) => onChange({ daysOfMonth: toggle(draft.daysOfMonth, day) })}
|
||||
options={DAYS_OF_MONTH}
|
||||
@@ -343,6 +368,7 @@ function RecurrenceFields({
|
||||
</div>
|
||||
<div className="ctv-settings-row-control">
|
||||
<ChipRow
|
||||
disabled={disabled}
|
||||
formatValue={(month) => monthName(month, 'short')}
|
||||
onToggle={(month) => onChange({ monthsOfYear: toggle(draft.monthsOfYear, month) })}
|
||||
options={MONTHS}
|
||||
@@ -437,6 +463,11 @@ export function PlayoutAlternateSchedulesScreen({ playoutId }: { playoutId: numb
|
||||
.sort((a, b) => (a.name ?? '').localeCompare(b.name ?? ''))
|
||||
.map((schedule) => ({ label: schedule.name ?? `Schedule ${schedule.id}`, value: String(schedule.id) }));
|
||||
const selected = items.find((item) => item.key === selectedKey) ?? null;
|
||||
// Mirrors the "Default" badge below: the last row is the catch-all default whose recurrence
|
||||
// fields the server ignores entirely (ReplacePlayoutAlternateScheduleItemsHandler excludes the
|
||||
// highest-index item from the saved rows and only keeps its ProgramScheduleId as the playout's
|
||||
// default schedule) - so edits to those fields would silently vanish on save.
|
||||
const selectedIsDefault = selected !== null && items[items.length - 1]?.key === selected.key;
|
||||
|
||||
const patchSelected = (patch: Partial<AltDraftItem>) => {
|
||||
setItems((current) =>
|
||||
@@ -603,7 +634,12 @@ export function PlayoutAlternateSchedulesScreen({ playoutId }: { playoutId: numb
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<RecurrenceFields draft={selected} onChange={patchSelected} />
|
||||
<RecurrenceFields
|
||||
disabled={selectedIsDefault}
|
||||
disabledNote="The default entry always matches every day; reorder it above another entry to scope it."
|
||||
draft={selected}
|
||||
onChange={patchSelected}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
</EditorChrome>
|
||||
|
||||
Reference in New Issue
Block a user