Mountain/Command/
TreeView.rs

1//! # TreeView Commands
2//!
3//! Defines the specific Tauri command handlers for TreeView data requests
4//! that originate from the `Sky` frontend UI.
5
6#![allow(non_snake_case, non_camel_case_types)]
7
8use std::sync::Arc;
9
10use Common::{Environment::Requires::Requires, TreeView::TreeViewProvider::TreeViewProvider as CommonTreeViewProvider};
11use serde_json::{Value, json};
12use tauri::{AppHandle, Manager, State, Wry, command};
13
14use crate::{
15	ApplicationState::ApplicationState::ApplicationState,
16	Environment::MountainEnvironment::MountainEnvironment,
17	RunTime::ApplicationRunTime::ApplicationRunTime,
18};
19
20/// A specific Tauri command handler for the UI to fetch the children of a tree
21/// view node. This handler dispatches to the correct provider (native or
22/// proxied).
23#[command]
24pub async fn GetTreeViewChildren(
25	ApplicationHandle:AppHandle<Wry>,
26
27	_State:State<'_, Arc<ApplicationState>>,
28
29	ViewId:String,
30
31	ElementHandle:Option<String>,
32) -> Result<Value, String> {
33	log::debug!(
34		"[DispatchLogic] Getting TreeView children for '{}', element: {:?}",
35		ViewId,
36		ElementHandle
37	);
38
39	let RunTime = ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
40
41	let Environment:Arc<MountainEnvironment> = RunTime.Environment.clone();
42
43	let TreeProvider:Arc<dyn CommonTreeViewProvider> = Environment.Require();
44
45	match TreeProvider.GetChildren(ViewId, ElementHandle).await {
46		Ok(Children) => Ok(json!(Children)),
47
48		Err(Error) => {
49			let ErrorMessage = format!("Failed to get children for tree view: {}", Error);
50
51			log::error!("{}", ErrorMessage);
52
53			Err(ErrorMessage)
54		},
55	}
56}