feat: separate draft pull requests into their own tab
This commit is contained in:
+34
-15
@@ -24,6 +24,7 @@ pub enum Category {
|
||||
Tags,
|
||||
Open,
|
||||
Closed,
|
||||
Drafts,
|
||||
All,
|
||||
}
|
||||
impl Category {
|
||||
@@ -36,6 +37,7 @@ impl Category {
|
||||
Self::Tags => "Tags",
|
||||
Self::Open => "Open",
|
||||
Self::Closed => "Closed",
|
||||
Self::Drafts => "Drafts",
|
||||
Self::All => "All",
|
||||
}
|
||||
}
|
||||
@@ -814,7 +816,12 @@ impl DiffState {
|
||||
|
||||
pub fn categories(&self) -> &'static [Category] {
|
||||
if self.pull_request_remote.is_some() {
|
||||
&[Category::Open, Category::Closed, Category::All]
|
||||
&[
|
||||
Category::Open,
|
||||
Category::Closed,
|
||||
Category::Drafts,
|
||||
Category::All,
|
||||
]
|
||||
} else {
|
||||
self.catalog
|
||||
.as_ref()
|
||||
@@ -1207,26 +1214,34 @@ impl DiffState {
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn pull_request_streams(&self) -> std::ops::Range<usize> {
|
||||
match self.categories().get(self.category) {
|
||||
Some(Category::All) => 0..2,
|
||||
Some(Category::Closed) => 1..2,
|
||||
_ => 0..1,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn pull_request_partial(&self) -> bool {
|
||||
self.pull_request_remote.is_some()
|
||||
&& self
|
||||
.pull_request_categories
|
||||
.iter()
|
||||
.enumerate()
|
||||
.any(|(index, status)| {
|
||||
(self.category == 2 || self.category == index) && !status.complete
|
||||
})
|
||||
.pull_request_streams()
|
||||
.any(|index| !self.pull_request_categories[index].complete)
|
||||
}
|
||||
|
||||
pub(crate) fn pull_request_notice(&self) -> Option<String> {
|
||||
self.pull_request_remote.as_ref()?;
|
||||
let active = self.categories()[self.category];
|
||||
let statuses: Vec<_> = self
|
||||
.pull_request_categories
|
||||
.categories()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(index, _)| self.category == 2 || self.category == *index)
|
||||
.map(|(index, status)| {
|
||||
let category = [Category::Open, Category::Closed][index];
|
||||
.copied()
|
||||
.filter(|category| {
|
||||
*category != Category::All && (active == Category::All || *category == active)
|
||||
})
|
||||
.map(|category| {
|
||||
let status =
|
||||
&self.pull_request_categories[usize::from(category == Category::Closed)];
|
||||
let count = self.catalog.as_ref().map_or(0, |catalog| {
|
||||
catalog
|
||||
.entries
|
||||
@@ -1254,8 +1269,9 @@ impl DiffState {
|
||||
}
|
||||
|
||||
fn retry_pull_requests(&mut self) {
|
||||
for (index, status) in self.pull_request_categories.iter_mut().enumerate() {
|
||||
if (self.category == 2 || self.category == index) && status.error.take().is_some() {
|
||||
for index in self.pull_request_streams() {
|
||||
let status = &mut self.pull_request_categories[index];
|
||||
if status.error.take().is_some() {
|
||||
self.pull_request_retries[index] += 1;
|
||||
self.loading = true;
|
||||
}
|
||||
@@ -1284,7 +1300,10 @@ impl DiffState {
|
||||
if entry.target == RevisionTarget::Working
|
||||
|| (entry.category != category
|
||||
&& !(category == Category::All
|
||||
&& matches!(entry.category, Category::Open | Category::Closed)))
|
||||
&& matches!(
|
||||
entry.category,
|
||||
Category::Open | Category::Closed | Category::Drafts
|
||||
)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user