diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 241e17c62d..23bc1b46bc 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -296,10 +296,13 @@ f.is_shared, ft.media_id AS thumbnail_id, p.team_id, + -- the live branches of the family, archived ones included: + -- the set the branches-per-file quote counts (select count(*) from file_branch as fb - where fb.source_file_id = f.id + join file as sf on (sf.id = fb.source_file_id) + where sf.family_id = f.family_id and fb.deleted_at is null - and fb.status = 'open') as branches_count + and fb.status <> 'merged') as branches_count from file as f inner join project as p on (p.id = f.project_id) left join file_thumbnail as ft on (ft.file_id = f.id @@ -858,10 +861,12 @@ f.name, f.is_shared, ft.media_id AS thumbnail_id, + -- the same count as sql:project-files (select count(*) from file_branch as fb - where fb.source_file_id = f.id + join file as sf on (sf.id = fb.source_file_id) + where sf.family_id = f.family_id and fb.deleted_at is null - and fb.status = 'open') as branches_count, + and fb.status <> 'merged') as branches_count, row_number() over w as row_num, p.team_id from file as f diff --git a/backend/src/app/rpc/commands/files_branch.clj b/backend/src/app/rpc/commands/files_branch.clj index 79d84d677b..34b0820136 100644 --- a/backend/src/app/rpc/commands/files_branch.clj +++ b/backend/src/app/rpc/commands/files_branch.clj @@ -585,6 +585,32 @@ (bfc/update-file-row! cfg file) nil)) +;; --- Helpers: a branch as the source of another (`:branch-stacking`) + +(def ^:private sql:get-source-edge + "SELECT f.is_branch, fb.status, fb.deleted_at + FROM file AS f + LEFT JOIN file_branch AS fb ON (fb.branch_file_id = f.id) + WHERE f.id = ?") + +(defn- check-source-open + "Refuse to use the file `file-id` as the source of a branch edge (cut a + branch from it, merge into it, update from it) when the file is itself a + branch whose own edge is not open: an archived branch is set aside, and + a merged or deleted one is gone. A root file, and a file detached from + its branch, pass. A caller that writes into `file-id` or pins it runs + the check under the lock of `file-id`, the lock an archive takes, so + the archive cannot commit between the check and the write." + [conn file-id] + (let [{:keys [is-branch status deleted-at]} (db/exec-one! conn [sql:get-source-edge file-id])] + (when (and is-branch + (or (not= "open" status) (some? deleted-at))) + (ex/raise :type :validation + :code :source-branch-not-open + :hint "the source of this operation is a branch that is not open" + :file-id file-id + :status status)))) + ;; --- COMMAND: create-file-branch (defn- check-branch-name! @@ -612,7 +638,7 @@ reviews, threads, and tasks of every file in it. A branch of a branch is refused unless the `:branch-stacking` flag is - on." + on, and then only while the branch it is cut from is open." {::doc/added "2.16" ::webhooks/event? true ::sm/params schema:create-file-branch @@ -642,12 +668,24 @@ ;; (same advisory lock) so the base snapshot and the ;; branch's initial state (the empty op log over that ;; base) are taken from the SAME state of main. - (db/xact-lock! conn file-id) + ;; + ;; The family id is locked too: the quota counts the + ;; whole family, and two creators cutting from two files + ;; of it (main and a child of main) would otherwise take + ;; two different locks and both pass the quota for the + ;; last slot. Sorted, as `merge-file-branch` takes its + ;; two, to avoid deadlocks. The family id is the root + ;; file id, so branching the root takes one lock. + (run! (partial db/xact-lock! conn) + (sort (distinct [file-id (:family-id file-row)]))) + + ;; an archived branch is no source for a new one + (check-source-open conn file-id) ;; The quota check runs INSIDE the transaction and - ;; AFTER the lock: two creators racing for the last - ;; branch slot serialize on the lock, and the loser's - ;; count must see the winner's committed row. + ;; AFTER the locks: two creators racing for the last + ;; branch slot serialize on the family lock, and the + ;; loser's count must see the winner's committed row. ;; `quotes/check!` reads through `::db/conn`, so it ;; counts on this transaction's connection. (-> cfg @@ -1247,6 +1285,9 @@ (ex/raise :type :validation :code :branch-not-open :branch-id branch-id)) + ;; a merge into a branch needs that branch open: an + ;; archived target is set aside (`:branch-stacking`) + _ (check-source-open conn main-id) [main-stored main-file] (read-main-for-write cfg main-id :merge) _ (check-oplog-depth-limit! (bfc/get-branch-oplog-depth cfg branch-file-id) branch-file-id @@ -1600,6 +1641,9 @@ (ex/raise :type :validation :code :branch-not-open :branch-id branch-id)) + ;; an archived source is set aside, so nothing flows + ;; from it either (`:branch-stacking`) + _ (check-source-open conn main-id) [main-stored main-file] (read-main-for-write cfg main-id :update-from-source) _ (when (and (some? expected-source-revn) (not= expected-source-revn (:revn main-file))) @@ -2106,25 +2150,27 @@ [:file-id ::sm/uuid]]) (def ^:private sql:get-file-branch-count + ;; the same count as the `branches-per-file` quote + ;; (`quotes.clj::sql:get-branches-per-file`), so the number a user sees + ;; is the number the limit is checked against "SELECT count(*) AS count FROM file_branch AS fb - WHERE fb.deleted_at IS NULL - AND fb.status != 'merged' - AND fb.source_file_id = coalesce((SELECT b.source_file_id - FROM file_branch AS b - WHERE b.branch_file_id = ? - AND b.deleted_at IS NULL), - ?)") + JOIN file AS sf ON (sf.id = fb.source_file_id) + WHERE sf.family_id = (SELECT f.family_id FROM file AS f WHERE f.id = ?) + AND fb.deleted_at IS NULL + AND fb.status != 'merged'") (sv/defmethod ::get-file-branch-count - "How many branches the file has, archived ones included, as the - listing with `:include-archived` returns them. When the file is - itself a branch, the branches of its source (main) are counted. + "How many live branches the family of the file has, archived ones + included and merged ones left out: the count the `branches-per-file` + quote checks. A branch of a branch (`:branch-stacking`) counts in the + family of its root, so a file and every branch in its family answer the + same number. The workspace header asks this on every file open to decide whether to - show its branch row, so it compares nothing and takes no climit: it is - the dashboard's `branches_count` subquery, one indexed count. Returns a - zero count when branching is disabled, so it is safe on every open." + show its branch row, so it compares nothing and takes no climit: one + indexed count. Returns a zero count when branching is disabled, so it + is safe on every open." {::doc/added "2.16" ::sm/params schema:get-file-branch-count} [cfg {:keys [::rpc/profile-id file-id]}] @@ -2132,7 +2178,7 @@ (db/run! cfg (fn [{:keys [::db/conn] :as cfg}] (files/check-read-permissions! cfg profile-id file-id) - (-> (db/exec-one! conn [sql:get-file-branch-count file-id file-id]) + (-> (db/exec-one! conn [sql:get-file-branch-count file-id]) (select-keys [:count])))) {:count 0})) diff --git a/backend/src/app/rpc/commands/files_branch_review.clj b/backend/src/app/rpc/commands/files_branch_review.clj index 195cf86d5a..95374902ca 100644 --- a/backend/src/app/rpc/commands/files_branch_review.clj +++ b/backend/src/app/rpc/commands/files_branch_review.clj @@ -88,7 +88,8 @@ fb.source_file_id AS target_file_id, bf.revn AS branch_revn, sf.revn AS source_revn, - sf.name AS target_name + sf.name AS target_name, + (sf.id = sf.family_id) AS target_is_main FROM file_branch_review AS r JOIN file_branch AS fb ON (fb.id = r.file_branch_id) LEFT JOIN file AS bf ON (bf.id = fb.branch_file_id) @@ -463,7 +464,8 @@ fb.source_file_id AS target_file_id, bf.revn AS branch_revn, sf.revn AS source_revn, - sf.name AS target_name + sf.name AS target_name, + (sf.id = sf.family_id) AS target_is_main FROM file_branch_review AS r JOIN file_branch AS fb ON (fb.id = r.file_branch_id) LEFT JOIN file AS bf ON (bf.id = fb.branch_file_id) @@ -1071,7 +1073,8 @@ fb.branch_file_id AS source_file_id, fb.source_file_id AS target_file_id, fb.name AS branch_name, - sf.name AS target_name + sf.name AS target_name, + (sf.id = sf.family_id) AS target_is_main FROM file_branch_reviewer AS v JOIN file_branch_review AS r ON (r.id = v.review_id) JOIN file_branch AS fb ON (fb.id = r.file_branch_id) diff --git a/backend/src/app/rpc/quotes.clj b/backend/src/app/rpc/quotes.clj index e55ca6cc5c..a914b18bef 100644 --- a/backend/src/app/rpc/quotes.clj +++ b/backend/src/app/rpc/quotes.clj @@ -494,9 +494,17 @@ (sm/lazy-validator schema:branches-per-file)) (def ^:private sql:get-branches-per-file + ;; The limit holds for the family of the file the branch is cut from: a + ;; branch of a branch (`:branch-stacking`) counts against the same + ;; limit as its parent, so a family never holds more live branches than + ;; the quote allows. An edge belongs to the family of its source file. + ;; An archived branch counts, because its designer still has it and can + ;; restore it. A merged branch does not: its work is in its target and + ;; the merge deleted it. "SELECT count(*) AS total FROM file_branch AS fb - WHERE fb.source_file_id = ? + JOIN file AS sf ON (sf.id = fb.source_file_id) + WHERE sf.family_id = (SELECT f.family_id FROM file AS f WHERE f.id = ?) AND fb.deleted_at IS NULL AND fb.status <> 'merged'") diff --git a/backend/test/backend_tests/rpc_file_branch_test.clj b/backend/test/backend_tests/rpc_file_branch_test.clj index 8dca399310..8c15680e1b 100644 --- a/backend/test/backend_tests/rpc_file_branch_test.clj +++ b/backend/test/backend_tests/rpc_file_branch_test.clj @@ -73,7 +73,7 @@ src (first (filter #(= (:id %) (:id file)) rows))] (t/is (contains? ids (:id file))) (t/is (not (contains? ids @branch-file-id))) - ;; the source file card reports its open branch count + ;; the source file card reports the live branches of its family (t/is (= 1 (:branches-count src)))))) (t/testing "list branches" @@ -1280,7 +1280,112 @@ :name name}))) child (create (:id file) "child") grand (create (:branch-file-id child) "grandchild")] - {:proj-id proj-id :file file :branches [child grand]})) + {:profile profile :proj-id proj-id :file file :branches [child grand]})) + +(defn- archive-branch* + [profile branch archived] + (th/command! {::th/type :archive-file-branch + ::rpc/profile-id (:id profile) + :branch-id (:id branch) + :archived archived})) + +(t/deftest the-branch-quota-counts-the-whole-family + ;; Counted by direct source, the chain below holds one branch per + ;; source, so a third branch from main passed a quota of two. + (with-redefs [cf/flags (stacking-flags) + cf/get (th/config-get-mock {:quotes-branches-per-file 2})] + (let [{:keys [profile proj-id file branches]} (branch-chain*) + [child grand] branches + create (fn [source-id name] + (th/command! {::th/type :create-file-branch + ::rpc/profile-id (:id profile) + :file-id source-id + :name name})) + count-of (fn [file-id] + (-> (th/command! {::th/type :get-file-branch-count + ::rpc/profile-id (:id profile) + :file-id file-id}) + :result :count))] + + (t/testing "the chain fills the family's two slots" + (doseq [source-id [(:id file) (:branch-file-id child) (:branch-file-id grand)]] + (let [data (-> (create source-id "one-too-many") :error ex-data)] + (t/is (= :restriction (:type data))) + (t/is (= :max-quote-reached (:code data)))))) + + (t/testing "every file of the family shows the count the quota checks" + (doseq [file-id [(:id file) (:branch-file-id child) (:branch-file-id grand)]] + (t/is (= 2 (count-of file-id)))) + (let [rows (:result (th/command! {::th/type :get-project-files + ::rpc/profile-id (:id profile) + :project-id proj-id})) + src (first (filter #(= (:id %) (:id file)) rows))] + (t/is (= 2 (:branches-count src))))) + + (t/testing "an archived branch still counts, a deleted one frees its slot" + (t/is (nil? (:error (archive-branch* profile grand true)))) + (t/is (= 2 (count-of (:id file)))) + (t/is (nil? (:error (th/command! {::th/type :delete-file-branch + ::rpc/profile-id (:id profile) + :branch-id (:id grand)})))) + (t/is (= 1 (count-of (:id file)))) + (t/is (nil? (:error (create (:branch-file-id child) "fits")))))))) + +(t/deftest merge-into-an-archived-branch-is-refused + ;; The merge checked only the merged branch: an archived parent took + ;; its child's changes. + (with-redefs [cf/flags (stacking-flags)] + (let [{:keys [profile branches]} (branch-chain*) + [child grand] branches + _ (apply-change* profile (:branch-file-id grand) (color-change (uuid/random))) + merge-grand (fn [] + (th/command! {::th/type :merge-file-branch + ::rpc/profile-id (:id profile) + :branch-id (:id grand)}))] + (t/is (nil? (:error (archive-branch* profile child true)))) + + (let [data (-> (merge-grand) :error ex-data)] + (t/is (= :validation (:type data))) + (t/is (= :source-branch-not-open (:code data)))) + (t/is (= "open" (:status (th/db-get :file-branch {:id (:id grand)})))) + + (t/testing "the merge goes through once the parent is restored" + (t/is (nil? (:error (archive-branch* profile child false)))) + (let [out (merge-grand)] + (t/is (nil? (:error out))) + (t/is (= :merged (-> out :result :status)))))))) + +(t/deftest an-archived-branch-is-no-source + ;; Creation checked only the stacking flag and the update checked only + ;; the child, so both ran against an archived parent. + (with-redefs [cf/flags (stacking-flags)] + (let [{:keys [profile branches]} (branch-chain*) + [child grand] branches + _ (apply-change* profile (:branch-file-id child) (color-change (uuid/random))) + _ (t/is (nil? (:error (archive-branch* profile child true))))] + + (t/testing "no branch is cut from it" + (let [data (-> (th/command! {::th/type :create-file-branch + ::rpc/profile-id (:id profile) + :file-id (:branch-file-id child) + :name "from-archived"}) + :error ex-data)] + (t/is (= :validation (:type data))) + (t/is (= :source-branch-not-open (:code data))))) + + (t/testing "its child does not update from it" + (let [data (-> (th/command! {::th/type :update-file-branch-from-source + ::rpc/profile-id (:id profile) + :branch-id (:id grand)}) + :error ex-data)] + (t/is (= :validation (:type data))) + (t/is (= :source-branch-not-open (:code data))))) + + (t/testing "a restored branch is a source again" + (t/is (nil? (:error (archive-branch* profile child false)))) + (t/is (nil? (:error (th/command! {::th/type :update-file-branch-from-source + ::rpc/profile-id (:id profile) + :branch-id (:id grand)})))))))) (defn- branch-files-deleted? [branches] diff --git a/frontend/src/app/main/data/workspace/branches.cljs b/frontend/src/app/main/data/workspace/branches.cljs index cc4c23dfc2..c83c71c317 100644 --- a/frontend/src/app/main/data/workspace/branches.cljs +++ b/frontend/src/app/main/data/workspace/branches.cljs @@ -85,8 +85,8 @@ (assoc state :workspace-branch-count (assoc count-state :file-id file-id))))) (defn fetch-branch-count - "Load how many branches the open file has, archived ones included and - counted from main when the file is itself a branch. The header reads it + "Load how many live branches the family of the open file has, archived + ones included: the count the branch quota checks. The header reads it to decide whether to show its branch row, so it loads with the file; it compares nothing, unlike the listing, which loads only when a user opens the switcher or the all-branches dialog. A count belonging to ANOTHER @@ -118,9 +118,10 @@ (defn fetch-branches "Load the branch listing of the open file. A failure leaves the listing in `:error`, never in an empty list, so it cannot read as a file with no - branches. A successful listing also refreshes the branch count, since it - covers the same branches, so the header follows a delete or a - materialize made from the listing." + branches. A successful listing also reloads the branch count, so the + header follows a delete or a materialize made from the listing. The + count is reloaded rather than taken from the listing, which holds only + the branches of one source while the count covers the family." [] (ptk/reify ::fetch-branches ptk/WatchEvent @@ -135,7 +136,7 @@ (rp/cmd! :get-file-branches {:file-id root :include-archived true})))) (rx/mapcat (fn [data] (rx/of (update-branches-state {:status :loaded :data data}) - (set-branch-count file-id {:count (count data)})))) + (fetch-branch-count)))) (rx/catch (fn [_] (rx/of (update-branches-state {:status :error}))))))))) @@ -207,6 +208,11 @@ (:branch-not-found :branch-merged :branch-not-open) (ntf/warn (tr "workspace.branches.limits.refuse-stale")) + ;; the branch to cut from, merge into, or update from is archived + ;; or gone (`:branch-stacking`) + :source-branch-not-open + (ntf/warn (tr "workspace.branches.limits.refuse-source-not-open")) + :invalid-branch-name (ntf/warn (tr "workspace.branches.limits.refuse-name")) @@ -232,9 +238,10 @@ (assoc state :dashboard-branches bs)))) (defn load-file-branches - "Load the open branches of `file-id` into `:dashboard-branches` (used by - the dashboard branches popover). The previous list is cleared first so a - popover opened on another file never shows stale entries." + "Load the open and archived branches of `file-id` into + `:dashboard-branches` (used by the dashboard branches popover), the set + its badge counts. The previous list is cleared first so a popover opened + on another file never shows stale entries." [file-id] (ptk/reify ::load-file-branches ptk/UpdateEvent @@ -243,7 +250,7 @@ ptk/WatchEvent (watch [_ _ _] - (->> (rp/cmd! :get-file-branches {:file-id file-id}) + (->> (rp/cmd! :get-file-branches {:file-id file-id :include-archived true}) (rx/map set-dashboard-branches) (rx/catch (fn [_] (rx/of (set-dashboard-branches [])))))))) diff --git a/frontend/src/app/main/ui/dashboard/branches_popover.cljs b/frontend/src/app/main/ui/dashboard/branches_popover.cljs index 2fb210525d..2d184aa625 100644 --- a/frontend/src/app/main/ui/dashboard/branches_popover.cljs +++ b/frontend/src/app/main/ui/dashboard/branches_popover.cljs @@ -77,7 +77,10 @@ [:> branch-row* {:label (:name b) :data-branch (dm/str (:branch-file-id b)) :on-click on-open-branch} - [:> branch-status* {:ahead (:ahead b) - :behind (:behind b) - :conflicts (:conflicts b) - :has-error (boolean (or (:diff-error b) (nil? (:ahead b))))}]]])]]]])) + ;; an archived branch has no live comparison to show + (if (= "archived" (:status b)) + (tr "workspace.branches.archived") + [:> branch-status* {:ahead (:ahead b) + :behind (:behind b) + :conflicts (:conflicts b) + :has-error (boolean (or (:diff-error b) (nil? (:ahead b))))}])]])]]]])) diff --git a/frontend/src/app/main/ui/workspace/review/common.cljs b/frontend/src/app/main/ui/workspace/review/common.cljs index ab4076500f..7f571ce466 100644 --- a/frontend/src/app/main/ui/workspace/review/common.cljs +++ b/frontend/src/app/main/ui/workspace/review/common.cljs @@ -20,6 +20,15 @@ (or (get-in profiles [profile-id :fullname]) (tr "workspace.review.unknown-name"))) +(defn route-target + "The name the route of the review `pr` gives the file it merges into: + `main-label` when that file is the root of its family (main), and the + file's own name when it is a branch (`:branch-stacking`). A row that + does not say keeps `main-label`, the wording of every review before + branches could stack." + [{:keys [target-is-main target-name]} main-label] + (if (false? target-is-main) target-name main-label)) + (defn status-tone "The tone a task in `status` is drawn in, the colour of its state." [status] diff --git a/frontend/src/app/main/ui/workspace/review/details.cljs b/frontend/src/app/main/ui/workspace/review/details.cljs index 6ea35c3cef..a0b7c1b6dd 100644 --- a/frontend/src/app/main/ui/workspace/review/details.cljs +++ b/frontend/src/app/main/ui/workspace/review/details.cljs @@ -653,7 +653,8 @@ [:> pr-state-badge* {:pr pr}] [:> text* {:as "span" :typography t/body-small :class (stl/css :muted)} (tr "workspace.review.text-and-detail" - (tr "workspace.review.route" (:branch-name pr) (tr "workspace.branches.main")) + (tr "workspace.review.route" (:branch-name pr) + (rvc/route-target pr (tr "workspace.branches.main"))) (tr "workspace.review.details.opened-by" (ct/format-inst (:created-at pr) :localized-date) (or (:fullname author) (tr "workspace.review.unknown-name"))))]])}] diff --git a/frontend/src/app/main/ui/workspace/review/panel.cljs b/frontend/src/app/main/ui/workspace/review/panel.cljs index 34d756f313..b47fe68f01 100644 --- a/frontend/src/app/main/ui/workspace/review/panel.cljs +++ b/frontend/src/app/main/ui/workspace/review/panel.cljs @@ -228,7 +228,8 @@ {::mf/private true} [{:keys [pr]}] (let [[approvals total] (prui/current-approvals pr) - route (tr "workspace.review.route" (:branch-name pr) (tr "workspace.branches.main"))] + route (tr "workspace.review.route" (:branch-name pr) + (rvc/route-target pr (tr "workspace.branches.main")))] [:div {:class (stl/css :review-header)} [:div {:class (stl/css :review-title-row)} [:> heading* {:level 2 :typography t/body-large :class (stl/css :review-title)} diff --git a/frontend/src/app/main/ui/workspace/sidebar/pull_requests.cljs b/frontend/src/app/main/ui/workspace/sidebar/pull_requests.cljs index 402ba57e64..a818e395ff 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/pull_requests.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/pull_requests.cljs @@ -38,6 +38,7 @@ [app.main.ui.ds.product.avatar :refer [avatar*]] [app.main.ui.ds.tooltip :refer [tooltip*]] [app.main.ui.workspace.compare.common :as cc] + [app.main.ui.workspace.review.common :as rvc] [app.util.dom :as dom] [app.util.i18n :refer [tr]] [cuerdas.core :as str] @@ -443,10 +444,11 @@ [:> text* {:as "span" :typography t/body-small :class (stl/css :dialog-subtitle)} - ;; the route reads branch → target BRANCH (reviews always merge - ;; into main); the target file name would be redundant here, - ;; inside the file itself - (tr "workspace.review.route" (:branch-name pr) (tr "workspace.branches.main"))] + ;; the route reads branch → target: "Main" for the root of the + ;; family, whose file name would be redundant inside the file + ;; itself, and the target's name for a branch of a branch + (tr "workspace.review.route" (:branch-name pr) + (rvc/route-target pr (tr "workspace.branches.main")))] (when (and open? (:outdated pr)) [:span {:class (stl/css :pr-badge :badge-outdated)} (tr "workspace.pull-requests.badge.outdated")]) @@ -566,8 +568,12 @@ (tr "workspace.compare.bar.comparing")] [:span {:class (stl/css :pr-banner-name)} (if (:incoming comparison) - (tr "workspace.review.route" (tr "workspace.branches.main") (:branch-name pr)) - (tr "workspace.review.route" (:branch-name pr) (tr "workspace.branches.main")))]])] + (tr "workspace.review.route" + (rvc/route-target pr (tr "workspace.branches.main")) + (:branch-name pr)) + (tr "workspace.review.route" + (:branch-name pr) + (rvc/route-target pr (tr "workspace.branches.main"))))]])] (when (some? progress) [:* diff --git a/frontend/test/frontend_tests/data/workspace_branches_test.cljs b/frontend/test/frontend_tests/data/workspace_branches_test.cljs index 074046e168..47f72da1e4 100644 --- a/frontend/test/frontend_tests/data/workspace_branches_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_branches_test.cljs @@ -461,14 +461,15 @@ (await (mock/with-mocks* {rp/cmd! (mock/stub (fn [cmd _] (case cmd - :get-file-branch-info (rx/of nil) - :get-file-branches (rx/of [{:id (uuid/next) :status "open"}]) + :get-file-branch-info (rx/of nil) + :get-file-branches (rx/of [{:id (uuid/next) :status "open"}]) + :get-file-branch-count (rx/of {:count 1}) (rx/empty))))} (let [store (make-store-with (assoc main-without-branches :workspace-branch-count {:file-id file-id :status :error}))] (ptk/emit! store (dwb/init-branches-state)) - (await (async/wait-for #(= :loaded (get-in @store [:workspace-branches :status])) - "the listing lands")) + (await (async/wait-for #(some? (get-in @store [:workspace-branch-count :count])) + "the listing reloads the count")) (t/is (= {:file-id file-id :count 1} (:workspace-branch-count @store))) (t/is (false? (dwb/branch-count-failed? @store))) (rx/dispose! store))))) @@ -477,13 +478,14 @@ (await (mock/with-mocks* {rp/cmd! (mock/stub (fn [cmd _] (case cmd - :get-file-branch-info (rx/of nil) - :get-file-branches (rx/of []) + :get-file-branch-info (rx/of nil) + :get-file-branches (rx/of []) + :get-file-branch-count (rx/of {:count 0}) (rx/empty))))} (let [store (make-store-with main-with-branches)] (ptk/emit! store (dwb/fetch-branches)) - (await (async/wait-for #(= :loaded (get-in @store [:workspace-branches :status])) - "the listing lands")) + (await (async/wait-for #(= 0 (get-in @store [:workspace-branch-count :count])) + "the listing reloads the count")) (t/is (= 0 (get-in @store [:workspace-branch-count :count])) "deleting the last branch from the listing hides the switcher") (t/is (false? (dwb/has-branches? @store))) diff --git a/frontend/test/frontend_tests/ui/review_details_test.cljs b/frontend/test/frontend_tests/ui/review_details_test.cljs index 79870bc2f5..bc023e87f4 100644 --- a/frontend/test/frontend_tests/ui/review_details_test.cljs +++ b/frontend/test/frontend_tests/ui/review_details_test.cljs @@ -45,6 +45,11 @@ (t/is (= ["info" "success" "warning" "purple" "error"] (mapv rvc/status-tone dwrv/task-statuses)))) +(t/deftest the-route-names-a-branch-target-and-calls-the-root-main + (t/is (= "Parent" (rvc/route-target {:target-name "Parent" :target-is-main false} "Main"))) + (t/is (= "Main" (rvc/route-target {:target-name "Design file" :target-is-main true} "Main"))) + (t/is (= "Main" (rvc/route-target {:target-name "Design file"} "Main")))) + (t/deftest the-activity-comes-folded-from-the-server (let [entry {:id (uuid/random) :page-id (uuid/random) :kind :added} session {:profile-id (uuid/random) diff --git a/frontend/translations/en.po b/frontend/translations/en.po index ed93957bb9..c2c48c30a6 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -7251,6 +7251,12 @@ msgstr "" "This branch is no longer in the state the panel showed. Reopen the branches " "panel to see where it is now." +#: src/app/main/data/workspace/branches.cljs +msgid "workspace.branches.limits.refuse-source-not-open" +msgstr "" +"The branch to branch from, merge into, or update from is archived or gone. " +"Restore it first." + #: src/app/main/data/workspace/branches.cljs msgid "workspace.branches.limits.refuse-name" msgstr "A branch name can't be empty." diff --git a/frontend/translations/es.po b/frontend/translations/es.po index ebc595c31a..c4c8e28b81 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -7357,6 +7357,12 @@ msgstr "" "Esta rama ya no está como la mostraba el panel. Vuelve a abrir el panel de " "ramas para ver su estado actual." +#: src/app/main/data/workspace/branches.cljs +msgid "workspace.branches.limits.refuse-source-not-open" +msgstr "" +"La rama desde la que quieres crear, en la que quieres fusionar o desde la que " +"quieres actualizar está archivada o ya no existe. Restáurala primero." + #: src/app/main/data/workspace/branches.cljs msgid "workspace.branches.limits.refuse-name" msgstr "El nombre de una rama no puede estar vacío."