event_map.rs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. use crate::event_handler::*;
  2. use crate::manager::GridManager;
  3. use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
  4. use lib_dispatch::prelude::*;
  5. use std::sync::Arc;
  6. use strum_macros::Display;
  7. pub fn create(grid_manager: Arc<GridManager>) -> Module {
  8. let mut module = Module::new().name(env!("CARGO_PKG_NAME")).data(grid_manager);
  9. module = module
  10. .event(GridEvent::GetGrid, get_grid_handler)
  11. .event(GridEvent::GetGridBlocks, get_grid_blocks_handler)
  12. .event(GridEvent::GetGridSetting, get_grid_setting_handler)
  13. .event(GridEvent::UpdateGridSetting, update_grid_setting_handler)
  14. .event(GridEvent::GetAllFilters, get_all_filters_handler)
  15. // Field
  16. .event(GridEvent::GetFields, get_fields_handler)
  17. .event(GridEvent::UpdateField, update_field_handler)
  18. .event(GridEvent::UpdateFieldTypeOption, update_field_type_option_handler)
  19. .event(GridEvent::DeleteField, delete_field_handler)
  20. .event(GridEvent::SwitchToField, switch_to_field_handler)
  21. .event(GridEvent::DuplicateField, duplicate_field_handler)
  22. .event(GridEvent::MoveField, move_field_handler)
  23. .event(GridEvent::GetFieldTypeOption, get_field_type_option_data_handler)
  24. .event(GridEvent::CreateFieldTypeOption, create_field_type_option_data_handler)
  25. // Row
  26. .event(GridEvent::CreateTableRow, create_table_row_handler)
  27. .event(GridEvent::GetRow, get_row_handler)
  28. .event(GridEvent::DeleteRow, delete_row_handler)
  29. .event(GridEvent::DuplicateRow, duplicate_row_handler)
  30. .event(GridEvent::MoveRow, move_row_handler)
  31. // Cell
  32. .event(GridEvent::GetCell, get_cell_handler)
  33. .event(GridEvent::UpdateCell, update_cell_handler)
  34. // SelectOption
  35. .event(GridEvent::NewSelectOption, new_select_option_handler)
  36. .event(GridEvent::UpdateSelectOption, update_select_option_handler)
  37. .event(GridEvent::GetSelectOptionCellData, get_select_option_handler)
  38. .event(GridEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
  39. // Date
  40. .event(GridEvent::UpdateDateCell, update_date_cell_handler)
  41. // Group
  42. .event(GridEvent::CreateBoardCard, create_board_card_handler)
  43. .event(GridEvent::MoveGroup, move_group_handler)
  44. .event(GridEvent::MoveGroupRow, move_group_row_handler)
  45. .event(GridEvent::GetGroup, get_groups_handler);
  46. module
  47. }
  48. /// [GridEvent] defines events that are used to interact with the Grid. You could check [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/backend/protobuf)
  49. /// out, it includes how to use these annotations: input, output, etc.
  50. #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
  51. #[event_err = "FlowyError"]
  52. pub enum GridEvent {
  53. /// [GetGrid] event is used to get the [GridPB]
  54. ///
  55. /// The event handler accepts a [GridIdPB] and returns a [GridPB] if there are no errors.
  56. #[event(input = "GridIdPB", output = "GridPB")]
  57. GetGrid = 0,
  58. /// [GetGridBlocks] event is used to get the grid's block.
  59. ///
  60. /// The event handler accepts a [QueryBlocksPayloadPB] and returns a [RepeatedBlockPB]
  61. /// if there are no errors.
  62. #[event(input = "QueryBlocksPayloadPB", output = "RepeatedBlockPB")]
  63. GetGridBlocks = 1,
  64. /// [GetGridSetting] event is used to get the grid's settings.
  65. ///
  66. /// The event handler accepts [GridIdPB] and return [GridSettingPB]
  67. /// if there is no errors.
  68. #[event(input = "GridIdPB", output = "GridSettingPB")]
  69. GetGridSetting = 2,
  70. /// [UpdateGridSetting] event is used to update the grid's settings.
  71. ///
  72. /// The event handler accepts [GridSettingChangesetPB] and return errors if failed to modify the grid's settings.
  73. #[event(input = "GridSettingChangesetPB")]
  74. UpdateGridSetting = 3,
  75. #[event(input = "GridIdPB", output = "RepeatedFilterPB")]
  76. GetAllFilters = 4,
  77. /// [GetFields] event is used to get the grid's settings.
  78. ///
  79. /// The event handler accepts a [GetFieldPayloadPB] and returns a [RepeatedFieldPB]
  80. /// if there are no errors.
  81. #[event(input = "GetFieldPayloadPB", output = "RepeatedFieldPB")]
  82. GetFields = 10,
  83. /// [UpdateField] event is used to update a field's attributes.
  84. ///
  85. /// The event handler accepts a [FieldChangesetPB] and returns errors if failed to modify the
  86. /// field.
  87. #[event(input = "FieldChangesetPB")]
  88. UpdateField = 11,
  89. /// [UpdateFieldTypeOption] event is used to update the field's type-option data. Certain field
  90. /// types have user-defined options such as color, date format, number format, or a list of values
  91. /// for a multi-select list. These options are defined within a specialization of the
  92. /// FieldTypeOption class.
  93. ///
  94. /// Check out [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid#fieldtype)
  95. /// for more information.
  96. ///
  97. /// The event handler accepts a [TypeOptionChangesetPB] and returns errors if failed to modify the
  98. /// field.
  99. #[event(input = "TypeOptionChangesetPB")]
  100. UpdateFieldTypeOption = 12,
  101. /// [DeleteField] event is used to delete a Field. [DeleteFieldPayloadPB] is the context that
  102. /// is used to delete the field from the Grid.
  103. #[event(input = "DeleteFieldPayloadPB")]
  104. DeleteField = 14,
  105. /// [SwitchToField] event is used to update the current Field's type.
  106. /// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
  107. /// reuse the existing FieldTypeOptionData. You could check the [GridRevisionPad] for more details.
  108. #[event(input = "EditFieldChangesetPB")]
  109. SwitchToField = 20,
  110. /// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
  111. /// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
  112. /// used to duplicate the field.
  113. ///
  114. /// Return errors if failed to duplicate the field.
  115. ///
  116. #[event(input = "DuplicateFieldPayloadPB")]
  117. DuplicateField = 21,
  118. /// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
  119. /// [MoveItemTypePB].
  120. #[event(input = "MoveFieldPayloadPB")]
  121. MoveField = 22,
  122. /// [TypeOptionPathPB] event is used to get the FieldTypeOption data for a specific field type.
  123. ///
  124. /// Check out the [TypeOptionPB] for more details. If the [FieldTypeOptionData] does exist
  125. /// for the target type, the [TypeOptionBuilder] will create the default data for that type.
  126. ///
  127. /// Return the [TypeOptionPB] if there are no errors.
  128. #[event(input = "TypeOptionPathPB", output = "TypeOptionPB")]
  129. GetFieldTypeOption = 23,
  130. /// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData.
  131. #[event(input = "CreateFieldPayloadPB", output = "TypeOptionPB")]
  132. CreateFieldTypeOption = 24,
  133. /// [NewSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
  134. /// there are no errors.
  135. #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
  136. NewSelectOption = 30,
  137. /// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
  138. /// [CellPathPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
  139. /// contains the available options and the currently selected options.
  140. #[event(input = "CellPathPB", output = "SelectOptionCellDataPB")]
  141. GetSelectOptionCellData = 31,
  142. /// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
  143. /// FieldType::SingleSelect or FieldType::MultiSelect.
  144. ///
  145. /// This event may trigger the GridNotification::DidUpdateCell event.
  146. /// For example, GridNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPB]
  147. /// carries a change that updates the name of the option.
  148. #[event(input = "SelectOptionChangesetPB")]
  149. UpdateSelectOption = 32,
  150. #[event(input = "CreateTableRowPayloadPB", output = "RowPB")]
  151. CreateTableRow = 50,
  152. /// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
  153. /// to return a nullable row data.
  154. #[event(input = "RowIdPB", output = "OptionalRowPB")]
  155. GetRow = 51,
  156. #[event(input = "RowIdPB")]
  157. DeleteRow = 52,
  158. #[event(input = "RowIdPB")]
  159. DuplicateRow = 53,
  160. #[event(input = "MoveRowPayloadPB")]
  161. MoveRow = 54,
  162. #[event(input = "CellPathPB", output = "CellPB")]
  163. GetCell = 70,
  164. /// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
  165. /// carries the changes that will be applied to the cell content by calling `update_cell` function.
  166. ///
  167. /// The 'content' property of the [CellChangesetPB] is a String type. It can be used directly if the
  168. /// cell uses string data. For example, the TextCell or NumberCell.
  169. ///
  170. /// But,it can be treated as a generic type, because we can use [serde] to deserialize the string
  171. /// into a specific data type. For the moment, the 'content' will be deserialized to a concrete type
  172. /// when the FieldType is SingleSelect, DateTime, and MultiSelect. Please see
  173. /// the [UpdateSelectOptionCell] and [UpdateDateCell] events for more details.
  174. #[event(input = "CellChangesetPB")]
  175. UpdateCell = 71,
  176. /// [UpdateSelectOptionCell] event is used to update a select option cell's data. [SelectOptionCellChangesetPB]
  177. /// contains options that will be deleted or inserted. It can be cast to [CellChangesetPB] that
  178. /// will be used by the `update_cell` function.
  179. #[event(input = "SelectOptionCellChangesetPB")]
  180. UpdateSelectOptionCell = 72,
  181. /// [UpdateDateCell] event is used to update a date cell's data. [DateChangesetPB]
  182. /// contains the date and the time string. It can be cast to [CellChangesetPB] that
  183. /// will be used by the `update_cell` function.
  184. #[event(input = "DateChangesetPB")]
  185. UpdateDateCell = 80,
  186. #[event(input = "GridIdPB", output = "RepeatedGridGroupPB")]
  187. GetGroup = 100,
  188. #[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
  189. CreateBoardCard = 110,
  190. #[event(input = "MoveGroupPayloadPB")]
  191. MoveGroup = 111,
  192. #[event(input = "MoveGroupRowPayloadPB")]
  193. MoveGroupRow = 112,
  194. #[event(input = "MoveGroupRowPayloadPB")]
  195. GroupByField = 113,
  196. }