notification.rs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. use flowy_derive::ProtoBuf_Enum;
  2. use flowy_notification::NotificationBuilder;
  3. const DATABASE_OBSERVABLE_SOURCE: &str = "Database";
  4. #[derive(ProtoBuf_Enum, Debug, Default)]
  5. pub enum DatabaseNotification {
  6. #[default]
  7. Unknown = 0,
  8. /// Fetch row data from the remote server. It will be triggered if the backend support remote
  9. /// storage.
  10. DidFetchRow = 19,
  11. /// Trigger after inserting/deleting/updating a row
  12. DidUpdateViewRows = 20,
  13. /// Trigger when the visibility of the row was changed. For example, updating the filter will trigger the notification
  14. DidUpdateViewRowsVisibility = 21,
  15. /// Trigger after inserting/deleting/updating a field
  16. DidUpdateFields = 22,
  17. /// Trigger after editing a cell
  18. DidUpdateCell = 40,
  19. /// Trigger after editing a field properties including rename,update type option, etc
  20. DidUpdateField = 50,
  21. /// Trigger after the number of groups is changed
  22. DidUpdateNumOfGroups = 60,
  23. /// Trigger after inserting/deleting/updating/moving a row
  24. DidUpdateGroupRow = 61,
  25. /// Trigger when setting a new grouping field
  26. DidGroupByField = 62,
  27. /// Trigger after inserting/deleting/updating a filter
  28. DidUpdateFilter = 63,
  29. /// Trigger after inserting/deleting/updating a sort
  30. DidUpdateSort = 64,
  31. /// Trigger after the sort configurations are changed
  32. DidReorderRows = 65,
  33. /// Trigger after editing the row that hit the sort rule
  34. DidReorderSingleRow = 66,
  35. /// Trigger after updating the row meta
  36. DidUpdateRowMeta = 67,
  37. /// Trigger when the settings of the database are changed
  38. DidUpdateSettings = 70,
  39. // Trigger when the layout setting of the database is updated
  40. DidUpdateLayoutSettings = 80,
  41. // Trigger when the layout field of the database is changed
  42. DidSetNewLayoutField = 81,
  43. // Trigger when the layout of the database is changed
  44. DidUpdateDatabaseLayout = 82,
  45. // Trigger when the database view is deleted
  46. DidDeleteDatabaseView = 83,
  47. // Trigger when the database view is moved to trash
  48. DidMoveDatabaseViewToTrash = 84,
  49. DidUpdateDatabaseSyncUpdate = 85,
  50. DidUpdateDatabaseSnapshotState = 86,
  51. }
  52. impl std::convert::From<DatabaseNotification> for i32 {
  53. fn from(notification: DatabaseNotification) -> Self {
  54. notification as i32
  55. }
  56. }
  57. impl std::convert::From<i32> for DatabaseNotification {
  58. fn from(notification: i32) -> Self {
  59. match notification {
  60. 19 => DatabaseNotification::DidFetchRow,
  61. 20 => DatabaseNotification::DidUpdateViewRows,
  62. 21 => DatabaseNotification::DidUpdateViewRowsVisibility,
  63. 22 => DatabaseNotification::DidUpdateFields,
  64. 40 => DatabaseNotification::DidUpdateCell,
  65. 50 => DatabaseNotification::DidUpdateField,
  66. 60 => DatabaseNotification::DidUpdateNumOfGroups,
  67. 61 => DatabaseNotification::DidUpdateGroupRow,
  68. 62 => DatabaseNotification::DidGroupByField,
  69. 63 => DatabaseNotification::DidUpdateFilter,
  70. 64 => DatabaseNotification::DidUpdateSort,
  71. 65 => DatabaseNotification::DidReorderRows,
  72. 66 => DatabaseNotification::DidReorderSingleRow,
  73. 67 => DatabaseNotification::DidUpdateRowMeta,
  74. 70 => DatabaseNotification::DidUpdateSettings,
  75. 80 => DatabaseNotification::DidUpdateLayoutSettings,
  76. 81 => DatabaseNotification::DidSetNewLayoutField,
  77. 82 => DatabaseNotification::DidUpdateDatabaseLayout,
  78. 83 => DatabaseNotification::DidDeleteDatabaseView,
  79. 84 => DatabaseNotification::DidMoveDatabaseViewToTrash,
  80. _ => DatabaseNotification::Unknown,
  81. }
  82. }
  83. }
  84. #[tracing::instrument(level = "trace")]
  85. pub fn send_notification(id: &str, ty: DatabaseNotification) -> NotificationBuilder {
  86. NotificationBuilder::new(id, ty, DATABASE_OBSERVABLE_SOURCE)
  87. }