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(cargo-shuttle): adapt project response for beta #1756

Merged
merged 6 commits into from
Apr 26, 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
2 changes: 2 additions & 0 deletions backends/src/client/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ mod tests {
id: "00000000000000000000000001".to_string(),
name: "user-1-project-1".to_string(),
state: State::Stopped,
deployment_state: None,
idle_minutes: Some(30),
owner: shuttle_common::models::project::Owner::User("user-1".to_string()),
is_admin: true,
Expand All @@ -115,6 +116,7 @@ mod tests {
id: "00000000000000000000000002".to_string(),
name: "user-1-project-2".to_string(),
state: State::Ready,
deployment_state: None,
idle_minutes: Some(30),
owner: shuttle_common::models::project::Owner::User("user-1".to_string()),
is_admin: true,
Expand Down
4 changes: 2 additions & 2 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ impl Shuttle {
"getting the projects list fails repeatedly",
)
})?;
let projects_table = project::get_projects_table(&projects, raw);
let projects_table = project::get_projects_table(self.beta, &projects, raw);

println!("{}", "Personal Projects".bold());
println!("{projects_table}");
Expand All @@ -2125,7 +2125,7 @@ impl Shuttle {
"getting the team projects list fails repeatedly",
)
})?;
let team_projects_table = project::get_projects_table(&team_projects, raw);
let team_projects_table = project::get_projects_table(self.beta, &team_projects, raw);

println!("{}", format!("{}'s Projects", team.display_name).bold());
println!("{team_projects_table}");
Expand Down
35 changes: 29 additions & 6 deletions common/src/models/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use strum::EnumString;

use crate::deployment::EcsState;

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct Response {
pub id: String,
pub name: String,
// Ignored on beta.
pub state: State,
// Ignored on alpha. Present on beta if an ECS service exists (something has been deployed).
pub deployment_state: Option<EcsState>,
// Always None on beta.
pub idle_minutes: Option<u64>,
#[serde(flatten)]
pub owner: Owner,
/// Whether the calling user is an admin in this project
pub is_admin: bool,
}

Expand Down Expand Up @@ -174,7 +181,7 @@ pub enum Owner {
Team(String),
}

pub fn get_projects_table(projects: &[Response], raw: bool) -> String {
pub fn get_projects_table(beta: bool, projects: &[Response], raw: bool) -> String {
if projects.is_empty() {
let mut s = "No projects are linked to this account\n".to_string();
if !raw {
Expand All @@ -191,7 +198,8 @@ pub fn get_projects_table(projects: &[Response], raw: bool) -> String {
.set_content_arrangement(ContentArrangement::Disabled)
.set_header(vec![
Cell::new("Project Name").set_alignment(CellAlignment::Left),
Cell::new("Status").set_alignment(CellAlignment::Left),
Cell::new(if beta { "Deployment Status" } else { "Status" })
.set_alignment(CellAlignment::Left),
]);
} else {
table
Expand All @@ -202,21 +210,36 @@ pub fn get_projects_table(projects: &[Response], raw: bool) -> String {
Cell::new("Project Name")
.set_alignment(CellAlignment::Center)
.add_attribute(Attribute::Bold),
Cell::new("Status")
Cell::new(if beta { "Deployment Status" } else { "Status" })
.set_alignment(CellAlignment::Center)
.add_attribute(Attribute::Bold),
]);
}

for project in projects.iter() {
let state = if beta {
project
.deployment_state
.as_ref()
.map(|s| s.to_string())
.unwrap_or_default()
} else {
project.state.to_string()
};
if raw {
table.add_row(vec![Cell::new(&project.name), Cell::new(&project.state)]);
table.add_row(vec![Cell::new(&project.name), Cell::new(state)]);
} else {
table.add_row(vec![
Cell::new(&project.name),
Cell::new(&project.state)
Cell::new(state)
// Unwrap is safe because Color::from_str returns the color white if the argument is not a Color.
.fg(Color::from_str(project.state.get_color()).unwrap())
.fg(Color::from_str(if beta {
// TODO: Color for EcsState
""
} else {
project.state.get_color()
})
.unwrap())
.set_alignment(CellAlignment::Center),
]);
}
Expand Down
5 changes: 5 additions & 0 deletions gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async fn get_project(
id: project.id.to_uppercase(),
name: scope.to_string(),
state: project.state.into(),
deployment_state: None,
idle_minutes,
owner,
is_admin,
Expand Down Expand Up @@ -165,6 +166,7 @@ async fn get_projects_list(
id: project.id,
name: project.name,
state: project.state.into(),
deployment_state: None,
idle_minutes,
owner,
is_admin,
Expand Down Expand Up @@ -227,6 +229,7 @@ async fn create_project(
id: project.id.to_string().to_uppercase(),
name: project_name.to_string(),
state: project.state.into(),
deployment_state: None,
idle_minutes,
owner: project::Owner::User(claim.sub),
is_admin: true,
Expand Down Expand Up @@ -262,6 +265,7 @@ async fn destroy_project(
id: project.id.to_uppercase(),
name: project_name.to_string(),
state: project.state.into(),
deployment_state: None,
idle_minutes,
owner,
is_admin,
Expand Down Expand Up @@ -582,6 +586,7 @@ async fn get_team_projects(
id: project.id,
name: project.name,
state: project.state.into(),
deployment_state: None,
idle_minutes,
owner,
is_admin,
Expand Down