event_map.rs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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::MoveItem, move_item_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::CreateRow, create_row_handler)
  27. .event(GridEvent::GetRow, get_row_handler)
  28. .event(GridEvent::DeleteRow, delete_row_handler)
  29. .event(GridEvent::DuplicateRow, duplicate_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. module
  41. }
  42. /// [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)
  43. /// out, it includes how to use these annotations: input, output, etc.
  44. #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
  45. #[event_err = "FlowyError"]
  46. pub enum GridEvent {
  47. /// [GetGrid] event is used to get the [GridPB]
  48. ///
  49. /// The event handler accepts a [GridIdPB] and returns a [GridPB] if there are no errors.
  50. #[event(input = "GridIdPB", output = "GridPB")]
  51. GetGrid = 0,
  52. /// [GetGridBlocks] event is used to get the grid's block.
  53. ///
  54. /// The event handler accepts a [QueryGridBlocksPayloadPB] and returns a [RepeatedGridBlockPB]
  55. /// if there are no errors.
  56. #[event(input = "QueryGridBlocksPayloadPB", output = "RepeatedGridBlockPB")]
  57. GetGridBlocks = 1,
  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 [GridIdPB] and return errors if failed to modify the grid's settings.
  67. #[event(input = "GridIdPB", input = "GridSettingChangesetPayloadPB")]
  68. UpdateGridSetting = 3,
  69. /// [GetFields] event is used to get the grid's settings.
  70. ///
  71. /// The event handler accepts a [QueryFieldPayloadPB] and returns a [RepeatedGridFieldPB]
  72. /// if there are no errors.
  73. #[event(input = "QueryFieldPayloadPB", output = "RepeatedGridFieldPB")]
  74. GetFields = 10,
  75. /// [UpdateField] event is used to update a field's attributes.
  76. ///
  77. /// The event handler accepts a [FieldChangesetPayloadPB] and returns errors if failed to modify the
  78. /// field.
  79. #[event(input = "FieldChangesetPayloadPB")]
  80. UpdateField = 11,
  81. /// [UpdateFieldTypeOption] event is used to update the field's type option data. Certain field
  82. /// types have user-defined options such as color, date format, number format, or a list of values
  83. /// for a multi-select list. These options are defined within a specialization of the
  84. /// FieldTypeOption class.
  85. ///
  86. /// Check out [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid#fieldtype)
  87. /// for more information.
  88. ///
  89. /// The event handler accepts a [UpdateFieldTypeOptionPayloadPB] and returns errors if failed to modify the
  90. /// field.
  91. #[event(input = "UpdateFieldTypeOptionPayloadPB")]
  92. UpdateFieldTypeOption = 12,
  93. /// [InsertField] event is used to insert a new Field. If the Field already exists, the event
  94. /// handler will replace the value with the new Field value.
  95. #[event(input = "InsertFieldPayloadPB")]
  96. InsertField = 13,
  97. /// [DeleteField] event is used to delete a Field. [DeleteFieldPayloadPB] is the context that
  98. /// is used to delete the field from the Grid.
  99. #[event(input = "DeleteFieldPayloadPB")]
  100. DeleteField = 14,
  101. /// [SwitchToField] event is used to update the current Field's type.
  102. /// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
  103. /// reuse the existing FieldTypeOptionData. You could check the [GridRevisionPad] for more details.
  104. #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")]
  105. SwitchToField = 20,
  106. /// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
  107. /// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
  108. /// used to duplicate the field.
  109. ///
  110. /// Return errors if failed to duplicate the field.
  111. ///
  112. #[event(input = "DuplicateFieldPayloadPB")]
  113. DuplicateField = 21,
  114. /// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
  115. /// [MoveItemTypePB].
  116. #[event(input = "MoveItemPayloadPB")]
  117. MoveItem = 22,
  118. /// [GetFieldTypeOption] event is used to get the FieldTypeOption data for a specific field type.
  119. ///
  120. /// Check out the [FieldTypeOptionDataPB] for more details. If the [FieldTypeOptionData] does exist
  121. /// for the target type, the [TypeOptionBuilder] will create the default data for that type.
  122. ///
  123. /// Return the [FieldTypeOptionDataPB] if there are no errors.
  124. #[event(input = "GridFieldTypeOptionIdPB", output = "FieldTypeOptionDataPB")]
  125. GetFieldTypeOption = 23,
  126. /// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData.
  127. #[event(input = "CreateFieldPayloadPB", output = "FieldTypeOptionDataPB")]
  128. CreateFieldTypeOption = 24,
  129. /// [NewSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
  130. /// there are no errors.
  131. #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
  132. NewSelectOption = 30,
  133. /// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
  134. /// [GridCellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
  135. /// contains the available options and the currently selected options.
  136. #[event(input = "GridCellIdPB", output = "SelectOptionCellDataPB")]
  137. GetSelectOptionCellData = 31,
  138. /// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
  139. /// FieldType::SingleSelect or FieldType::MultiSelect.
  140. ///
  141. /// This event may trigger the GridNotification::DidUpdateCell event.
  142. /// For example, GridNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPayloadPB]
  143. /// carries a change that updates the name of the option.
  144. #[event(input = "SelectOptionChangesetPayloadPB")]
  145. UpdateSelectOption = 32,
  146. #[event(input = "CreateRowPayloadPB", output = "GridRowPB")]
  147. CreateRow = 50,
  148. /// [GetRow] event is used to get the row data,[GridRowPB]. [OptionalRowPB] is a wrapper that enables
  149. /// to return a nullable row data.
  150. #[event(input = "GridRowIdPB", output = "OptionalRowPB")]
  151. GetRow = 51,
  152. #[event(input = "GridRowIdPB")]
  153. DeleteRow = 52,
  154. #[event(input = "GridRowIdPB")]
  155. DuplicateRow = 53,
  156. #[event(input = "GridCellIdPB", output = "GridCellPB")]
  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. [SelectOptionCellChangesetPayloadPB]
  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 = "SelectOptionCellChangesetPayloadPB")]
  174. UpdateSelectOptionCell = 72,
  175. /// [UpdateDateCell] event is used to update a date cell's data. [DateChangesetPayloadPB]
  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 = "DateChangesetPayloadPB")]
  179. UpdateDateCell = 80,
  180. }