Common/UserInterface/ShowQuickPick.rs
1// File: Common/Source/UserInterface/ShowQuickPick.rs
2// Role: Defines the `ShowQuickPick` ActionEffect.
3// Responsibilities:
4// - Provide a declarative effect for showing a quick pick list to the user.
5// - This effect abstracts the "what" (show a quick pick) from the "how" (the
6// UserInterfaceProvider implementation).
7
8//! # ShowQuickPick Effect
9//!
10//! Defines the `ActionEffect` for showing a quick pick list to the user.
11
12use std::sync::Arc;
13
14use super::{
15 DTO::{QuickPickItemDTO::QuickPickItemDTO, QuickPickOptionsDTO::QuickPickOptionsDTO},
16 UserInterfaceProvider::UserInterfaceProvider,
17};
18use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
19
20/// Creates an effect that, when executed, will display a quick pick list to
21/// the user, allowing them to select one or more items.
22///
23/// It uses the `UserInterfaceProvider` capability from the environment to
24/// orchestrate the interaction with the frontend UI.
25///
26/// # Parameters
27/// * `Items`: A `Vec<QuickPickItemDTO>` representing the list of items to
28/// display.
29/// * `Options`: An `Option<QuickPickOptionsDTO>` containing settings for the
30/// quick pick, such as the title and whether multiple selections are allowed.
31///
32/// # Returns
33/// An `ActionEffect` that resolves with an `Option<Vec<String>>`, containing
34/// the labels of the items selected by the user, or `None` if the quick pick
35/// was cancelled.
36pub fn ShowQuickPick(
37 Items:Vec<QuickPickItemDTO>,
38
39 Options:Option<QuickPickOptionsDTO>,
40) -> ActionEffect<Arc<dyn UserInterfaceProvider>, CommonError, Option<Vec<String>>> {
41 ActionEffect::New(Arc::new(move |Provider:Arc<dyn UserInterfaceProvider>| {
42 let ItemsClone = Items.clone();
43
44 let OptionsClone = Options.clone();
45
46 Box::pin(async move { Provider.ShowQuickPick(ItemsClone, OptionsClone).await })
47 }))
48}