Skip to content

Commit 9307897

Browse files
committed
chore: uuid importer
1 parent a4d488e commit 9307897

File tree

6 files changed

+30
-49
lines changed

6 files changed

+30
-49
lines changed

collab-folder/src/folder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl FolderBody {
723723
let view = self.views.get_view_with_txn(txn, view_id, uid)?;
724724
self
725725
.views
726-
.move_child(txn, &view.parent_view_id.to_string(), from, to);
726+
.move_child(txn, &view.parent_view_id, from, to);
727727
Some(view)
728728
}
729729

collab-folder/src/view.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,18 @@ impl ViewsMap {
8989
*self.subscription.lock().await = subscription;
9090
}
9191

92-
pub fn move_child(&self, txn: &mut TransactionMut, parent_id: &str, from: u32, to: u32) {
93-
if let Ok(parent_uuid) = uuid::Uuid::parse_str(parent_id) {
94-
self
95-
.parent_children_relation
96-
.move_child_with_txn(txn, &parent_uuid, from, to);
97-
}
92+
pub fn move_child(&self, txn: &mut TransactionMut, parent_id: &Uuid, from: u32, to: u32) {
93+
self
94+
.parent_children_relation
95+
.move_child_with_txn(txn, parent_id, from, to);
9896
}
9997

10098
/// Dissociate the relationship between parent_id and view_id.
10199
/// Why don't we use the move method to replace dissociate_parent_child and associate_parent_child?
102100
/// Because the views and workspaces are stored in two separate maps, we can't directly move a view from one map to another.
103101
/// So, we have to dissociate the relationship between parent_id and view_id, and then associate the relationship between parent_id and view_id.
104-
pub fn dissociate_parent_child(&self, txn: &mut TransactionMut, parent_id: &str, view_id: &str) {
105-
if let (Ok(parent_uuid), Ok(view_uuid)) = (
106-
uuid::Uuid::parse_str(parent_id),
107-
uuid::Uuid::parse_str(view_id),
108-
) {
109-
self.dissociate_parent_child_with_txn(txn, &parent_uuid.to_string(), &view_uuid.to_string());
110-
}
102+
pub fn dissociate_parent_child(&self, txn: &mut TransactionMut, parent_id: &Uuid, view_id: &Uuid) {
103+
self.dissociate_parent_child_with_txn(txn, &parent_id.to_string(), &view_id.to_string());
111104
}
112105

113106
/// Establish a relationship between the parent_id and view_id, and insert the view below the prev_id.
@@ -117,11 +110,11 @@ impl ViewsMap {
117110
pub fn associate_parent_child(
118111
&self,
119112
txn: &mut TransactionMut,
120-
parent_id: &str,
121-
view_id: &str,
113+
parent_id: &Uuid,
114+
view_id: &Uuid,
122115
prev_id: Option<ViewId>,
123116
) {
124-
self.associate_parent_child_with_txn(txn, parent_id, view_id, prev_id);
117+
self.associate_parent_child_with_txn(txn, &parent_id.to_string(), &view_id.to_string(), prev_id);
125118
}
126119

127120
pub fn dissociate_parent_child_with_txn(
@@ -157,15 +150,13 @@ impl ViewsMap {
157150
}
158151
}
159152

160-
pub fn remove_child(&self, txn: &mut TransactionMut, parent_id: &str, child_index: u32) {
161-
if let Ok(parent_uuid) = uuid::Uuid::parse_str(parent_id) {
162-
if let Some(parent) = self
163-
.parent_children_relation
164-
.get_children_with_txn(txn, &parent_uuid)
165-
{
166-
if let Some(identifier) = parent.remove_child_with_txn(txn, child_index) {
167-
self.delete_views(txn, vec![identifier.id]);
168-
}
153+
pub fn remove_child(&self, txn: &mut TransactionMut, parent_id: &Uuid, child_index: u32) {
154+
if let Some(parent) = self
155+
.parent_children_relation
156+
.get_children_with_txn(txn, parent_id)
157+
{
158+
if let Some(identifier) = parent.remove_child_with_txn(txn, child_index) {
159+
self.delete_views(txn, vec![identifier.id]);
169160
}
170161
}
171162
}

collab-folder/tests/folder_test/child_views_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ fn move_child_views_test() {
233233
folder
234234
.body
235235
.views
236-
.move_child(&mut txn, &v_1.id.to_string(), 2, 0);
236+
.move_child(&mut txn, &v_1.id, 2, 0);
237237
folder
238238
.body
239239
.views
240-
.move_child(&mut txn, &v_1.id.to_string(), 0, 1);
240+
.move_child(&mut txn, &v_1.id, 0, 1);
241241

242242
let v_1_child_views = folder
243243
.body

collab-importer/src/workspace/space_view_edge_case_handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl SpaceViewEdgeCaseHandler {
3939
id_mapper
4040
.id_map
4141
.insert(space_view_uuid, space_view_uuid);
42-
self.reparent_workspace_views(relation_map, &space_view_uuid.to_string())?;
43-
self.generate_space_document(&space_view_uuid.to_string(), export_path)?;
42+
self.reparent_workspace_views(relation_map, &space_view_uuid)?;
43+
self.generate_space_document(&space_view_uuid, export_path)?;
4444

4545
Ok(Some(space_view_uuid.to_string()))
4646
}
@@ -90,11 +90,11 @@ impl SpaceViewEdgeCaseHandler {
9090
fn reparent_workspace_views(
9191
&self,
9292
relation_map: &mut WorkspaceRelationMap,
93-
space_view_id: &str,
93+
space_view_id: &Uuid,
9494
) -> Result<()> {
9595
let mut workspace_children = Vec::new();
9696

97-
let space_view_uuid = Uuid::parse_str(space_view_id)?;
97+
let space_view_uuid = *space_view_id;
9898
let original_workspace_uuid = self.original_workspace_id;
9999

100100
for (view_id, view_metadata) in relation_map.views.iter_mut() {
@@ -114,15 +114,15 @@ impl SpaceViewEdgeCaseHandler {
114114
Ok(())
115115
}
116116

117-
fn generate_space_document(&self, space_view_id: &str, export_path: &Path) -> Result<()> {
117+
fn generate_space_document(&self, space_view_id: &Uuid, export_path: &Path) -> Result<()> {
118118
let documents_dir = export_path.join("collab_jsons").join("documents");
119119
fs::create_dir_all(&documents_dir)?;
120120

121121
let document_path = documents_dir.join(format!("{}.json", space_view_id));
122122

123123
let document_content = serde_json::json!({
124124
"document": {
125-
"page_id": space_view_id,
125+
"page_id": space_view_id.to_string(),
126126
"blocks": {},
127127
"meta": {
128128
"children_map": {},

collab-importer/tests/notion_test/import_test.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ use collab_document::blocks::{
1515
use collab_document::importer::define::URL_FIELD;
1616
use collab_entity::CollabType;
1717
use collab_folder::hierarchy_builder::ParentChildViews;
18-
use collab_folder::{Folder, View, ViewId, default_folder_data};
18+
use collab_folder::{Folder, View, default_folder_data};
1919
use collab_importer::error::ImporterError;
2020
use collab_importer::imported_collab::{ImportType, ImportedCollabInfo, import_notion_zip_file};
2121
use collab_importer::notion::page::NotionPage;
2222
use collab_importer::notion::{CSVContentCache, NotionImporter, is_csv_contained_cached};
2323
use collab_importer::util::{CSVRow, parse_csv};
24-
use uuid::Uuid;
2524

2625
use collab::core::collab::default_client_id;
2726
use collab_document::document::Document;
@@ -55,10 +54,6 @@ use std::sync::Arc;
5554
// println!("{}", nested_view);
5655
// }
5756

58-
/// Helper function to parse string to ViewId for tests
59-
fn parse_view_id(s: &str) -> ViewId {
60-
Uuid::parse_str(s).expect(&format!("Invalid UUID format: {}", s))
61-
}
6257

6358
#[tokio::test]
6459
async fn import_zip_file_contains_zip_as_attachments() {
@@ -761,7 +756,7 @@ async fn import_level_test() {
761756
assert_eq!(view_hierarchy.flatten_views().len(), 14);
762757
folder.insert_nested_views(view_hierarchy.into_inner(), uid);
763758

764-
let first_level_views = folder.get_views_belong_to(&parse_view_id(&info.workspace_id.to_string()), uid);
759+
let first_level_views = folder.get_views_belong_to(&info.workspace_id, uid);
765760
assert_eq!(first_level_views.len(), 1);
766761
assert_eq!(first_level_views[0].children.len(), 3);
767762
println!("first_level_views: {:?}", first_level_views);

collab-importer/tests/workspace/folder_collab_remapper.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
use crate::util::sync_unzip_asset;
2-
use collab_folder::{Folder, ViewId, ViewLayout};
2+
use collab_folder::{Folder, ViewLayout};
33
use collab_importer::workspace::folder_collab_remapper::FolderCollabRemapper;
44
use collab_importer::workspace::id_mapper::IdMapper;
55
use collab_importer::workspace::relation_map_parser::RelationMapParser;
6-
use uuid::Uuid;
76

8-
/// Helper function to parse string to ViewId for tests
9-
fn parse_view_id(s: &str) -> ViewId {
10-
Uuid::parse_str(s).expect(&format!("Invalid UUID format: {}", s))
11-
}
127

138
#[allow(clippy::too_many_arguments)]
149
fn verify_view(
@@ -22,7 +17,7 @@ fn verify_view(
2217
uid: i64,
2318
) {
2419
let new_id = id_mapper.get_new_id(old_id).unwrap();
25-
let view = folder.get_view(&parse_view_id(&new_id.to_string()), uid).unwrap();
20+
let view = folder.get_view(&new_id, uid).unwrap();
2621

2722
assert_eq!(view.name, expected_name);
2823
assert_eq!(
@@ -238,6 +233,6 @@ async fn test_folder_hierarchy_structure() {
238233
uid,
239234
);
240235

241-
let child_views = folder.get_views_belong_to(&parse_view_id(&getting_started_new_id.to_string()), uid);
236+
let child_views = folder.get_views_belong_to(&getting_started_new_id, uid);
242237
assert_eq!(child_views.len(), 3);
243238
}

0 commit comments

Comments
 (0)