From 17586953bb9c6ac1f9044efe5ee7df56b270c9c7 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Fri, 27 Jun 2025 15:26:07 +0200 Subject: [PATCH] Draft reviews before publishing Reviews are locally persisted but only published to the network by an explicit user action. - [ ] Delete line comments on draft reviews [squash] Sort imports, separate type imports into own section --- .../radicle-tauri/src/commands/cob/patch.rs | 38 +++- crates/radicle-tauri/src/lib.rs | 1 + .../bindings/cob/patch/CreateReviewArgs.ts | 12 ++ .../bindings/cob/patch/ReviewInit.ts | 10 + .../src/domain/patch/models/patch.rs | 23 ++ src/components/Review.svelte | 167 ++++++++++---- src/components/ReviewButton.svelte | 142 ------------ src/components/ReviewTeaser.svelte | 17 +- src/components/Reviews.svelte | 114 +++++----- src/components/Revision.svelte | 2 +- src/lib/draftReviewStorage.ts | 204 ++++++++++++++++++ src/views/repo/Patch.svelte | 52 +++-- src/views/repo/router.ts | 21 +- 13 files changed, 521 insertions(+), 282 deletions(-) create mode 100644 crates/radicle-types/bindings/cob/patch/CreateReviewArgs.ts create mode 100644 crates/radicle-types/bindings/cob/patch/ReviewInit.ts delete mode 100644 src/components/ReviewButton.svelte create mode 100644 src/lib/draftReviewStorage.ts diff --git a/crates/radicle-tauri/src/commands/cob/patch.rs b/crates/radicle-tauri/src/commands/cob/patch.rs index 8b40548de..673aed730 100644 --- a/crates/radicle-tauri/src/commands/cob/patch.rs +++ b/crates/radicle-tauri/src/commands/cob/patch.rs @@ -1,6 +1,7 @@ use std::ops::ControlFlow; -use radicle::patch::TYPENAME; +use radicle::patch::cache::Patches as _; +use radicle::patch::{ReviewId, TYPENAME}; use radicle::storage::ReadStorage; use radicle::{cob, git, identity}; @@ -120,6 +121,41 @@ pub fn edit_patch( ctx.edit_patch(rid, cob_id, action, opts) } +#[tauri::command] +pub fn create_patch_review( + ctx: tauri::State, + args: models::patch::CreateReviewArgs, +) -> Result { + let repo = ctx.profile.storage.repository(args.rid)?; + let signer = ctx.profile.signer()?; + let mut patches = ctx.profile.patches_mut(&repo)?; + let patch_id = match patches.find_by_revision(&args.revision)? { + Some(found) => found.id, + None => return Err(cob::patch::Error::RevisionNotFound(args.revision).into()), + }; + let mut patch = patches.get_mut(&patch_id)?; + let review_id = patch.review( + args.revision, + args.verdict.map(Into::into), + args.summary, + args.labels, + &signer, + )?; + + for comment in args.comments { + patch.review_comment( + review_id, + comment.body, + comment.location.map(Into::into), + None, + vec![], + &signer, + )?; + } + + Ok(review_id) +} + #[tauri::command] pub fn activity_by_patch( ctx: tauri::State, diff --git a/crates/radicle-tauri/src/lib.rs b/crates/radicle-tauri/src/lib.rs index e217c537b..185dfc63b 100644 --- a/crates/radicle-tauri/src/lib.rs +++ b/crates/radicle-tauri/src/lib.rs @@ -37,6 +37,7 @@ pub fn run() { cob::patch::list_patches, cob::patch::patch_by_id, cob::patch::edit_patch, + cob::patch::create_patch_review, cob::patch::rebuild_patch_cache, cob::patch::review_by_patch_and_revision_and_id, cob::patch::revisions_by_patch, diff --git a/crates/radicle-types/bindings/cob/patch/CreateReviewArgs.ts b/crates/radicle-types/bindings/cob/patch/CreateReviewArgs.ts new file mode 100644 index 000000000..6f45248e0 --- /dev/null +++ b/crates/radicle-types/bindings/cob/patch/CreateReviewArgs.ts @@ -0,0 +1,12 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { CodeLocation } from "../thread/CodeLocation"; +import type { Verdict } from "./Verdict"; + +export type CreateReviewArgs = { + rid: string; + revision: string; + verdict: Verdict | null; + summary: string | null; + labels: Array; + comments: Array<{ body: string; location: CodeLocation | null }>; +}; diff --git a/crates/radicle-types/bindings/cob/patch/ReviewInit.ts b/crates/radicle-types/bindings/cob/patch/ReviewInit.ts new file mode 100644 index 000000000..95f85498a --- /dev/null +++ b/crates/radicle-types/bindings/cob/patch/ReviewInit.ts @@ -0,0 +1,10 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Verdict } from "./Verdict"; + +export type ReviewInit = { + "type": "ReviewInit"; + revision: string; + summary?: string; + verdict?: Verdict; + labels?: Array; +}; diff --git a/crates/radicle-types/src/domain/patch/models/patch.rs b/crates/radicle-types/src/domain/patch/models/patch.rs index 37ffbf62f..4416e54d5 100644 --- a/crates/radicle-types/src/domain/patch/models/patch.rs +++ b/crates/radicle-types/src/domain/patch/models/patch.rs @@ -4,6 +4,7 @@ use std::ops::Index; use radicle::node::AliasStore; use radicle::patch::Status; +use radicle::prelude::RepoId; use radicle::profile::Aliases; use serde::{Deserialize, Serialize}; use ts_rs::TS; @@ -671,6 +672,28 @@ impl FromRadicleAction for Action { } } +#[derive(Debug, TS, Deserialize)] +#[ts(export)] +#[ts(export_to = "cob/patch/")] +pub struct CreateReviewArgs { + #[ts(as = "String")] + pub rid: RepoId, + #[ts(as = "String")] + pub revision: patch::RevisionId, + pub verdict: Option, + pub summary: Option, + #[ts(as = "Vec")] + pub labels: Vec, + #[ts(inline)] + pub comments: Vec, +} + +#[derive(Debug, TS, Deserialize)] +pub struct CreateReviewComment { + pub body: String, + pub location: Option, +} + #[derive(Debug, Default, TS, Serialize)] #[ts(export)] #[ts(export_to = "cob/patch/")] diff --git a/src/components/Review.svelte b/src/components/Review.svelte index 4b1fa6829..c2768b168 100644 --- a/src/components/Review.svelte +++ b/src/components/Review.svelte @@ -2,6 +2,7 @@ import type { Author } from "@bindings/cob/Author"; import type { CodeLocation } from "@bindings/cob/thread/CodeLocation"; import type { Config } from "@bindings/config/Config"; + import type { DraftReview } from "@app/lib/draftReviewStorage"; import type { Embed } from "@bindings/cob/thread/Embed"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; import type { Review } from "@bindings/cob/patch/Review"; @@ -19,6 +20,7 @@ import { nodeRunning } from "@app/lib/events"; import Border from "@app/components/Border.svelte"; + import Button from "./Button.svelte"; import Changes from "@app/components/Changes.svelte"; import CommentComponent from "@app/components/Comment.svelte"; import Discussion from "@app/components/Discussion.svelte"; @@ -29,6 +31,8 @@ import NodeId from "@app/components/NodeId.svelte"; import VerdictBadge from "@app/components/VerdictBadge.svelte"; import VerdictButton from "@app/components/VerdictButton.svelte"; + import { draftReviewStorage } from "@app/lib/draftReviewStorage"; + import { push } from "@app/lib/router"; interface Props { config: Config; @@ -36,7 +40,7 @@ patchId: string; loadReview: () => Promise; repo: RepoInfo; - review: Review; + review: Review | DraftReview; revision: Revision; } @@ -62,6 +66,9 @@ ), ); + let publishingInProgress = $state(false); + const canPublish = $derived(review.verdict || review.summary); + const commentThreads = $derived( ((review.comments && review.comments @@ -123,18 +130,26 @@ try { labelSaveInProgress = true; - await invoke("edit_patch", { - rid: repo.rid, - cobId: patchId, - action: { - type: "review.edit", - review: reviewId, - summary, + if ("draft" in review) { + draftReviewStorage.update(review.id, { verdict, + summary: summary ?? "", labels, - }, - opts: { announce: $nodeRunning && $announce }, - }); + }); + } else { + await invoke("edit_patch", { + rid: repo.rid, + cobId: patchId, + action: { + type: "review.edit", + review: reviewId, + summary, + verdict, + labels, + }, + opts: { announce: $nodeRunning && $announce }, + }); + } } catch (error) { console.error("Editing review failed: ", error); } finally { @@ -150,19 +165,27 @@ location?: CodeLocation, ) { try { - await invoke("edit_patch", { - rid: repo.rid, - cobId: patchId, - action: { - type: "review.comment", - review: review.id, + if ("draft" in review) { + draftReviewStorage.addComment(review.id, { body, embeds, - replyTo, - location, - }, - opts: { announce: $nodeRunning && $announce }, - }); + location: location!, + }); + } else { + await invoke("edit_patch", { + rid: repo.rid, + cobId: patchId, + action: { + type: "review.comment", + review: review.id, + body, + embeds, + replyTo, + location, + }, + opts: { announce: $nodeRunning && $announce }, + }); + } } catch (error) { console.error("Creating comment failed", error); } finally { @@ -172,18 +195,25 @@ async function editComment(commentId: string, body: string, embeds: Embed[]) { try { - await invoke("edit_patch", { - rid: repo.rid, - cobId: patchId, - action: { - type: "review.comment.edit", - comment: commentId, + if ("draft" in review) { + draftReviewStorage.updateComment(review.id, commentId, { body, - review: review.id, embeds, - }, - opts: { announce: $nodeRunning && $announce }, - }); + }); + } else { + await invoke("edit_patch", { + rid: repo.rid, + cobId: patchId, + action: { + type: "review.comment.edit", + comment: commentId, + body, + review: review.id, + embeds, + }, + opts: { announce: $nodeRunning && $announce }, + }); + } } catch (error) { console.error("Editing comment failed: ", error); } finally { @@ -197,6 +227,9 @@ authors: Author[], reaction: string, ) { + if ("draft" in review) { + throw new Error("Cannot react on comment for draft review"); + } try { await invoke("edit_patch", { rid: repo.rid, @@ -220,6 +253,9 @@ } async function changeCommentStatus(commentId: string, resolved: boolean) { + if ("draft" in review) { + throw new Error("Cannot change comment status for draft review"); + } try { await invoke("edit_patch", { rid: repo.rid, @@ -309,8 +345,40 @@ 's review + styleFontWeight="var(--font-weight-medium)" />'s + {#if "draft" in review} + draft + {/if} + review + {#if "draft" in review} +
+ +
+ {/if} @@ -370,10 +438,10 @@ disallowEmptyBody={review.verdict === undefined} emptyBodyTooltip="Summary is mandatory when verdict is None" styleWidth="100%" - caption="published review" - id={review.id} + caption={"draft" in review ? "draft review" : "published review"} + id={"draft" in review ? undefined : review.id} author={review.author} - timestamp={review.timestamp} + timestamp={"draft" in review ? undefined : review.timestamp} editComment={(publicKeyFromDid(review.author.did) === config.publicKey || undefined) && @@ -388,24 +456,29 @@ - + {#if !("draft" in review)} + + {/if} - import type { Config } from "@bindings/config/Config"; - import type { PatchStatus } from "@app/views/repo/router"; - import type { Review } from "@bindings/cob/patch/Review"; - import type { Revision } from "@bindings/cob/patch/Revision"; - import type { Verdict } from "@bindings/cob/patch/Verdict"; - - import { closeFocused } from "./Popover.svelte"; - import { didFromPublicKey } from "@app/lib/utils"; - import { push } from "@app/lib/router"; - - import Border from "@app/components/Border.svelte"; - import Icon from "@app/components/Icon.svelte"; - import NakedButton from "@app/components/NakedButton.svelte"; - import OutlineButton from "@app/components/OutlineButton.svelte"; - import Popover from "@app/components/Popover.svelte"; - - interface Props { - rid: string; - patchId: string; - revision: Revision; - config: Config; - status: PatchStatus | undefined; - loadPatch: () => Promise; - createReview: (verdict?: Verdict) => Promise; - } - - const { - rid, - patchId, - revision, - config, - status, - loadPatch, - createReview, - }: Props = $props(); - - const hasOwnReview = $derived( - Boolean( - revision.reviews && - revision.reviews.some( - value => value.author.did === didFromPublicKey(config.publicKey), - ), - ), - ); - - let popoverExpanded: boolean = $state(false); - - - - {#snippet toggle(onclick)} - - - Review - - {/snippet} - - {#snippet popover()} - -
- { - const newReview = await createReview(); - if (newReview) { - await push({ - resource: "repo.patch", - rid, - patch: patchId, - status, - reviewId: newReview.id, - }); - } - closeFocused(); - }}> - - - Write Review - - - { - await createReview("reject"); - await loadPatch(); - closeFocused(); - }}> - - - Reject - - - { - await createReview("accept"); - await loadPatch(); - closeFocused(); - }}> - - - Accept - - - -
- -
-
-
- Clicking the buttons will create a blank review, add comments, a - summary, and your verdict after. Depending on your sync settings your - review might be published to the network right away. We are actively - working on draft reviews, stay tuned. -
-
-
- {/snippet} -
diff --git a/src/components/ReviewTeaser.svelte b/src/components/ReviewTeaser.svelte index 06bcf6e17..97ee08a02 100644 --- a/src/components/ReviewTeaser.svelte +++ b/src/components/ReviewTeaser.svelte @@ -1,4 +1,5 @@