event_map.rs 10 KB

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