fix(sonarr): Pass the root folder ID alongside all DeleteRootFolder events when publishing to the networking channel
This commit is contained in:
@@ -42,6 +42,16 @@ impl<'a, 'b> RootFoldersHandler<'a, 'b> {
|
||||
self.app.data.sonarr_data.edit_root_folder = None;
|
||||
AddRootFolderBody { path: root_folder }
|
||||
}
|
||||
|
||||
fn extract_root_folder_id(&self) -> i64 {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.root_folders
|
||||
.current_selection()
|
||||
.id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<'a, 'b> {
|
||||
@@ -138,7 +148,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<'
|
||||
ActiveSonarrBlock::DeleteRootFolderPrompt => {
|
||||
if self.app.data.sonarr_data.prompt_confirm {
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteRootFolder(None));
|
||||
Some(SonarrEvent::DeleteRootFolder(self.extract_root_folder_id()));
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
@@ -208,7 +218,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<'
|
||||
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteRootFolder(None));
|
||||
Some(SonarrEvent::DeleteRootFolder(self.extract_root_folder_id()));
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ mod tests {
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::root_folders::RootFoldersHandler;
|
||||
use crate::handlers::sonarr_handlers::sonarr_handler_test_utils::utils::root_folder;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, ROOT_FOLDERS_BLOCKS};
|
||||
use crate::models::servarr_models::{AddRootFolderBody, RootFolder};
|
||||
@@ -326,7 +327,7 @@ mod tests {
|
||||
.data
|
||||
.sonarr_data
|
||||
.root_folders
|
||||
.set_items(vec![RootFolder::default()]);
|
||||
.set_items(vec![root_folder()]);
|
||||
app.data.sonarr_data.prompt_confirm = true;
|
||||
app.push_navigation_stack(ActiveSonarrBlock::RootFolders.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::DeleteRootFolderPrompt.into());
|
||||
@@ -342,7 +343,7 @@ mod tests {
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::DeleteRootFolder(None))
|
||||
Some(SonarrEvent::DeleteRootFolder(1))
|
||||
);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
@@ -619,7 +620,7 @@ mod tests {
|
||||
.data
|
||||
.sonarr_data
|
||||
.root_folders
|
||||
.set_items(vec![RootFolder::default()]);
|
||||
.set_items(vec![root_folder()]);
|
||||
app.push_navigation_stack(ActiveSonarrBlock::RootFolders.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::DeleteRootFolderPrompt.into());
|
||||
|
||||
@@ -634,7 +635,7 @@ mod tests {
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::DeleteRootFolder(None))
|
||||
Some(SonarrEvent::DeleteRootFolder(1))
|
||||
);
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
@@ -654,6 +655,26 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_root_folder_id() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.root_folders
|
||||
.set_items(vec![root_folder()]);
|
||||
|
||||
let root_folder_id = RootFoldersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::DeleteRootFolderPrompt,
|
||||
None,
|
||||
)
|
||||
.extract_root_folder_id();
|
||||
|
||||
assert_eq!(root_folder_id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_add_root_folder_body() {
|
||||
let mut app = App::default();
|
||||
|
||||
Reference in New Issue
Block a user