Skip to content

Commit ed5f1f8

Browse files
committed
chore: uuid ViewsMap
1 parent 9307897 commit ed5f1f8

File tree

4 files changed

+57
-65
lines changed

4 files changed

+57
-65
lines changed

collab-folder/src/folder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl FolderBody {
738738
tracing::debug!("Move nested view: {}", view_id);
739739
let view = self.views.get_view_with_txn(txn, view_id, uid)?;
740740
let current_workspace_id = self.get_workspace_id_with_txn(txn)?;
741-
let parent_id = view.parent_view_id.to_string();
741+
let parent_id = view.parent_view_id;
742742

743743
let new_parent_view = self.views.get_view_with_txn(txn, new_parent_id, uid);
744744

@@ -753,13 +753,13 @@ impl FolderBody {
753753
// dissociate the child from its parent
754754
self
755755
.views
756-
.dissociate_parent_child_with_txn(txn, &parent_id, &view_id.to_string());
756+
.dissociate_parent_child_with_txn(txn, &parent_id, view_id);
757757
// associate the child with its new parent and place it after the prev_view_id. If the prev_view_id is None,
758758
// place it as the first child.
759759
self.views.associate_parent_child_with_txn(
760760
txn,
761-
&new_parent_id.to_string(),
762-
&view_id.to_string(),
761+
new_parent_id,
762+
view_id,
763763
prev_view_id,
764764
);
765765
// Update the view's parent ID.

collab-folder/src/view.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl ViewsMap {
100100
/// Because the views and workspaces are stored in two separate maps, we can't directly move a view from one map to another.
101101
/// So, we have to dissociate the relationship between parent_id and view_id, and then associate the relationship between parent_id and view_id.
102102
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());
103+
self.dissociate_parent_child_with_txn(txn, parent_id, view_id);
104104
}
105105

106106
/// Establish a relationship between the parent_id and view_id, and insert the view below the prev_id.
@@ -114,40 +114,30 @@ impl ViewsMap {
114114
view_id: &Uuid,
115115
prev_id: Option<ViewId>,
116116
) {
117-
self.associate_parent_child_with_txn(txn, &parent_id.to_string(), &view_id.to_string(), prev_id);
117+
self.associate_parent_child_with_txn(txn, parent_id, view_id, prev_id);
118118
}
119119

120120
pub fn dissociate_parent_child_with_txn(
121121
&self,
122122
txn: &mut TransactionMut,
123-
parent_id: &str,
124-
view_id: &str,
123+
parent_id: &Uuid,
124+
view_id: &Uuid,
125125
) {
126-
if let (Ok(parent_uuid), Ok(view_uuid)) = (
127-
uuid::Uuid::parse_str(parent_id),
128-
uuid::Uuid::parse_str(view_id),
129-
) {
130-
self
131-
.parent_children_relation
132-
.dissociate_parent_child_with_txn(txn, &parent_uuid, &view_uuid);
133-
}
126+
self
127+
.parent_children_relation
128+
.dissociate_parent_child_with_txn(txn, parent_id, view_id);
134129
}
135130

136131
pub fn associate_parent_child_with_txn(
137132
&self,
138133
txn: &mut TransactionMut,
139-
parent_id: &str,
140-
view_id: &str,
134+
parent_id: &Uuid,
135+
view_id: &Uuid,
141136
prev_view_id: Option<ViewId>,
142137
) {
143-
if let (Ok(parent_uuid), Ok(view_uuid)) = (
144-
uuid::Uuid::parse_str(parent_id),
145-
uuid::Uuid::parse_str(view_id),
146-
) {
147-
self
148-
.parent_children_relation
149-
.associate_parent_child_with_txn(txn, &parent_uuid, &view_uuid, prev_view_id);
150-
}
138+
self
139+
.parent_children_relation
140+
.associate_parent_child_with_txn(txn, parent_id, view_id, prev_view_id);
151141
}
152142

153143
pub fn remove_child(&self, txn: &mut TransactionMut, parent_id: &Uuid, child_index: u32) {

collab-folder/tests/folder_test/child_views_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn delete_view_test() {
283283
.views
284284
.insert(&mut txn, view_3, None, uid.as_i64());
285285

286-
folder.body.views.remove_child(&mut txn, &workspace_id, 1);
286+
folder.body.views.remove_child(&mut txn, &uuid::Uuid::parse_str(&workspace_id).unwrap(), 1);
287287
let w_1_child_views =
288288
folder
289289
.body

collab-folder/tests/folder_test/view_test.rs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -356,51 +356,53 @@ fn dissociate_and_associate_view_test() {
356356
.views
357357
.insert(&mut txn, view_2, None, uid.as_i64());
358358

359-
let v1_uuid_str = crate::util::test_uuid(view_1_id).to_string();
360-
let v2_uuid_str = crate::util::test_uuid(view_2_id).to_string();
361-
let v1_child_uuid_str = crate::util::test_uuid(view_1_child_id).to_string();
359+
let v1_uuid = crate::util::test_uuid(view_1_id);
360+
let v2_uuid = crate::util::test_uuid(view_2_id);
361+
let v1_child_uuid = crate::util::test_uuid(view_1_child_id);
362362
let r_view = folder
363363
.body
364364
.views
365-
.get_view(&txn, &parse_view_id(&v1_uuid_str), uid.as_i64())
365+
.get_view(&txn, &v1_uuid, uid.as_i64())
366366
.unwrap();
367367
assert_eq!(r_view.children.items.iter().len(), 1);
368368

369369
// move out not exist parent view
370+
let not_exist_parent_uuid = uuid::Uuid::new_v4();
371+
let not_exist_view_uuid = uuid::Uuid::new_v4();
370372
folder
371373
.body
372374
.views
373-
.dissociate_parent_child(&mut txn, "not_exist_parent_view", "not_exist_view");
375+
.dissociate_parent_child(&mut txn, &not_exist_parent_uuid, &not_exist_view_uuid);
374376

375377
// move in not exist parent view
376378
folder.body.views.associate_parent_child(
377379
&mut txn,
378-
"not_exist_parent_view",
379-
"not_exist_view",
380+
&not_exist_parent_uuid,
381+
&not_exist_view_uuid,
380382
None,
381383
);
382384

383385
// move out view_1_child from view_2
384386
folder
385387
.body
386388
.views
387-
.dissociate_parent_child(&mut txn, &v2_uuid_str, &v1_child_uuid_str);
389+
.dissociate_parent_child(&mut txn, &v2_uuid, &v1_child_uuid);
388390
let r_view = folder
389391
.body
390392
.views
391-
.get_view(&txn, &parse_view_id(&v2_uuid_str), uid.as_i64())
393+
.get_view(&txn, &v2_uuid, uid.as_i64())
392394
.unwrap();
393395
assert_eq!(r_view.children.items.iter().len(), 0);
394396

395397
folder
396398
.body
397399
.views
398-
.associate_parent_child(&mut txn, &v1_uuid_str, &v2_uuid_str, None);
400+
.associate_parent_child(&mut txn, &v1_uuid, &v2_uuid, None);
399401

400402
let r_view = folder
401403
.body
402404
.views
403-
.get_view(&txn, &parse_view_id(&v1_uuid_str), uid.as_i64())
405+
.get_view(&txn, &v1_uuid, uid.as_i64())
404406
.unwrap();
405407
assert_eq!(r_view.children.items.iter().len(), 2);
406408
assert_eq!(
@@ -415,25 +417,25 @@ fn dissociate_and_associate_view_test() {
415417
folder
416418
.body
417419
.views
418-
.dissociate_parent_child(&mut txn, &v1_uuid_str, &v2_uuid_str);
420+
.dissociate_parent_child(&mut txn, &v1_uuid, &v2_uuid);
419421
let r_view = folder
420422
.body
421423
.views
422-
.get_view(&txn, &parse_view_id(&v1_uuid_str), uid.as_i64())
424+
.get_view(&txn, &v1_uuid, uid.as_i64())
423425
.unwrap();
424426
assert_eq!(r_view.children.items.iter().len(), 1);
425427

426428
folder.body.views.associate_parent_child(
427429
&mut txn,
428-
&v1_uuid_str,
429-
&v2_uuid_str,
430+
&v1_uuid,
431+
&v2_uuid,
430432
Some(crate::util::test_uuid(view_1_child_id)),
431433
);
432434

433435
let r_view = folder
434436
.body
435437
.views
436-
.get_view(&txn, &parse_view_id(&v1_uuid_str), uid.as_i64())
438+
.get_view(&txn, &v1_uuid, uid.as_i64())
437439
.unwrap();
438440
assert_eq!(r_view.children.items.iter().len(), 2);
439441
assert_eq!(
@@ -468,33 +470,33 @@ fn move_view_across_parent_test() {
468470
folder.insert_view(view_1, None, uid.as_i64());
469471
folder.insert_view(view_2, None, uid.as_i64());
470472

471-
let v1_uuid_str = crate::util::test_uuid(view_1_id).to_string();
472-
let v2_uuid_str = crate::util::test_uuid(view_2_id).to_string();
473-
let v1_child_uuid_str = crate::util::test_uuid(view_1_child_id).to_string();
473+
let v1_uuid = crate::util::test_uuid(view_1_id);
474+
let v2_uuid = crate::util::test_uuid(view_2_id);
475+
let v1_child_uuid = crate::util::test_uuid(view_1_child_id);
474476

475477
// Move out of the current workspace.
476478
let res = folder.move_nested_view(
477-
&parse_view_id(&v1_child_uuid_str),
479+
&v1_child_uuid,
478480
&crate::util::test_uuid("w2"),
479481
None,
480482
uid.as_i64(),
481483
);
482484
assert!(res.is_none());
483485
// Move view_1_child from view_1 to view_2.
484486
folder.move_nested_view(
485-
&parse_view_id(&v1_child_uuid_str),
486-
&parse_view_id(&v2_uuid_str),
487+
&v1_child_uuid,
488+
&v2_uuid,
487489
None,
488490
uid.as_i64(),
489491
);
490492
let view_1 = folder
491-
.get_view(&parse_view_id(&v1_uuid_str), uid.as_i64())
493+
.get_view(&v1_uuid, uid.as_i64())
492494
.unwrap();
493495
let view_2 = folder
494-
.get_view(&parse_view_id(&v2_uuid_str), uid.as_i64())
496+
.get_view(&v2_uuid, uid.as_i64())
495497
.unwrap();
496498
let view_1_child = folder
497-
.get_view(&parse_view_id(&v1_child_uuid_str), uid.as_i64())
499+
.get_view(&v1_child_uuid, uid.as_i64())
498500
.unwrap();
499501
assert_eq!(view_1.children.items.iter().len(), 0);
500502
assert_eq!(view_2.children.items.iter().len(), 1);
@@ -507,19 +509,19 @@ fn move_view_across_parent_test() {
507509
let workspace_uuid = uuid::Uuid::new_v5(&uuid::Uuid::NAMESPACE_OID, workspace_id.as_bytes());
508510
let workspace_uuid_str = workspace_uuid.to_string();
509511
folder.move_nested_view(
510-
&parse_view_id(&v1_child_uuid_str),
512+
&v1_child_uuid,
511513
&parse_view_id(&workspace_uuid_str),
512514
None,
513515
uid.as_i64(),
514516
);
515517
let view_1 = folder
516-
.get_view(&parse_view_id(&v1_uuid_str), uid.as_i64())
518+
.get_view(&v1_uuid, uid.as_i64())
517519
.unwrap();
518520
let view_2 = folder
519-
.get_view(&parse_view_id(&v2_uuid_str), uid.as_i64())
521+
.get_view(&v2_uuid, uid.as_i64())
520522
.unwrap();
521523
let view_1_child = folder
522-
.get_view(&parse_view_id(&v1_child_uuid_str), uid.as_i64())
524+
.get_view(&v1_child_uuid, uid.as_i64())
523525
.unwrap();
524526
let workspace = folder
525527
.get_workspace_info(&workspace_uuid, uid.as_i64())
@@ -538,19 +540,19 @@ fn move_view_across_parent_test() {
538540

539541
// Move view_1_child from position 0 to position 1 in the current workspace.
540542
folder.move_nested_view(
541-
&parse_view_id(&v1_child_uuid_str),
543+
&v1_child_uuid,
542544
&parse_view_id(&workspace_uuid_str),
543545
Some(crate::util::test_uuid(view_1_id)),
544546
uid.as_i64(),
545547
);
546548
let view_1 = folder
547-
.get_view(&parse_view_id(&v1_uuid_str), uid.as_i64())
549+
.get_view(&v1_uuid, uid.as_i64())
548550
.unwrap();
549551
let view_2 = folder
550-
.get_view(&parse_view_id(&v2_uuid_str), uid.as_i64())
552+
.get_view(&v2_uuid, uid.as_i64())
551553
.unwrap();
552554
let view_1_child = folder
553-
.get_view(&parse_view_id(&v1_child_uuid_str), uid.as_i64())
555+
.get_view(&v1_child_uuid, uid.as_i64())
554556
.unwrap();
555557
let workspace = folder
556558
.get_workspace_info(&workspace_uuid, uid.as_i64())
@@ -573,19 +575,19 @@ fn move_view_across_parent_test() {
573575

574576
// move view_1_child from current workspace to view_1
575577
folder.move_nested_view(
576-
&parse_view_id(&v1_child_uuid_str),
577-
&parse_view_id(&v1_uuid_str),
578+
&v1_child_uuid,
579+
&v1_uuid,
578580
None,
579581
uid.as_i64(),
580582
);
581583
let view_1 = folder
582-
.get_view(&parse_view_id(&v1_uuid_str), uid.as_i64())
584+
.get_view(&v1_uuid, uid.as_i64())
583585
.unwrap();
584586
let view_2 = folder
585-
.get_view(&parse_view_id(&v2_uuid_str), uid.as_i64())
587+
.get_view(&v2_uuid, uid.as_i64())
586588
.unwrap();
587589
let view_1_child = folder
588-
.get_view(&parse_view_id(&v1_child_uuid_str), uid.as_i64())
590+
.get_view(&v1_child_uuid, uid.as_i64())
589591
.unwrap();
590592
let workspace = folder
591593
.get_workspace_info(&workspace_uuid, uid.as_i64())

0 commit comments

Comments
 (0)