Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Command/TreeView/
GetTreeViewChildren.rs

1//! Tauri command - fetch children for a tree node. `ElementHandle =
2//! None` returns the root level. Dispatches through
3//! `MountainEnvironment::Require<dyn TreeViewProvider>`.
4
5use std::sync::Arc;
6
7use CommonLibrary::{
8	Environment::Requires::Requires,
9	TreeView::TreeViewProvider::TreeViewProvider as CommonTreeViewProvider,
10};
11use serde_json::{Value, json};
12use tauri::{AppHandle, Manager, State, Wry, command};
13
14use crate::{
15	ApplicationState::State::ApplicationState::ApplicationState,
16	Environment::MountainEnvironment::MountainEnvironment,
17	RunTime::ApplicationRunTime::ApplicationRunTime,
18	dev_log,
19};
20
21#[command]
22pub async fn GetTreeViewChildren(
23	ApplicationHandle:AppHandle<Wry>,
24
25	_State:State<'_, Arc<ApplicationState>>,
26
27	ViewId:String,
28
29	ElementHandle:Option<String>,
30) -> Result<Value, String> {
31	dev_log!(
32		"commands",
33		"getting TreeView children for '{}', element: {:?}",
34		ViewId,
35		ElementHandle
36	);
37
38	let RunTime = ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
39
40	let Environment:Arc<MountainEnvironment> = RunTime.Environment.clone();
41
42	let TreeProvider:Arc<dyn CommonTreeViewProvider> = Environment.Require();
43
44	match TreeProvider.GetChildren(ViewId.clone(), ElementHandle).await {
45		Ok(Children) => Ok(json!(Children)),
46
47		Err(Error) => {
48			let ErrorMessage = format!("Failed to get children for tree view '{}': {}", ViewId, Error);
49
50			dev_log!("commands", "error: {}", ErrorMessage);
51
52			Err(ErrorMessage)
53		},
54	}
55}