open_lark/card/components/interactive_components/
select_person.rs1use serde::{Deserialize, Serialize};
2
3use crate::card::components::{
4 content_components::plain_text::PlainText, interactive_components::input::InputConfirm,
5};
6
7#[derive(Debug, Serialize, Deserialize)]
9pub struct SelectPerson {
10 tag: String,
12 #[serde(skip_serializing_if = "Option::is_none")]
17 r#type: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
26 required: Option<bool>,
27 #[serde(skip_serializing_if = "Option::is_none")]
32 disabled: Option<bool>,
33 #[serde(skip_serializing_if = "Option::is_none")]
35 placeholder: Option<PlainText>,
36 #[serde(skip_serializing_if = "Option::is_none")]
42 width: Option<String>,
43 #[serde(skip_serializing_if = "Option::is_none")]
45 options: Option<Vec<SelectPersonOption>>,
46 #[serde(skip_serializing_if = "Option::is_none")]
51 confirm: Option<InputConfirm>,
52}
53
54impl Default for SelectPerson {
55 fn default() -> Self {
56 Self {
57 tag: "select_person".to_string(),
58 r#type: None,
59 required: None,
60 disabled: None,
61 placeholder: None,
62 width: None,
63 options: None,
64 confirm: None,
65 }
66 }
67}
68
69impl SelectPerson {
70 pub fn new() -> Self {
71 Self::default()
72 }
73
74 pub fn r#type(mut self, r#type: &str) -> Self {
75 self.r#type = Some(r#type.to_string());
76 self
77 }
78
79 pub fn required(mut self, required: bool) -> Self {
80 self.required = Some(required);
81 self
82 }
83
84 pub fn disabled(mut self, disabled: bool) -> Self {
85 self.disabled = Some(disabled);
86 self
87 }
88
89 pub fn placeholder(mut self, placeholder: PlainText) -> Self {
90 self.placeholder = Some(placeholder);
91 self
92 }
93
94 pub fn width(mut self, width: &str) -> Self {
95 self.width = Some(width.to_string());
96 self
97 }
98
99 pub fn options(mut self, options: Vec<SelectPersonOption>) -> Self {
100 self.options = Some(options);
101 self
102 }
103
104 pub fn confirm(mut self, confirm: InputConfirm) -> Self {
105 self.confirm = Some(confirm);
106 self
107 }
108}
109
110#[derive(Debug, Serialize, Deserialize)]
112pub struct SelectPersonOption {
113 value: String,
115}
116
117impl SelectPersonOption {
118 pub fn new(value: &str) -> Self {
119 Self {
120 value: value.to_string(),
121 }
122 }
123}
124
125#[cfg(test)]
126mod test {
127 use serde_json::json;
128
129 use super::*;
130
131 #[test]
132 fn test_select_person() {
133 let select_person = SelectPerson::new()
134 .r#type("text")
135 .required(true)
136 .disabled(false)
137 .placeholder(PlainText::text("默认提示文本"))
138 .width("default")
139 .options(vec![
140 SelectPersonOption::new("ou_48d0958ee4b2ab3eaf0b5f6c968xxxxx"),
141 SelectPersonOption::new("ou_f9d24af786a14340721288cda6axxxxx"),
142 ])
143 .confirm(InputConfirm::new("弹窗标题", "弹窗正文文案"));
144
145 let json = json!({
146 "tag": "select_person", "type": "text", "required":true, "disabled":false, "placeholder": {
151 "tag": "plain_text",
153 "content": "默认提示文本"
154 },
155 "width": "default", "options": [
157 {
159 "value": "ou_48d0958ee4b2ab3eaf0b5f6c968xxxxx" },
161 {
162 "value": "ou_f9d24af786a14340721288cda6axxxxx" }
164 ],
165 "confirm": {
166 "title": {
168 "tag": "plain_text",
169 "content": "弹窗标题"
170 },
171 "text": {
172 "tag": "plain_text",
173 "content": "弹窗正文文案"
174 }
175 }
176 });
177
178 assert_eq!(serde_json::to_value(&select_person).unwrap(), json);
179 }
180}