mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: add support for renaming and updating the icon for workspaces (#4806)
This commit is contained in:
@ -225,6 +225,9 @@ pub struct UserWorkspacePB {
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub created_at_timestamp: i64,
|
||||
}
|
||||
|
||||
impl From<UserWorkspace> for UserWorkspacePB {
|
||||
@ -232,6 +235,7 @@ impl From<UserWorkspace> for UserWorkspacePB {
|
||||
Self {
|
||||
workspace_id: value.id,
|
||||
name: value.name,
|
||||
created_at_timestamp: value.created_at.timestamp(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,3 +116,24 @@ pub struct CreateWorkspacePB {
|
||||
#[validate(custom = "required_not_empty_str")]
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Clone, Validate)]
|
||||
pub struct RenameWorkspacePB {
|
||||
#[pb(index = 1)]
|
||||
#[validate(custom = "required_not_empty_str")]
|
||||
pub workspace_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
#[validate(custom = "required_not_empty_str")]
|
||||
pub new_name: String,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Clone, Validate)]
|
||||
pub struct ChangeWorkspaceIconPB {
|
||||
#[pb(index = 1)]
|
||||
#[validate(custom = "required_not_empty_str")]
|
||||
pub workspace_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub new_icon: String,
|
||||
}
|
||||
|
@ -683,3 +683,29 @@ pub async fn delete_workspace_handler(
|
||||
manager.delete_workspace(&workspace_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub async fn rename_workspace_handler(
|
||||
rename_workspace_param: AFPluginData<RenameWorkspacePB>,
|
||||
manager: AFPluginState<Weak<UserManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params = rename_workspace_param.try_into_inner()?;
|
||||
let manager = upgrade_manager(manager)?;
|
||||
manager
|
||||
.patch_workspace(¶ms.workspace_id, Some(¶ms.new_name), None)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub async fn change_workspace_icon_handler(
|
||||
change_workspace_icon_param: AFPluginData<ChangeWorkspaceIconPB>,
|
||||
manager: AFPluginState<Weak<UserManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params = change_workspace_icon_param.try_into_inner()?;
|
||||
let manager = upgrade_manager(manager)?;
|
||||
manager
|
||||
.patch_workspace(¶ms.workspace_id, None, Some(¶ms.new_icon))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
|
||||
.event(UserEvent::GetAllWorkspace, get_all_workspace_handler)
|
||||
.event(UserEvent::CreateWorkspace, create_workspace_handler)
|
||||
.event(UserEvent::DeleteWorkspace, delete_workspace_handler)
|
||||
.event(UserEvent::RenameWorkspace, rename_workspace_handler)
|
||||
.event(UserEvent::ChangeWorkspaceIcon, change_workspace_icon_handler)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
|
||||
@ -200,6 +202,12 @@ pub enum UserEvent {
|
||||
|
||||
#[event(input = "UserWorkspaceIdPB")]
|
||||
DeleteWorkspace = 43,
|
||||
|
||||
#[event(input = "RenameWorkspacePB")]
|
||||
RenameWorkspace = 44,
|
||||
|
||||
#[event(input = "ChangeWorkspaceIconPB")]
|
||||
ChangeWorkspaceIcon = 45,
|
||||
}
|
||||
|
||||
pub trait UserStatusCallback: Send + Sync + 'static {
|
||||
|
@ -167,6 +167,21 @@ impl UserManager {
|
||||
Ok(new_workspace)
|
||||
}
|
||||
|
||||
pub async fn patch_workspace(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
new_workspace_name: Option<&str>,
|
||||
new_workspace_icon: Option<&str>,
|
||||
) -> FlowyResult<()> {
|
||||
self
|
||||
.cloud_services
|
||||
.get_user_service()?
|
||||
.patch_workspace(workspace_id, new_workspace_name, new_workspace_icon)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_workspace(&self, workspace_id: &str) -> FlowyResult<()> {
|
||||
self
|
||||
.cloud_services
|
||||
|
Reference in New Issue
Block a user