refactor: inline event list into issue and pull request views
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
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 helpers::{IssueFilter, StatusCounts, filter_by_status};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::PublicKey;
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::button::Button;
|
||||
use ui::common::{Sizable, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
@@ -21,8 +24,8 @@ use self::detail::IssueDetailView;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::new_issue::NewIssueView;
|
||||
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 mod detail;
|
||||
pub(crate) mod helpers;
|
||||
@@ -214,54 +217,8 @@ impl Render for IssuesView {
|
||||
let directory = self.directory.clone();
|
||||
let store = self.store.clone();
|
||||
let workspace = self.workspace.clone();
|
||||
|
||||
let rows = visible_issues
|
||||
.iter()
|
||||
.filter_map(|&issue_ix| {
|
||||
// The store re-read per frame can shrink below a captured index.
|
||||
let issue = store.read(cx).issues.get(issue_ix)?;
|
||||
let profile = directory.read(cx).profile(&issue.pubkey, cx);
|
||||
let issue_id = issue.id;
|
||||
let id_hex = issue.id.to_hex();
|
||||
let status = store.read(cx).status_of(issue);
|
||||
|
||||
let on_click: EventHandler = {
|
||||
let workspace = workspace.clone();
|
||||
let store = store.clone();
|
||||
Rc::new(move |_, window, cx| {
|
||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||
let store = store.clone();
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(store.clone(), issue_id, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
})
|
||||
};
|
||||
|
||||
Some(EventRow {
|
||||
id: SharedString::from(format!("issue:{id_hex}")).into(),
|
||||
status,
|
||||
title: issue.activity_subject().into(),
|
||||
author: profile.name(),
|
||||
picture: profile.picture(),
|
||||
pubkey: issue.pubkey,
|
||||
short_id: short_id(&id_hex),
|
||||
age: SharedString::from(relative_time(issue.created_at)),
|
||||
on_click,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let scroll_handle = self.scroll_handle.clone();
|
||||
let count = visible_issues.len();
|
||||
|
||||
let empty_message = match filter {
|
||||
IssueFilter::All => "No issues",
|
||||
@@ -272,12 +229,126 @@ impl Render for IssuesView {
|
||||
v_flex()
|
||||
.size_full()
|
||||
.child(
|
||||
EventList::new("issues")
|
||||
.toolbar(self.render_header(cx))
|
||||
.scroll_handle(self.scroll_handle.clone())
|
||||
.rows(rows)
|
||||
.empty_message(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("issues", count, move |range, _, cx| {
|
||||
range
|
||||
.map(|ix| {
|
||||
// The store re-read per frame can shrink below a captured index.
|
||||
let Some(issue) =
|
||||
visible_issues.get(ix).and_then(|issue_ix| {
|
||||
store.read(cx).issues.get(*issue_ix)
|
||||
})
|
||||
else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
let profile = directory.read(cx).profile(&issue.pubkey, cx);
|
||||
let issue_id = issue.id;
|
||||
let id_hex = issue.id.to_hex();
|
||||
let status = store.read(cx).status_of(issue);
|
||||
let store = store.clone();
|
||||
let workspace = workspace.clone();
|
||||
|
||||
h_flex()
|
||||
.id(SharedString::from(format!("issue:{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!("issue:{issue_id}"));
|
||||
let store = store.clone();
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(
|
||||
cx,
|
||||
|panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(
|
||||
store.clone(),
|
||||
issue_id,
|
||||
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(issue.activity_subject()),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.text_xs()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Avatar::new(issue.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(issue.created_at)),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
.child(Scrollbar::vertical("issues-scroll", scroll_handle.clone()))
|
||||
})
|
||||
.when(count == 0, |this| {
|
||||
this.child(EmptyState::centered(empty_message))
|
||||
})
|
||||
.into_any_element(),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -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| {
|
||||
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() {
|
||||
let id = commit.id.clone();
|
||||
log_dropped(view.update(cx, |this, cx| {
|
||||
this.open_commit_diff(worktree, &id, window, 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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -4,25 +4,28 @@ use std::sync::Arc;
|
||||
use anyhow::Error;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, SharedString,
|
||||
Styled as _, Task, UniformListScrollHandle, WeakEntity, Window, div,
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, SharedString, StatefulInteractiveElement as _, Styled as _, Task,
|
||||
UniformListScrollHandle, WeakEntity, Window, div, uniform_list,
|
||||
};
|
||||
use signed_git::{CommitList, FileCommit, Repo};
|
||||
use signed_state::{Backend, RepoStore, SyncStatusDirectory};
|
||||
use ui::alert::{Alert, AlertSeverity, AlertStyle};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::{Sizable as _, v_flex};
|
||||
use ui::common::{Sizable as _, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::PanelSlot;
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::spinner::Spinner;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use ui::tooltip::Tooltip;
|
||||
use utils::relative_time_secs;
|
||||
|
||||
use super::RepoDetailView;
|
||||
use super::commit_diff::CommitDiffView;
|
||||
use super::helpers::short_id;
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::event_list::commit_list;
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
pub struct RepoHistoryView {
|
||||
@@ -202,13 +205,19 @@ impl Render for RepoHistoryView {
|
||||
let commits = Arc::clone(&self.commits);
|
||||
let shown = commits.len();
|
||||
let total = list.total;
|
||||
|
||||
let view = cx.entity().downgrade();
|
||||
let detail = self.detail.clone();
|
||||
|
||||
let user = Backend::global(cx).read(cx).current_user();
|
||||
let backend = Backend::global(cx);
|
||||
let user = backend.read(cx).current_user();
|
||||
|
||||
let author = user.is_some_and(|user| self.store.read(cx).is_author(&user));
|
||||
let checkout = self.worktree.clone();
|
||||
|
||||
let pushing = self.store.read(cx).pushing;
|
||||
let scroll_handle = self.scroll_handle.clone();
|
||||
|
||||
let ahead = self
|
||||
.store
|
||||
.read(cx)
|
||||
@@ -222,30 +231,95 @@ impl Render for RepoHistoryView {
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let pushing = self.store.read(cx).pushing;
|
||||
v_flex()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.min_h_0()
|
||||
.child(
|
||||
v_flex()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.child(
|
||||
uniform_list("commits", shown, move |range, _, cx| {
|
||||
range
|
||||
.map(|ix| {
|
||||
let Some(commit) = commits.get(ix) else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
|
||||
let list = commit_list(
|
||||
"commits",
|
||||
"commits-scroll",
|
||||
commits,
|
||||
self.scroll_handle.clone(),
|
||||
move |ix, commit, _| {
|
||||
ahead
|
||||
let row_id = commit.id.clone();
|
||||
let view = view.clone();
|
||||
let ahead = ahead
|
||||
.iter()
|
||||
.find(|(id, _)| id.starts_with(commit.id.as_str()))
|
||||
.map(|(ahead_id, path)| {
|
||||
.find(|(id, _)| id.starts_with(commit.id.as_str()));
|
||||
|
||||
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()
|
||||
.justify_center()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
div()
|
||||
.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)),
|
||||
),
|
||||
)
|
||||
.when_some(ahead, |row, (ahead_id, path)| {
|
||||
let detail = detail.clone();
|
||||
let path = path.clone();
|
||||
let target = ahead_id.clone();
|
||||
let short = super::helpers::short_id(&commit.id);
|
||||
let short = short_id(&commit.id);
|
||||
|
||||
row.child(
|
||||
Button::new(("sync-commit", ix))
|
||||
.label("Sync")
|
||||
.icon(Icon::named(IconRole::ArrowUp))
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.small()
|
||||
.disabled(pushing)
|
||||
.tooltip(Tooltip::text(format!("Sync up to {short}")))
|
||||
.tooltip(Tooltip::text(format!(
|
||||
"Sync up to {short}"
|
||||
)))
|
||||
.on_click(move |_, window, cx| {
|
||||
cx.stop_propagation();
|
||||
if let Some(detail) = detail.upgrade() {
|
||||
@@ -258,25 +332,25 @@ impl Render for RepoHistoryView {
|
||||
);
|
||||
});
|
||||
}
|
||||
}),
|
||||
)
|
||||
})
|
||||
.into_any_element()
|
||||
})
|
||||
},
|
||||
move |commit, window, cx| {
|
||||
.on_click(move |_, window, cx| {
|
||||
if let Err(error) = view.update(cx, |this, cx| {
|
||||
this.open_commit_diff(&commit.id, window, cx);
|
||||
this.open_commit_diff(&row_id, window, cx);
|
||||
}) {
|
||||
log::warn!("failed to open commit diff: {error}");
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
v_flex()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.min_h_0()
|
||||
.child(list)
|
||||
})
|
||||
.into_any_element()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
.child(Scrollbar::vertical("commits-scroll", scroll_handle)),
|
||||
)
|
||||
.when(shown < total, |this| {
|
||||
this.child(
|
||||
div()
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
//! The shared issue and pull-request lists: uniform rows, scrollbar overlay, and
|
||||
//! empty state, plus the scrollable commit list.
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Pixels, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||
UniformListScrollHandle, Window, div, px, uniform_list,
|
||||
};
|
||||
use nostr::prelude::PublicKey;
|
||||
use signed_core::RepoStatus;
|
||||
use signed_git::FileCommit;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::common::{Sizable as _, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time_secs;
|
||||
|
||||
use crate::repo::helpers::short_id;
|
||||
use crate::shared::widgets::status_badge;
|
||||
|
||||
/// The height of one issue or pull-request row.
|
||||
pub const ROW_HEIGHT: f32 = 73.;
|
||||
/// The height of one commit row in the commit list.
|
||||
pub const COMMIT_ROW_HEIGHT: f32 = 56.;
|
||||
|
||||
/// A row's activation handler.
|
||||
pub type EventHandler = Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>;
|
||||
|
||||
/// One issue or pull-request row's display data and click handler.
|
||||
pub struct EventRow {
|
||||
pub id: ElementId,
|
||||
pub status: RepoStatus,
|
||||
pub title: SharedString,
|
||||
pub author: SharedString,
|
||||
pub picture: Option<SharedString>,
|
||||
pub pubkey: PublicKey,
|
||||
pub short_id: SharedString,
|
||||
pub age: SharedString,
|
||||
pub on_click: EventHandler,
|
||||
}
|
||||
|
||||
impl EventRow {
|
||||
/// Renders one issue or pull-request row.
|
||||
fn render(&self, row_height: Pixels, cx: &App) -> AnyElement {
|
||||
h_flex()
|
||||
.id(self.id.clone())
|
||||
.w_full()
|
||||
.h(row_height)
|
||||
.gap_4()
|
||||
.px_4()
|
||||
.border_b_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
||||
.on_click({
|
||||
let on_click = self.on_click.clone();
|
||||
move |event, window, cx| on_click(event, window, cx)
|
||||
})
|
||||
.child(status_badge(self.status))
|
||||
.child(
|
||||
v_flex()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.gap_1()
|
||||
.child(
|
||||
div()
|
||||
.text_base()
|
||||
.text_ellipsis()
|
||||
.whitespace_nowrap()
|
||||
.child(self.title.clone()),
|
||||
)
|
||||
.child(self.meta_row(cx)),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
/// The author, age, and id line under a row's title.
|
||||
fn meta_row(&self, cx: &App) -> AnyElement {
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.text_xs()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Avatar::new(self.pubkey)
|
||||
.name(self.author.clone())
|
||||
.picture(self.picture.clone())
|
||||
.small(),
|
||||
)
|
||||
.child(div().child(self.author.clone())),
|
||||
)
|
||||
.child(SharedString::from("opened"))
|
||||
.child(
|
||||
div()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(self.short_id.clone()),
|
||||
)
|
||||
.child(self.age.clone())
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
/// The shared issue and pull-request list,
|
||||
pub struct EventList {
|
||||
id: ElementId,
|
||||
toolbar: Option<AnyElement>,
|
||||
rows: Vec<EventRow>,
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
empty_message: SharedString,
|
||||
}
|
||||
|
||||
impl EventList {
|
||||
/// Builds a list rendering `rows` under `toolbar`.
|
||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
toolbar: None,
|
||||
rows: Vec::new(),
|
||||
scroll_handle: UniformListScrollHandle::new(),
|
||||
empty_message: "Nothing here".into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaces the list's scroll handle with the caller's.
|
||||
pub fn scroll_handle(mut self, handle: UniformListScrollHandle) -> Self {
|
||||
self.scroll_handle = handle;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the toolbar above the rows.
|
||||
pub fn toolbar(mut self, toolbar: AnyElement) -> Self {
|
||||
self.toolbar = Some(toolbar);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the rendered rows.
|
||||
pub fn rows(mut self, rows: Vec<EventRow>) -> Self {
|
||||
self.rows = rows;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the empty-state message shown when no rows match.
|
||||
pub fn empty_message(mut self, message: impl Into<SharedString>) -> Self {
|
||||
self.empty_message = message.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Renders the list.
|
||||
pub fn render(self, _cx: &App) -> AnyElement {
|
||||
let count = self.rows.len();
|
||||
let rows = self.rows;
|
||||
let row_height = px(ROW_HEIGHT);
|
||||
|
||||
v_flex()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.w_full()
|
||||
.children(self.toolbar)
|
||||
.when(count > 0, |this| {
|
||||
this.child(
|
||||
uniform_list((self.id.clone(), "rows"), count, move |range, _, cx| {
|
||||
range
|
||||
.map(|ix| {
|
||||
let Some(row) = rows.get(ix) else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
row.render(row_height, cx)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&self.scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
.child(Scrollbar::vertical(
|
||||
(self.id.clone(), "scroll"),
|
||||
self.scroll_handle.clone(),
|
||||
))
|
||||
})
|
||||
.when(count == 0, |this| {
|
||||
this.child(EmptyState::centered(self.empty_message))
|
||||
})
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
/// A scrollable commit list: uniform `commit_row`s under a scrollbar overlay.
|
||||
pub fn commit_list(
|
||||
id: &'static str,
|
||||
scroll_id: &'static str,
|
||||
commits: Arc<Vec<FileCommit>>,
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
action: impl Fn(usize, &FileCommit, &App) -> Option<AnyElement> + 'static,
|
||||
on_click: impl Fn(&FileCommit, &mut Window, &mut App) + Clone + 'static,
|
||||
) -> AnyElement {
|
||||
let count = commits.len();
|
||||
|
||||
v_flex()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.child(
|
||||
uniform_list(id, count, move |range, _, cx| {
|
||||
range
|
||||
.map(|ix| {
|
||||
let commit = commits[ix].clone();
|
||||
let action = action(ix, &commit, cx);
|
||||
let on_click = on_click.clone();
|
||||
let row_commit = commit.clone();
|
||||
commit_row(
|
||||
&commit,
|
||||
action,
|
||||
move |window, cx| on_click(&row_commit, window, cx),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
.child(Scrollbar::vertical(scroll_id, scroll_handle))
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
/// One copyable commit summary row: id, subject, author, and age.
|
||||
pub(crate) fn commit_row(
|
||||
commit: &FileCommit,
|
||||
action: Option<AnyElement>,
|
||||
on_click: impl Fn(&mut Window, &mut gpui::App) + 'static,
|
||||
cx: &gpui::App,
|
||||
) -> gpui::AnyElement {
|
||||
h_flex()
|
||||
.id(commit.id.clone())
|
||||
.px_4()
|
||||
.h(px(COMMIT_ROW_HEIGHT))
|
||||
.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)),
|
||||
),
|
||||
)
|
||||
.when_some(action, |row, action| row.child(action))
|
||||
.on_click(move |_, window, cx| on_click(window, cx))
|
||||
.into_any_element()
|
||||
}
|
||||
@@ -2,7 +2,6 @@ use gpui::{App, Entity};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::PublicKey;
|
||||
|
||||
pub mod event_list;
|
||||
pub mod progress;
|
||||
|
||||
pub mod widgets;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use signed_core::RepoStatus;
|
||||
use ui::badge::{Badge, BadgeVariant};
|
||||
use ui::common::Sizable;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::tooltip::Tooltip;
|
||||
|
||||
@@ -16,4 +17,5 @@ pub fn status_badge(status: RepoStatus) -> Badge {
|
||||
.variant(variant)
|
||||
.icon(Icon::named(icon))
|
||||
.tooltip(Tooltip::text(label))
|
||||
.small()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user