event_map.rs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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::InsertField, insert_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 [GridIdPB] and return errors if failed to modify the grid's settings.
  73. #[event(input = "GridIdPB", input = "GridSettingChangesetPayloadPB")]
  74. UpdateGridSetting = 3,
  75. /// [GetFields] event is used to get the grid's settings.
  76. ///
  77. /// The event handler accepts a [QueryFieldPayloadPB] and returns a [RepeatedFieldPB]
  78. /// if there are no errors.
  79. #[event(input = "QueryFieldPayloadPB", output = "RepeatedFieldPB")]
  80. GetFields = 10,
  81. /// [UpdateField] event is used to update a field's attributes.
  82. ///
  83. /// The event handler accepts a [FieldChangesetPayloadPB] and returns errors if failed to modify the
  84. /// field.
  85. #[event(input = "FieldChangesetPayloadPB")]
  86. UpdateField = 11,
  87. /// [UpdateFieldTypeOption] event is used to update the field's type option data. Certain field
  88. /// types have user-defined options such as color, date format, number format, or a list of values
  89. /// for a multi-select list. These options are defined within a specialization of the
  90. /// FieldTypeOption class.
  91. ///
  92. /// Check out [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid#fieldtype)
  93. /// for more information.
  94. ///
  95. /// The event handler accepts a [UpdateFieldTypeOptionPayloadPB] and returns errors if failed to modify the
  96. /// field.
  97. #[event(input = "UpdateFieldTypeOptionPayloadPB")]
  98. UpdateFieldTypeOption = 12,
  99. /// [InsertField] event is used to insert a new Field. If the Field already exists, the event
  100. /// handler will replace the value with the new Field value.
  101. #[event(input = "InsertFieldPayloadPB")]
  102. InsertField = 13,
  103. /// [DeleteField] event is used to delete a Field. [DeleteFieldPayloadPB] is the context that
  104. /// is used to delete the field from the Grid.
  105. #[event(input = "DeleteFieldPayloadPB")]
  106. DeleteField = 14,
  107. /// [SwitchToField] event is used to update the current Field's type.
  108. /// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
  109. /// reuse the existing FieldTypeOptionData. You could check the [GridRevisionPad] for more details.
  110. #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")]
  111. SwitchToField = 20,
  112. /// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
  113. /// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
  114. /// used to duplicate the field.
  115. ///
  116. /// Return errors if failed to duplicate the field.
  117. ///
  118. #[event(input = "DuplicateFieldPayloadPB")]
  119. DuplicateField = 21,
  120. /// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
  121. /// [MoveItemTypePB].
  122. #[event(input = "MoveFieldPayloadPB")]
  123. MoveField = 22,
  124. /// [FieldTypeOptionIdPB] event is used to get the FieldTypeOption data for a specific field type.
  125. ///
  126. /// Check out the [FieldTypeOptionDataPB] for more details. If the [FieldTypeOptionData] does exist
  127. /// for the target type, the [TypeOptionBuilder] will create the default data for that type.
  128. ///
  129. /// Return the [FieldTypeOptionDataPB] if there are no errors.
  130. #[event(input = "FieldTypeOptionIdPB", output = "FieldTypeOptionDataPB")]
  131. GetFieldTypeOption = 23,
  132. /// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData.
  133. #[event(input = "CreateFieldPayloadPB", output = "FieldTypeOptionDataPB")]
  134. CreateFieldTypeOption = 24,
  135. /// [NewSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
  136. /// there are no errors.
  137. #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
  138. NewSelectOption = 30,
  139. /// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
  140. /// [GridCellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
  141. /// contains the available options and the currently selected options.
  142. #[event(input = "GridCellIdPB", output = "SelectOptionCellDataPB")]
  143. GetSelectOptionCellData = 31,
  144. /// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
  145. /// FieldType::SingleSelect or FieldType::MultiSelect.
  146. ///
  147. /// This event may trigger the GridNotification::DidUpdateCell event.
  148. /// For example, GridNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPayloadPB]
  149. /// carries a change that updates the name of the option.
  150. #[event(input = "SelectOptionChangesetPayloadPB")]
  151. UpdateSelectOption = 32,
  152. #[event(input = "CreateTableRowPayloadPB", output = "RowPB")]
  153. CreateTableRow = 50,
  154. /// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
  155. /// to return a nullable row data.
  156. #[event(input = "RowIdPB", output = "OptionalRowPB")]
  157. GetRow = 51,
  158. #[event(input = "RowIdPB")]
  159. DeleteRow = 52,
  160. #[event(input = "RowIdPB")]
  161. DuplicateRow = 53,
  162. #[event(input = "MoveRowPayloadPB")]
  163. MoveRow = 54,
  164. #[event(input = "GridCellIdPB", output = "GridCellPB")]
  165. GetCell = 70,
  166. /// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
  167. /// carries the changes that will be applied to the cell content by calling `update_cell` function.
  168. ///
  169. /// The 'content' property of the [CellChangesetPB] is a String type. It can be used directly if the
  170. /// cell uses string data. For example, the TextCell or NumberCell.
  171. ///
  172. /// But,it can be treated as a generic type, because we can use [serde] to deserialize the string
  173. /// into a specific data type. For the moment, the 'content' will be deserialized to a concrete type
  174. /// when the FieldType is SingleSelect, DateTime, and MultiSelect. Please see
  175. /// the [UpdateSelectOptionCell] and [UpdateDateCell] events for more details.
  176. #[event(input = "CellChangesetPB")]
  177. UpdateCell = 71,
  178. /// [UpdateSelectOptionCell] event is used to update a select option cell's data. [SelectOptionCellChangesetPayloadPB]
  179. /// contains options that will be deleted or inserted. It can be cast to [CellChangesetPB] that
  180. /// will be used by the `update_cell` function.
  181. #[event(input = "SelectOptionCellChangesetPayloadPB")]
  182. UpdateSelectOptionCell = 72,
  183. /// [UpdateDateCell] event is used to update a date cell's data. [DateChangesetPayloadPB]
  184. /// contains the date and the time string. It can be cast to [CellChangesetPB] that
  185. /// will be used by the `update_cell` function.
  186. #[event(input = "DateChangesetPayloadPB")]
  187. UpdateDateCell = 80,
  188. #[event(input = "GridIdPB", output = "RepeatedGridGroupPB")]
  189. GetGroup = 100,
  190. #[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
  191. CreateBoardCard = 110,
  192. #[event(input = "MoveGroupPayloadPB")]
  193. MoveGroup = 111,
  194. #[event(input = "MoveGroupRowPayloadPB")]
  195. MoveGroupRow = 112,
  196. }