这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: order tasks in order of interest, namely failed, successful, then cached #9353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ crossterm = { version = "0.27.0", features = ["event-stream"] }
dialoguer = { workspace = true }
futures = { workspace = true }
indicatif = { workspace = true }
itertools.workspace = true
lazy_static = { workspace = true }
nix = { version = "0.26.2", features = ["signal"] }
ratatui = { workspace = true }
Expand Down
64 changes: 40 additions & 24 deletions crates/turborepo-ui/src/tui/table.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use itertools::Itertools;
use ratatui::{
layout::{Constraint, Rect},
style::{Color, Style, Stylize},
Expand All @@ -9,8 +10,13 @@ use super::{event::TaskResult, spinner::SpinnerState, task::TasksByStatus};

/// A widget that renders a table of their tasks and their current status
///
/// The table contains finished tasks, running tasks, and planned tasks rendered
/// in that order.
/// The tasks are ordered as follows:
/// - running tasks
/// - planned tasks
/// - finished tasks
/// - failed tasks
/// - successful tasks
/// - cached tasks
pub struct TaskTable<'b> {
tasks_by_type: &'b TasksByStatus,
spinner: SpinnerState,
Expand Down Expand Up @@ -46,29 +52,39 @@ impl<'b> TaskTable<'b> {
}

fn finished_rows(&self) -> impl Iterator<Item = Row> + '_ {
self.tasks_by_type.finished.iter().map(move |task| {
let name = if matches!(task.result(), TaskResult::CacheHit) {
Cell::new(Text::styled(task.name(), Style::default().italic()))
} else {
Cell::new(task.name())
};
self.tasks_by_type
.finished
.iter()
// note we can't use the default Ord impl because
// we want failed tasks first
.sorted_by_key(|task| match task.result() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking TODO for myself (or anyone else), but we should try to insert tasks as they finish in this order instead of sorting it on every render.

TaskResult::Failure => 0,
TaskResult::Success => 1,
TaskResult::CacheHit => 2,
})
.map(move |task| {
let name = if matches!(task.result(), TaskResult::CacheHit) {
Cell::new(Text::styled(task.name(), Style::default().italic()))
} else {
Cell::new(task.name())
};

Row::new(vec![
name,
match task.result() {
// matches Next.js (and many other CLI tools) https://github.com/vercel/next.js/blob/1a04d94aaec943d3cce93487fea3b8c8f8898f31/packages/next/src/build/output/log.ts
TaskResult::Success => {
Cell::new(Text::styled("✓", Style::default().green().bold()))
}
TaskResult::CacheHit => {
Cell::new(Text::styled("⊙", Style::default().magenta()))
}
TaskResult::Failure => {
Cell::new(Text::styled("⨯", Style::default().red().bold()))
}
},
])
})
Row::new(vec![
name,
match task.result() {
// matches Next.js (and many other CLI tools) https://github.com/vercel/next.js/blob/1a04d94aaec943d3cce93487fea3b8c8f8898f31/packages/next/src/build/output/log.ts
TaskResult::Success => {
Cell::new(Text::styled("✓", Style::default().green().bold()))
}
TaskResult::CacheHit => {
Cell::new(Text::styled("⊙", Style::default().magenta()))
}
TaskResult::Failure => {
Cell::new(Text::styled("⨯", Style::default().red().bold()))
}
},
])
})
}

fn running_rows(&self) -> impl Iterator<Item = Row> + '_ {
Expand Down
Loading