Skip to content

Commit db58719

Browse files
committed
chore: add collab version to view
1 parent d71bb7c commit db58719

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

collab-folder/src/folder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ mod tests {
909909
let view_2_id = view_2.id;
910910
let space_view = View {
911911
id: Uuid::parse_str("00000000-0000-0000-0000-000000000001").unwrap(),
912+
version: None,
912913
parent_view_id: workspace_id.to_string(),
913914
name: "Space 1".to_string(),
914915
children: RepeatedViewIdentifier::new(vec![
@@ -978,6 +979,7 @@ mod tests {
978979
.collect();
979980
let space_view = View {
980981
id: space_view_id,
982+
version: None,
981983
parent_view_id: "".to_string(),
982984
name: "Space".to_string(),
983985
children: RepeatedViewIdentifier::new(

collab-folder/src/hierarchy_builder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
ViewLayout, timestamp,
66
};
77

8+
use collab::core::collab::CollabVersion;
89
use serde_json::json;
910
use std::fmt::{Display, Formatter};
1011
use std::future::Future;
@@ -109,6 +110,7 @@ impl DerefMut for NestedViews {
109110
pub struct NestedChildViewBuilder {
110111
uid: i64,
111112
parent_view_id: ViewId,
113+
version: Option<CollabVersion>,
112114
view_id: ViewId,
113115
name: String,
114116
desc: String,
@@ -127,6 +129,7 @@ impl NestedChildViewBuilder {
127129
Self {
128130
uid,
129131
parent_view_id,
132+
version: None,
130133
view_id: uuid::Uuid::new_v4(),
131134
name: Default::default(),
132135
desc: Default::default(),
@@ -148,6 +151,11 @@ impl NestedChildViewBuilder {
148151
self
149152
}
150153

154+
pub fn with_collab_version(mut self, version: CollabVersion) -> Self {
155+
self.version = Some(version);
156+
self
157+
}
158+
151159
pub fn with_children(mut self, mut views: Vec<ParentChildViews>) -> Self {
152160
self.children.append(&mut views);
153161
self
@@ -203,6 +211,7 @@ impl NestedChildViewBuilder {
203211
pub fn build(self) -> ParentChildViews {
204212
let view = View {
205213
id: self.view_id,
214+
version: self.version,
206215
parent_view_id: self.parent_view_id.to_string(),
207216
name: self.name,
208217
created_at: timestamp(),

collab-folder/src/view.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::collections::{HashMap, HashSet};
2+
use std::str::FromStr;
23
use std::sync::Arc;
34

5+
use crate::folder_observe::ViewChangeSender;
46
use anyhow::bail;
7+
use collab::core::collab::CollabVersion;
58
use collab::preclude::{
69
Any, Map, MapExt, MapPrelim, MapRef, ReadTxn, Subscription, TransactionMut,
710
};
@@ -12,8 +15,6 @@ use tokio::sync::Mutex;
1215
use tracing::{instrument, trace};
1316
use uuid::Uuid;
1417

15-
use crate::folder_observe::ViewChangeSender;
16-
1718
use crate::revision::RevisionMapping;
1819
use crate::section::{Section, SectionItem, SectionMap};
1920
use crate::space_info::SpaceInfo;
@@ -33,6 +34,7 @@ const VIEW_LAST_EDITED_TIME: &str = "last_edited_time";
3334
const VIEW_LAST_EDITED_BY: &str = "last_edited_by";
3435
const VIEW_IS_LOCKED: &str = "is_locked";
3536
const VIEW_EXTRA: &str = "extra";
37+
const COLLAB_VERSION: &str = "version";
3638
// const VIEW_LAST_VIEWED_TIME: &str = "last_viewed_time";
3739

3840
pub fn timestamp() -> i64 {
@@ -556,8 +558,12 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
556558
let is_locked = map_ref.get_with_txn(txn, VIEW_IS_LOCKED);
557559
let extra = map_ref.get_with_txn(txn, VIEW_EXTRA);
558560

561+
let version: Option<String> = map_ref.get_with_txn(txn, COLLAB_VERSION);
562+
let version = version.and_then(|v| Uuid::from_str(&v).ok());
563+
559564
Some(View {
560565
id,
566+
version,
561567
parent_view_id,
562568
name,
563569
children,
@@ -783,6 +789,8 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
783789
pub struct View {
784790
/// The id of the view
785791
pub id: collab_entity::uuid_validation::ViewId,
792+
/// The version of the view, used when corresponding page has been reverted to past state.
793+
pub version: Option<CollabVersion>,
786794
/// The id for given parent view
787795
pub parent_view_id: String,
788796
/// The name that display on the left sidebar
@@ -822,6 +830,7 @@ impl View {
822830
) -> Self {
823831
Self {
824832
id: view_id,
833+
version: None,
825834
parent_view_id,
826835
name,
827836
children: Default::default(),

collab-folder/src/workspace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl From<Workspace> for View {
4646
fn from(value: Workspace) -> Self {
4747
Self {
4848
id: value.id,
49+
version: None,
4950
parent_view_id: "".to_string(),
5051
name: value.name,
5152
children: value.child_views,

collab-folder/tests/folder_test/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub fn make_test_view(view_id: &str, parent_view_id: &str, belongings: Vec<ViewI
101101
id: collab_entity::uuid_validation::view_id_from_any_string(view_id),
102102
parent_view_id: collab_entity::uuid_validation::view_id_from_any_string(parent_view_id)
103103
.to_string(),
104+
version: None,
104105
name: "".to_string(),
105106
children: RepeatedViewIdentifier::new(belongings),
106107
created_at: 0,

0 commit comments

Comments
 (0)