Refactor GridPlanner and GenerateGridDialog for improved functionality and UI
ci / build-backend (push) Successful in 2m28s
ci / build-frontend (push) Successful in 1m8s
ci / tests (push) Successful in 2m48s
ci / sonar (push) Successful in 6m30s

Updated the GridPlanner class to streamline fallback group handling by removing unnecessary notes and clarifying comments. Enhanced the GenerateGridDialog component to limit its height for better usability, ensuring that the dialog remains accessible even with long slot lists. Adjusted layout properties to improve scrolling behavior and overall user experience.
This commit is contained in:
Leonid Pershin
2026-07-27 08:21:33 +03:00
parent bef029b858
commit 6306919ecd
2 changed files with 8 additions and 8 deletions
@@ -79,13 +79,10 @@ public sealed class GridPlanner(
.Week.SelectMany(day => GridCoverage.Gaps(existing, day, run.DayStart)) .Week.SelectMany(day => GridCoverage.Gaps(existing, day, run.DayStart))
.Sum(gap => gap.To - gap.From); .Sum(gap => gap.To - gap.From);
// Аварийная группа отдаётся отдельным полем, а не замечанием: замечания — про то, что пошло
// не так, а это штатное действие, и в предпросмотре у него своя строка.
var fallback = groups.MaxBy(g => g.UnitCount); var fallback = groups.MaxBy(g => g.UnitCount);
var needsFallback = template.FallbackGroupId is null && fallback is not null; var needsFallback = template.FallbackGroupId is null && fallback is not null;
if (needsFallback)
run.Note(
$"Аварийной группы у сетки не было — ею станет «{fallback!.Name}»: без неё паузы "
+ "между слотами останутся пустыми."
);
var everyDaySpan = mode == GridGenerationMode.Rebuild && profile.Weekend.Count > 0 ? 5 : 7; var everyDaySpan = mode == GridGenerationMode.Rebuild && profile.Weekend.Count > 0 ? 5 : 7;
var covered = slots.Sum(s => s.DurationMinutes * (s.Weekday is null ? everyDaySpan : 1)); var covered = slots.Sum(s => s.DurationMinutes * (s.Weekday is null ? everyDaySpan : 1));
@@ -70,13 +70,16 @@ export function GenerateGridDialog({
return ( return (
<Dialog open onOpenChange={(next) => !next && onClose()}> <Dialog open onOpenChange={(next) => !next && onClose()}>
<DialogContent className="max-w-3xl"> {/* Окно не выше экрана: список слотов на неделю длинный, и без ограничения диалог вылезал
за оба края — верх с выбором профиля становился недостижим. Скроллится тело, шапка
и кнопки остаются на месте. */}
<DialogContent className="flex max-h-[90vh] max-w-3xl flex-col">
<DialogHeader> <DialogHeader>
<DialogTitle>{t('admin.channels.generate.title')}</DialogTitle> <DialogTitle>{t('admin.channels.generate.title')}</DialogTitle>
<DialogDescription>{t('admin.channels.generate.hint')}</DialogDescription> <DialogDescription>{t('admin.channels.generate.hint')}</DialogDescription>
</DialogHeader> </DialogHeader>
<div className="flex flex-col gap-3 text-sm"> <div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto pr-1 text-sm">
{/* Профиль — то, ради чего окно и открыли: ритм суток задаёт всё остальное. */} {/* Профиль — то, ради чего окно и открыли: ритм суток задаёт всё остальное. */}
<div className="grid gap-1.5 sm:grid-cols-2"> <div className="grid gap-1.5 sm:grid-cols-2">
{(profiles ?? []).map((item) => ( {(profiles ?? []).map((item) => (
@@ -151,7 +154,7 @@ export function GenerateGridDialog({
{plan.slots.length === 0 ? ( {plan.slots.length === 0 ? (
<p className="text-muted-foreground">{t('admin.channels.generate.nothing')}</p> <p className="text-muted-foreground">{t('admin.channels.generate.nothing')}</p>
) : ( ) : (
<ul className="crt-panel max-h-72 divide-y divide-border overflow-y-auto rounded-md text-xs"> <ul className="crt-panel divide-y divide-border rounded-md text-xs">
{plan.slots.map((slot, index) => ( {plan.slots.map((slot, index) => (
<PlanRow key={`${slot.weekday}-${slot.start}-${index}`} slot={slot} /> <PlanRow key={`${slot.weekday}-${slot.start}-${index}`} slot={slot} />
))} ))}