refactor: inline event list into issue and pull request views

This commit is contained in:
2026-11-25 13:51:01 +07:00
parent f305c56e9e
commit d421a10a3e
8 changed files with 562 additions and 502 deletions
+85 -19
View File
@@ -4,8 +4,8 @@ use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, Render, SharedString, StyleRefinement, Styled as _, Subscription,
UniformListScrollHandle, WeakEntity, Window, div,
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, StyleRefinement,
Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div, uniform_list,
};
use metadata::ProfileDirectory;
use nostr::prelude::{EventId, Kind, Url};
@@ -22,16 +22,17 @@ use ui::input::InputState;
use ui::layout::panel::{Panel, PanelSlot};
use ui::layout::root::RootContext as _;
use ui::scroll_area::ScrollArea;
use ui::scrollbar::Scrollbar;
use ui::spinner::Spinner;
use ui::tabs::{Tab, Tabs};
use ui::theme::ActiveTheme as _;
use utils::relative_time;
use utils::{relative_time, relative_time_secs};
use crate::app::AppRoot;
use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
use crate::pull_requests::dialogs::update::UpdatePrDialog;
use crate::repo::commit_diff::{CommitDiffView, DiffPane};
use crate::shared::event_list::commit_list;
use crate::repo::helpers::short_id;
use crate::shared::log_dropped;
use crate::shared::widgets::status_badge;
@@ -493,21 +494,86 @@ impl PullRequestDetailView {
let worktree = self.worktree.clone();
let view = cx.entity().downgrade();
commit_list(
"pr-commits",
"pr-commits-scroll",
commits,
self.commit_scroll_handle.clone(),
|_, _, _| None,
move |commit, window, cx| {
if let Some(worktree) = worktree.clone() {
let id = commit.id.clone();
log_dropped(view.update(cx, |this, cx| {
this.open_commit_diff(worktree, &id, window, cx);
}));
}
},
)
let scroll_handle = self.commit_scroll_handle.clone();
v_flex()
.relative()
.flex_1()
.min_h_0()
.child(
uniform_list("pr-commits", commits.len(), move |range, _, cx| {
range
.map(|ix| {
let Some(commit) = commits.get(ix) else {
return div().into_any_element();
};
let row_id = commit.id.clone();
let worktree = worktree.clone();
let view = view.clone();
h_flex()
.id(commit.id.clone())
.px_4()
.h_16()
.w_full()
.gap_3()
.border_b_1()
.border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted_hover))
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.justify_center()
.child(
h_flex()
.gap_2()
.overflow_hidden()
.child(
div()
.font_family(cx.theme().mono_font)
.text_sm()
.text_color(
cx.theme().colors.muted_foreground,
)
.child(short_id(&commit.id)),
)
.child(
div()
.flex_1()
.min_w_0()
.text_sm()
.text_ellipsis()
.whitespace_nowrap()
.child(commit.summary.clone()),
),
)
.child(
h_flex()
.gap_2()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(commit.author.clone())
.child(relative_time_secs(commit.time)),
),
)
.on_click(move |_, window, cx| {
if let Some(worktree) = worktree.clone() {
log_dropped(view.update(cx, |this, cx| {
this.open_commit_diff(worktree, &row_id, window, cx);
}));
}
})
.into_any_element()
})
.collect()
})
.track_scroll(&scroll_handle)
.size_full(),
)
.child(Scrollbar::vertical("pr-commits-scroll", scroll_handle))
.into_any_element()
}
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
+131 -65
View File
@@ -1,20 +1,22 @@
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div,
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _,
Subscription, UniformListScrollHandle, WeakEntity, Window, div, uniform_list,
};
use metadata::ProfileDirectory;
use nostr::prelude::{Kind, PublicKey};
use signed_core::GitEvent;
use signed_state::RepoStore;
use ui::alert::{Alert, AlertSeverity};
use ui::avatar::Avatar;
use ui::common::{Sizable, h_flex, v_flex};
use ui::dropdown_menu::DropdownMenu;
use ui::empty_state::EmptyState;
use ui::icons::{Icon, IconRole};
use ui::layout::panel::{Panel, PanelSlot};
use ui::menu::MenuItem;
use ui::scrollbar::Scrollbar;
use ui::segmented::{Segmented, SegmentedOption};
use ui::theme::ActiveTheme as _;
use utils::relative_time;
@@ -33,8 +35,8 @@ pub use send_patch::SendPatchView;
use crate::app::AppRoot;
use crate::issues::helpers::{StatusCounts, filter_by_status};
use crate::repo::helpers::short_id;
use crate::shared::event_list::{EventHandler, EventList, EventRow};
use crate::shared::log_dropped;
use crate::shared::widgets::status_badge;
pub struct PullRequestsView {
workspace: WeakEntity<AppRoot>,
@@ -299,60 +301,8 @@ impl Render for PullRequestsView {
let dismiss_warning_store = self.store.clone();
let dismiss_error_store = self.store.clone();
let rows = visible
.iter()
.filter_map(|&pr_ix| {
// The store re-read per frame can shrink below a captured index.
let pr = store.read(cx).pull_requests.get(pr_ix)?;
let profile = directory.read(cx).profile(&pr.pubkey, cx);
let pr_id = pr.id;
let id_hex = pr.id.to_hex();
let status = store.read(cx).status_of(pr);
let on_click: EventHandler = {
let workspace = workspace.clone();
let store = store.clone();
Rc::new(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::Split,
id,
move |window, cx| {
cx.new(|cx| {
PullRequestDetailView::new(
workspace_for_build.clone(),
store.clone(),
pr_id,
window,
cx,
)
})
},
window,
cx,
)
})
}));
})
};
Some(EventRow {
id: SharedString::from(format!("pr:{id_hex}")).into(),
status,
title: pr.activity_subject().into(),
author: profile.name(),
picture: profile.picture(),
pubkey: pr.pubkey,
short_id: short_id(&id_hex),
age: SharedString::from(relative_time(pr.created_at)),
on_click,
})
})
.collect();
let scroll_handle = self.scroll_handle.clone();
let count = visible.len();
v_flex()
.size_full()
@@ -385,12 +335,128 @@ impl Render for PullRequestsView {
)
})
.child(
EventList::new("prl")
.toolbar(self.render_header(cx))
.scroll_handle(self.scroll_handle.clone())
.rows(rows)
.empty_message(filter.empty_message())
.render(cx),
v_flex()
.relative()
.flex_1()
.min_h_0()
.w_full()
.child(self.render_header(cx))
.when(count > 0, |this| {
this.child(
uniform_list("prl", count, move |range, _, cx| {
range
.map(|ix| {
// The store re-read per frame can shrink below a captured index.
let Some(pr) = visible.get(ix).and_then(|pr_ix| {
store.read(cx).pull_requests.get(*pr_ix)
}) else {
return div().into_any_element();
};
let profile = directory.read(cx).profile(&pr.pubkey, cx);
let pr_id = pr.id;
let id_hex = pr.id.to_hex();
let status = store.read(cx).status_of(pr);
let workspace = workspace.clone();
let store = store.clone();
h_flex()
.id(SharedString::from(format!("pr:{id_hex}")))
.w_full()
.h_16()
.gap_4()
.px_2()
.border_b_1()
.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::Split,
id,
move |window, cx| {
cx.new(|cx| {
PullRequestDetailView::new(
workspace_for_build
.clone(),
store.clone(),
pr_id,
window,
cx,
)
})
},
window,
cx,
)
},
)
}));
})
.child(status_badge(status))
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.child(
div()
.text_sm()
.text_ellipsis()
.whitespace_nowrap()
.child(pr.activity_subject()),
)
.child(
h_flex()
.gap_2()
.text_xs()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(pr.pubkey)
.name(profile.name())
.picture(
profile.picture(),
)
.small(),
)
.child(
div().child(profile.name()),
),
)
.child("opened")
.child(
div()
.text_color(
cx.theme()
.colors
.muted_foreground,
)
.child(short_id(&id_hex)),
)
.child(relative_time(pr.created_at)),
),
)
.into_any_element()
})
.collect()
})
.track_scroll(&scroll_handle)
.size_full(),
)
.child(Scrollbar::vertical("prl-scroll", scroll_handle.clone()))
})
.when(count == 0, |this| {
this.child(EmptyState::centered(filter.empty_message()))
})
.into_any_element(),
)
.into_any_element()
}
+85 -17
View File
@@ -4,8 +4,9 @@ use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, PathPromptOptions, Render, SharedString, StyleRefinement, Styled as _,
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px,
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
StyleRefinement, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div,
px, uniform_list,
};
use nostr::prelude::{PublicKey, Url};
use signed_core::Announcement;
@@ -19,14 +20,16 @@ use ui::icons::{Icon, IconRole};
use ui::input::{Input, InputState};
use ui::layout::panel::{Panel, PanelSlot};
use ui::menu::Menu;
use ui::scrollbar::Scrollbar;
use ui::spinner::Spinner;
use ui::tabs::{Tab, Tabs};
use ui::theme::ActiveTheme as _;
use utils::relative_time_secs;
use super::helpers::{ForkCompare, truncate_label};
use crate::app::AppRoot;
use crate::repo::commit_diff::{CommitDiffView, DiffPane};
use crate::repo::helpers::announcement_display_name;
use crate::shared::event_list::commit_list;
use crate::repo::helpers::{announcement_display_name, short_id};
use crate::shared::log_dropped;
use crate::shared::progress::error_row;
@@ -445,25 +448,90 @@ impl NewPullRequestView {
let Some(commits) = self.commits.as_ref() else {
return EmptyState::centered("No commits");
};
if commits.is_empty() {
return EmptyState::centered("No commits between the branches");
}
let commits = Arc::clone(commits);
let view = cx.entity().downgrade();
let scroll_handle = self.scroll_handle.clone();
commit_list(
"new-pr-commits",
"new-pr-commits-scroll",
commits,
self.scroll_handle.clone(),
|_, _, _| None,
move |commit, window, cx| {
let id = commit.id.clone();
log_dropped(view.update(cx, |this, cx| {
this.open_commit_diff(&id, window, cx);
}));
},
)
v_flex()
.relative()
.flex_1()
.min_h_0()
.child(
uniform_list("new-pr-commits", commits.len(), move |range, _, cx| {
range
.map(|ix| {
let Some(commit) = commits.get(ix) else {
return div().into_any_element();
};
let row_id = commit.id.clone();
let view = view.clone();
h_flex()
.id(commit.id.clone())
.px_4()
.h_16()
.w_full()
.gap_3()
.border_b_1()
.border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted_hover))
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.justify_center()
.child(
h_flex()
.gap_2()
.overflow_hidden()
.child(
div()
.font_family(cx.theme().mono_font)
.text_sm()
.text_color(
cx.theme().colors.muted_foreground,
)
.child(short_id(&commit.id)),
)
.child(
div()
.flex_1()
.min_w_0()
.text_sm()
.text_ellipsis()
.whitespace_nowrap()
.child(commit.summary.clone()),
),
)
.child(
h_flex()
.gap_2()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(commit.author.clone())
.child(relative_time_secs(commit.time)),
),
)
.on_click(move |_, window, cx| {
log_dropped(view.update(cx, |this, cx| {
this.open_commit_diff(&row_id, window, cx);
}));
})
.into_any_element()
})
.collect()
})
.track_scroll(&scroll_handle)
.size_full(),
)
.child(Scrollbar::vertical("new-pr-commits-scroll", scroll_handle))
.into_any_element()
}
pub(super) fn has_source(&self) -> bool {