Skip to content

Commit

Permalink
feat: support publish view and unpublish views
Browse files Browse the repository at this point in the history
  • Loading branch information
qinluhe committed Jun 21, 2024
1 parent 63fe1a6 commit cf8f7ea
Show file tree
Hide file tree
Showing 27 changed files with 909 additions and 24 deletions.
2 changes: 1 addition & 1 deletion frontend/appflowy_tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ collab-user = { version = "0.2" }
# Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6262816043efeede8823d7a7ea252083adf407e9" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "fa7565d9de2a5e65e3886c8230588d58140637c5" }

[dependencies]
serde_json.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion frontend/appflowy_web/wasm-libs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ yrs = "0.18.8"
# Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6262816043efeede8823d7a7ea252083adf407e9" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "fa7565d9de2a5e65e3886c8230588d58140637c5" }

[profile.dev]
opt-level = 0
Expand Down
2 changes: 1 addition & 1 deletion frontend/appflowy_web_app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ collab-user = { version = "0.2" }
# Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6262816043efeede8823d7a7ea252083adf407e9" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "fa7565d9de2a5e65e3886c8230588d58140637c5" }

[dependencies]
serde_json.workspace = true
Expand Down
30 changes: 18 additions & 12 deletions frontend/rust-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/rust-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ validator = { version = "0.16.1", features = ["derive"] }
# Run the script.add_workspace_members:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6262816043efeede8823d7a7ea252083adf407e9" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "6262816043efeede8823d7a7ea252083adf407e9" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "fa7565d9de2a5e65e3886c8230588d58140637c5" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "fa7565d9de2a5e65e3886c8230588d58140637c5" }

[profile.dev]
opt-level = 1
Expand Down
20 changes: 20 additions & 0 deletions frontend/rust-lib/event-integration-test/src/folder_event.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use collab::entity::EncodedCollab;
use std::sync::Arc;

