93 lines
5.6 KiB
TypeScript
93 lines
5.6 KiB
TypeScript
// PEP-23: project autonomy in «⋯ Настройки проекта» — preset levels and the individual settings.
|
||
import { AUTONOMY_LEVEL_HINT, AUTONOMY_LEVEL_RU, AUTONOMY_LEVELS, autonomyLevel, type AutonomyLevel, type AutonomySettings } from "@peppa/core";
|
||
import { setAutonomyAction } from "@/app/(app)/actions";
|
||
import { Hidden } from "@/components/cards";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Input, Label, NativeSelect } from "@/components/ui/input";
|
||
import { getT } from "@/lib/i18n";
|
||
|
||
export async function AutonomyPanel({ projectId, settings, back }: { projectId: number; settings: AutonomySettings; back: string }) {
|
||
const t = await getT();
|
||
const current = autonomyLevel(settings);
|
||
const s = settings;
|
||
return (
|
||
<div className="flex flex-col gap-3">
|
||
<div className="flex flex-wrap gap-2" role="group" aria-label={t("Уровень автономности")}>
|
||
{(Object.keys(AUTONOMY_LEVELS) as AutonomyLevel[]).map((level) => (
|
||
<form key={level} action={setAutonomyAction}>
|
||
<Hidden fields={{ projectId, level, back }} />
|
||
<Button size="sm" variant={current === level ? "default" : "outline"} aria-pressed={current === level} title={t.text(AUTONOMY_LEVEL_HINT[level])}>
|
||
{t.text(AUTONOMY_LEVEL_RU[level])}
|
||
</Button>
|
||
</form>
|
||
))}
|
||
{current === "custom" && (
|
||
<Button size="sm" variant="default" disabled aria-pressed>
|
||
{t.text(AUTONOMY_LEVEL_RU.custom)}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
<p className="m-0 text-xs text-muted-foreground">{current === "custom" ? t("Своя комбинация настроек ниже.") : t.text(AUTONOMY_LEVEL_HINT[current])}</p>
|
||
<details>
|
||
<summary className="cursor-pointer text-sm text-primary">{t("Настроить подробно")}</summary>
|
||
<form action={setAutonomyAction} className="mt-3 flex flex-col gap-3">
|
||
<Hidden fields={{ projectId, back }} />
|
||
<Label>
|
||
{t("Кто берёт стори из бэклога")}
|
||
<NativeSelect name="pick" defaultValue={s.pick} className="h-8">
|
||
<option value="pm">{t("PM — двигает карточки сам")}</option>
|
||
<option value="auto">{t("Пеппа — сама, по номеру стори")}</option>
|
||
</NativeSelect>
|
||
</Label>
|
||
<Label>
|
||
{t("Сколько стори в работе одновременно (для «Пеппа сама»)")}
|
||
<Input name="wipLimit" type="number" min={1} max={5} defaultValue={s.wipLimit} className="h-8" />
|
||
</Label>
|
||
<Label>
|
||
{t("Proposal")}
|
||
<NativeSelect name="proposal" defaultValue={s.proposal} className="h-8">
|
||
<option value="agent">{t("Без одобрения — PM только на архитектурные стопперы")}</option>
|
||
<option value="pm">{t("Каждый proposal одобряет PM")}</option>
|
||
</NativeSelect>
|
||
</Label>
|
||
<Label>
|
||
{t("Мерж PR")}
|
||
<NativeSelect name="merge" defaultValue={s.merge} className="h-8">
|
||
<option value="manual">{t("По кнопке «Принять»")}</option>
|
||
<option value="auto">{t("Сам после зелёных проверок и без конфликтов")}</option>
|
||
</NativeSelect>
|
||
</Label>
|
||
<Label>
|
||
{t("Закрытие стори")}
|
||
<NativeSelect name="close" defaultValue={s.close} className="h-8">
|
||
<option value="pm">{t("PM принимает")}</option>
|
||
<option value="after_merge">{t("Сразу после мержа")}</option>
|
||
<option value="after_hours">{t("Само через N часов без замечаний")}</option>
|
||
</NativeSelect>
|
||
</Label>
|
||
<Label>
|
||
{t("N часов до автозакрытия")}
|
||
<Input name="closeAfterHours" type="number" min={1} max={336} defaultValue={s.closeAfterHours} className="h-8" />
|
||
</Label>
|
||
<label className="flex items-center gap-2 text-sm">
|
||
<input type="checkbox" name="idlePush" defaultChecked={s.idlePush} /> {t("Пуш, если агенты простаивают, а в бэклоге есть стори")}
|
||
</label>
|
||
<Label>
|
||
{t("Не чаще раза в (часов); столько же длится «Не сейчас»")}
|
||
<Input name="idlePushHours" type="number" min={1} max={168} defaultValue={s.idlePushHours} className="h-8" />
|
||
</Label>
|
||
<label className="flex items-center gap-2 text-sm">
|
||
<input type="checkbox" name="quiet" defaultChecked={s.quietFrom != null} /> {t("Тихие часы")}
|
||
</label>
|
||
<div className="flex items-center gap-2 text-sm">
|
||
{t("с")} <Input name="quietFrom" type="number" min={0} max={23} defaultValue={s.quietFrom ?? 22} className="h-8 w-20" aria-label={t("Тихие часы с")} />
|
||
{t("до")} <Input name="quietTo" type="number" min={0} max={23} defaultValue={s.quietTo ?? 9} className="h-8 w-20" aria-label={t("Тихие часы до")} />
|
||
</div>
|
||
<Button size="sm" className="self-start">{t("Сохранить")}</Button>
|
||
</form>
|
||
</details>
|
||
<p className="m-0 text-xs text-muted-foreground">{t("PR, меняющий конвейер (.gitea/, checks, deploy), сам не мержится и не закрывается — его принимает PM.")}</p>
|
||
</div>
|
||
);
|
||
}
|