Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: add icon field (#4824)

Zackbf70be18416b
diff --git a/frontend/appflowy_flutter/lib/user/application/user_service.dart b/frontend/appflowy_flutter/lib/user/application/user_service.dart
index 34673ae4f4..c250125c65 100644
--- a/frontend/appflowy_flutter/lib/user/application/user_service.dart
+++ b/frontend/appflowy_flutter/lib/user/application/user_service.dart
@@ -109,7 +109,7 @@ class UserBackendService {
final request = CreateWorkspacePayloadPB.create()
..name = name
..desc = desc;
- return FolderEventCreateWorkspace(request).send().then((result) {
+ return FolderEventCreateFolderWorkspace(request).send().then((result) {
return result.fold(
(workspace) => FlowyResult.success(workspace),
(error) => FlowyResult.failure(error),
diff --git a/frontend/rust-lib/event-integration/src/event_builder.rs b/frontend/rust-lib/event-integration/src/event_builder.rs
index fa20de726f..0d083b1037 100644
--- a/frontend/rust-lib/event-integration/src/event_builder.rs
+++ b/frontend/rust-lib/event-integration/src/event_builder.rs
@@ -63,19 +63,11 @@ impl EventBuilder {
match response.clone().parse::<R, FlowyError>() {
Ok(Ok(data)) => data,
Ok(Err(e)) => {
- panic!(
- "Parser {:?} failed: {:?}, response {:?}",
- std::any::type_name::<R>(),
- e,
- response
- )
+ panic!("Parser {:?} failed: {:?}", std::any::type_name::<R>(), e)
+ },
+ Err(e) => {
+ panic!("Parser {:?} failed: {:?}", std::any::type_name::<R>(), e)
},
- Err(e) => panic!(
- "Dispatch {:?} failed: {:?}, response {:?}",
- std::any::type_name::<R>(),
- e,
- response
- ),
}
}
diff --git a/frontend/rust-lib/event-integration/src/folder_event.rs b/frontend/rust-lib/event-integration/src/folder_event.rs
index 4f3d218e26..1daae0d35d 100644
--- a/frontend/rust-lib/event-integration/src/folder_event.rs
+++ b/frontend/rust-lib/event-integration/src/folder_event.rs
@@ -210,7 +210,7 @@ async fn create_workspace(sdk: &EventIntegrationTest, name: &str, desc: &str) ->
};
EventBuilder::new(sdk.clone())
- .event(CreateWorkspace)
+ .event(CreateFolderWorkspace)
.payload(request)
.async_send()
.await
diff --git a/frontend/rust-lib/event-integration/tests/folder/local_test/script.rs b/frontend/rust-lib/event-integration/tests/folder/local_test/script.rs
index a43aafc144..c240ce9844 100644
--- a/frontend/rust-lib/event-integration/tests/folder/local_test/script.rs
+++ b/frontend/rust-lib/event-integration/tests/folder/local_test/script.rs
@@ -210,7 +210,7 @@ pub async fn create_workspace(sdk: &EventIntegrationTest, name: &str, desc: &str
};
EventBuilder::new(sdk.clone())
- .event(CreateWorkspace)
+ .event(CreateFolderWorkspace)
.payload(request)
.async_send()
.await
diff --git a/frontend/rust-lib/event-integration/tests/folder/local_test/test.rs b/frontend/rust-lib/event-integration/tests/folder/local_test/test.rs
index 0c67bf7373..327d4f5843 100644
--- a/frontend/rust-lib/event-integration/tests/folder/local_test/test.rs
+++ b/frontend/rust-lib/event-integration/tests/folder/local_test/test.rs
@@ -12,7 +12,7 @@ async fn create_workspace_event_test() {
desc: "".to_owned(),
};
let view_pb = EventBuilder::new(test)
- .event(flowy_folder::event_map::FolderEvent::CreateWorkspace)
+ .event(flowy_folder::event_map::FolderEvent::CreateFolderWorkspace)
.payload(request)
.async_send()
.await
@@ -474,7 +474,7 @@ async fn create_parent_view_with_invalid_name() {
};
assert_eq!(
EventBuilder::new(sdk)
- .event(flowy_folder::event_map::FolderEvent::CreateWorkspace)
+ .event(flowy_folder::event_map::FolderEvent::CreateFolderWorkspace)
.payload(request)
.async_send()
.await
diff --git a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs
index 176a39aa9a..2b93a97bd5 100644
--- a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs
+++ b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs
@@ -58,7 +58,10 @@ async fn af_cloud_create_workspace_test() {
let workspaces = get_synced_workspaces(&test, user_profile_pb.id).await;
assert_eq!(workspaces.len(), 2);
- assert_eq!(workspaces[1].name, "my second workspace".to_string());
+ let _second_workspace = workspaces
+ .iter()
+ .find(|w| w.name == "my second workspace")
+ .expect("created workspace not found");
{
// before opening new workspace
diff --git a/frontend/rust-lib/flowy-folder/src/event_map.rs b/frontend/rust-lib/flowy-folder/src/event_map.rs
index a3f8d2b657..b97a386e33 100644
--- a/frontend/rust-lib/flowy-folder/src/event_map.rs
+++ b/frontend/rust-lib/flowy-folder/src/event_map.rs
@@ -11,7 +11,7 @@ use crate::manager::FolderManager;
pub fn init(folder: Weak<FolderManager>) -> AFPlugin {
AFPlugin::new().name("Flowy-Folder").state(folder)
// Workspace
- .event(FolderEvent::CreateWorkspace, create_workspace_handler)
+ .event(FolderEvent::CreateFolderWorkspace, create_workspace_handler)
.event(FolderEvent::GetCurrentWorkspaceSetting, read_current_workspace_setting_handler)
.event(FolderEvent::ReadCurrentWorkspace, read_current_workspace_handler)
.event(FolderEvent::ReadWorkspaceViews, get_workspace_views_handler)
@@ -45,7 +45,7 @@ pub fn init(folder: Weak<FolderManager>) -> AFPlugin {
pub enum FolderEvent {
/// Create a new workspace
#[event(input = "CreateWorkspacePayloadPB", output = "WorkspacePB")]
- CreateWorkspace = 0,
+ CreateFolderWorkspace = 0,
/// Read the current opening workspace. Currently, we only support one workspace
#[event(output = "WorkspaceSettingPB")]
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
index bc3b6f4863..35153a6f0d 100644
--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
@@ -409,6 +409,7 @@ fn to_user_workspace(af_workspace: AFWorkspace) -> UserWorkspace {
name: af_workspace.workspace_name,
created_at: af_workspace.created_at,
workspace_database_object_id: af_workspace.database_storage_id.to_string(),
+ icon: af_workspace.icon,
}
}
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
index 367d1bd732..648217871d 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
@@ -214,5 +214,6 @@ fn make_user_workspace() -> UserWorkspace {
name: "My Workspace".to_string(),
created_at: Default::default(),
workspace_database_object_id: uuid::Uuid::new_v4().to_string(),
+ icon: "".to_string(),
}
}
diff --git a/frontend/rust-lib/flowy-sqlite/migrations/.gitkeep b/frontend/rust-lib/flowy-sqlite/migrations/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/frontend/rust-lib/flowy-sqlite/migrations/2024-03-09-031208_user_workspace_icon/down.sql b/frontend/rust-lib/flowy-sqlite/migrations/2024-03-09-031208_user_workspace_icon/down.sql
new file mode 100644
index 0000000000..6adb7719f8
--- /dev/null
+++ b/frontend/rust-lib/flowy-sqlite/migrations/2024-03-09-031208_user_workspace_icon/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE user_workspace_table DROP COLUMN icon TEXT;
diff --git a/frontend/rust-lib/flowy-sqlite/migrations/2024-03-09-031208_user_workspace_icon/up.sql b/frontend/rust-lib/flowy-sqlite/migrations/2024-03-09-031208_user_workspace_icon/up.sql
new file mode 100644
index 0000000000..61dfcf40b8
--- /dev/null
+++ b/frontend/rust-lib/flowy-sqlite/migrations/2024-03-09-031208_user_workspace_icon/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+ALTER TABLE user_workspace_table ADD COLUMN icon TEXT NOT NULL DEFAULT '';
diff --git a/frontend/rust-lib/flowy-sqlite/src/schema.rs b/frontend/rust-lib/flowy-sqlite/src/schema.rs
index a5ccad50f2..37c2ff8bbd 100644
--- a/frontend/rust-lib/flowy-sqlite/src/schema.rs
+++ b/frontend/rust-lib/flowy-sqlite/src/schema.rs
@@ -43,6 +43,7 @@ diesel::table! {
uid -> BigInt,
created_at -> BigInt,
database_storage_id -> Text,
+ icon -> Text,
}
}
diff --git a/frontend/rust-lib/flowy-user-pub/src/entities.rs b/frontend/rust-lib/flowy-user-pub/src/entities.rs
index 9728c0cd09..ec338fd4f4 100644
--- a/frontend/rust-lib/flowy-user-pub/src/entities.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/entities.rs
@@ -140,6 +140,8 @@ pub struct UserWorkspace {
/// The database storage id is used indexing all the database views in current workspace.
#[serde(rename = "database_storage_id")]
pub workspace_database_object_id: String,
+ #[serde(default)]
+ pub icon: String,
}
impl UserWorkspace {
@@ -149,6 +151,7 @@ impl UserWorkspace {
name: "".to_string(),
created_at: Utc::now(),
workspace_database_object_id: Uuid::new_v4().to_string(),
+ icon: "".to_string(),
}
}
}
diff --git a/frontend/rust-lib/flowy-user-pub/src/session.rs b/frontend/rust-lib/flowy-user-pub/src/session.rs
index 2b742690b4..f4d45aff70 100644
--- a/frontend/rust-lib/flowy-user-pub/src/session.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/session.rs
@@ -63,6 +63,7 @@ impl<'de> Visitor<'de> for SessionVisitor {
created_at: Utc::now(),
// For historical reasons, the database_storage_id is constructed by the user_id.
workspace_database_object_id: STANDARD.encode(format!("{}:user:database", user_id)),
+ icon: "".to_owned(),
})
}
}
diff --git a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs
index 2ccbe6143b..80dcfd1b7f 100644
--- a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs
@@ -228,6 +228,9 @@ pub struct UserWorkspacePB {
#[pb(index = 3)]
pub created_at_timestamp: i64,
+
+ #[pb(index = 4)]
+ pub icon: String,
}
impl From<UserWorkspace> for UserWorkspacePB {
@@ -236,6 +239,7 @@ impl From<UserWorkspace> for UserWorkspacePB {
workspace_id: value.id,
name: value.name,
created_at_timestamp: value.created_at.timestamp(),
+ icon: value.icon,
}
}
}
diff --git a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs
index e335949448..529865234b 100644
--- a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs
+++ b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs
@@ -15,6 +15,7 @@ pub struct UserWorkspaceTable {
pub uid: i64,
pub created_at: i64,
pub database_storage_id: String,
+ pub icon: String,
}
pub fn get_user_workspace_op(workspace_id: &str, mut conn: DBConnection) -> Option<UserWorkspace> {
@@ -90,6 +91,7 @@ impl TryFrom<(i64, &UserWorkspace)> for UserWorkspaceTable {
uid: value.0,
created_at: value.1.created_at.timestamp(),
database_storage_id: value.1.workspace_database_object_id.clone(),
+ icon: value.1.icon.clone(),
})
}
}
@@ -104,6 +106,7 @@ impl From<UserWorkspaceTable> for UserWorkspace {
.single()
.unwrap_or_default(),
workspace_database_object_id: value.database_storage_id,
+ icon: value.icon,
}
}
}
diff --git a/frontend/rust-lib/lib-dispatch/src/dispatcher.rs b/frontend/rust-lib/lib-dispatch/src/dispatcher.rs
index 32f6968c4c..dc1d158282 100644
--- a/frontend/rust-lib/lib-dispatch/src/dispatcher.rs
+++ b/frontend/rust-lib/lib-dispatch/src/dispatcher.rs
@@ -11,7 +11,7 @@ use crate::module::AFPluginStateMap;
use crate::runtime::AFPluginRuntime;
use crate::{
errors::{DispatchError, Error, InternalError},
- module::{as_plugin_map, AFPlugin, AFPluginMap, AFPluginRequest},
+ module::{plugin_map_or_crash, AFPlugin, AFPluginMap, AFPluginRequest},
response::AFPluginEventResponse,
service::{AFPluginServiceFactory, Service},
};
@@ -87,7 +87,7 @@ impl AFPluginDispatcher {
pub fn new(runtime: Arc<AFPluginRuntime>, plugins: Vec<AFPlugin>) -> AFPluginDispatcher {
tracing::trace!("{}", plugin_info(&plugins));
AFPluginDispatcher {
- plugins: as_plugin_map(plugins),
+ plugins: plugin_map_or_crash(plugins),
runtime,
}
}
diff --git a/frontend/rust-lib/lib-dispatch/src/module/module.rs b/frontend/rust-lib/lib-dispatch/src/module/module.rs
index 0eb162b515..1e0a81016b 100644
--- a/frontend/rust-lib/lib-dispatch/src/module/module.rs
+++ b/frontend/rust-lib/lib-dispatch/src/module/module.rs
@@ -27,12 +27,16 @@ use crate::{
};
pub type AFPluginMap = Arc<HashMap<AFPluginEvent, Arc<AFPlugin>>>;
-pub(crate) fn as_plugin_map(plugins: Vec<AFPlugin>) -> AFPluginMap {
- let mut plugin_map = HashMap::new();
+pub(crate) fn plugin_map_or_crash(plugins: Vec<AFPlugin>) -> AFPluginMap {
+ let mut plugin_map: HashMap<AFPluginEvent, Arc<AFPlugin>> = HashMap::new();
plugins.into_iter().for_each(|m| {
let events = m.events();
let plugins = Arc::new(m);
events.into_iter().for_each(|e| {
+ if plugin_map.contains_key(&e) {
+ let plugin_name = plugin_map.get(&e).and_then(|p| Some(&p.name));
+ panic!("⚠️⚠️⚠️Error: {:?} is already defined in {:?}", &e, plugin_name,);
+ }
plugin_map.insert(e, plugins.clone());
});
});
@@ -40,7 +44,7 @@ pub(crate) fn as_plugin_map(plugins: Vec<AFPlugin>) -> AFPluginMap {
}
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
-pub struct AFPluginEvent(pub String);
+pub struct AFPluginEvent(String);
impl<T: Display + Eq + Hash + Debug + Clone> std::convert::From<T> for AFPluginEvent {
fn from(t: T) -> Self {