use collab_folder::{FolderData, View};
use flowy_folder::entities::icon::UpdateViewIconPayloadPB;
use flowy_folder::event_map::FolderEvent;
use flowy_folder::event_map::FolderEvent::*;
use flowy_folder::{entities::*, ViewLayout};
use flowy_folder_pub::entities::PublishViewPayload;
use flowy_search::services::manager::{SearchHandler, SearchType};
use flowy_user::entities::{
AcceptWorkspaceInvitationPB, AddWorkspaceMemberPB, QueryWorkspacePB, RemoveWorkspaceMemberPB,
Expand Down Expand Up @@ -165,6 +167,24 @@ impl EventIntegrationTest {
folder.get_folder_data(&workspace_id).clone().unwrap()
}

pub async fn get_publish_payload(&self, view_id: &str) -> Vec<PublishViewPayload> {
let manager = self.folder_manager.clone();
let payload = manager.get_batch_publish_payload(view_id, None).await;

if payload.is_err() {
panic!("Get publish payload failed")
}

payload.unwrap()
}

pub async fn encoded_collab_v1(&self, view_id: &str, layout: ViewLayout) -> EncodedCollab {
let manager = self.folder_manager.clone();
let handlers = manager.get_operation_handlers();
let handler = handlers.get(&layout).unwrap();
handler.encoded_collab_v1(view_id, layout).await.unwrap()
}

pub async fn get_all_workspace_views(&self) -> Vec<ViewPB> {
EventBuilder::new(self.clone())
.event(FolderEvent::ReadCurrentWorkspaceViews)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mod import_test;
mod script;
mod subscription_test;
mod test;
mod view_publish_test;
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
use collab_folder::ViewLayout;
use event_integration_test::EventIntegrationTest;
use flowy_folder::entities::{ViewLayoutPB, ViewPB};
use flowy_folder::publish_util::generate_publish_name;
use flowy_folder_pub::entities::{
PublishViewInfo, PublishViewMeta, PublishViewMetaData, PublishViewPayload,
};

async fn mock_single_document_view_publish_payload(
test: &EventIntegrationTest,
view: &ViewPB,
publish_name: String,
) -> Vec<PublishViewPayload> {
let view_id = &view.id;
let layout: ViewLayout = view.layout.clone().into();
let view_encoded_collab = test.encoded_collab_v1(view_id, layout).await;
let publish_view_info = PublishViewInfo {
view_id: view_id.to_string(),
name: view.name.to_string(),
icon: None,
layout: ViewLayout::Document,
extra: None,
created_by: view.created_by,
last_edited_by: view.last_edited_by,
last_edited_time: view.last_edited,
created_at: view.create_time,
child_views: None,
};

vec![PublishViewPayload {
meta: PublishViewMeta {
metadata: PublishViewMetaData {
view: publish_view_info.clone(),
child_views: vec![],
ancestor_views: vec![publish_view_info],
},
view_id: view_id.to_string(),
publish_name,
},
data: Vec::from(view_encoded_collab.doc_state),
}]
}

async fn mock_nested_document_view_publish_payload(
test: &EventIntegrationTest,
view: &ViewPB,
publish_name: String,
) -> Vec<PublishViewPayload> {
let view_id = &view.id;
let layout: ViewLayout = view.layout.clone().into();
let view_encoded_collab = test.encoded_collab_v1(view_id, layout).await;
let publish_view_info = PublishViewInfo {
view_id: view_id.to_string(),
name: view.name.to_string(),
icon: None,
layout: ViewLayout::Document,
extra: None,
created_by: view.created_by,
last_edited_by: view.last_edited_by,
last_edited_time: view.last_edited,
created_at: view.create_time,
child_views: None,
};

let child_view_id = &view.child_views[0].id;
let child_view = test.get_view(child_view_id).await;
let child_layout: ViewLayout = child_view.layout.clone().into();
let child_view_encoded_collab = test.encoded_collab_v1(child_view_id, child_layout).await;
let child_publish_view_info = PublishViewInfo {
view_id: child_view_id.to_string(),
name: child_view.name.to_string(),
icon: None,
layout: ViewLayout::Document,
extra: None,
created_by: child_view.created_by,
last_edited_by: child_view.last_edited_by,
last_edited_time: child_view.last_edited,
created_at: child_view.create_time,
child_views: None,
};
let child_publish_name = generate_publish_name(&child_view.id, &child_view.name);

vec![
PublishViewPayload {
meta: PublishViewMeta {
metadata: PublishViewMetaData {
view: publish_view_info.clone(),
child_views: vec![child_publish_view_info.clone()],
ancestor_views: vec![publish_view_info.clone()],
},
view_id: view_id.to_string(),
publish_name,
},
data: Vec::from(view_encoded_collab.doc_state),
},
PublishViewPayload {
meta: PublishViewMeta {
metadata: PublishViewMetaData {
view: child_publish_view_info.clone(),
child_views: vec![],
ancestor_views: vec![publish_view_info.clone(), child_publish_view_info.clone()],
},
view_id: child_view_id.to_string(),
publish_name: child_publish_name,
},
data: Vec::from(child_view_encoded_collab.doc_state),
},
]
}

async fn create_single_document(test: &EventIntegrationTest, view_id: &str, name: &str) {
test
.create_orphan_view(name, view_id, ViewLayoutPB::Document)
.await;
}

async fn create_nested_document(test: &EventIntegrationTest, view_id: &str, name: &str) {
create_single_document(test, view_id, name).await;
let child_name = "Child View";
test.create_view(view_id, child_name.to_string()).await;
}
#[tokio::test]
async fn single_document_get_publish_view_payload_test() {
let test = EventIntegrationTest::new_anon().await;
let view_id = "20240521";
let name = "Orphan View";
create_single_document(&test, view_id, name).await;
let view = test.get_view(view_id).await;
let payload = test.get_publish_payload(view_id).await;

let expect_payload = mock_single_document_view_publish_payload(
&test,
&view,
format!("{}-{}", "Orphan_View", view_id),
)
.await;

assert_eq!(payload, expect_payload);
}

#[tokio::test]
async fn nested_document_get_publish_view_payload_test() {
let test = EventIntegrationTest::new_anon().await;
let name = "Orphan View";
let view_id = "20240521";
create_nested_document(&test, view_id, name).await;
let view = test.get_view(view_id).await;
let payload = test.get_publish_payload(view_id).await;

let expect_payload = mock_nested_document_view_publish_payload(
&test,
&view,
format!("{}-{}", "Orphan_View", view_id),
)
.await;

assert_eq!(payload.len(), 2);
assert_eq!(payload, expect_payload);
}
Loading

0 comments on commit cf8f7ea

Please sign in to comment.