grid_mock_data.rs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. use crate::database::mock_data::{COMPLETED, FACEBOOK, GOOGLE, PAUSED, PLANNED, TWITTER};
  2. use collab_database::database::{gen_database_id, gen_database_view_id, DatabaseData};
  3. use collab_database::views::{DatabaseLayout, DatabaseView};
  4. use crate::database::database_editor::TestRowBuilder;
  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, NumberFormat, NumberTypeOption,
  9. SelectOption, SelectOptionColor, SingleSelectTypeOption, TimeFormat,
  10. };
  11. use strum::IntoEnumIterator;
  12. pub fn make_test_grid() -> DatabaseData {
  13. let mut fields = vec![];
  14. let mut rows = vec![];
  15. // Iterate through the FieldType to create the corresponding Field.
  16. for field_type in FieldType::iter() {
  17. match field_type {
  18. FieldType::RichText => {
  19. let text_field = FieldBuilder::from_field_type(field_type.clone())
  20. .name("Name")
  21. .visibility(true)
  22. .primary(true)
  23. .build();
  24. fields.push(text_field);
  25. },
  26. FieldType::Number => {
  27. // Number
  28. let mut type_option = NumberTypeOption::default();
  29. type_option.set_format(NumberFormat::USD);
  30. let number_field = FieldBuilder::new(field_type.clone(), type_option)
  31. .name("Price")
  32. .visibility(true)
  33. .build();
  34. fields.push(number_field);
  35. },
  36. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => {
  37. // Date
  38. let date_type_option = DateTypeOption {
  39. date_format: DateFormat::US,
  40. time_format: TimeFormat::TwentyFourHour,
  41. field_type: field_type.clone(),
  42. };
  43. let name = match field_type {
  44. FieldType::DateTime => "Time",
  45. FieldType::UpdatedAt => "Updated At",
  46. FieldType::CreatedAt => "Created At",
  47. _ => "",
  48. };
  49. let date_field = FieldBuilder::new(field_type.clone(), date_type_option)
  50. .name(name)
  51. .visibility(true)
  52. .build();
  53. fields.push(date_field);
  54. },
  55. FieldType::SingleSelect => {
  56. // Single Select
  57. let option1 = SelectOption::with_color(COMPLETED, SelectOptionColor::Purple);
  58. let option2 = SelectOption::with_color(PLANNED, SelectOptionColor::Orange);
  59. let option3 = SelectOption::with_color(PAUSED, SelectOptionColor::Yellow);
  60. let mut single_select_type_option = SingleSelectTypeOption::default();
  61. single_select_type_option
  62. .options
  63. .extend(vec![option1, option2, option3]);
  64. let single_select_field = FieldBuilder::new(field_type.clone(), single_select_type_option)
  65. .name("Status")
  66. .visibility(true)
  67. .build();
  68. fields.push(single_select_field);
  69. },
  70. FieldType::MultiSelect => {
  71. // MultiSelect
  72. let option1 = SelectOption::with_color(GOOGLE, SelectOptionColor::Purple);
  73. let option2 = SelectOption::with_color(FACEBOOK, SelectOptionColor::Orange);
  74. let option3 = SelectOption::with_color(TWITTER, SelectOptionColor::Yellow);
  75. let mut type_option = MultiSelectTypeOption::default();
  76. type_option.options.extend(vec![option1, option2, option3]);
  77. let multi_select_field = FieldBuilder::new(field_type.clone(), type_option)
  78. .name("Platform")
  79. .visibility(true)
  80. .build();
  81. fields.push(multi_select_field);
  82. },
  83. FieldType::Checkbox => {
  84. // Checkbox
  85. let checkbox_field = FieldBuilder::from_field_type(field_type.clone())
  86. .name("is urgent")
  87. .visibility(true)
  88. .build();
  89. fields.push(checkbox_field);
  90. },
  91. FieldType::URL => {
  92. // URL
  93. let url = FieldBuilder::from_field_type(field_type.clone())
  94. .name("link")
  95. .visibility(true)
  96. .build();
  97. fields.push(url);
  98. },
  99. FieldType::Checklist => {
  100. // let option1 = SelectOption::with_color(FIRST_THING, SelectOptionColor::Purple);
  101. // let option2 = SelectOption::with_color(SECOND_THING, SelectOptionColor::Orange);
  102. // let option3 = SelectOption::with_color(THIRD_THING, SelectOptionColor::Yellow);
  103. let type_option = ChecklistTypeOption::default();
  104. // type_option.options.extend(vec![option1, option2, option3]);
  105. let checklist_field = FieldBuilder::new(field_type.clone(), type_option)
  106. .name("TODO")
  107. .visibility(true)
  108. .build();
  109. fields.push(checklist_field);
  110. },
  111. }
  112. }
  113. for i in 0..6 {
  114. let mut row_builder = TestRowBuilder::new(i.into(), &fields);
  115. match i {
  116. 0 => {
  117. for field_type in FieldType::iter() {
  118. match field_type {
  119. FieldType::RichText => row_builder.insert_text_cell("A"),
  120. FieldType::Number => row_builder.insert_number_cell("1"),
  121. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => row_builder
  122. .insert_date_cell(
  123. "1647251762",
  124. None,
  125. None,
  126. Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
  127. &field_type,
  128. ),
  129. FieldType::MultiSelect => row_builder
  130. .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
  131. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  132. FieldType::URL => {
  133. row_builder.insert_url_cell("AppFlowy website - https://www.appflowy.io")
  134. },
  135. FieldType::Checklist => {
  136. row_builder.insert_checklist_cell(vec!["First thing".to_string()])
  137. },
  138. _ => "".to_owned(),
  139. };
  140. }
  141. },
  142. 1 => {
  143. for field_type in FieldType::iter() {
  144. match field_type {
  145. FieldType::RichText => row_builder.insert_text_cell(""),
  146. FieldType::Number => row_builder.insert_number_cell("2"),
  147. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => row_builder
  148. .insert_date_cell(
  149. "1647251762",
  150. None,
  151. None,
  152. Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
  153. &field_type,
  154. ),
  155. FieldType::MultiSelect => row_builder
  156. .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(1)]),
  157. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  158. _ => "".to_owned(),
  159. };
  160. }
  161. },
  162. 2 => {
  163. for field_type in FieldType::iter() {
  164. match field_type {
  165. FieldType::RichText => row_builder.insert_text_cell("C"),
  166. FieldType::Number => row_builder.insert_number_cell("3"),
  167. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => row_builder
  168. .insert_date_cell(
  169. "1647251762",
  170. None,
  171. None,
  172. Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
  173. &field_type,
  174. ),
  175. FieldType::SingleSelect => {
  176. row_builder.insert_single_select_cell(|mut options| options.remove(0))
  177. },
  178. FieldType::MultiSelect => {
  179. row_builder.insert_multi_select_cell(|mut options| vec![options.remove(1)])
  180. },
  181. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  182. _ => "".to_owned(),
  183. };
  184. }
  185. },
  186. 3 => {
  187. for field_type in FieldType::iter() {
  188. match field_type {
  189. FieldType::RichText => row_builder.insert_text_cell("DA"),
  190. FieldType::Number => row_builder.insert_number_cell("14"),
  191. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => row_builder
  192. .insert_date_cell(
  193. "1668704685",
  194. None,
  195. None,
  196. Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
  197. &field_type,
  198. ),
  199. FieldType::SingleSelect => {
  200. row_builder.insert_single_select_cell(|mut options| options.remove(0))
  201. },
  202. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  203. _ => "".to_owned(),
  204. };
  205. }
  206. },
  207. 4 => {
  208. for field_type in FieldType::iter() {
  209. match field_type {
  210. FieldType::RichText => row_builder.insert_text_cell("AE"),
  211. FieldType::Number => row_builder.insert_number_cell(""),
  212. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => row_builder
  213. .insert_date_cell(
  214. "1668359085",
  215. None,
  216. None,
  217. Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
  218. &field_type,
  219. ),
  220. FieldType::SingleSelect => {
  221. row_builder.insert_single_select_cell(|mut options| options.remove(1))
  222. },
  223. FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
  224. _ => "".to_owned(),
  225. };
  226. }
  227. },
  228. 5 => {
  229. for field_type in FieldType::iter() {
  230. match field_type {
  231. FieldType::RichText => row_builder.insert_text_cell("AE"),
  232. FieldType::Number => row_builder.insert_number_cell("5"),
  233. FieldType::DateTime | FieldType::UpdatedAt | FieldType::CreatedAt => row_builder
  234. .insert_date_cell(
  235. "1671938394",
  236. None,
  237. None,
  238. Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
  239. &field_type,
  240. ),
  241. FieldType::SingleSelect => {
  242. row_builder.insert_single_select_cell(|mut options| options.remove(1))
  243. },
  244. FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
  245. _ => "".to_owned(),
  246. };
  247. }
  248. },
  249. _ => {},
  250. }
  251. let row = row_builder.build();
  252. rows.push(row);
  253. }
  254. let view = DatabaseView {
  255. id: gen_database_view_id(),
  256. database_id: gen_database_id(),
  257. name: "".to_string(),
  258. layout: DatabaseLayout::Grid,
  259. ..Default::default()
  260. };
  261. DatabaseData { view, fields, rows }
  262. }