From 55de957de386510a97e9652665ad8feacc01ab70 Mon Sep 17 00:00:00 2001 From: cc Date: Mon, 30 Oct 2023 13:07:31 -0400 Subject: [PATCH 1/3] feat: adapative page hints (client-side only) --- cargo-shuttle/src/lib.rs | 22 ++++++++++++++++++---- common/src/models/deployment.rs | 10 +++++++--- common/src/models/project.rs | 16 ++++++++++++---- examples | 2 +- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 5305a783e..a7d1f46f3 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -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 ` to get logs for a given deployment."); @@ -1695,8 +1702,9 @@ 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", @@ -1704,7 +1712,13 @@ impl Shuttle { "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}"); diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index 4b8e8e628..2847e107e 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -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,12 @@ 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 projects might be available on the next page using --page.\n") + } else { + formatted_table + } } } diff --git a/common/src/models/project.rs b/common/src/models/project.rs index 1ef395ccd..b743e9b36 100644 --- a/common/src/models/project.rs +++ b/common/src/models/project.rs @@ -191,7 +191,12 @@ pub struct AdminResponse { pub account_name: String, } -pub fn get_projects_table(projects: &Vec, page: u32, raw: bool) -> String { +pub fn get_projects_table( + projects: &Vec, + 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,11 @@ pub fn get_projects_table(projects: &Vec, 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 might be available on the next page using --page.\n") + } else { + formatted_table + } } } diff --git a/examples b/examples index 24246f8ee..2105ff2e3 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 24246f8ee561db0948703280f290752e4ed0cacf +Subproject commit 2105ff2e380ca77e3c9d08172db6d6c40deb38c8 From 41b1172093f55286c1758ec71852f0ba78cc5c1e Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:56:40 +0100 Subject: [PATCH 2/3] fix: submodule --- examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples b/examples index 2105ff2e3..24246f8ee 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 2105ff2e380ca77e3c9d08172db6d6c40deb38c8 +Subproject commit 24246f8ee561db0948703280f290752e4ed0cacf From c49b03800249b0fbfb748f5adb93e52ab01f2535 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:27:39 +0100 Subject: [PATCH 3/3] nit: add page number, better wording --- common/src/models/deployment.rs | 5 ++++- common/src/models/project.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index 2847e107e..cc0f7945e 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -199,7 +199,10 @@ pub fn get_deployments_table( let formatted_table = format!("\nMost recent deployments for {service_name}\n{table}\n"); if page_hint { - format!("{formatted_table}More projects might be available on the next page using --page.\n") + format!( + "{formatted_table}More deployments are available on the next page using `--page {}`\n", + page + 1 + ) } else { formatted_table } diff --git a/common/src/models/project.rs b/common/src/models/project.rs index b743e9b36..5eb1cc26f 100644 --- a/common/src/models/project.rs +++ b/common/src/models/project.rs @@ -251,7 +251,10 @@ pub fn get_projects_table( let formatted_table = format!("\nThese projects are linked to this account\n{table}\n"); if page_hint { - format!("{formatted_table}More projects might be available on the next page using --page.\n") + format!( + "{formatted_table}More projects are available on the next page using `--page {}`\n", + page + 1 + ) } else { formatted_table }