board_mock_data.rs 8.6 KB

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