fix: upload all imported csv rows (#6063)

* chore: upload imported csv rows

* chore: format number
This commit is contained in:
Nathan.fooo 2024-08-25 15:14:54 +08:00 committed by GitHub
parent a487aa74fd
commit d1ed45c312
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 138 additions and 90 deletions

View File

@ -964,7 +964,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -989,7 +989,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"async-trait",
@ -1018,7 +1018,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -1038,7 +1038,7 @@ dependencies = [
[[package]]
name = "collab-entity"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"bytes",
@ -1057,7 +1057,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -1100,7 +1100,7 @@ dependencies = [
[[package]]
name = "collab-plugins"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"async-stream",
@ -1180,7 +1180,7 @@ dependencies = [
[[package]]
name = "collab-user"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"collab",

View File

@ -116,13 +116,13 @@ custom-protocol = ["tauri/custom-protocol"]
# To switch to the local path, run:
# scripts/tool/update_collab_source.sh
# ⚠️⚠️⚠️️
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
# Working directory: frontend
# To update the commit ID, run:

View File

@ -947,7 +947,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -972,7 +972,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"async-trait",
@ -1001,7 +1001,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -1021,7 +1021,7 @@ dependencies = [
[[package]]
name = "collab-entity"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"bytes",
@ -1040,7 +1040,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -1083,7 +1083,7 @@ dependencies = [
[[package]]
name = "collab-plugins"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"async-stream",
@ -1163,7 +1163,7 @@ dependencies = [
[[package]]
name = "collab-user"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"collab",

View File

@ -116,13 +116,13 @@ custom-protocol = ["tauri/custom-protocol"]
# To switch to the local path, run:
# scripts/tool/update_collab_source.sh
# ⚠️⚠️⚠️️
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
# Working directory: frontend
# To update the commit ID, run:

View File

@ -825,7 +825,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -850,7 +850,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"async-trait",
@ -879,7 +879,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -899,7 +899,7 @@ dependencies = [
[[package]]
name = "collab-entity"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"bytes",
@ -918,7 +918,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"arc-swap",
@ -961,7 +961,7 @@ dependencies = [
[[package]]
name = "collab-plugins"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"async-stream",
@ -1041,7 +1041,7 @@ dependencies = [
[[package]]
name = "collab-user"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e51cde161cbce9af08f707ab1b3a3564eee90bac#e51cde161cbce9af08f707ab1b3a3564eee90bac"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d#f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d"
dependencies = [
"anyhow",
"collab",

View File

@ -136,13 +136,13 @@ rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb", rev = "1710120
# To switch to the local path, run:
# scripts/tool/update_collab_source.sh
# ⚠️⚠️⚠️️
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e51cde161cbce9af08f707ab1b3a3564eee90bac" }
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f148b6ba98a12270c2faffaeaf2ee41b2cd84e7d" }
# Working directory: frontend
# To update the commit ID, run:

View File

@ -17,7 +17,7 @@ use flowy_folder::manager::{FolderManager, FolderUser};
use flowy_folder::share::ImportType;
use flowy_folder::view_operation::{
DatabaseEncodedCollab, DocumentEncodedCollab, EncodedCollabWrapper, FolderOperationHandler,
FolderOperationHandlers, View, ViewData,
FolderOperationHandlers, ImportedData, View, ViewData,
};
use flowy_folder::ViewLayout;
use flowy_folder_pub::folder_builder::NestedViewBuilder;
@ -254,13 +254,17 @@ impl FolderOperationHandler for DocumentFolderOperation {
_name: &str,
_import_type: ImportType,
bytes: Vec<u8>,
) -> Result<EncodedCollab, FlowyError> {
) -> Result<Vec<ImportedData>, FlowyError> {
let data = DocumentDataPB::try_from(Bytes::from(bytes))?;
let encoded_collab = self
.0
.create_document(uid, view_id, Some(data.into()))
.await?;
Ok(encoded_collab)
Ok(vec![(
view_id.to_string(),
CollabType::Document,
encoded_collab,
)])
}
// will implement soon
@ -462,7 +466,7 @@ impl FolderOperationHandler for DatabaseFolderOperation {
_name: &str,
import_type: ImportType,
bytes: Vec<u8>,
) -> Result<EncodedCollab, FlowyError> {
) -> Result<Vec<ImportedData>, FlowyError> {
let format = match import_type {
ImportType::CSV => CSVFormat::Original,
ImportType::HistoryDatabase => CSVFormat::META,
@ -477,7 +481,19 @@ impl FolderOperationHandler for DatabaseFolderOperation {
.0
.import_csv(view_id.to_string(), content, format)
.await?;
Ok(result.encoded_collab)
Ok(
result
.encoded_collabs
.into_iter()
.map(|encoded| {
(
encoded.object_id,
encoded.collab_type,
encoded.encoded_collab,
)
})
.collect(),
)
}
async fn import_from_file_path(
@ -570,7 +586,7 @@ impl FolderOperationHandler for ChatFolderOperation {
_name: &str,
_import_type: ImportType,
_bytes: Vec<u8>,
) -> Result<EncodedCollab, FlowyError> {
) -> Result<Vec<ImportedData>, FlowyError> {
Err(FlowyError::not_support())
}

View File

@ -22,7 +22,7 @@ use dashmap::DashMap;
use tokio::select;
use tokio::sync::{Mutex, RwLock};
use tokio_util::sync::CancellationToken;
use tracing::{error, instrument, trace};
use tracing::{error, info, instrument, trace};
use collab_integrate::collab_builder::{AppFlowyCollabBuilder, CollabBuilderConfig};
use collab_integrate::{CollabKVAction, CollabKVDB};
@ -437,15 +437,17 @@ impl DatabaseManager {
let view_id = params.inline_view_id.clone();
let database_id = params.database_id.clone();
let database = self.create_database_with_params(params).await?;
let encoded_collab = database
.read()
.await
.encode_collab_v1(|collab| CollabType::Database.validate_require_data(collab))?;
let encoded_database = database.read().await.encode_database_collabs().await?;
let encoded_collabs = std::iter::once(encoded_database.encoded_database_collab)
.chain(encoded_database.encoded_row_collabs.into_iter())
.collect::<Vec<_>>();
let result = ImportResult {
database_id,
view_id,
encoded_collab,
encoded_collabs,
};
info!("import csv result: {}", result);
Ok(result)
}

View File

@ -145,7 +145,6 @@ pub(crate) async fn observe_block_event(database_id: &str, database_editor: &Arc
.subscribe_block_event();
let database_editor = Arc::downgrade(database_editor);
af_spawn(async move {
// let token = CancellationToken::new();
while let Ok(event) = block_event_rx.recv().await {
if database_editor.upgrade().is_none() {
break;

View File

@ -5,7 +5,7 @@ use std::cmp::Ordering;
use std::default::Default;
use std::str::FromStr;
use collab_database::fields::{TypeOptionData, TypeOptionDataBuilder};
use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
use collab_database::rows::{new_cell_builder, Cell};
use fancy_regex::Regex;
use lazy_static::lazy_static;
@ -54,6 +54,12 @@ impl TypeOptionCellData for NumberCellData {
}
}
impl AsRef<str> for NumberCellData {
fn as_ref(&self) -> &str {
&self.0
}
}
impl From<&Cell> for NumberCellData {
fn from(cell: &Cell) -> Self {
Self(cell.get_as(CELL_DATA).unwrap_or_default())
@ -122,21 +128,21 @@ impl NumberTypeOption {
Self::default()
}
fn format_cell_data(&self, num_cell_data: &NumberCellData) -> FlowyResult<NumberCellFormat> {
fn format_cell_data<T: AsRef<str>>(&self, num_cell_data: T) -> FlowyResult<NumberCellFormat> {
match self.format {
NumberFormat::Num => {
if SCIENTIFIC_NOTATION_REGEX
.is_match(&num_cell_data.0)
.is_match(&num_cell_data.as_ref())
.unwrap()
{
match Decimal::from_scientific(&num_cell_data.0.to_lowercase()) {
match Decimal::from_scientific(&num_cell_data.as_ref().to_lowercase()) {
Ok(value, ..) => Ok(NumberCellFormat::from_decimal(value)),
Err(_) => Ok(NumberCellFormat::new()),
}
} else {
// Test the input string is start with dot and only contains number.
// If it is, add a 0 before the dot. For example, ".123" -> "0.123"
let num_str = match START_WITH_DOT_NUM_REGEX.captures(&num_cell_data.0) {
let num_str = match START_WITH_DOT_NUM_REGEX.captures(&num_cell_data.as_ref()) {
Ok(Some(captures)) => match captures.get(0).map(|m| m.as_str().to_string()) {
Some(s) => {
format!("0{}", s)
@ -146,7 +152,7 @@ impl NumberTypeOption {
// Extract the number from the string.
// For example, "123abc" -> "123". check out the number_type_option_input_test test for
// more examples.
_ => match EXTRACT_NUM_REGEX.captures(&num_cell_data.0) {
_ => match EXTRACT_NUM_REGEX.captures(&num_cell_data.as_ref()) {
Ok(Some(captures)) => captures
.get(0)
.map(|m| m.as_str().to_string())
@ -163,7 +169,7 @@ impl NumberTypeOption {
},
_ => {
// If the format is not number, use the format string to format the number.
NumberCellFormat::from_format_str(&num_cell_data.0, &self.format)
NumberCellFormat::from_format_str(&num_cell_data.as_ref(), &self.format)
},
}
}
@ -191,6 +197,18 @@ impl CellDataDecoder for NumberTypeOption {
}
}
fn decode_cell_with_transform(
&self,
cell: &Cell,
_from_field_type: FieldType,
_field: &Field,
) -> Option<<Self as TypeOption>::CellData> {
let num_cell = Self::CellData::from(cell);
Some(Self::CellData::from(
self.format_cell_data(&num_cell).ok()?.to_string(),
))
}
fn numeric_cell(&self, cell: &Cell) -> Option<f64> {
let num_cell_data = self.parse_cell(cell).ok()?;
num_cell_data.0.parse::<f64>().ok()

View File

@ -522,6 +522,7 @@ pub fn is_type_option_cell_transformable(
| (FieldType::RichText, FieldType::SingleSelect)
| (FieldType::RichText, FieldType::MultiSelect)
| (FieldType::RichText, FieldType::URL)
| (FieldType::RichText, FieldType::Number)
| (_, FieldType::RichText)
)
}

View File

@ -1,13 +1,11 @@
use std::{fs::File, io::prelude::*};
use collab_database::database::{gen_database_id, gen_field_id, gen_row_id, timestamp};
use collab_database::entity::{CreateDatabaseParams, CreateViewParams};
use collab_database::entity::{CreateDatabaseParams, CreateViewParams, EncodedCollabInfo};
use collab_database::fields::Field;
use collab_database::rows::{new_cell_builder, Cell, CreateRowParams};
use collab_database::views::DatabaseLayout;
use collab_entity::EncodedCollab;
use flowy_error::{FlowyError, FlowyResult};
use std::fmt::Display;
use std::{fs::File, io::prelude::*};
use crate::entities::FieldType;
use crate::services::field::{default_type_option_data_from_type, CELL_DATA};
@ -169,9 +167,26 @@ impl FieldsRows {
pub struct ImportResult {
pub database_id: String,
pub view_id: String,
pub encoded_collab: EncodedCollab,
pub encoded_collabs: Vec<EncodedCollabInfo>,
}
impl Display for ImportResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let total_size: usize = self
.encoded_collabs
.iter()
.map(|c| c.encoded_collab.doc_state.len())
.sum();
write!(
f,
"ImportResult {{ database_id: {}, view_id: {}, num collabs: {}, size: {} }}",
self.database_id,
self.view_id,
self.encoded_collabs.len(),
total_size
)
}
}
#[cfg(test)]
mod tests {
use collab_database::database::gen_database_view_id;

View File

@ -1421,7 +1421,7 @@ impl FolderManager {
&self,
parent_view_id: String,
import_data: ImportValue,
) -> FlowyResult<(View, Option<EncodedCollab>)> {
) -> FlowyResult<(View, Vec<(String, CollabType, EncodedCollab)>)> {
// Ensure either data or file_path is provided
if import_data.data.is_none() && import_data.file_path.is_none() {
return Err(FlowyError::new(
@ -1433,12 +1433,11 @@ impl FolderManager {
let handler = self.get_handler(&import_data.view_layout)?;
let view_id = gen_view_id().to_string();
let uid = self.user.user_id()?;
let mut encoded_collab: Option<EncodedCollab> = None;
let mut encoded_collab = vec![];
// Import data from bytes if available
if let Some(data) = import_data.data {
encoded_collab = Some(
handler
encoded_collab = handler
.import_from_bytes(
uid,
&view_id,
@ -1446,8 +1445,7 @@ impl FolderManager {
import_data.import_type,
data,
)
.await?,
);
.await?;
}
// Import data from file path if available
@ -1494,20 +1492,15 @@ impl FolderManager {
// Iterate over the values in the import data
for data in import_data.values {
let collab_type = data.import_type.clone().into();
// Import a single file and get the view and encoded collab data
let (view, encoded_collab) = self
let (view, encoded_collabs) = self
.import_single_file(import_data.parent_view_id.clone(), data)
.await?;
let object_id = view.id.clone();
views.push(view_pb_without_child_views(view));
if sync_after_create {
if let Some(encoded_collab) = encoded_collab {
// don't block the whole import process if the view can't be encoded
match self.get_folder_collab_params(object_id, collab_type, encoded_collab) {
for (object_id, collab_type, encode_collab) in encoded_collabs {
match self.get_folder_collab_params(object_id, collab_type, encode_collab) {
Ok(params) => objects.push(params),
Err(e) => {
error!("import error {}", e);
@ -1519,6 +1512,7 @@ impl FolderManager {
// Sync the view to the cloud
if sync_after_create {
info!("Syncing the imported {} collab to the cloud", objects.len());
self
.cloud_service
.batch_create_folder_collab_objects(&workspace_id, objects)

View File

@ -1,6 +1,7 @@
use async_trait::async_trait;
use bytes::Bytes;
use collab::entity::EncodedCollab;
use collab_entity::CollabType;
pub use collab_folder::View;
use collab_folder::ViewLayout;
use std::collections::HashMap;
@ -37,6 +38,8 @@ pub struct DatabaseEncodedCollab {
pub database_relations: HashMap<String, String>,
}
pub type ImportedData = (String, CollabType, EncodedCollab);
/// The handler will be used to handler the folder operation for a specific
/// view layout. Each [ViewLayout] will have a handler. So when creating a new
/// view, the [ViewLayout] will be used to get the handler.
@ -118,7 +121,7 @@ pub trait FolderOperationHandler {
name: &str,
import_type: ImportType,
bytes: Vec<u8>,
) -> Result<EncodedCollab, FlowyError>;
) -> Result<Vec<ImportedData>, FlowyError>;
/// Create a view by importing data from a file
async fn import_from_file_path(