chore: rework pull request detail into a split layout
This commit is contained in:
@@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Show a pull request's description, commits and changes in one scrollable main panel, and its discussion with a pinned comment form in the split pane
|
||||||
|
- Show the repository owner's avatar and the pull request title in a pull request's tab
|
||||||
|
- Show each pull request commit's id, title and changed line counts on one row
|
||||||
|
- Show who opened a pull request, when, and its target and source branches under the title
|
||||||
|
- Show the commits and discussions titles with an icon and a count badge
|
||||||
- Opening a repository no longer runs a forced checkout of its worktree
|
- Opening a repository no longer runs a forced checkout of its worktree
|
||||||
- Deleting a repository now waits until its deletion events are accepted by a relay
|
- Deleting a repository now waits until its deletion events are accepted by a relay
|
||||||
- Keep the Explore list at its scroll position across background refreshes, a new search or filter still starts at the top
|
- Keep the Explore list at its scroll position across background refreshes, a new search or filter still starts at the top
|
||||||
|
|||||||
@@ -41,6 +41,32 @@ pub struct IssueDetailView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IssueDetailView {
|
impl IssueDetailView {
|
||||||
|
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
|
||||||
|
let comment_input = InputState::builder().multiline().build(cx);
|
||||||
|
let directory = ProfileDirectory::new(cx);
|
||||||
|
let weak = cx.entity().downgrade();
|
||||||
|
|
||||||
|
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||||
|
this.track_participants(cx);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.defer(move |cx| {
|
||||||
|
log_dropped(weak.update(cx, |this, cx| {
|
||||||
|
this.track_participants(cx);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
store,
|
||||||
|
issue_id,
|
||||||
|
comment_input,
|
||||||
|
directory,
|
||||||
|
scroll_handle: ScrollHandle::new(),
|
||||||
|
_subscription: subscription,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Opens the issue's detail as the main panel and its sidebar in the split pane.
|
/// Opens the issue's detail as the main panel and its sidebar in the split pane.
|
||||||
pub fn open(
|
pub fn open(
|
||||||
workspace: &WeakEntity<AppRoot>,
|
workspace: &WeakEntity<AppRoot>,
|
||||||
@@ -83,32 +109,6 @@ impl IssueDetailView {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
|
|
||||||
let comment_input = InputState::builder().multiline().build(cx);
|
|
||||||
let directory = ProfileDirectory::new(cx);
|
|
||||||
let weak = cx.entity().downgrade();
|
|
||||||
|
|
||||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
|
||||||
this.track_participants(cx);
|
|
||||||
cx.notify();
|
|
||||||
});
|
|
||||||
|
|
||||||
cx.defer(move |cx| {
|
|
||||||
log_dropped(weak.update(cx, |this, cx| {
|
|
||||||
this.track_participants(cx);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
Self {
|
|
||||||
store,
|
|
||||||
issue_id,
|
|
||||||
comment_input,
|
|
||||||
directory,
|
|
||||||
scroll_handle: ScrollHandle::new(),
|
|
||||||
_subscription: subscription,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Track the issue author, everyone who commented and the repository owner.
|
/// Track the issue author, everyone who commented and the repository owner.
|
||||||
fn track_participants(&mut self, cx: &mut Context<Self>) {
|
fn track_participants(&mut self, cx: &mut Context<Self>) {
|
||||||
let store = self.store.read(cx);
|
let store = self.store.read(cx);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use nostr::prelude::{Event, EventId};
|
|||||||
use signed_core::RepoStatus;
|
use signed_core::RepoStatus;
|
||||||
use signed_state::RepoStore;
|
use signed_state::RepoStore;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
|
use ui::badge::Badge;
|
||||||
use ui::button::Button;
|
use ui::button::Button;
|
||||||
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
@@ -82,11 +83,20 @@ pub(crate) fn comments_section(
|
|||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
let store = store.read(cx);
|
let store = store.read(cx);
|
||||||
let comments: Vec<&Event> = store.comments_of(&root).collect();
|
let comments: Vec<&Event> = store.comments_of(&root).collect();
|
||||||
let title = SharedString::from(format!("Discussions {}", comments.len()));
|
let count = comments.len();
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_4()
|
.gap_4()
|
||||||
.child(div().text_xs().font_semibold().child(title))
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(Icon::named(IconRole::Message))
|
||||||
|
.child(div().text_sm().font_semibold().child("Discussions"))
|
||||||
|
.child(Badge::new(
|
||||||
|
format!("discussion-count:{root}"),
|
||||||
|
count.to_string(),
|
||||||
|
)),
|
||||||
|
)
|
||||||
.children(comments.iter().map(|comment| {
|
.children(comments.iter().map(|comment| {
|
||||||
let profile = directory.read(cx).profile(&comment.pubkey, cx);
|
let profile = directory.read(cx).profile(&comment.pubkey, cx);
|
||||||
let author = profile.name();
|
let author = profile.name();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -371,35 +371,13 @@ impl Render for PullRequestsView {
|
|||||||
.border_color(cx.theme().colors.border)
|
.border_color(cx.theme().colors.border)
|
||||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
||||||
.on_click(move |_, window, cx| {
|
.on_click(move |_, window, cx| {
|
||||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
PullRequestDetailView::open(
|
||||||
let workspace_for_build = workspace.clone();
|
&workspace,
|
||||||
let store = store.clone();
|
|
||||||
|
|
||||||
log_dropped(workspace.update(cx, |root, cx| {
|
|
||||||
root.panels().clone().update(
|
|
||||||
cx,
|
|
||||||
|panels, cx| {
|
|
||||||
panels.open(
|
|
||||||
PanelSlot::Main,
|
|
||||||
id,
|
|
||||||
move |window, cx| {
|
|
||||||
cx.new(|cx| {
|
|
||||||
PullRequestDetailView::new(
|
|
||||||
workspace_for_build
|
|
||||||
.clone(),
|
|
||||||
store.clone(),
|
store.clone(),
|
||||||
pr_id,
|
pr_id,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
)
|
);
|
||||||
})
|
|
||||||
},
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}));
|
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
|||||||
@@ -64,30 +64,7 @@ pub fn open_repo_item(
|
|||||||
IssueDetailView::open(workspace, store, issue_id, window, cx);
|
IssueDetailView::open(workspace, store, issue_id, window, cx);
|
||||||
}
|
}
|
||||||
RepoItem::PullRequest(pr_id) => {
|
RepoItem::PullRequest(pr_id) => {
|
||||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
PullRequestDetailView::open(workspace, store.clone(), pr_id, window, cx);
|
||||||
let workspace_for_build = workspace.clone();
|
|
||||||
let store = store.clone();
|
|
||||||
log_dropped(workspace.update(cx, |root, cx| {
|
|
||||||
root.panels().update(cx, |panels, cx| {
|
|
||||||
panels.open(
|
|
||||||
PanelSlot::Main,
|
|
||||||
id,
|
|
||||||
move |window, cx| {
|
|
||||||
cx.new(|cx| {
|
|
||||||
PullRequestDetailView::new(
|
|
||||||
workspace_for_build.clone(),
|
|
||||||
store.clone(),
|
|
||||||
pr_id,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
// Opening a patch series directly is not a feature.
|
// Opening a patch series directly is not a feature.
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -320,8 +320,12 @@ impl DiffPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_toolbar(&self, cx: &mut Context<Self>) -> AnyElement {
|
fn render_toolbar(
|
||||||
let view = cx.entity().downgrade();
|
&self,
|
||||||
|
show_tree_toggle: bool,
|
||||||
|
view: WeakEntity<Self>,
|
||||||
|
cx: &App,
|
||||||
|
) -> AnyElement {
|
||||||
let (insertions, deletions) = self.diff().map_or((0, 0), |diff| {
|
let (insertions, deletions) = self.diff().map_or((0, 0), |diff| {
|
||||||
(
|
(
|
||||||
diff.files.iter().map(|file| file.insertions).sum(),
|
diff.files.iter().map(|file| file.insertions).sum(),
|
||||||
@@ -338,7 +342,8 @@ impl DiffPane {
|
|||||||
.flex_none()
|
.flex_none()
|
||||||
.border_b_1()
|
.border_b_1()
|
||||||
.border_color(cx.theme().colors.border)
|
.border_color(cx.theme().colors.border)
|
||||||
.child(
|
.when(show_tree_toggle, |this| {
|
||||||
|
this.child(
|
||||||
Toggle::new("toggle-tree")
|
Toggle::new("toggle-tree")
|
||||||
.icon(Icon::named(IconRole::PanelLeft))
|
.icon(Icon::named(IconRole::PanelLeft))
|
||||||
.pressed(self.tree_visible)
|
.pressed(self.tree_visible)
|
||||||
@@ -354,6 +359,7 @@ impl DiffPane {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
})
|
||||||
.when(insertions > 0 || deletions > 0, |this| {
|
.when(insertions > 0 || deletions > 0, |this| {
|
||||||
this.child(GroupedBadge::new(
|
this.child(GroupedBadge::new(
|
||||||
"toolbar-diff-stats",
|
"toolbar-diff-stats",
|
||||||
@@ -393,7 +399,7 @@ impl DiffPane {
|
|||||||
.variant(ButtonVariant::Ghost)
|
.variant(ButtonVariant::Ghost)
|
||||||
.small()
|
.small()
|
||||||
.on_click({
|
.on_click({
|
||||||
let view = view;
|
let view = view.clone();
|
||||||
move |_, _, cx| {
|
move |_, _, cx| {
|
||||||
if let Err(error) =
|
if let Err(error) =
|
||||||
view.update(cx, |this, cx| this.toggle_all_files(cx))
|
view.update(cx, |this, cx| this.toggle_all_files(cx))
|
||||||
@@ -411,9 +417,13 @@ impl DiffPane {
|
|||||||
.variant(ButtonVariant::Ghost)
|
.variant(ButtonVariant::Ghost)
|
||||||
.tooltip(Tooltip::text("Download commit"))
|
.tooltip(Tooltip::text("Download commit"))
|
||||||
.small()
|
.small()
|
||||||
.on_click(cx.listener(|_, _, _, cx| {
|
.on_click(move |_, _, cx| {
|
||||||
|
if let Err(error) = view.update(cx, |_, cx| {
|
||||||
cx.emit(DiffPaneEvent::DownloadCommit);
|
cx.emit(DiffPaneEvent::DownloadCommit);
|
||||||
})),
|
}) {
|
||||||
|
log::warn!("failed to download commit patch: {error}");
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
@@ -448,6 +458,39 @@ impl DiffPane {
|
|||||||
.child(Scrollbar::vertical("commit-diff-files", self.list.clone()))
|
.child(Scrollbar::vertical("commit-diff-files", self.list.clone()))
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Renders every diff row inline, for embedding in a page that scrolls as a whole.
|
||||||
|
pub fn render_flow(&self, view: WeakEntity<Self>, cx: &App) -> AnyElement {
|
||||||
|
let Some(diff) = self.diff.as_ref() else {
|
||||||
|
return div()
|
||||||
|
.p_4()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().colors.muted_foreground)
|
||||||
|
.child("No changes")
|
||||||
|
.into_any_element();
|
||||||
|
};
|
||||||
|
if diff.files.is_empty() {
|
||||||
|
return div()
|
||||||
|
.p_4()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().colors.muted_foreground)
|
||||||
|
.child("No files changed")
|
||||||
|
.into_any_element();
|
||||||
|
}
|
||||||
|
|
||||||
|
let wrap = self.wrap;
|
||||||
|
let rows = self
|
||||||
|
.pane_rows
|
||||||
|
.iter()
|
||||||
|
.map(|row| render_pane_row(row, &diff.files, &view, wrap, cx))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
v_flex()
|
||||||
|
.w_full()
|
||||||
|
.child(self.render_toolbar(false, view, cx))
|
||||||
|
.child(v_flex().w_full().p_2().children(rows))
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_pane_row(
|
fn render_pane_row(
|
||||||
@@ -572,7 +615,7 @@ impl Render for DiffPane {
|
|||||||
return EmptyState::centered("No files changed");
|
return EmptyState::centered("No files changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
let toolbar = self.render_toolbar(cx);
|
let toolbar = self.render_toolbar(true, cx.entity().downgrade(), cx);
|
||||||
let file_list = self.render_file_list(cx);
|
let file_list = self.render_file_list(cx);
|
||||||
|
|
||||||
let content = if self.tree_visible {
|
let content = if self.tree_visible {
|
||||||
|
|||||||
@@ -31,12 +31,34 @@ impl PatchParser {
|
|||||||
Ok(CommitDiff::new(files))
|
Ok(CommitDiff::new(files))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lists the commits represented by the mbox messages that carry an id.
|
/// Lists the commits represented by the mbox messages that carry an id, with their total insertions and deletions.
|
||||||
pub fn patch_commits(patch: &str) -> Vec<FileCommit> {
|
pub fn patch_commits_with_stats(patch: &str) -> Vec<(FileCommit, usize, usize)> {
|
||||||
Self::envelopes(patch)
|
Self::envelopes(patch)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|message| !message.id.is_empty())
|
.filter(|message| !message.id.is_empty())
|
||||||
.map(|message| {
|
.map(|message| {
|
||||||
|
let (insertions, deletions) = match Self::patch_diffs(message.text) {
|
||||||
|
Ok(diff) => (
|
||||||
|
diff.files.iter().map(|file| file.insertions).sum(),
|
||||||
|
diff.files.iter().map(|file| file.deletions).sum(),
|
||||||
|
),
|
||||||
|
Err(_) => (0, 0),
|
||||||
|
};
|
||||||
|
(Self::commit_from_envelope(&message), insertions, deletions)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Lists the commits represented by the mbox messages that carry an id.
|
||||||
|
pub fn patch_commits(patch: &str) -> Vec<FileCommit> {
|
||||||
|
Self::patch_commits_with_stats(patch)
|
||||||
|
.into_iter()
|
||||||
|
.map(|(commit, _, _)| commit)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a commit from one parsed mbox message.
|
||||||
|
fn commit_from_envelope(message: &Envelope<'_>) -> FileCommit {
|
||||||
let time = message
|
let time = message
|
||||||
.header("Date")
|
.header("Date")
|
||||||
.and_then(|value| gix::date::parse(value.trim(), None).ok());
|
.and_then(|value| gix::date::parse(value.trim(), None).ok());
|
||||||
@@ -56,8 +78,6 @@ impl PatchParser {
|
|||||||
time.map(format_commit_date).unwrap_or_default(),
|
time.map(format_commit_date).unwrap_or_default(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
)
|
)
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Splits `patch` on `From <40-hex> <date>` envelopes, falling back to one message.
|
/// Splits `patch` on `From <40-hex> <date>` envelopes, falling back to one message.
|
||||||
|
|||||||
@@ -928,6 +928,11 @@ diff --git a/b.txt b/b.txt
|
|||||||
assert_eq!(commits[1].summary, "second");
|
assert_eq!(commits[1].summary, "second");
|
||||||
assert_eq!(commits[1].author, "Bob");
|
assert_eq!(commits[1].author, "Bob");
|
||||||
assert_eq!(commits[1].time, 1690975800);
|
assert_eq!(commits[1].time, 1690975800);
|
||||||
|
|
||||||
|
let stats = PatchParser::patch_commits_with_stats(patch);
|
||||||
|
assert_eq!(stats.len(), 2);
|
||||||
|
assert_eq!((stats[0].1, stats[0].2), (1, 0));
|
||||||
|
assert_eq!((stats[1].1, stats[1].2), (1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M5.25195 7.75H14.752C16.1327 7.75 17.252 8.86929 17.252 10.25V15.75C17.252 17.1307 16.1327 18.25 14.752 18.25H10.502L6.00195 20.75V18.25H5.25195C3.87124 18.25 2.75195 17.1307 2.75195 15.75V10.25C2.75195 8.86929 3.87124 7.75 5.25195 7.75Z" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M17.2498 14.25H18.752C20.1327 14.25 21.252 13.1307 21.252 11.75V6.25C21.252 4.86929 20.1327 3.75 18.752 3.75H9.50195C8.12124 3.75 7.00195 4.86929 7.00195 6.25V7.75" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 667 B |
@@ -59,6 +59,7 @@ pub enum IconRole {
|
|||||||
ArrowUp,
|
ArrowUp,
|
||||||
Inbox,
|
Inbox,
|
||||||
Stack,
|
Stack,
|
||||||
|
Message,
|
||||||
PanelLeft,
|
PanelLeft,
|
||||||
UnfoldVertical,
|
UnfoldVertical,
|
||||||
Download,
|
Download,
|
||||||
@@ -111,6 +112,7 @@ impl IconRole {
|
|||||||
Self::ArrowUp => "arrow-up",
|
Self::ArrowUp => "arrow-up",
|
||||||
Self::Inbox => "inbox",
|
Self::Inbox => "inbox",
|
||||||
Self::Stack => "stack",
|
Self::Stack => "stack",
|
||||||
|
Self::Message => "message",
|
||||||
Self::PanelLeft => "panel-left",
|
Self::PanelLeft => "panel-left",
|
||||||
Self::UnfoldVertical => "unfold-vertical",
|
Self::UnfoldVertical => "unfold-vertical",
|
||||||
Self::Download => "download",
|
Self::Download => "download",
|
||||||
|
|||||||
Reference in New Issue
Block a user