Skip to content
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
3 changes: 3 additions & 0 deletions openstack_tui/.config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ mode_keybindings:
SetNetworkSecurityGroupRuleListFilters: {}
description: All
type: Filter
"ctrl-d":
action: DeleteNetworkSecurityGroupRule
description: Delete
# Global keybindings
# <KEYBINDING>:
# action: <ACTION>
Expand Down
2 changes: 2 additions & 0 deletions openstack_tui/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ pub enum Action {
SetNetworkSecurityGroupListFilters(cloud_types::NetworkSecurityGroupList),
/// Switch to NetworkSecurityGroupRules
ShowNetworkSecurityGroupRules,
/// Delete the security group rule.
DeleteNetworkSecurityGroupRule,
/// Switch to routers view
ShowNetworkRouters,
/// Set Security group rule filters
Expand Down
5 changes: 2 additions & 3 deletions openstack_tui/src/components/identity/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ impl Component for IdentityUsers<'_> {
self.sync_table_data()?;
}
self.set_loading(false);
} else if let IdentityUserApiRequest::Delete(del) = *req
&& let IdentityUserDelete { id, .. } = *del
{
} else if let IdentityUserApiRequest::Delete(del) = *req {
let IdentityUserDelete { id, .. } = *del;
if self.delete_item_row_by_res_id_mut(&id)?.is_none() {
return Ok(Some(Action::Refresh));
}
Expand Down
13 changes: 13 additions & 0 deletions openstack_tui/src/components/image/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ impl Component for Images<'_> {
self.set_data(data)?;
}
}
Action::ApiResponseData {
request: ApiRequest::Image(ImageApiRequest::Image(req)),
..
} => {
if let ImageImageApiRequest::Delete(del) = *req {
let ImageImageDelete { ref id, .. } = *del;
if self.delete_item_row_by_res_id_mut(&id)?.is_none() {
return Ok(Some(Action::Refresh));
}
self.sync_table_data()?;
self.set_loading(false);
}
}
Action::SetImageListFilters(filters) => {
self.set_filters(filters);
self.set_loading(true);
Expand Down
48 changes: 46 additions & 2 deletions openstack_tui/src/components/network/security_group_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// SPDX-License-Identifier: Apache-2.0

use crossterm::event::KeyEvent;
use eyre::Result;
use eyre::{Result, WrapErr};
use ratatui::prelude::*;
use tokio::sync::mpsc::UnboundedSender;

Expand All @@ -22,7 +22,9 @@ use openstack_types::network::v2::security_group_rule::response::list::SecurityG
use crate::{
action::Action,
cloud_worker::network::v2::{
NetworkApiRequest, NetworkSecurityGroupRuleApiRequest, NetworkSecurityGroupRuleList,
NetworkApiRequest, NetworkSecurityGroupRuleApiRequest, NetworkSecurityGroupRuleDelete,
NetworkSecurityGroupRuleDeleteBuilder, NetworkSecurityGroupRuleDeleteBuilderError,
NetworkSecurityGroupRuleList,
},
cloud_worker::types::ApiRequest,
components::{Component, table_view::TableViewComponentBase},
Expand Down Expand Up @@ -71,6 +73,17 @@ impl NetworkSecurityGroupRules<'_> {
}
}

impl TryFrom<&SecurityGroupRuleResponse> for NetworkSecurityGroupRuleDelete {
type Error = NetworkSecurityGroupRuleDeleteBuilderError;
fn try_from(value: &SecurityGroupRuleResponse) -> Result<Self, Self::Error> {
let mut builder = NetworkSecurityGroupRuleDeleteBuilder::default();
if let Some(val) = &value.id {
builder.id(val.clone());
}
builder.build()
}
}

impl Component for NetworkSecurityGroupRules<'_> {
fn register_config_handler(&mut self, config: Config) -> Result<(), TuiError> {
self.set_config(config)
Expand Down Expand Up @@ -125,6 +138,37 @@ impl Component for NetworkSecurityGroupRules<'_> {
self.set_data(data)?;
}
}
Action::ApiResponseData {
request: ApiRequest::Network(NetworkApiRequest::SecurityGroupRule(req)),
..
} => {
if let NetworkSecurityGroupRuleApiRequest::Delete(del) = *req {
let NetworkSecurityGroupRuleDelete { ref id, .. } = *del;
if self.delete_item_row_by_res_id_mut(&id)?.is_none() {
return Ok(Some(Action::Refresh));
}
self.sync_table_data()?;
self.set_loading(false);
}
}
Action::DeleteNetworkSecurityGroupRule => {
// only if we are currently in the right mode
if current_mode == Mode::NetworkSecurityGroupRules {
// and have command_tx
if let Some(command_tx) = self.get_command_tx() {
// and have a selected entry
if let Some(selected_entry) = self.get_selected() {
// send action to delete the selected SecurityGroupRule
command_tx.send(Action::Confirm(ApiRequest::from(
NetworkSecurityGroupRuleApiRequest::Delete(Box::new(
NetworkSecurityGroupRuleDelete::try_from(selected_entry)
.wrap_err("error preparing OpenStack request")?,
)),
)))?;
}
}
}
}
_ => {}
};
Ok(None)
Expand Down
Loading