board_mock_data.rs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. use collab_database::database::{gen_database_id, gen_database_view_id, gen_row_id, DatabaseData};
  2. use collab_database::views::{DatabaseLayout, DatabaseView};
  3. use flowy_database2::services::field_settings::default_field_settings_by_layout;
  4. use strum::IntoEnumIterator;
  5. use flowy_database2::entities::FieldType;
  6. use flowy_database2::services::field::checklist_type_option::ChecklistTypeOption;
  7. use flowy_database2::services::field::{
  8. DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption, SelectOption, SelectOptionColor,
  9. SingleSelectTypeOption, TimeFormat,
  10. };
  11. use crate::database::database_editor::TestRowBuilder;
  12. use crate::database::mock_data::{COMPLETED, FACEBOOK, GOOGLE, PAUSED, PLANNED, TWITTER};
  13. // Kanban board unit test mock data
  14. pub fn make_test_board() -> DatabaseData {
  15. let mut fields = vec![];
  16. let mut rows = vec![];
  17. // Iterate through the FieldType to create the corresponding Field.
  18. let field_settings = default_field_settings_by_layout(DatabaseLayout::Board);
  19. for field_type in FieldType::iter() {
  20. match field_type {
  21. FieldType::RichText => {
  22. let text_field = FieldBuilder::from_field_type(field_type.clone())
  23. .name("Name")
  24. .visibility(true)
  25. .primary(true)
  26. .build();
  27. fields.push(text_field);
  28. },
  29. FieldType::Number => {
  30. // Number
  31. let number_field = FieldBuilder::from_field_type(field_type.clone())
  32. .name("Price")
  33. .visibility(true)
  34. .build();
  35. fields.push(number_field);
  36. },
  37. FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
  38. // Date
  39. let date_type_option = DateTypeOption {
  40. date_format: DateFormat::US,
  41. time_format: TimeFormat::TwentyFourHour,
  42. timezone_id: "Etc/UTC".to_owned(),
  43. field_type: field_type.clone(),
  44. };
  45. let name = match field_type {
  46. FieldType::DateTime => "Time",
  47. FieldType::LastEditedTime => "Updated At",
  48. FieldType::CreatedTime => "Created At",
  49. _ => "",
  50. };
  51. let date_field = FieldBuilder::new(field_type.clone(), date_type_option)
  52. .name(name)
  53. .visibility(true)
  54. .build();
  55. fields.push(date_field);
  56. },
  57. FieldType::SingleSelect => {
  58. // Single Select
  59. let option1 = SelectOption::with_color(COMPLETED, SelectOptionColor::Purple);
  60. let option2 = SelectOption::with_color(PLANNED, SelectOptionColor::Orange);
  61. let option3 = SelectOption::with_color(PAUSED, SelectOptionColor::Yellow);
  62. let mut single_select_type_option = SingleSelectTypeOption::default();
  63. single_select_type_option
  64. .options
  65. .extend(vec![option1, option2, option3]);
  66. let single_select_field = FieldBuilder::new(field_type.clone(), single_select_type_option)
  67. .name("Status")
  68. .visibility(true)
  69. .build();
  70. fields.push(single_select_field);
  71. },
  72. FieldType::MultiSelect => {
  73. // MultiSelect
  74. let option1 = SelectOption::with_color(GOOGLE, SelectOptionColor::Purple);
  75. let option2 = SelectOption::with_color(FACEBOOK, SelectOptionColor::Orange);
  76. let option3 = SelectOption::with_color(TWITTER, SelectOptionColor::Yellow);
  77. let mut type_option = MultiSelectTypeOption::default();
  78. type_option.options.extend(vec![option1, option2, option3]);
  79. let multi_select_field = FieldBuilder::new(field_type.clone(), type_option)
  80. .name("Platform")
  81. .visibility(true)
  82. .build();
  83. fields.push(multi_select_field);
  84. },
  85. FieldType::Checkbox => {
  86. // Checkbox
  87. let checkbox_field = FieldBuilder::from_field_type(field_type.clone())
  88. .name("is urgent")
  89. .visibility(true)
  90. .build();
  91. fields.push(checkbox_field);
  92. },
  93. FieldType::URL => {
  94. // URL
  95. let url = FieldBuilder::from_field_type(field_type.clone())
  96. .name("link")
  97. .visibility(true)
  98. .build();
  99. fields.push(url);
  100. },
  101. FieldType::Checklist => {
  102. // let option1 = SelectOption::with_color(FIRST_THING, SelectOptionColor::Purple);
  103. // let option2 = SelectOption::with_color(SECOND_THING, SelectOptionColor::Orange);
  104. // let option3 = SelectOption::with_color(THIRD_THING, SelectOptionColor::Yellow);
  105. let type_option = ChecklistTypeOption::default();
  106. // type_option.options.extend(vec![option1, option2, option3]);
  107. let checklist_field = FieldBuilder::new(field_type.clone(), type_option)
  108. .name("TODO")
  109. .visibility(true)
  110. .build();
  111. fields.push(checklist_field);
  112. },
  113. }
  114. }
  115. // We have many assumptions base on the number of the rows, so do not change the number of the loop.
  116. for i in 0..5 {
  117. let mut row_builder = TestRowBuilder::new(gen_row_id(), &fields);
  118. match i {
  119. 0 => {
  120. for field_type in FieldType::iter() {
  121. match field_type {
  122. FieldType::RichText => row_builder.insert_text_cell("A"),
  123. FieldType::Number => row_builder.insert_number_cell("1"),
  124. // 1647251762 => Mar 14,2022
  125. FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
  126. row_builder.insert_date_cell("1647251762", None, None, &field_type)
  127. },
  128. FieldType::SingleSelect => {
  129. row_builder.insert_single_select_cell(|mut options| options.remove(0))
  130. },
  131. FieldType::MultiSelect => row_builder
  132. .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
  133. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  134. FieldType::URL => row_builder.insert_url_cell("https://appflowy.io"),
  135. _ => "".to_owned(),
  136. };
  137. }
  138. },
  139. 1 => {
  140. for field_type in FieldType::iter() {
  141. match field_type {
  142. FieldType::RichText => row_builder.insert_text_cell("B"),
  143. FieldType::Number => row_builder.insert_number_cell("2"),
  144. // 1647251762 => Mar 14,2022
  145. FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
  146. row_builder.insert_date_cell("1647251762", None, None, &field_type)
  147. },
  148. FieldType::SingleSelect => {
  149. row_builder.insert_single_select_cell(|mut options| options.remove(0))
  150. },
  151. FieldType::MultiSelect => row_builder
  152. .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
  153. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  154. _ => "".to_owned(),
  155. };
  156. }
  157. },
  158. 2 => {
  159. for field_type in FieldType::iter() {
  160. match field_type {
  161. FieldType::RichText => row_builder.insert_text_cell("C"),
  162. FieldType::Number => row_builder.insert_number_cell("3"),
  163. // 1647251762 => Mar 14,2022
  164. FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
  165. row_builder.insert_date_cell("1647251762", None, None, &field_type)
  166. },
  167. FieldType::SingleSelect => {
  168. row_builder.insert_single_select_cell(|mut options| options.remove(1))
  169. },
  170. FieldType::MultiSelect => {
  171. row_builder.insert_multi_select_cell(|mut options| vec![options.remove(0)])
  172. },
  173. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  174. FieldType::URL => {
  175. row_builder.insert_url_cell("https://github.com/AppFlowy-IO/AppFlowy")
  176. },
  177. _ => "".to_owned(),
  178. };
  179. }
  180. },
  181. 3 => {
  182. for field_type in FieldType::iter() {
  183. match field_type {
  184. FieldType::RichText => row_builder.insert_text_cell("DA"),
  185. FieldType::Number => row_builder.insert_number_cell("4"),
  186. FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
  187. row_builder.insert_date_cell("1668704685", None, None, &field_type)
  188. },
  189. FieldType::SingleSelect => {
  190. row_builder.insert_single_select_cell(|mut options| options.remove(1))
  191. },
  192. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  193. FieldType::URL => row_builder.insert_url_cell("https://appflowy.io"),
  194. _ => "".to_owned(),
  195. };
  196. }
  197. },
  198. 4 => {
  199. for field_type in FieldType::iter() {
  200. match field_type {
  201. FieldType::RichText => row_builder.insert_text_cell("AE"),
  202. FieldType::Number => row_builder.insert_number_cell(""),
  203. FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
  204. row_builder.insert_date_cell("1668359085", None, None, &field_type)
  205. },
  206. FieldType::SingleSelect => {
  207. row_builder.insert_single_select_cell(|mut options| options.remove(2))
  208. },
  209. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  210. _ => "".to_owned(),
  211. };
  212. }
  213. },
  214. _ => {},
  215. }
  216. let row = row_builder.build();
  217. rows.push(row);
  218. }
  219. let view = DatabaseView {
  220. id: gen_database_view_id(),
  221. database_id: gen_database_id(),
  222. name: "".to_string(),
  223. layout: DatabaseLayout::Board,
  224. layout_settings: Default::default(),
  225. filters: vec![],
  226. group_settings: vec![],
  227. sorts: vec![],
  228. row_orders: vec![],
  229. field_orders: vec![],
  230. created_at: 0,
  231. modified_at: 0,
  232. field_settings,
  233. };
  234. DatabaseData { view, fields, rows }
  235. }