formatting pass
This commit is contained in:
1 parent
d976eebbbc
commit
e4cfa53bce
21 files changed
+333
-194
No files matched your search
+88
-33
@@ -8,13 +8,12 @@ use gpui_omarchy::{
|
||||
focus_scope, icon_button, input, tab_list,
|
||||
};
|
||||
|
||||
use super::Screen;
|
||||
use crate::components::{PassphraseInput, PassphraseInputEvent, colored_switch, error_alert};
|
||||
use crate::credentials::AwsCredential;
|
||||
use crate::session::AppSession;
|
||||
use super::Screen;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
||||
pub struct CredentialsScreen {
|
||||
tab: usize,
|
||||
aws: Vec<AwsCredential>,
|
||||
@@ -36,7 +35,13 @@ struct AwsForm {
|
||||
|
||||
impl CredentialsScreen {
|
||||
pub fn new(cx: &mut Context<Self>) -> Self {
|
||||
let mut this = Self { tab: 0, aws: Vec::new(), aws_form: None, aws_deleting: None, error: None };
|
||||
let mut this = Self {
|
||||
tab: 0,
|
||||
aws: Vec::new(),
|
||||
aws_form: None,
|
||||
aws_deleting: None,
|
||||
error: None,
|
||||
};
|
||||
this.load_aws(cx);
|
||||
this
|
||||
}
|
||||
@@ -50,20 +55,27 @@ impl CredentialsScreen {
|
||||
Ok(creds) => {
|
||||
self.aws = creds;
|
||||
self.error = None;
|
||||
},
|
||||
}
|
||||
Err(e) => self.error = Some(format!("Failed to load credentials: {e}").into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn open_aws_form(&mut self, editing: Option<Uuid>, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let existing = self.aws
|
||||
fn open_aws_form(
|
||||
&mut self,
|
||||
editing: Option<Uuid>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let existing = self
|
||||
.aws
|
||||
.iter()
|
||||
.find(|cred| Some(cred.id) == editing)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
|
||||
let name = cx.new(|cx| InputState::new(window, cx).default_value(existing.name));
|
||||
let access_key_id = cx.new(|cx| InputState::new(window, cx).default_value(existing.access_key_id));
|
||||
let access_key_id =
|
||||
cx.new(|cx| InputState::new(window, cx).default_value(existing.access_key_id));
|
||||
let secret_access_key = PassphraseInput::builder("aws-secret")
|
||||
.value(existing.secret_access_key)
|
||||
.build(window, cx);
|
||||
@@ -106,13 +118,21 @@ impl CredentialsScreen {
|
||||
is_default: form.is_default,
|
||||
};
|
||||
|
||||
if cred.name.is_empty() || cred.access_key_id.is_empty() || cred.secret_access_key.is_empty() {
|
||||
if cred.name.is_empty()
|
||||
|| cred.access_key_id.is_empty()
|
||||
|| cred.secret_access_key.is_empty()
|
||||
{
|
||||
self.error = Some("All fields are required.".into());
|
||||
cx.notify();
|
||||
return;
|
||||
}
|
||||
if self.aws.iter().any(|existing| existing.name == cred.name && existing.id != cred.id) {
|
||||
self.error = Some(format!("An AWS credential named \"{}\" already exists.", cred.name).into());
|
||||
if self
|
||||
.aws
|
||||
.iter()
|
||||
.any(|existing| existing.name == cred.name && existing.id != cred.id)
|
||||
{
|
||||
self.error =
|
||||
Some(format!("An AWS credential named \"{}\" already exists.", cred.name).into());
|
||||
cx.notify();
|
||||
return;
|
||||
}
|
||||
@@ -124,7 +144,7 @@ impl CredentialsScreen {
|
||||
Ok(()) => {
|
||||
self.aws_form = None;
|
||||
self.load_aws(cx);
|
||||
},
|
||||
}
|
||||
Err(e) => self.error = Some(format!("Failed to save credential: {e}").into()),
|
||||
}
|
||||
cx.notify();
|
||||
@@ -138,7 +158,7 @@ impl CredentialsScreen {
|
||||
Ok(()) => {
|
||||
self.aws_deleting = None;
|
||||
self.load_aws(cx);
|
||||
},
|
||||
}
|
||||
Err(e) => self.error = Some(format!("Failed to delete credential: {e}").into()),
|
||||
}
|
||||
cx.notify();
|
||||
@@ -149,7 +169,11 @@ impl CredentialsScreen {
|
||||
|
||||
let mut panel = div().flex().flex_col().gap(rems(0.5));
|
||||
if self.aws.is_empty() {
|
||||
panel = panel.child(empty_state("AWS access keys", "You have no saved AWS credentials.", cx));
|
||||
panel = panel.child(empty_state(
|
||||
"AWS access keys",
|
||||
"You have no saved AWS credentials.",
|
||||
cx,
|
||||
));
|
||||
}
|
||||
for cred in &self.aws {
|
||||
if let Some(form) = &self.aws_form
|
||||
@@ -180,7 +204,9 @@ impl CredentialsScreen {
|
||||
)
|
||||
.child(
|
||||
button("aws-delete-confirm", "Delete", ButtonVariant::Danger, cx)
|
||||
.on_click(cx.listener(move |this, _, _, cx| this.delete_aws(id, cx))),
|
||||
.on_click(
|
||||
cx.listener(move |this, _, _, cx| this.delete_aws(id, cx)),
|
||||
),
|
||||
),
|
||||
);
|
||||
continue;
|
||||
@@ -197,7 +223,10 @@ impl CredentialsScreen {
|
||||
.border_1()
|
||||
.border_color(if cred.is_default { t.accent } else { t.border })
|
||||
.child(div().font_weight(FontWeight::BOLD).child(cred.name.clone()))
|
||||
.children(cred.is_default.then(|| badge("Default", Status::Success, cx)))
|
||||
.children(
|
||||
cred.is_default
|
||||
.then(|| badge("Default", Status::Success, cx)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.ml_auto()
|
||||
@@ -213,9 +242,9 @@ impl CredentialsScreen {
|
||||
ButtonVariant::Outline,
|
||||
cx,
|
||||
)
|
||||
.on_click(cx.listener(move |this, _, window, cx| {
|
||||
this.open_aws_form(Some(id), window, cx)
|
||||
})),
|
||||
.on_click(cx.listener(
|
||||
move |this, _, window, cx| this.open_aws_form(Some(id), window, cx),
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
icon_button(
|
||||
@@ -238,9 +267,13 @@ impl CredentialsScreen {
|
||||
button("aws-add", "Add", ButtonVariant::Primary, cx)
|
||||
.self_center()
|
||||
.mt(rems(0.5))
|
||||
.on_click(cx.listener(|this, _, window, cx| this.open_aws_form(None, window, cx))),
|
||||
.on_click(
|
||||
cx.listener(|this, _, window, cx| this.open_aws_form(None, window, cx)),
|
||||
),
|
||||
),
|
||||
Some(form) if form.editing.is_none() => panel.child(self.render_aws_form(form, window, cx)),
|
||||
Some(form) if form.editing.is_none() => {
|
||||
panel.child(self.render_aws_form(form, window, cx))
|
||||
}
|
||||
Some(_) => panel,
|
||||
}
|
||||
}
|
||||
@@ -264,27 +297,41 @@ impl CredentialsScreen {
|
||||
.p(rems(1.))
|
||||
.border_1()
|
||||
.border_color(t.border)
|
||||
.child(field("Name", input("aws-name", &form.name, window, cx).into_any_element()))
|
||||
.child(field(
|
||||
"Name",
|
||||
input("aws-name", &form.name, window, cx).into_any_element(),
|
||||
))
|
||||
.child(field(
|
||||
"Key ID",
|
||||
input("aws-key-id", &form.access_key_id, window, cx)
|
||||
.font_family(t.mono_font.clone())
|
||||
.into_any_element(),
|
||||
))
|
||||
.child(field("Secret key", form.secret_access_key.clone().into_any_element()))
|
||||
.child(field(
|
||||
"Secret key",
|
||||
form.secret_access_key.clone().into_any_element(),
|
||||
))
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(rems(0.5))
|
||||
.child(
|
||||
colored_switch("aws-default", "Default AWS access key", form.is_default, t.success, cx)
|
||||
.on_change(move |value, _, _, cx| this.update(cx, |this, cx| {
|
||||
colored_switch(
|
||||
"aws-default",
|
||||
"Default AWS access key",
|
||||
form.is_default,
|
||||
t.success,
|
||||
cx,
|
||||
)
|
||||
.on_change(move |value, _, _, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
if let Some(form) = &mut this.aws_form {
|
||||
form.is_default = value;
|
||||
}
|
||||
cx.notify();
|
||||
})),
|
||||
})
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
button("aws-cancel", "Cancel", ButtonVariant::Outline, cx)
|
||||
@@ -315,10 +362,12 @@ impl Render for CredentialsScreen {
|
||||
],
|
||||
Some(self.tab),
|
||||
false,
|
||||
move |index, _, cx| this.update(cx, |this, cx| {
|
||||
this.tab = index;
|
||||
cx.notify();
|
||||
}),
|
||||
move |index, _, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.tab = index;
|
||||
cx.notify();
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
@@ -343,10 +392,16 @@ impl Render for CredentialsScreen {
|
||||
.flex()
|
||||
.justify_center()
|
||||
.child(
|
||||
icon_button("back", IconName::ChevronLeft, "Back", ButtonVariant::Secondary, cx)
|
||||
.absolute()
|
||||
.left_0()
|
||||
.on_click(|_, _, cx| cx.set_global(Screen::Home)),
|
||||
icon_button(
|
||||
"back",
|
||||
IconName::ChevronLeft,
|
||||
"Back",
|
||||
ButtonVariant::Secondary,
|
||||
cx,
|
||||
)
|
||||
.absolute()
|
||||
.left_0()
|
||||
.on_click(|_, _, cx| cx.set_global(Screen::Home)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
|
||||
Reference in new issue
Block a user