board_mock_data.rs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. include_time: false,
  45. };
  46. let date_field = FieldBuilder::new(field_type.clone(), date_type_option)
  47. .name("Time")
  48. .visibility(true)
  49. .build();
  50. fields.push(date_field);
  51. },
  52. FieldType::SingleSelect => {
  53. // Single Select
  54. let option1 = SelectOption::with_color(COMPLETED, SelectOptionColor::Purple);
  55. let option2 = SelectOption::with_color(PLANNED, SelectOptionColor::Orange);
  56. let option3 = SelectOption::with_color(PAUSED, SelectOptionColor::Yellow);
  57. let mut single_select_type_option = SingleSelectTypeOption::default();
  58. single_select_type_option
  59. .options
  60. .extend(vec![option1, option2, option3]);
  61. let single_select_field = FieldBuilder::new(field_type.clone(), single_select_type_option)
  62. .name("Status")
  63. .visibility(true)
  64. .build();
  65. fields.push(single_select_field);
  66. },
  67. FieldType::MultiSelect => {
  68. // MultiSelect
  69. let option1 = SelectOption::with_color(GOOGLE, SelectOptionColor::Purple);
  70. let option2 = SelectOption::with_color(FACEBOOK, SelectOptionColor::Orange);
  71. let option3 = SelectOption::with_color(TWITTER, SelectOptionColor::Yellow);
  72. let mut type_option = MultiSelectTypeOption::default();
  73. type_option.options.extend(vec![option1, option2, option3]);
  74. let multi_select_field = FieldBuilder::new(field_type.clone(), type_option)
  75. .name("Platform")
  76. .visibility(true)
  77. .build();
  78. fields.push(multi_select_field);
  79. },
  80. FieldType::Checkbox => {
  81. // Checkbox
  82. let checkbox_field = FieldBuilder::from_field_type(field_type.clone())
  83. .name("is urgent")
  84. .visibility(true)
  85. .build();
  86. fields.push(checkbox_field);
  87. },
  88. FieldType::URL => {
  89. // URL
  90. let url = FieldBuilder::from_field_type(field_type.clone())
  91. .name("link")
  92. .visibility(true)
  93. .build();
  94. fields.push(url);
  95. },
  96. FieldType::Checklist => {
  97. let option1 = SelectOption::with_color(FIRST_THING, SelectOptionColor::Purple);
  98. let option2 = SelectOption::with_color(SECOND_THING, SelectOptionColor::Orange);
  99. let option3 = SelectOption::with_color(THIRD_THING, SelectOptionColor::Yellow);
  100. let mut type_option = ChecklistTypeOption::default();
  101. type_option.options.extend(vec![option1, option2, option3]);
  102. let checklist_field = FieldBuilder::new(field_type.clone(), type_option)
  103. .name("TODO")
  104. .visibility(true)
  105. .build();
  106. fields.push(checklist_field);
  107. },
  108. }
  109. }
  110. // We have many assumptions base on the number of the rows, so do not change the number of the loop.
  111. for i in 0..5 {
  112. let mut row_builder = TestRowBuilder::new(i.into(), fields.clone());
  113. match i {
  114. 0 => {
  115. for field_type in FieldType::iter() {
  116. match field_type {
  117. FieldType::RichText => row_builder.insert_text_cell("A"),
  118. FieldType::Number => row_builder.insert_number_cell("1"),
  119. // 1647251762 => Mar 14,2022
  120. FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
  121. FieldType::SingleSelect => {
  122. row_builder.insert_single_select_cell(|mut options| options.remove(0))
  123. },
  124. FieldType::MultiSelect => row_builder
  125. .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
  126. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  127. FieldType::URL => row_builder.insert_url_cell("https://appflowy.io"),
  128. _ => "".to_owned(),
  129. };
  130. }
  131. },
  132. 1 => {
  133. for field_type in FieldType::iter() {
  134. match field_type {
  135. FieldType::RichText => row_builder.insert_text_cell("B"),
  136. FieldType::Number => row_builder.insert_number_cell("2"),
  137. // 1647251762 => Mar 14,2022
  138. FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
  139. FieldType::SingleSelect => {
  140. row_builder.insert_single_select_cell(|mut options| options.remove(0))
  141. },
  142. FieldType::MultiSelect => row_builder
  143. .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
  144. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  145. _ => "".to_owned(),
  146. };
  147. }
  148. },
  149. 2 => {
  150. for field_type in FieldType::iter() {
  151. match field_type {
  152. FieldType::RichText => row_builder.insert_text_cell("C"),
  153. FieldType::Number => row_builder.insert_number_cell("3"),
  154. // 1647251762 => Mar 14,2022
  155. FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
  156. FieldType::SingleSelect => {
  157. row_builder.insert_single_select_cell(|mut options| options.remove(1))
  158. },
  159. FieldType::MultiSelect => {
  160. row_builder.insert_multi_select_cell(|mut options| vec![options.remove(0)])
  161. },
  162. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  163. FieldType::URL => {
  164. row_builder.insert_url_cell("https://github.com/AppFlowy-IO/AppFlowy")
  165. },
  166. _ => "".to_owned(),
  167. };
  168. }
  169. },
  170. 3 => {
  171. for field_type in FieldType::iter() {
  172. match field_type {
  173. FieldType::RichText => row_builder.insert_text_cell("DA"),
  174. FieldType::Number => row_builder.insert_number_cell("4"),
  175. FieldType::DateTime => row_builder.insert_date_cell("1668704685"),
  176. FieldType::SingleSelect => {
  177. row_builder.insert_single_select_cell(|mut options| options.remove(1))
  178. },
  179. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  180. FieldType::URL => row_builder.insert_url_cell("https://appflowy.io"),
  181. _ => "".to_owned(),
  182. };
  183. }
  184. },
  185. 4 => {
  186. for field_type in FieldType::iter() {
  187. match field_type {
  188. FieldType::RichText => row_builder.insert_text_cell("AE"),
  189. FieldType::Number => row_builder.insert_number_cell(""),
  190. FieldType::DateTime => row_builder.insert_date_cell("1668359085"),
  191. FieldType::SingleSelect => {
  192. row_builder.insert_single_select_cell(|mut options| options.remove(2))
  193. },
  194. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  195. _ => "".to_owned(),
  196. };
  197. }
  198. },
  199. _ => {},
  200. }
  201. let row = row_builder.build();
  202. rows.push(row);
  203. }
  204. let view = DatabaseView {
  205. id: gen_database_view_id(),
  206. database_id: gen_database_id(),
  207. name: "".to_string(),
  208. layout: DatabaseLayout::Board,
  209. layout_settings: Default::default(),
  210. filters: vec![],
  211. group_settings: vec![],
  212. sorts: vec![],
  213. row_orders: vec![],
  214. field_orders: vec![],
  215. created_at: 0,
  216. modified_at: 0,
  217. };
  218. DatabaseData { view, fields, rows }
  219. }