entities.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use collab_database::rows::{RowDetail, RowId};
  2. use collab_database::views::DatabaseLayout;
  3. #[derive(Debug, Clone)]
  4. pub enum DatabaseRowEvent {
  5. InsertRow(InsertedRow),
  6. UpdateRow(UpdatedRow),
  7. DeleteRow(RowId),
  8. Move {
  9. deleted_row_id: RowId,
  10. inserted_row: InsertedRow,
  11. },
  12. }
  13. #[derive(Debug, Clone)]
  14. pub struct InsertedRow {
  15. pub row_detail: RowDetail,
  16. pub index: Option<i32>,
  17. pub is_new: bool,
  18. }
  19. #[derive(Debug, Clone)]
  20. pub struct UpdatedRow {
  21. pub row_id: String,
  22. pub height: Option<i32>,
  23. /// Indicates which cells were updated.
  24. pub field_ids: Vec<String>,
  25. /// The meta of row was updated if this is Some.
  26. pub row_detail: Option<RowDetail>,
  27. }
  28. impl UpdatedRow {
  29. pub fn new(row_id: &str) -> Self {
  30. Self {
  31. row_id: row_id.to_string(),
  32. height: None,
  33. field_ids: vec![],
  34. row_detail: None,
  35. }
  36. }
  37. pub fn with_field_ids(mut self, field_ids: Vec<String>) -> Self {
  38. self.field_ids = field_ids;
  39. self
  40. }
  41. pub fn with_height(mut self, height: i32) -> Self {
  42. self.height = Some(height);
  43. self
  44. }
  45. pub fn with_row_meta(mut self, row_detail: RowDetail) -> Self {
  46. self.row_detail = Some(row_detail);
  47. self
  48. }
  49. }
  50. #[derive(Debug, Clone)]
  51. pub struct CreateDatabaseViewParams {
  52. pub name: String,
  53. pub view_id: String,
  54. pub layout_type: DatabaseLayout,
  55. }