event_map.rs 10 KB

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