chore: rework pull request detail into a split layout
This commit is contained in:
@@ -41,6 +41,32 @@ pub struct 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.
|
||||
pub fn open(
|
||||
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.
|
||||
fn track_participants(&mut self, cx: &mut Context<Self>) {
|
||||
let store = self.store.read(cx);
|
||||
|
||||
@@ -6,6 +6,7 @@ use nostr::prelude::{Event, EventId};
|
||||
use signed_core::RepoStatus;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::badge::Badge;
|
||||
use ui::button::Button;
|
||||
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
@@ -82,11 +83,20 @@ pub(crate) fn comments_section(
|
||||
) -> AnyElement {
|
||||
let store = store.read(cx);
|
||||
let comments: Vec<&Event> = store.comments_of(&root).collect();
|
||||
let title = SharedString::from(format!("Discussions {}", comments.len()));
|
||||
let count = comments.len();
|
||||
|
||||
v_flex()
|
||||
.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| {
|
||||
let profile = directory.read(cx).profile(&comment.pubkey, cx);
|
||||
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)
|
||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
||||
.on_click(move |_, window, cx| {
|
||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||
let workspace_for_build = workspace.clone();
|
||||
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(),
|
||||
pr_id,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
},
|
||||
)
|
||||
}));
|
||||
PullRequestDetailView::open(
|
||||
&workspace,
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.child(
|
||||
h_flex()
|
||||
|
||||
@@ -64,30 +64,7 @@ pub fn open_repo_item(
|
||||
IssueDetailView::open(workspace, store, issue_id, window, cx);
|
||||
}
|
||||
RepoItem::PullRequest(pr_id) => {
|
||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||
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,
|
||||
)
|
||||
})
|
||||
}));
|
||||
PullRequestDetailView::open(workspace, store.clone(), pr_id, window, cx);
|
||||
}
|
||||
// Opening a patch series directly is not a feature.
|
||||
_ => {}
|
||||
|
||||
@@ -320,8 +320,12 @@ impl DiffPane {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_toolbar(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
let view = cx.entity().downgrade();
|
||||
fn render_toolbar(
|
||||
&self,
|
||||
show_tree_toggle: bool,
|
||||
view: WeakEntity<Self>,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let (insertions, deletions) = self.diff().map_or((0, 0), |diff| {
|
||||
(
|
||||
diff.files.iter().map(|file| file.insertions).sum(),
|
||||
@@ -338,22 +342,24 @@ impl DiffPane {
|
||||
.flex_none()
|
||||
.border_b_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.child(
|
||||
Toggle::new("toggle-tree")
|
||||
.icon(Icon::named(IconRole::PanelLeft))
|
||||
.pressed(self.tree_visible)
|
||||
.accessibility_label("Toggle file tree")
|
||||
.on_change({
|
||||
let view = view.clone();
|
||||
move |pressed, _, cx| {
|
||||
if let Err(error) =
|
||||
view.update(cx, |this, cx| this.set_tree_visible(pressed, cx))
|
||||
{
|
||||
log::warn!("failed to toggle file tree: {error}");
|
||||
.when(show_tree_toggle, |this| {
|
||||
this.child(
|
||||
Toggle::new("toggle-tree")
|
||||
.icon(Icon::named(IconRole::PanelLeft))
|
||||
.pressed(self.tree_visible)
|
||||
.accessibility_label("Toggle file tree")
|
||||
.on_change({
|
||||
let view = view.clone();
|
||||
move |pressed, _, cx| {
|
||||
if let Err(error) =
|
||||
view.update(cx, |this, cx| this.set_tree_visible(pressed, cx))
|
||||
{
|
||||
log::warn!("failed to toggle file tree: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
})
|
||||
.when(insertions > 0 || deletions > 0, |this| {
|
||||
this.child(GroupedBadge::new(
|
||||
"toolbar-diff-stats",
|
||||
@@ -393,7 +399,7 @@ impl DiffPane {
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.on_click({
|
||||
let view = view;
|
||||
let view = view.clone();
|
||||
move |_, _, cx| {
|
||||
if let Err(error) =
|
||||
view.update(cx, |this, cx| this.toggle_all_files(cx))
|
||||
@@ -411,9 +417,13 @@ impl DiffPane {
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.tooltip(Tooltip::text("Download commit"))
|
||||
.small()
|
||||
.on_click(cx.listener(|_, _, _, cx| {
|
||||
cx.emit(DiffPaneEvent::DownloadCommit);
|
||||
})),
|
||||
.on_click(move |_, _, cx| {
|
||||
if let Err(error) = view.update(cx, |_, cx| {
|
||||
cx.emit(DiffPaneEvent::DownloadCommit);
|
||||
}) {
|
||||
log::warn!("failed to download commit patch: {error}");
|
||||
}
|
||||
}),
|
||||
)
|
||||
})
|
||||
.into_any_element()
|
||||
@@ -448,6 +458,39 @@ impl DiffPane {
|
||||
.child(Scrollbar::vertical("commit-diff-files", self.list.clone()))
|
||||
.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(
|
||||
@@ -572,7 +615,7 @@ impl Render for DiffPane {
|
||||
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 content = if self.tree_visible {
|
||||
|
||||
@@ -31,35 +31,55 @@ impl PatchParser {
|
||||
Ok(CommitDiff::new(files))
|
||||
}
|
||||
|
||||
/// Lists the commits represented by the mbox messages that carry an id.
|
||||
pub fn patch_commits(patch: &str) -> Vec<FileCommit> {
|
||||
/// Lists the commits represented by the mbox messages that carry an id, with their total insertions and deletions.
|
||||
pub fn patch_commits_with_stats(patch: &str) -> Vec<(FileCommit, usize, usize)> {
|
||||
Self::envelopes(patch)
|
||||
.into_iter()
|
||||
.filter(|message| !message.id.is_empty())
|
||||
.map(|message| {
|
||||
let time = message
|
||||
.header("Date")
|
||||
.and_then(|value| gix::date::parse(value.trim(), None).ok());
|
||||
|
||||
FileCommit::new(
|
||||
message.id.to_string(),
|
||||
message
|
||||
.header("Subject")
|
||||
.map(Self::strip_patch_prefix)
|
||||
.unwrap_or_default(),
|
||||
None,
|
||||
message
|
||||
.header("From")
|
||||
.map(Self::name_from_address)
|
||||
.unwrap_or_default(),
|
||||
time.map(|time| time.seconds).unwrap_or(0),
|
||||
time.map(format_commit_date).unwrap_or_default(),
|
||||
Vec::new(),
|
||||
)
|
||||
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
|
||||
.header("Date")
|
||||
.and_then(|value| gix::date::parse(value.trim(), None).ok());
|
||||
|
||||
FileCommit::new(
|
||||
message.id.to_string(),
|
||||
message
|
||||
.header("Subject")
|
||||
.map(Self::strip_patch_prefix)
|
||||
.unwrap_or_default(),
|
||||
None,
|
||||
message
|
||||
.header("From")
|
||||
.map(Self::name_from_address)
|
||||
.unwrap_or_default(),
|
||||
time.map(|time| time.seconds).unwrap_or(0),
|
||||
time.map(format_commit_date).unwrap_or_default(),
|
||||
Vec::new(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Splits `patch` on `From <40-hex> <date>` envelopes, falling back to one message.
|
||||
fn envelopes(patch: &str) -> Vec<Envelope<'_>> {
|
||||
let mut messages: Vec<Envelope<'_>> = Vec::new();
|
||||
|
||||
@@ -928,6 +928,11 @@ diff --git a/b.txt b/b.txt
|
||||
assert_eq!(commits[1].summary, "second");
|
||||
assert_eq!(commits[1].author, "Bob");
|
||||
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]
|
||||
|
||||
@@ -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,
|
||||
Inbox,
|
||||
Stack,
|
||||
Message,
|
||||
PanelLeft,
|
||||
UnfoldVertical,
|
||||
Download,
|
||||
@@ -111,6 +112,7 @@ impl IconRole {
|
||||
Self::ArrowUp => "arrow-up",
|
||||
Self::Inbox => "inbox",
|
||||
Self::Stack => "stack",
|
||||
Self::Message => "message",
|
||||
Self::PanelLeft => "panel-left",
|
||||
Self::UnfoldVertical => "unfold-vertical",
|
||||
Self::Download => "download",
|
||||
|
||||
Reference in New Issue
Block a user