aws credential deletion

This commit is contained in:
jfmonty2 committed 2026-11-20 06:18:06 -05:00
1 parent 21efa29fdd
commit ce8727ee9a
4 files changed
+114 -3

No files matched your search

+56 -1
View File
@@ -19,6 +19,8 @@ pub struct CredentialsScreen {
tab: usize,
aws: Vec<AwsCredential>,
aws_form: Option<AwsForm>,
/// The id of the credential awaiting delete confirmation.
aws_deleting: Option<Uuid>,
error: Option<SharedString>,
}
@@ -34,7 +36,7 @@ struct AwsForm {
impl CredentialsScreen {
pub fn new(cx: &mut Context<Self>) -> Self {
let mut this = Self { tab: 0, aws: Vec::new(), aws_form: 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
}
@@ -128,6 +130,20 @@ impl CredentialsScreen {
cx.notify();
}
fn delete_aws(&mut self, id: Uuid, cx: &mut Context<Self>) {
let AppSession::Unlocked(db) = cx.global::<AppSession>() else {
unreachable!("credentials screen is only shown while unlocked");
};
match db.delete_aws_credential(id) {
Ok(()) => {
self.aws_deleting = None;
self.load_aws(cx);
},
Err(e) => self.error = Some(format!("Failed to delete credential: {e}").into()),
}
cx.notify();
}
fn render_aws_tab(&self, window: &mut Window, cx: &mut Context<Self>) -> Div {
let t = cx.omarchy().clone();
@@ -144,6 +160,32 @@ impl CredentialsScreen {
}
let id = cred.id;
if self.aws_deleting == Some(id) {
panel = panel.child(
div()
.flex()
.items_center()
.gap(rems(0.5))
.p(rems(0.625))
.border_1()
.border_color(t.danger)
.child(format!("Delete AWS credential \"{}\"?", cred.name))
.child(
button("aws-delete-cancel", "Cancel", ButtonVariant::Outline, cx)
.ml_auto()
.on_click(cx.listener(|this, _, _, cx| {
this.aws_deleting = None;
cx.notify();
})),
)
.child(
button("aws-delete-confirm", "Delete", ButtonVariant::Danger, cx)
.on_click(cx.listener(move |this, _, _, cx| this.delete_aws(id, cx))),
),
);
continue;
}
panel = panel.child(
div()
.id(SharedString::from(&cred.name))
@@ -174,6 +216,19 @@ impl CredentialsScreen {
.on_click(cx.listener(move |this, _, window, cx| {
this.open_aws_form(Some(id), window, cx)
})),
)
.child(
icon_button(
SharedString::from(format!("delete-{}", cred.name)),
IconName::Trash,
"Delete",
ButtonVariant::Danger,
cx,
)
.on_click(cx.listener(move |this, _, _, cx| {
this.aws_deleting = Some(id);
cx.notify();
})),
),
);
}