Skip to content

Commit

Permalink
Add issue_activity_by_id tauri command
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Oct 10, 2024
1 parent 98bd1ee commit d901cd6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions crates/radicle-tauri/src/commands/cob/issue.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use radicle::cob;
use radicle::git;
use radicle::identity::RepoId;
use radicle::issue;
use radicle::issue::cache::Issues;
use radicle::node::Handle;
use radicle::node::Node;
Expand Down Expand Up @@ -132,3 +134,34 @@ pub fn issue_by_id(

Ok::<_, Error>(issue)
}

#[tauri::command]
pub fn issue_activity_by_id(
ctx: tauri::State<AppState>,
rid: RepoId,
id: git::Oid,
) -> Result<Vec<serde_json::Value>, Error> {
let aliases = ctx.profile.aliases();
let repo = ctx.profile.storage.repository(rid)?;
let ops = cob::store::ops(&id.into(), &issue::TYPENAME, &repo).unwrap();
let mut actions: Vec<serde_json::Value> = Vec::new();

for op in ops.into_iter().rev() {
actions.extend(
op.actions
.iter()
.filter_map(|action: &Vec<u8>| -> Option<serde_json::Value> {
serde_json::from_slice(action).ok()
})
.map(|actions| {
serde_json::json!({
"actions": actions,
"author": cobs::Author::new(op.author.into(), &aliases),
"timestamp": op.timestamp
})
}),
)
}

Ok::<_, Error>(actions)
}
1 change: 1 addition & 0 deletions crates/radicle-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn run() {
cob::issue::issue_by_id,
cob::issue::create_issue,
cob::issue::edit_issue,
cob::issue::issue_activity_by_id,
cob::patch::list_patches,
cob::patch::patch_by_id,
cob::patch::revisions_by_patch,
Expand Down
7 changes: 7 additions & 0 deletions src/views/repo/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import capitalize from "lodash/capitalize";
import { formatTimestamp, formatOid, issueStatusColor } from "@app/lib/utils";
import { invoke } from "@tauri-apps/api/core";
import Border from "@app/components/Border.svelte";
import CopyableId from "@app/components/CopyableId.svelte";
Expand All @@ -21,6 +22,12 @@
export let issues: Issue[];
export let config: Config;
// Test example how to get the history of a cob similar to the `rad cob log` output
$: void invoke("issue_activity_by_id", {
rid: repo.rid,
id: issue.id,
}).then(console.log);
$: project = repo.payloads["xyz.radicle.project"]!;
</script>

Expand Down

0 comments on commit d901cd6

Please sign in to comment.