chore: optimize the UI if fail to open the workspace (#3246)

* chore: async load user profile

* chore: enable reset workspace

* chore: add confirm dialog
This commit is contained in:
Nathan.fooo
2023-08-22 00:19:15 +08:00
committed by GitHub
parent bd30e31f6c
commit 12d6cbd46a
64 changed files with 928 additions and 322 deletions

View File

@ -22,7 +22,7 @@ fn upgrade_manager(
) -> FlowyResult<Arc<DatabaseManager>> {
let manager = database_manager
.upgrade()
.ok_or(FlowyError::internal().context("The database manager is already dropped"))?;
.ok_or(FlowyError::internal().with_context("The database manager is already dropped"))?;
Ok(manager)
}
@ -459,7 +459,7 @@ pub(crate) async fn create_row_handler(
.create_row(&view_id, group_id, params)
.await?
{
None => Err(FlowyError::internal().context("Create row fail")),
None => Err(FlowyError::internal().with_context("Create row fail")),
Some(row) => data_result_ok(RowMetaPB::from(row.meta)),
}
}
@ -510,9 +510,10 @@ pub(crate) async fn new_select_option_handler(
.create_select_option(&params.field_id, params.option_name)
.await;
match result {
None => {
Err(FlowyError::record_not_found().context("Create select option fail. Can't find the field"))
},
None => Err(
FlowyError::record_not_found()
.with_context("Create select option fail. Can't find the field"),
),
Some(pb) => data_result_ok(pb),
}
}

View File

@ -95,7 +95,7 @@ impl DatabaseManager {
collab_raw_data = updates;
},
Err(err) => {
return Err(FlowyError::record_not_found().context(format!(
return Err(FlowyError::record_not_found().with_context(format!(
"get workspace database :{} failed: {}",
database_storage_id, err,
)));
@ -156,7 +156,7 @@ impl DatabaseManager {
let wdb = self.get_workspace_database().await?;
wdb.get_database_id_with_view_id(view_id).ok_or_else(|| {
FlowyError::record_not_found()
.context(format!("The database for view id: {} not found", view_id))
.with_context(format!("The database for view id: {} not found", view_id))
})
}
@ -331,7 +331,7 @@ impl DatabaseManager {
async fn get_workspace_database(&self) -> FlowyResult<Arc<WorkspaceDatabase>> {
let database = self.workspace_database.read().await;
match &*database {
None => Err(FlowyError::internal().context("Workspace database not initialized")),
None => Err(FlowyError::internal().with_context("Workspace database not initialized")),
Some(user_database) => Ok(user_database.clone()),
}
}

View File

@ -32,7 +32,7 @@ impl TypeCellData {
pub fn from_json_str(s: &str) -> FlowyResult<Self> {
let type_cell_data: TypeCellData = serde_json::from_str(s).map_err(|err| {
let msg = format!("Deserialize {} to type cell data failed.{}", s, err);
FlowyError::internal().context(msg)
FlowyError::internal().with_context(msg)
})?;
Ok(type_cell_data)
}

View File

@ -673,7 +673,7 @@ impl DatabaseEditor {
Some(field) => Ok(field),
None => {
let msg = format!("Field with id:{} not found", &field_id);
Err(FlowyError::internal().context(msg))
Err(FlowyError::internal().with_context(msg))
},
}?;
(field, database.get_cell(field_id, &row_id).cell)
@ -767,7 +767,8 @@ impl DatabaseEditor {
.fields
.get_field(field_id)
.ok_or_else(|| {
FlowyError::record_not_found().context(format!("Field with id:{} not found", &field_id))
FlowyError::record_not_found()
.with_context(format!("Field with id:{} not found", &field_id))
})?;
debug_assert!(FieldType::from(field.field_type).is_select_option());
@ -802,7 +803,7 @@ impl DatabaseEditor {
Some(field) => Ok(field),
None => {
let msg = format!("Field with id:{} not found", &field_id);
Err(FlowyError::internal().context(msg))
Err(FlowyError::internal().with_context(msg))
},
}?;
let mut type_option = select_type_option_from_field(&field)?;
@ -868,7 +869,8 @@ impl DatabaseEditor {
.fields
.get_field(field_id)
.ok_or_else(|| {
FlowyError::record_not_found().context(format!("Field with id:{} not found", &field_id))
FlowyError::record_not_found()
.with_context(format!("Field with id:{} not found", &field_id))
})?;
debug_assert!(FieldType::from(field.field_type).is_checklist());
@ -1047,11 +1049,10 @@ impl DatabaseEditor {
&self,
view_id: &str,
) -> FlowyResult<DatabaseViewSettingPB> {
let view = self
.database
.lock()
.get_view(view_id)
.ok_or_else(|| FlowyError::record_not_found().context("Can't find the database view"))?;
let view =
self.database.lock().get_view(view_id).ok_or_else(|| {
FlowyError::record_not_found().with_context("Can't find the database view")
})?;
Ok(database_view_setting_pb_from_view(view))
}

View File

@ -418,7 +418,7 @@ impl DatabaseViewEditor {
.as_ref()
.and_then(|group| group.get_group(group_id))
{
None => Err(FlowyError::record_not_found().context("Can't find the group")),
None => Err(FlowyError::record_not_found().with_context("Can't find the group")),
Some((_, group)) => Ok(GroupPB::from(group)),
}
}

View File

@ -125,7 +125,10 @@ impl CellDataChangeset for RichTextTypeOption {
_cell: Option<Cell>,
) -> FlowyResult<(Cell, <Self as TypeOption>::CellData)> {
if changeset.len() > 10000 {
Err(FlowyError::text_too_long().context("The len of the text should not be more than 10000"))
Err(
FlowyError::text_too_long()
.with_context("The len of the text should not be more than 10000"),
)
} else {
let text_cell_data = StrCellData(changeset);
Ok((text_cell_data.clone().into(), text_cell_data))

View File

@ -223,7 +223,9 @@ where
})?;
Ok(())
},
_ => Err(FlowyError::record_not_found().context("Moving group failed. Groups are not exist")),
_ => Err(
FlowyError::record_not_found().with_context("Moving group failed. Groups are not exist"),
),
}
}

View File

@ -33,7 +33,7 @@ impl CSVExport {
.collect::<Vec<String>>();
wtr
.write_record(&field_records)
.map_err(|e| FlowyError::internal().context(e))?;
.map_err(|e| FlowyError::internal().with_context(e))?;
// Write rows
let mut field_by_field_id = IndexMap::new();
@ -63,8 +63,8 @@ impl CSVExport {
let data = wtr
.into_inner()
.map_err(|e| FlowyError::internal().context(e))?;
let csv = String::from_utf8(data).map_err(|e| FlowyError::internal().context(e))?;
.map_err(|e| FlowyError::internal().with_context(e))?;
let csv = String::from_utf8(data).map_err(|e| FlowyError::internal().with_context(e))?;
Ok(csv)
}
}

View File

@ -1,13 +1,15 @@
use crate::entities::FieldType;
use std::{fs::File, io::prelude::*};
use crate::services::field::{default_type_option_data_from_type, CELL_DATA};
use crate::services::share::csv::CSVFormat;
use collab_database::database::{gen_database_id, gen_field_id, gen_row_id};
use collab_database::fields::Field;
use collab_database::rows::{new_cell_builder, Cell, CreateRowParams};
use collab_database::views::{CreateDatabaseParams, DatabaseLayout};
use flowy_error::{FlowyError, FlowyResult};
use std::{fs::File, io::prelude::*};
use crate::entities::FieldType;
use crate::services::field::{default_type_option_data_from_type, CELL_DATA};
use crate::services::share::csv::CSVFormat;
#[derive(Default)]
pub struct CSVImporter;
@ -41,7 +43,7 @@ impl CSVImporter {
fn get_fields_and_rows(&self, content: String) -> Result<FieldsRows, FlowyError> {
let mut fields: Vec<String> = vec![];
if content.is_empty() {
return Err(FlowyError::invalid_data().context("Import content is empty"));
return Err(FlowyError::invalid_data().with_context("Import content is empty"));
}
let mut reader = csv::Reader::from_reader(content.as_bytes());
@ -50,7 +52,7 @@ impl CSVImporter {
fields.push(header.to_string());
}
} else {
return Err(FlowyError::invalid_data().context("Header not found"));
return Err(FlowyError::invalid_data().with_context("Header not found"));
}
let rows = reader
@ -164,9 +166,10 @@ pub struct ImportResult {
#[cfg(test)]
mod tests {
use crate::services::share::csv::{CSVFormat, CSVImporter};
use collab_database::database::gen_database_view_id;
use crate::services::share::csv::{CSVFormat, CSVImporter};
#[test]
fn test_import_csv_from_str() {
let s = r#"Name,Tags,Number,Date,Checkbox,URL