yang_base/definition/ui/
module.rs1use super::action::{ActionPresentationSchema, ActionPresentationSpec};
4use crate::definition::ActionRef;
5use schemars::JsonSchema;
6use serde::Serialize;
7use std::collections::BTreeMap;
8
9#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct AccountIdentitySpec {
12 pub id: String,
14 pub title: String,
16 pub icon: String,
18 pub order: i32,
20}
21
22impl AccountIdentitySpec {
23 pub fn new(id: impl Into<String>, title: impl Into<String>, icon: impl Into<String>) -> Self {
25 Self {
26 id: id.into(),
27 title: title.into(),
28 icon: icon.into(),
29 order: 0,
30 }
31 }
32
33 #[must_use]
35 pub fn order(mut self, order: i32) -> Self {
36 self.order = order;
37 self
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
46pub struct ModulePresentationSpec {
47 pub identity: AccountIdentitySpec,
49 pub title: String,
51 pub description: String,
53 pub icon: String,
55 pub order: i32,
57 pub app_route: Option<String>,
59 pub primary_action: Option<ActionRef>,
61 pub action_presentations: BTreeMap<ActionRef, ActionPresentationSpec>,
63}
64
65impl ModulePresentationSpec {
66 pub fn new(
68 identity: AccountIdentitySpec,
69 title: impl Into<String>,
70 icon: impl Into<String>,
71 ) -> Self {
72 Self {
73 identity,
74 title: title.into(),
75 description: String::new(),
76 icon: icon.into(),
77 order: 0,
78 app_route: None,
79 primary_action: None,
80 action_presentations: BTreeMap::new(),
81 }
82 }
83
84 #[must_use]
86 pub fn description(mut self, description: impl Into<String>) -> Self {
87 self.description = description.into();
88 self
89 }
90
91 #[must_use]
93 pub fn order(mut self, order: i32) -> Self {
94 self.order = order;
95 self
96 }
97
98 #[must_use]
100 pub fn app_route(mut self, route: impl Into<String>) -> Self {
101 self.app_route = Some(route.into());
102 self
103 }
104
105 #[must_use]
107 pub fn primary_action(mut self, action: ActionRef) -> Self {
108 self.primary_action = Some(action);
109 self
110 }
111
112 #[must_use]
114 pub fn present_action(
115 mut self,
116 action: ActionRef,
117 presentation: ActionPresentationSpec,
118 ) -> Self {
119 self.action_presentations.insert(action, presentation);
120 self
121 }
122}
123
124#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
126pub struct AccountIdentitySchema {
127 pub id: String,
129 pub title: String,
131 pub icon: String,
133 pub order: i32,
135}
136
137#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
139pub struct ModulePresentationSchema {
140 pub module_id: String,
142 pub identity: AccountIdentitySchema,
144 pub title: String,
146 pub description: String,
148 pub icon: String,
150 pub order: i32,
152 pub app_route: Option<String>,
154 pub primary_action: Option<String>,
156 pub actions: Vec<String>,
158 pub action_presentations: Vec<ActionPresentationSchema>,
160 pub views: Vec<String>,
162}