From 5d315842027b1fdee125d053fe6849e5b940a494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 05:44:14 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20style:=20branch=20protection=20r?= =?UTF-8?q?ules=20are=20cards=20with=20summary=20pills=20that=20open=20the?= =?UTF-8?q?ir=20own=20form,=20grouped=20into=20sections=20with=20switches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/src/i18n/repo_admin.rs | 106 +++--- crates/forge-web/src/pages/repo_settings.rs | 327 +++++++++++------ .../forge-web/tests/e2e/repo_settings_e2e.rs | 53 +-- style/main.scss | 340 ++++++++++++++++-- 4 files changed, 588 insertions(+), 238 deletions(-) diff --git a/crates/forge-web/src/i18n/repo_admin.rs b/crates/forge-web/src/i18n/repo_admin.rs index 8d6d5a5..0692087 100644 --- a/crates/forge-web/src/i18n/repo_admin.rs +++ b/crates/forge-web/src/i18n/repo_admin.rs @@ -10,7 +10,6 @@ pub enum K { AddCollaboratorHeading, AddCollaboratorHelp, AddOrUpdate, - AddOrUpdateRule, AllowDeletion, AllowForcePush, AlreadyOwner, @@ -47,31 +46,31 @@ pub enum K { DeleteRepoHelp, DeleteTrashHelp, DeletionAllowed, + DeletionDesc, Description, DescriptionHelp, DescriptionLong, EnterUsername, EnterValue, ForcePushAllowed, + ForcePushDesc, General, GeneralSaved, IUnderstand, InvalidRole, LastUpdated, - MergePushRules, Mirrors, Name, NameRule, NewName, NewOwnerLabel, + NewRule, NoBranchesYet, NoCollaborators, NoPendingTransfer, - NoRule, NoSecrets, NotCollaborator, OwnerIsMember, - PatternColumn, PatternHelpA, PatternHelpB, PatternHelpC, @@ -91,7 +90,8 @@ pub enum K { RepoUnarchived, RequireUpToDate, RequiredApprovals, - RestrictPush, + RestrictPushDesc, + RestrictPushTitle, Role, RoleAdminDesc, RoleMaintainDesc, @@ -100,12 +100,13 @@ pub enum K { RoleTriageDesc, RoleUpdated, RoleWriteDesc, - RuleChangesBlock, - RuleRestrictPush, - RuleUpToDate, RequiredChecks, RequiredChecksHelp, RecentContexts, + RuleChangesShort, + RuleNoExtra, + RulePrOnly, + RuleUpToDateShort, SaveGeneral, SaveRole, SaveRule, @@ -116,6 +117,10 @@ pub enum K { SecretSaved, Secrets, SecretsHelp, + SectionChecks, + SectionMerging, + SectionPattern, + SectionPushes, SettingsNavLabel, StartTransferLink, TransferHelp, @@ -156,8 +161,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { } (AddOrUpdate, En) => "Add or update a secret", (AddOrUpdate, Tr) => "Gizli anahtar ekle veya güncelle", - (AddOrUpdateRule, En) => "Add or update a rule", - (AddOrUpdateRule, Tr) => "Kural ekle veya güncelle", (AllowDeletion, En) => "Allow deletion", (AllowDeletion, Tr) => "Silmeye izin verilir", (AllowForcePush, En) => "Allow force pushes", @@ -262,7 +265,9 @@ pub fn t(lang: Lang, key: K) -> &'static str { } (DeletionAllowed, En) => "Deletion allowed", (DeletionAllowed, Tr) => "Silmeye izin var", + (DeletionDesc, En) => "The branch can be deleted.", (Description, En) => "Description", + (DeletionDesc, Tr) => "Dal silinebilir.", (Description, Tr) => "Açıklama", (DescriptionHelp, En) => { "Up to 350 characters, on one line. It is shown under the repository name." @@ -282,7 +287,9 @@ pub fn t(lang: Lang, key: K) -> &'static str { (EnterValue, Tr) => "Bir değer girin.", (ForcePushAllowed, En) => "Force push allowed", (ForcePushAllowed, Tr) => "Zorla gönderime izin var", + (ForcePushDesc, En) => "Rewriting history with git push --force is allowed.", (General, En) => "General", + (ForcePushDesc, Tr) => "git push --force ile geçmişin yeniden yazılmasına izin verilir.", (General, Tr) => "Genel", (GeneralSaved, En) => "General settings saved.", (GeneralSaved, Tr) => "Genel ayarlar kaydedildi.", @@ -292,8 +299,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { (InvalidRole, Tr) => "Geçerli bir rol seçin.", (LastUpdated, En) => "Last updated", (LastUpdated, Tr) => "Son güncelleme", - (MergePushRules, En) => "Merge and push rules", - (MergePushRules, Tr) => "Birleştirme ve gönderme kuralları", (Mirrors, En) => "Mirrors", (Mirrors, Tr) => "Yansılar", (Name, En) => "Name", @@ -308,16 +313,16 @@ pub fn t(lang: Lang, key: K) -> &'static str { (NewName, Tr) => "Yeni ad", (NewOwnerLabel, En) => "New owner (username)", (NewOwnerLabel, Tr) => "Yeni sahip (kullanıcı adı)", + (NewRule, En) => "New rule", (NoBranchesYet, En) => { "No branches yet. The default branch can be chosen after the first push." } + (NewRule, Tr) => "Yeni kural", (NoBranchesYet, Tr) => "Henüz dal yok. Varsayılan dal, ilk gönderimden sonra seçilebilir.", (NoCollaborators, En) => "No collaborators yet. Add one below.", (NoCollaborators, Tr) => "Henüz ortak çalışan yok. Aşağıdan bir ortak çalışan ekleyin.", (NoPendingTransfer, En) => "No transfer is pending for this repository.", (NoPendingTransfer, Tr) => "Bu depo için bekleyen bir devir yok.", - (NoRule, En) => "none", - (NoRule, Tr) => "yok", (NoSecrets, En) => "No secrets yet.", (NoSecrets, Tr) => "Henüz gizli anahtar yok.", (NotCollaborator, En) => "That user is not a collaborator on this repo.", @@ -328,8 +333,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { (OwnerIsMember, Tr) => { "Depo sahibi zaten tam erişimli bir üyedir ve ortak çalışan olarak eklenemez." } - (PatternColumn, En) => "Pattern", - (PatternColumn, Tr) => "Desen", (PatternHelpA, En) => "A branch name, or a pattern: ", (PatternHelpA, Tr) => "Bir dal adı veya desen: ", (PatternHelpB, En) => " matches within one path segment and ", @@ -380,13 +383,11 @@ pub fn t(lang: Lang, key: K) -> &'static str { } (RequiredApprovals, En) => "Required approvals (0 to 20)", (RequiredApprovals, Tr) => "Gerekli onay sayısı (0 ile 20 arası)", - (RestrictPush, En) => { - "Only accept changes through pull requests (direct pushes are limited to repo admins)" - } - (RestrictPush, Tr) => { - "Değişiklikler yalnızca çekme istekleri üzerinden kabul edilir (doğrudan gönderimler depo yöneticileriyle sınırlıdır)" - } + (RestrictPushDesc, En) => "Direct pushes are limited to repo admins.", + (RestrictPushTitle, En) => "Only accept changes through pull requests", (Role, En) => "Role", + (RestrictPushDesc, Tr) => "Doğrudan gönderimler depo yöneticileriyle sınırlıdır.", + (RestrictPushTitle, Tr) => "Değişiklikler yalnızca çekme istekleri üzerinden kabul edilir", (Role, Tr) => "Rol", (RoleAdminDesc, En) => "full repo settings except delete and transfer", (RoleAdminDesc, Tr) => "silme ve devir dışında tüm depo ayarları", @@ -402,10 +403,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { (RoleUpdated, Tr) => "Rol güncellendi.", (RoleWriteDesc, En) => "push", (RoleWriteDesc, Tr) => "gönderme (push)", - (RuleChangesBlock, En) => "changes requested block merges", - (RuleChangesBlock, Tr) => "değişiklik istenmesi birleştirmeyi engeller", - (RuleRestrictPush, En) => "direct pushes limited to admins", - (RuleRestrictPush, Tr) => "doğrudan gönderimler yöneticilerle sınırlı", (RequiredChecks, En) => "Required status checks", (RequiredChecks, Tr) => "Gerekli durum denetimleri", (RequiredChecksHelp, En) => { @@ -416,9 +413,15 @@ pub fn t(lang: Lang, key: K) -> &'static str { } (RecentContexts, En) => "Recently seen:", (RecentContexts, Tr) => "Son görülenler:", - (RuleUpToDate, En) => "head must be up to date with base", - (RuleUpToDate, Tr) => "kaynak dal, hedef dalın güncel hâlini içermelidir", + (RuleChangesShort, En) => "Blocks on changes requested", + (RuleNoExtra, En) => "No extra rules", + (RulePrOnly, En) => "PR only", + (RuleUpToDateShort, En) => "Up to date", (SaveGeneral, En) => "Save general settings", + (RuleChangesShort, Tr) => "değişiklik istenirse engeller", + (RuleNoExtra, Tr) => "Ek kural yok", + (RulePrOnly, Tr) => "yalnızca PR", + (RuleUpToDateShort, Tr) => "güncel", (SaveGeneral, Tr) => "Genel ayarları kaydet", (SaveRole, En) => "Save", (SaveRole, Tr) => "Kaydet", @@ -442,7 +445,15 @@ pub fn t(lang: Lang, key: K) -> &'static str { (SecretsHelp, Tr) => { "Gizli anahtarlar, bu deponun CI işlerine ortam değişkeni olarak aktarılır. Değerler yalnızca yazılabilir: kaydedildikten sonra geri okunamazlar ve bir gizli anahtarı güncellemek değerini değiştirir." } + (SectionChecks, En) => "Status checks", + (SectionMerging, En) => "Merging", + (SectionPattern, En) => "Pattern", + (SectionPushes, En) => "Pushes", (SettingsNavLabel, En) => "Settings", + (SectionChecks, Tr) => "Durum denetimleri", + (SectionMerging, Tr) => "Birleştirme", + (SectionPattern, Tr) => "Desen", + (SectionPushes, Tr) => "Gönderimler", (SettingsNavLabel, Tr) => "Ayarlar", (StartTransferLink, En) => "Start or change a transfer in the settings", (StartTransferLink, Tr) => "Ayarlarda devir başlatın veya değiştirin", @@ -625,24 +636,6 @@ pub fn role_for(lang: Lang, username: &str) -> String { } } -/// `yes` or `no` for a rule column. -pub fn yes_no(lang: Lang, value: bool) -> &'static str { - match (lang, value) { - (Lang::En, true) => "yes", - (Lang::En, false) => "no", - (Lang::Tr, true) => "evet", - (Lang::Tr, false) => "hayır", - } -} - -/// The number of required status checks in a rule summary. -pub fn checks_count(lang: Lang, n: usize) -> String { - match lang { - Lang::En => format!("{n} required check{}", if n == 1 { "" } else { "s" }), - Lang::Tr => format!("{n} gerekli denetim"), - } -} - /// The number of required approvals in a rule summary. pub fn approvals_count(lang: Lang, n: u32) -> String { match lang { @@ -662,7 +655,6 @@ mod tests { K::AddCollaboratorHeading, K::AddCollaboratorHelp, K::AddOrUpdate, - K::AddOrUpdateRule, K::AllowDeletion, K::AllowForcePush, K::AlreadyOwner, @@ -699,31 +691,31 @@ mod tests { K::DeleteRepoHelp, K::DeleteTrashHelp, K::DeletionAllowed, + K::DeletionDesc, K::Description, K::DescriptionHelp, K::DescriptionLong, K::EnterUsername, K::EnterValue, K::ForcePushAllowed, + K::ForcePushDesc, K::General, K::GeneralSaved, K::IUnderstand, K::InvalidRole, K::LastUpdated, - K::MergePushRules, K::Mirrors, K::Name, K::NameRule, K::NewName, K::NewOwnerLabel, + K::NewRule, K::NoBranchesYet, K::NoCollaborators, K::NoPendingTransfer, - K::NoRule, K::NoSecrets, K::NotCollaborator, K::OwnerIsMember, - K::PatternColumn, K::PatternHelpA, K::PatternHelpB, K::PatternHelpC, @@ -743,7 +735,8 @@ mod tests { K::RepoUnarchived, K::RequireUpToDate, K::RequiredApprovals, - K::RestrictPush, + K::RestrictPushDesc, + K::RestrictPushTitle, K::Role, K::RoleAdminDesc, K::RoleMaintainDesc, @@ -752,12 +745,13 @@ mod tests { K::RoleTriageDesc, K::RoleUpdated, K::RoleWriteDesc, - K::RuleChangesBlock, - K::RuleRestrictPush, - K::RuleUpToDate, K::RequiredChecks, K::RequiredChecksHelp, K::RecentContexts, + K::RuleChangesShort, + K::RuleNoExtra, + K::RulePrOnly, + K::RuleUpToDateShort, K::SaveGeneral, K::SaveRole, K::SaveRule, @@ -768,6 +762,10 @@ mod tests { K::SecretSaved, K::Secrets, K::SecretsHelp, + K::SectionChecks, + K::SectionMerging, + K::SectionPattern, + K::SectionPushes, K::SettingsNavLabel, K::StartTransferLink, K::TransferHelp, diff --git a/crates/forge-web/src/pages/repo_settings.rs b/crates/forge-web/src/pages/repo_settings.rs index 323c8cc..8f5849f 100644 --- a/crates/forge-web/src/pages/repo_settings.rs +++ b/crates/forge-web/src/pages/repo_settings.rs @@ -448,149 +448,212 @@ fn parse_rule_flags(lang: Lang, form: &BranchForm) -> std::result::Result String { - let mut parts = Vec::new(); - if rule.required_approvals > 0 { - parts.push(g::approvals_count(lang, rule.required_approvals)); +/// One pill in a rule card's summary: its text and its classes. +struct RulePill { + text: String, + class: &'static str, +} + +/// The pills that describe a rule in its card summary. A rule that sets nothing gets one muted pill. +fn rule_pills(lang: Lang, rule: &BranchRule) -> Vec { + let warn = "rule-pill warn"; + let plain = "rule-pill"; + let mut pills = Vec::new(); + if rule.allow_force_push { + pills.push(pill(g::t(lang, K::ForcePushAllowed), warn)); } - if rule.block_on_changes_requested { - parts.push(g::t(lang, K::RuleChangesBlock).to_owned()); + if rule.allow_deletion { + pills.push(pill(g::t(lang, K::DeletionAllowed), warn)); } - if rule.require_up_to_date { - parts.push(g::t(lang, K::RuleUpToDate).to_owned()); + if rule.required_approvals > 0 { + pills.push(pill(&g::approvals_count(lang, rule.required_approvals), plain)); } if rule.restrict_push { - parts.push(g::t(lang, K::RuleRestrictPush).to_owned()); + pills.push(pill(g::t(lang, K::RulePrOnly), plain)); + } + if rule.require_up_to_date { + pills.push(pill(g::t(lang, K::RuleUpToDateShort), plain)); } if rule.require_merge_queue { - parts.push(mq::t(lang, mq::K::RuleMergeQueue).to_owned()); + pills.push(pill(mq::t(lang, mq::K::RuleMergeQueue), plain)); } - if !rule.required_checks.is_empty() { - parts.push(g::checks_count(lang, rule.required_checks.len())); + if rule.block_on_changes_requested { + pills.push(pill(g::t(lang, K::RuleChangesShort), plain)); } - if parts.is_empty() { - g::t(lang, K::NoRule).to_owned() - } else { - parts.join("; ") + for check in &rule.required_checks { + pills.push(pill(&format!("\u{2713} {check}"), "rule-pill check")); } + if pills.is_empty() { + pills.push(pill(g::t(lang, K::RuleNoExtra), "rule-pill muted")); + } + pills +} + +fn pill(text: &str, class: &'static str) -> RulePill { + RulePill { + text: text.to_owned(), + class, + } +} + +/// A rule as the settings page shows it: its id, its summary pills, and the form it opens with. +struct RuleCard { + id: String, + pills: Vec, + open: bool, + draft: RuleDraft, +} + +/// One switch row: a title with an optional muted line under it, and a toggle on the right. +#[component] +async fn switch_row( + name: String, + checked: bool, + title: String, + description: Option, +) -> Result { + Ok(view! { + + }) } -/// The rules table. A muted built-in row stands in for the default branch when no rule matches it. +/// The rule cards, then a muted row for the default branch when no rule covers it, then the New +/// rule card. A card opens with its rule's values. The card whose draft has an error opens with +/// the draft instead, and the New rule card opens with the draft when no card takes it. #[component] -async fn branch_rules_table( +async fn branch_rule_cards( lang: Lang, - rules: Vec, - default_branch: String, + cards: Vec, builtin_row: bool, - delete_action: String, + default_branch: String, + new_draft: RuleDraft, + new_open: bool, csrf: String, + save_action: String, + delete_action: String, + contexts: Vec, ) -> Result { Ok(view! { -
- - - - - - - - - - - - for rule in rules.iter() { - - - - - - - - } - if builtin_row { - - - - } - -
(g::t(lang, K::PatternColumn))(g::t(lang, K::ForcePushAllowed))(g::t(lang, K::DeletionAllowed))(g::t(lang, K::MergePushRules))(g::t(lang, K::Remove))
(rule.pattern.as_str())(g::yes_no(lang, rule.allow_force_push))(g::yes_no(lang, rule.allow_deletion))(rule_summary(lang, rule)) -
- - - -
-
(default_branch.as_str())(g::t(lang, K::BuiltinRowText))
+
+ for card in cards.iter() { +
+
+
+ + + (card.draft.pattern.as_str()) + + for pill in card.pills.iter() { + (pill.text.as_str()) + } + + + + + branch_rule_form(lang: lang, csrf: csrf.clone(), save_action: save_action.clone(), + draft: card.draft.clone(), contexts: contexts.clone()) +
+
+ + + +
+
+
+ } + if builtin_row { +
+ (default_branch.as_str()) + (g::t(lang, K::BuiltinRowText)) +
+ }
+
+ "+ "(g::t(lang, K::NewRule)) + branch_rule_form(lang: lang, csrf: csrf.clone(), save_action: save_action.clone(), + draft: new_draft, contexts: contexts.clone()) +
}) } -/// The add/update form. Saving an existing pattern updates its rule. +/// The rule form, in four sections. Saving an existing pattern updates its rule. #[component] async fn branch_rule_form( lang: Lang, csrf: String, save_action: String, - pattern: String, - allow_force_push: bool, - allow_deletion: bool, - required_approvals: String, - block_on_changes_requested: bool, - require_up_to_date: bool, - restrict_push: bool, - require_merge_queue: bool, - required_checks: String, + draft: RuleDraft, contexts: Vec, - error: Option, ) -> Result { + let RuleDraft { + pattern, + allow_force_push, + allow_deletion, + required_approvals, + block_on_changes_requested, + require_up_to_date, + restrict_push, + require_merge_queue, + required_checks, + error, + } = draft; Ok(view! { -
+ if let Some(message) = error { alert(message: message.as_str()) } -
+
+ (g::t(lang, K::SectionPattern))

(g::t(lang, K::PatternHelpA))"*"(g::t(lang, K::PatternHelpB))"**"(g::t(lang, K::PatternHelpC))"/"(g::t(lang, K::PatternHelpD))

-
-
- - -
-
- -

(g::t(lang, K::ApprovalsHelp))

- - - - -

(mq::t(lang, mq::K::RequireMergeQueueHint))

-
-
+ +
+ (g::t(lang, K::SectionPushes)) +
+ switch_row(name: "allow_force_push".to_owned(), checked: allow_force_push, + title: g::t(lang, K::AllowForcePush).to_owned(), + description: Some(g::t(lang, K::ForcePushDesc).to_owned())) + switch_row(name: "allow_deletion".to_owned(), checked: allow_deletion, + title: g::t(lang, K::AllowDeletion).to_owned(), + description: Some(g::t(lang, K::DeletionDesc).to_owned())) + switch_row(name: "restrict_push".to_owned(), checked: restrict_push, + title: g::t(lang, K::RestrictPushTitle).to_owned(), + description: Some(g::t(lang, K::RestrictPushDesc).to_owned())) +
+
+
+ (g::t(lang, K::SectionMerging)) +
+ + switch_row(name: "block_on_changes_requested".to_owned(), checked: block_on_changes_requested, + title: g::t(lang, K::BlockWhileChanges).to_owned(), description: None) + switch_row(name: "require_up_to_date".to_owned(), checked: require_up_to_date, + title: g::t(lang, K::RequireUpToDate).to_owned(), description: None) + switch_row(name: "require_merge_queue".to_owned(), checked: require_merge_queue, + title: mq::t(lang, mq::K::RequireMergeQueue).to_owned(), + description: Some(mq::t(lang, mq::K::RequireMergeQueueHint).to_owned())) +
+
+
+ (g::t(lang, K::SectionChecks))
} -
+
@@ -613,6 +676,7 @@ async fn branch_rule_form( } /// The form values to show: the pattern and checkboxes, plus any validation error. +#[derive(Clone)] struct RuleDraft { pattern: String, allow_force_push: bool, @@ -627,6 +691,22 @@ struct RuleDraft { } impl RuleDraft { + /// The values a saved rule opens with. + fn from_rule(rule: &BranchRule) -> Self { + Self { + pattern: rule.pattern.clone(), + allow_force_push: rule.allow_force_push, + allow_deletion: rule.allow_deletion, + required_approvals: rule.required_approvals.to_string(), + block_on_changes_requested: rule.block_on_changes_requested, + require_up_to_date: rule.require_up_to_date, + restrict_push: rule.restrict_push, + require_merge_queue: rule.require_merge_queue, + required_checks: rule.required_checks.join(", "), + error: None, + } + } + /// The default values for the add form, with the default branch as the pattern. fn for_default_branch(default_branch: &str) -> Self { Self { @@ -682,6 +762,27 @@ async fn settings_body( delete_error, contexts, } = page; + // A card takes the draft when the draft has an error and the pattern is its rule's pattern. + // Every other card opens with its saved values. A draft no card takes goes to the New rule card. + let mut draft = Some(draft); + let mut cards = Vec::with_capacity(rules.len()); + for rule in rules { + let card_draft = match draft.take() { + Some(d) if d.error.is_some() && d.pattern == rule.pattern => d, + other => { + draft = other; + RuleDraft::from_rule(&rule) + } + }; + cards.push(RuleCard { + id: rule.id.clone(), + pills: rule_pills(lang, &rule), + open: card_draft.error.is_some(), + draft: card_draft, + }); + } + let new_draft = draft.unwrap_or_else(|| RuleDraft::for_default_branch(&default_branch)); + let new_open = cards.is_empty() || new_draft.error.is_some(); let (description, visibility) = (head.description.clone(), head.visibility); let discussions_on = head.discussions; let notice = notice.map(|(key, is_error)| (g::t(lang, key), is_error)); @@ -701,17 +802,9 @@ async fn settings_body(

(g::t(lang, K::BranchProtection))

(g::t(lang, K::BranchProtectionHelp))

- branch_rules_table(lang: lang, rules: rules, default_branch: default_branch.clone(), - builtin_row: builtin_row, delete_action: delete_action, csrf: csrf.clone()) -

(g::t(lang, K::AddOrUpdateRule))

- branch_rule_form(lang: lang, csrf: csrf.clone(), save_action: rules_action, pattern: draft.pattern, - allow_force_push: draft.allow_force_push, allow_deletion: draft.allow_deletion, - required_approvals: draft.required_approvals, - block_on_changes_requested: draft.block_on_changes_requested, - require_up_to_date: draft.require_up_to_date, restrict_push: draft.restrict_push, - require_merge_queue: draft.require_merge_queue, - required_checks: draft.required_checks, contexts: contexts, - error: draft.error) + branch_rule_cards(lang: lang, cards: cards, builtin_row: builtin_row, default_branch: default_branch.clone(), + new_draft: new_draft, new_open: new_open, csrf: csrf.clone(), save_action: rules_action, + delete_action: delete_action, contexts: contexts)
discussions_card(lang: lang, action: format!("/{title}/settings/discussions"), csrf: csrf.clone(), enabled: discussions_on) if can_delete { diff --git a/crates/forge-web/tests/e2e/repo_settings_e2e.rs b/crates/forge-web/tests/e2e/repo_settings_e2e.rs index a4cf60b..1ff5a4b 100644 --- a/crates/forge-web/tests/e2e/repo_settings_e2e.rs +++ b/crates/forge-web/tests/e2e/repo_settings_e2e.rs @@ -365,26 +365,29 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() { ); } -/// Rows of the branch rules table as their cell texts, in page order. The built-in default-branch -/// row is a single cell with a `colspan`, so it appears as a one-cell row. +/// The rule cards of the branch rules list in page order, each as its pattern followed by the texts +/// of its summary pills. The built-in default-branch card has no rule behind it, so it is skipped. fn branch_rows(body: &str) -> Vec> { let doc = scraper::Html::parse_document(body); - let rows = scraper::Selector::parse("table.branch-rules tbody tr").expect("selector"); - let cells = scraper::Selector::parse("td").expect("selector"); - doc.select(&rows) - .map(|row| { - row.select(&cells) - .map(|cell| cell.text().collect::().trim().to_owned()) - .collect() + let cards = scraper::Selector::parse("div.rule-card:not(.rule-builtin)").expect("selector"); + let pattern = scraper::Selector::parse("summary code.rule-pattern").expect("selector"); + let pills = scraper::Selector::parse("summary .rule-pill").expect("selector"); + let text = |el: scraper::ElementRef| el.text().collect::().trim().to_owned(); + doc.select(&cards) + .map(|card| { + let mut cells: Vec = + card.select(&pattern).next().map(text).into_iter().collect(); + cells.extend(card.select(&pills).map(text)); + cells }) .collect() } -/// The cells of the rule row for `pattern`, if the table has one. +/// The card for `pattern` as its cells (see `branch_rows`), if the list has one. fn rule_row(body: &str, pattern: &str) -> Option> { branch_rows(body) .into_iter() - .find(|cells| cells.first().is_some_and(|c| c == pattern) && cells.len() == 5) + .find(|cells| cells.first().is_some_and(|c| c == pattern)) } /// Owner adds, updates, invalidates and removes branch rules. A Write collaborator and an Admin @@ -485,14 +488,8 @@ async fn branch_protection_end_to_end() { ); assert_eq!( rule_row(&page.body, "main"), - Some(vec![ - "main".into(), - "yes".into(), - "no".into(), - "none".into(), - "Remove".into() - ]), - "main row after add" + Some(vec!["main".into(), "Force push allowed".into()]), + "main card after add" ); assert!( !page.body.contains("(default branch): protected by default"), @@ -511,14 +508,8 @@ async fn branch_protection_end_to_end() { let page = http.get("/bob/app/settings", Some(&bob)).await; assert_eq!( rule_row(&page.body, "main"), - Some(vec![ - "main".into(), - "no".into(), - "no".into(), - "none".into(), - "Remove".into() - ]), - "main row after update" + Some(vec!["main".into(), "No extra rules".into()]), + "main card after update" ); assert_eq!( branch_rows(&page.body).len(), @@ -648,13 +639,7 @@ async fn branch_protection_end_to_end() { let page = http.get("/bob/app/settings", Some(&carol)).await; assert_eq!( rule_row(&page.body, "release/*"), - Some(vec![ - "release/*".into(), - "yes".into(), - "no".into(), - "none".into(), - "Remove".into() - ]), + Some(vec!["release/*".into(), "Force push allowed".into()]), "admin collaborator's rule" ); let carol_delete_rule = http diff --git a/style/main.scss b/style/main.scss index b0fb771..5f46801 100644 --- a/style/main.scss +++ b/style/main.scss @@ -2704,66 +2704,340 @@ code { } // branch protection -// Settings page: rules table with a Remove form per row, then the add/update form. -.branch-rules { - // Data columns size to their content; the rule summary takes the slack and the action sits at the end. - th:nth-child(4), - td:nth-child(4) { - width: 100%; +// Settings page: one card per rule (a summary with its pills and the form when open), a muted row +// for the default branch when no rule covers it, and a dashed New rule card at the end. +.rule-list { + display: flex; + flex-direction: column; + gap: 10px; + margin-bottom: 10px; +} + +.rule-card { + border: 1px solid var(--border); + border-radius: var(--radius-lg); + background: var(--surface); +} + +// The rule card's bordered box holds the summary and the form, with Remove beside the summary row. +.rule-card-head { + display: flex; + align-items: flex-start; + + > .rule-details { + flex: 1 1 auto; + min-width: 0; } - th:last-child, - td:last-child { - text-align: right; - white-space: nowrap; + > .remove-form { + flex: none; + margin: 10px 12px 0 0; } +} - .remove-form { - margin: 0; +.rule-details { + > summary { display: flex; - justify-content: flex-end; + align-items: center; + gap: 12px; + padding: 12px 16px; + cursor: pointer; + list-style: none; + border-radius: var(--radius-lg); - button { - width: auto; + &::-webkit-details-marker { + display: none; + } + + &:hover { + background: var(--surface-2); } } - tr.muted td { + &[open] > summary { + border-bottom: 1px solid var(--border); + } + + // The summary's chevron points down when closed and up when open. + > summary .rule-chevron { + flex: none; + width: 7px; + height: 7px; + margin: 0 4px 0 8px; + border-right: 2px solid var(--muted); + border-bottom: 2px solid var(--muted); + transform: rotate(45deg); + transition: transform 0.15s ease; + } + + &[open] > summary .rule-chevron { + transform: rotate(-135deg); + } +} + +.rule-summary-main { + display: flex; + flex: 1 1 auto; + flex-direction: column; + align-items: flex-start; + gap: 6px; + min-width: 0; +} + +.rule-pattern { + padding: 0; + background: none; + font-family: var(--mono); + font-size: 15px; + font-weight: 600; + color: var(--text); + overflow-wrap: anywhere; +} + +.rule-pills { + display: flex; + flex-wrap: wrap; + gap: 6px; +} + +.rule-pill { + display: inline-flex; + align-items: center; + padding: 1px 8px; + border: 1px solid var(--border); + border-radius: var(--radius-full); + background: var(--surface-2); + color: var(--text-2); + font-size: 12px; + line-height: 18px; + white-space: nowrap; + + &.warn { + border-color: var(--warn); + background: color-mix(in srgb, var(--warn) 14%, transparent); + color: var(--warn); + } + + &.check { + font-family: var(--mono); + } + + &.muted { + border-style: dashed; + background: none; color: var(--muted); } } -// Rule form: fields share one width, the approvals count is narrow, and each group of related -// fields sits apart from the next. Help text stays under its field. -.branch-form { - max-width: 40rem; - gap: 24px; +// The built-in default-branch row: muted, dashed, not a card to open. +.rule-builtin { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 6px; + padding: 12px 16px; + border-style: dashed; + border-color: var(--border-strong); + background: none; + color: var(--muted); + + .rule-pattern { + color: var(--muted); + } +} + +// New rule: a dashed row that becomes a card once open. +.rule-new { + border: 0; + background: none; + + > summary { + display: block; + padding: 12px 16px; + border: 1px dashed var(--border-strong); + border-radius: var(--radius-lg); + color: var(--muted); + font-weight: 600; + text-align: center; + cursor: pointer; + list-style: none; + + &::-webkit-details-marker { + display: none; + } + + &:hover { + border-color: var(--accent); + color: var(--accent); + } + } + + &[open] { + border: 1px solid var(--border); + border-radius: var(--radius-lg); + background: var(--surface); + } + + &[open] > summary { + border-style: none; + border-bottom: 1px solid var(--border); + border-radius: var(--radius-lg) var(--radius-lg) 0 0; + color: var(--text); + } +} + +// The rule form: four sections, each with a small uppercase legend. +.rule-form { + display: flex; + flex-direction: column; + gap: 20px; + min-width: 0; + padding: 16px; input[type="text"] { max-width: 28rem; } - input[type="number"] { - width: 8rem; - max-width: 8rem; + .form-actions { + justify-content: flex-end; + } +} + +.rule-section { + display: flex; + flex-direction: column; + gap: 8px; + min-width: 0; + margin: 0; + padding: 0; + border: 0; + + > legend { + padding: 0; + margin-bottom: 2px; + color: var(--muted); + font-size: 0.6875rem; + font-weight: 600; + letter-spacing: 0.06em; + text-transform: uppercase; + } + + > p.muted.small { + margin: 0; + max-width: 28rem; + } + + > label { + max-width: 28rem; + } + + > .context-picker { + margin-top: 2px; + } +} + +.switch-list { + display: flex; + flex-direction: column; + padding: 0 14px; + border: 1px solid var(--border); + border-radius: var(--radius-md); +} + +// A row is a label: text on the left, the toggle or a number input on the right. Rows are split by +// a 1px divider. +.switch-row { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + padding: 12px 0; + border-top: 1px solid var(--border); + cursor: pointer; + + &:first-child { + border-top: 0; } - .rule-group { + > .switch-text { display: flex; flex-direction: column; - gap: 8px; + gap: 2px; + min-width: 0; + } - > p.muted.small { - max-width: 28rem; - margin: -4px 0 0; + .switch-title { + color: var(--text); + font-size: 14px; + font-weight: 500; + line-height: 20px; + } + + .switch-desc { + color: var(--muted); + font-size: 12px; + line-height: 1.4; + } + + input[type="checkbox"] { + appearance: none; + -webkit-appearance: none; + position: relative; + flex: none; + width: 34px; + height: 20px; + margin: 0; + padding: 0; + border-radius: var(--radius-full); + background: var(--border-strong); + cursor: pointer; + transition: background 0.15s ease; + + &::after { + content: ""; + position: absolute; + top: 2px; + left: 2px; + width: 16px; + height: 16px; + border-radius: 50%; + background: var(--surface); + transition: transform 0.15s ease; } - // Help for a checkbox lines up with its label text, past the box. - > p.check-help { - margin-left: 24px; - max-width: 28rem; + &:checked { + background: var(--accent); + } + + &:checked::after { + transform: translateX(14px); + } + + &:focus-visible { + outline: 2px solid var(--focus); + outline-offset: 2px; } } + + input[type="number"] { + flex: none; + width: 72px; + max-width: 72px; + } +} + +@media (max-width: 600px) { + .rule-details > summary { + padding: 10px 12px; + } + + .rule-form { + padding: 12px; + } + + .rule-card-head > .remove-form { + margin-right: 8px; + } } // labels & milestones