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 primary_action: Option<ActionRef>,
59 pub action_presentations: BTreeMap<ActionRef, ActionPresentationSpec>,
61}
62
63impl ModulePresentationSpec {
64 pub fn new(
66 identity: AccountIdentitySpec,
67 title: impl Into<String>,
68 icon: impl Into<String>,
69 ) -> Self {
70 Self {
71 identity,
72 title: title.into(),
73 description: String::new(),
74 icon: icon.into(),
75 order: 0,
76 primary_action: None,
77 action_presentations: BTreeMap::new(),
78 }
79 }
80
81 #[must_use]
83 pub fn description(mut self, description: impl Into<String>) -> Self {
84 self.description = description.into();
85 self
86 }
87
88 #[must_use]
90 pub fn order(mut self, order: i32) -> Self {
91 self.order = order;
92 self
93 }
94
95 #[must_use]
97 pub fn primary_action(mut self, action: ActionRef) -> Self {
98 self.primary_action = Some(action);
99 self
100 }
101
102 #[must_use]
104 pub fn present_action(
105 mut self,
106 action: ActionRef,
107 presentation: ActionPresentationSpec,
108 ) -> Self {
109 self.action_presentations.insert(action, presentation);
110 self
111 }
112}
113
114#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
116pub struct AccountIdentitySchema {
117 pub id: String,
119 pub title: String,
121 pub icon: String,
123 pub order: i32,
125}
126
127#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
129pub struct ModulePresentationSchema {
130 pub module_id: String,
132 pub identity: AccountIdentitySchema,
134 pub title: String,
136 pub description: String,
138 pub icon: String,
140 pub order: i32,
142 pub primary_action: Option<String>,
144 pub actions: Vec<String>,
146 pub action_presentations: Vec<ActionPresentationSchema>,
148 pub views: Vec<String>,
150}