add credentials screen

This commit is contained in:
jfmonty2 committed 2026-11-19 20:26:56 -05:00
1 parent b1c8762981
commit 31edd55b0a
5 files changed
+206 -5

No files matched your search

+132
View File
@@ -0,0 +1,132 @@
use gpui_kit::{
Context, FontWeight, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
Styled, TestSupportExt, Window, div, rems,
};
use gpui_omarchy::{
ActiveTheme, ButtonVariant, ChoiceItem, IconName, empty_state, focus_scope, icon_button,
tab_list,
};
use crate::components::error_alert;
use crate::credentials::AwsCredential;
use crate::session::AppSession;
use super::Screen;
pub struct CredentialsScreen {
tab: usize,
aws: Vec<(String, AwsCredential)>,
error: Option<SharedString>,
}
impl CredentialsScreen {
pub fn new(cx: &mut Context<Self>) -> Self {
let AppSession::Unlocked(db) = cx.global::<AppSession>() else {
unreachable!("credentials screen is only shown while unlocked");
};
let (aws, error) = match db.list_aws_credentials() {
Ok(creds) => {
let mut creds: Vec<_> = creds.into_iter().collect();
creds.sort_by(|a, b| a.0.cmp(&b.0));
(creds, None)
},
Err(e) => (Vec::new(), Some(format!("Failed to load credentials: {e}").into())),
};
Self { tab: 0, aws, error }
}
}
impl Render for CredentialsScreen {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let t = cx.omarchy().clone();
let this = cx.entity();
let tabs = tab_list(
"credential-tabs",
vec![
ChoiceItem::new("aws", "AWS"),
ChoiceItem::new("ssh", "SSH"),
ChoiceItem::new("docker", "Docker"),
],
Some(self.tab),
false,
move |index, _, cx| this.update(cx, |this, cx| {
this.tab = index;
cx.notify();
}),
window,
cx,
);
let panel = match self.tab {
0 if self.aws.is_empty() => empty_state(
"AWS access keys",
"You have no saved AWS credentials.",
cx,
),
0 => div()
.flex()
.flex_col()
.gap(rems(0.5))
.children(self.aws.iter().map(|(name, cred)| {
div()
.id(SharedString::from(name))
.test_support()
.flex()
.justify_between()
.p(rems(0.625))
.border_1()
.border_color(t.border)
.child(div().font_weight(FontWeight::BOLD).child(name.clone()))
.child(
div()
.font_family(t.mono_font.clone())
.text_color(t.secondary)
.child(cred.access_key_id.clone()),
)
})),
1 => empty_state("SSH keys", "Not implemented yet.", cx),
_ => empty_state("Docker credentials", "Not implemented yet.", cx),
};
focus_scope("credentials-screen")
.size_full()
.flex()
.flex_col()
.items_center()
.gap(rems(1.))
.p(rems(0.5))
.child(
div()
.relative()
.w_full()
.flex()
.justify_center()
.child(
icon_button("back", IconName::ChevronLeft, "Back", ButtonVariant::Secondary, cx)
.absolute()
.left_0()
.on_click(|_, _, cx| cx.set_global(Screen::Home)),
)
.child(
div()
.text_size(rems(1.875))
.font_weight(FontWeight::BOLD)
.child("Credentials"),
),
)
.child(tabs)
.child(
div()
.w_full()
.max_w(rems(36.))
.flex()
.flex_col()
.gap(rems(1.))
.children(self.error.clone().map(|e| error_alert(e, cx)))
.child(panel),
)
}
}