notification.rs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Trigger when the field setting is changed
  52. DidUpdateFieldSettings = 87,
  53. }
  54. impl std::convert::From<DatabaseNotification> for i32 {
  55. fn from(notification: DatabaseNotification) -> Self {
  56. notification as i32
  57. }
  58. }
  59. impl std::convert::From<i32> for DatabaseNotification {
  60. fn from(notification: i32) -> Self {
  61. match notification {
  62. 19 => DatabaseNotification::DidFetchRow,
  63. 20 => DatabaseNotification::DidUpdateViewRows,
  64. 21 => DatabaseNotification::DidUpdateViewRowsVisibility,
  65. 22 => DatabaseNotification::DidUpdateFields,
  66. 40 => DatabaseNotification::DidUpdateCell,
  67. 50 => DatabaseNotification::DidUpdateField,
  68. 60 => DatabaseNotification::DidUpdateNumOfGroups,
  69. 61 => DatabaseNotification::DidUpdateGroupRow,
  70. 62 => DatabaseNotification::DidGroupByField,
  71. 63 => DatabaseNotification::DidUpdateFilter,
  72. 64 => DatabaseNotification::DidUpdateSort,
  73. 65 => DatabaseNotification::DidReorderRows,
  74. 66 => DatabaseNotification::DidReorderSingleRow,
  75. 67 => DatabaseNotification::DidUpdateRowMeta,
  76. 70 => DatabaseNotification::DidUpdateSettings,
  77. 80 => DatabaseNotification::DidUpdateLayoutSettings,
  78. 81 => DatabaseNotification::DidSetNewLayoutField,
  79. 82 => DatabaseNotification::DidUpdateDatabaseLayout,
  80. 83 => DatabaseNotification::DidDeleteDatabaseView,
  81. 84 => DatabaseNotification::DidMoveDatabaseViewToTrash,
  82. 87 => DatabaseNotification::DidUpdateFieldSettings,
  83. _ => DatabaseNotification::Unknown,
  84. }
  85. }
  86. }
  87. #[tracing::instrument(level = "trace")]
  88. pub fn send_notification(id: &str, ty: DatabaseNotification) -> NotificationBuilder {
  89. NotificationBuilder::new(id, ty, DATABASE_OBSERVABLE_SOURCE)
  90. }