Skip to content
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

feat: adapative page hints (client-side only) #1357

Merged
merged 3 commits into from
Nov 1, 2023
Merged
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
22 changes: 18 additions & 4 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -734,13 +734,20 @@ impl Shuttle {
println!();
return Ok(CommandOutcome::Ok);
}
let limit = limit + 1;

let proj_name = self.ctx.project_name();
let deployments = client
let mut deployments = client
.get_deployments(proj_name, page, limit)
.await
.map_err(suggestions::deployment::get_deployments_list_failure)?;
let table = get_deployments_table(&deployments, proj_name.as_str(), page, raw);
let page_hint = if deployments.len() == limit as usize {
deployments.pop();
true
} else {
false
};
let table = get_deployments_table(&deployments, proj_name.as_str(), page, raw, page_hint);

println!("{table}");
println!("Run `cargo shuttle logs <id>` to get logs for a given deployment.");
@@ -1695,16 +1702,23 @@ impl Shuttle {
println!();
return Ok(CommandOutcome::Ok);
}
let limit = limit + 1;

let projects = client.get_projects_list(page, limit).await.map_err(|err| {
let mut projects = client.get_projects_list(page, limit).await.map_err(|err| {
suggestions::project::project_request_failure(
err,
"Getting projects list failed",
false,
"getting the projects list fails repeteadly",
)
})?;
let projects_table = project::get_projects_table(&projects, page, raw);
let page_hint = if projects.len() == limit as usize {
projects.pop();
true
} else {
false
};
let projects_table = project::get_projects_table(&projects, page, raw, page_hint);

println!("{projects_table}");

13 changes: 10 additions & 3 deletions common/src/models/deployment.rs
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ pub fn get_deployments_table(
service_name: &str,
page: u32,
raw: bool,
page_hint: bool,
) -> String {
if deployments.is_empty() {
// The page starts at 1 in the CLI.
@@ -196,9 +197,15 @@ pub fn get_deployments_table(
}
}

format!(
"\nMost recent deployments for {service_name}\n{table}\nMore projects might be available on the next page using --page.\n",
)
let formatted_table = format!("\nMost recent deployments for {service_name}\n{table}\n");
if page_hint {
format!(
"{formatted_table}More deployments are available on the next page using `--page {}`\n",
page + 1
)
} else {
formatted_table
}
}
}

19 changes: 15 additions & 4 deletions common/src/models/project.rs
Original file line number Diff line number Diff line change
@@ -191,7 +191,12 @@ pub struct AdminResponse {
pub account_name: String,
}

pub fn get_projects_table(projects: &Vec<Response>, page: u32, raw: bool) -> String {
pub fn get_projects_table(
projects: &Vec<Response>,
page: u32,
raw: bool,
page_hint: bool,
) -> String {
if projects.is_empty() {
// The page starts at 1 in the CLI.
let mut s = if page <= 1 {
@@ -244,8 +249,14 @@ pub fn get_projects_table(projects: &Vec<Response>, page: u32, raw: bool) -> Str
}
}

format!(
"\nThese projects are linked to this account\n{table}\nMore projects might be available on the next page using --page.\n"
)
let formatted_table = format!("\nThese projects are linked to this account\n{table}\n");
if page_hint {
format!(
"{formatted_table}More projects are available on the next page using `--page {}`\n",
page + 1
)
} else {
formatted_table
}
}
}