chore: replace cell content when import from csv (#6073)

This commit is contained in:
Nathan.fooo 2024-08-26 14:19:30 +08:00 committed by GitHub
parent b649950d62
commit 12cb9bde39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 275 additions and 86 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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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 = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
# 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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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 = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
# 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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96"
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 = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" }
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" }
# Working directory: frontend
# To update the commit ID, run:

View File

@ -464,7 +464,7 @@ impl DatabaseEditor {
new_field_type,
old_type_option_data,
new_type_option_data,
&database,
&mut database,
)
.await;
@ -1362,6 +1362,21 @@ impl DatabaseEditor {
let opening_database_views = self.database_views.clone();
tokio::spawn(async move {
const CHUNK_SIZE: usize = 10;
let apply_filter_and_sort =
|mut loaded_rows, opening_database_views: Arc<DatabaseViews>| async move {
for database_view in opening_database_views.editors().await {
if database_view.has_filters().await {
database_view
.v_filter_rows_and_notify(&mut loaded_rows)
.await;
}
if database_view.has_sorts().await {
database_view.v_sort_rows_and_notify(&mut loaded_rows).await;
}
}
};
let mut loaded_rows = vec![];
for chunk_row_orders in cloned_row_orders.chunks(CHUNK_SIZE) {
match cloned_database.upgrade() {
@ -1382,23 +1397,15 @@ impl DatabaseEditor {
return;
}
if loaded_rows.len() % 100 == 0 {
for database_view in opening_database_views.editors().await {
let mut view_rows = loaded_rows.clone();
database_view.v_filter_rows_and_notify(&mut view_rows).await;
database_view.v_sort_rows_and_notify(&mut view_rows).await;
}
if loaded_rows.len() % 1000 == 0 {
apply_filter_and_sort(loaded_rows.clone(), opening_database_views.clone()).await;
}
},
}
tokio::task::yield_now().await;
}
for database_view in opening_database_views.editors().await {
let mut view_rows = loaded_rows.clone();
database_view.v_filter_rows_and_notify(&mut view_rows).await;
database_view.v_sort_rows_and_notify(&mut view_rows).await;
}
apply_filter_and_sort(loaded_rows.clone(), opening_database_views).await;
});
// Collect database details in a single block holding the `read` lock

View File

@ -124,6 +124,14 @@ impl DatabaseViewEditor {
self.calculations_controller.close().await;
}
pub async fn has_filters(&self) -> bool {
self.filter_controller.has_filters().await
}
pub async fn has_sorts(&self) -> bool {
self.sort_controller.read().await.has_sorts().await
}
pub async fn v_get_view(&self) -> Option<DatabaseView> {
self.delegate.get_view(&self.view_id).await
}

View File

@ -17,7 +17,7 @@ pub async fn transform_type_option(
new_field_type: FieldType,
old_type_option_data: Option<TypeOptionData>,
new_type_option_data: TypeOptionData,
database: &Database,
database: &mut Database,
) -> TypeOptionData {
if let Some(old_type_option_data) = old_type_option_data {
let mut transform_handler =
@ -28,6 +28,7 @@ pub async fn transform_type_option(
field_id,
old_field_type,
old_type_option_data,
new_field_type,
database,
)
.await;
@ -46,7 +47,8 @@ pub trait TypeOptionTransformHandler: Send + Sync {
field_id: &str,
old_type_option_field_type: FieldType,
old_type_option_data: TypeOptionData,
database: &Database,
new_type_option_field_type: FieldType,
database: &mut Database,
);
fn to_type_option_data(&self) -> TypeOptionData;
@ -63,7 +65,8 @@ where
field_id: &str,
old_type_option_field_type: FieldType,
old_type_option_data: TypeOptionData,
database: &Database,
new_type_option_field_type: FieldType,
database: &mut Database,
) {
self
.transform_type_option(
@ -71,6 +74,7 @@ where
field_id,
old_type_option_field_type,
old_type_option_data,
new_type_option_field_type,
database,
)
.await

View File

@ -1,16 +1,17 @@
use std::cmp::Ordering;
use std::str::FromStr;
use async_trait::async_trait;
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, NaiveTime, Offset, TimeZone};
use chrono_tz::Tz;
use collab::preclude::Any;
use collab::util::AnyMapExt;
use collab_database::database::Database;
use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
use collab_database::rows::Cell;
use collab_database::template::date_parse::cast_string_to_timestamp;
use serde::{Deserialize, Serialize};
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::str::FromStr;
use tracing::info;
use crate::entities::{DateCellDataPB, DateFilterPB, FieldType};
use crate::services::cell::{CellDataChangeset, CellDataDecoder};
@ -198,7 +199,52 @@ impl DateTypeOption {
}
}
impl TypeOptionTransform for DateTypeOption {}
#[async_trait]
impl TypeOptionTransform for DateTypeOption {
async fn transform_type_option(
&mut self,
view_id: &str,
field_id: &str,
old_type_option_field_type: FieldType,
_old_type_option_data: TypeOptionData,
_new_type_option_field_type: FieldType,
database: &mut Database,
) {
match old_type_option_field_type {
FieldType::RichText => {
let rows = database
.get_cells_for_field(view_id, field_id)
.await
.into_iter()
.filter_map(|row| row.cell.map(|cell| (row.row_id, cell)))
.collect::<Vec<_>>();
info!(
"Transforming RichText to DateTypeOption, updating {} row's cell content",
rows.len()
);
for (row_id, cell_data) in rows {
if let Some(cell_data) = cell_data
.get_as::<String>(CELL_DATA)
.and_then(|s| cast_string_to_timestamp(&s))
.map(DateCellData::from_timestamp)
{
database
.update_row(row_id, |row| {
row.update_cells(|cell| {
cell.insert(field_id, Cell::from(&cell_data));
});
})
.await;
}
}
},
_ => {
// do nothing
},
}
}
}
impl CellDataDecoder for DateTypeOption {
fn decode_cell(&self, cell: &Cell) -> FlowyResult<<Self as TypeOption>::CellData> {

View File

@ -1,18 +1,19 @@
use async_trait::async_trait;
use collab::preclude::encoding::serde::from_any;
use collab::preclude::Any;
use collab::util::AnyMapExt;
use std::cmp::Ordering;
use std::default::Default;
use std::str::FromStr;
use collab_database::database::Database;
use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
use collab_database::rows::{new_cell_builder, Cell};
use fancy_regex::Regex;
use flowy_error::FlowyResult;
use lazy_static::lazy_static;
use rust_decimal::Decimal;
use serde::{Deserialize, Deserializer, Serialize};
use flowy_error::FlowyResult;
use std::cmp::Ordering;
use std::default::Default;
use std::str::FromStr;
use tracing::info;
use crate::entities::{FieldType, NumberFilterPB};
use crate::services::cell::{CellDataChangeset, CellDataDecoder};
@ -180,7 +181,51 @@ impl NumberTypeOption {
}
}
impl TypeOptionTransform for NumberTypeOption {}
#[async_trait]
impl TypeOptionTransform for NumberTypeOption {
async fn transform_type_option(
&mut self,
view_id: &str,
field_id: &str,
old_type_option_field_type: FieldType,
_old_type_option_data: TypeOptionData,
_new_type_option_field_type: FieldType,
database: &mut Database,
) {
match old_type_option_field_type {
FieldType::RichText => {
let rows = database
.get_cells_for_field(view_id, field_id)
.await
.into_iter()
.filter_map(|row| row.cell.map(|cell| (row.row_id, cell)))
.collect::<Vec<_>>();
info!(
"Transforming RichText to NumberTypeOption, updating {} row's cell content",
rows.len()
);
for (row_id, cell_data) in rows {
if let Ok(num_cell) = self
.parse_cell(&cell_data)
.and_then(|num_cell_data| self.format_cell_data(num_cell_data))
{
database
.update_row(row_id, |row| {
row.update_cells(|cell| {
cell.insert(field_id, NumberCellData::from(num_cell.to_string()));
});
})
.await;
}
}
},
_ => {
// do nothing
},
}
}
}
impl CellDataDecoder for NumberTypeOption {
fn decode_cell(&self, cell: &Cell) -> FlowyResult<<Self as TypeOption>::CellData> {

View File

@ -80,7 +80,8 @@ where
field_id: &str,
old_type_option_field_type: FieldType,
old_type_option_data: TypeOptionData,
database: &Database,
new_type_option_field_type: FieldType,
database: &mut Database,
) {
SelectOptionTypeOptionTransformHelper::transform_type_option(
self,
@ -88,6 +89,7 @@ where
field_id,
&old_type_option_field_type,
old_type_option_data,
new_type_option_field_type,
database,
)
.await;

View File

@ -8,6 +8,7 @@ use collab_database::database::Database;
use collab_database::entity::{SelectOption, SelectOptionColor};
use collab_database::fields::TypeOptionData;
use collab_database::template::option_parse::build_options_from_cells;
use tracing::info;
/// Handles how to transform the cell data when switching between different field types
pub(crate) struct SelectOptionTypeOptionTransformHelper();
@ -24,7 +25,8 @@ impl SelectOptionTypeOptionTransformHelper {
field_id: &str,
old_field_type: &FieldType,
old_type_option_data: TypeOptionData,
database: &Database,
new_field_type: FieldType,
database: &mut Database,
) where
T: SelectTypeOptionSharedAction + TypeOption<CellData = SelectOptionIds>,
{
@ -34,19 +36,44 @@ impl SelectOptionTypeOptionTransformHelper {
return;
}
let text_type_option = RichTextTypeOption::from(old_type_option_data);
let cells = database
let rows = database
.get_cells_for_field(view_id, field_id)
.await
.into_iter()
.filter_map(|e| e.cell)
.map(|cell| {
text_type_option
.filter_map(|row| row.cell.map(|cell| (row.row_id, cell)))
.map(|(row_id, cell)| {
let text = text_type_option
.decode_cell(&cell)
.unwrap_or_default()
.into_inner()
.into_inner();
(row_id, text)
})
.collect::<Vec<_>>();
let options = build_options_from_cells(&cells);
let options =
build_options_from_cells(&rows.iter().map(|row| row.1.clone()).collect::<Vec<_>>());
info!(
"Transforming RichText to SelectOption, updating {} row's cell content",
rows.len()
);
for (row_id, text_cell) in rows {
let mut transformed_ids = Vec::new();
if let Some(option) = options.iter().find(|option| option.name == text_cell) {
transformed_ids.push(option.id.clone());
}
database
.update_row(row_id, |row| {
row.update_cells(|cell| {
cell.insert(
field_id,
SelectOptionIds::from(transformed_ids).to_cell_data(new_field_type),
);
});
})
.await;
}
shared.mut_options().extend(options);
},
FieldType::Checkbox => {

View File

@ -112,7 +112,8 @@ pub trait TypeOptionTransform: TypeOption + Send + Sync {
_field_id: &str,
_old_type_option_field_type: FieldType,
_old_type_option_data: TypeOptionData,
_database: &Database,
_new_type_option_field_type: FieldType,
_database: &mut Database,
) {
}
}

View File

@ -1,12 +1,6 @@
use collab::preclude::encoding::serde::from_any;
use collab::preclude::Any;
use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
use collab_database::rows::Cell;
use flowy_error::FlowyResult;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use crate::entities::{FieldType, TextFilterPB, URLCellDataPB};
use crate::services::cell::{CellDataChangeset, CellDataDecoder};
use crate::services::field::{
@ -14,6 +8,14 @@ use crate::services::field::{
TypeOptionTransform, URLCellData,
};
use crate::services::sort::SortCondition;
use async_trait::async_trait;
use collab_database::database::Database;
use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
use collab_database::rows::Cell;
use flowy_error::FlowyResult;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use tracing::trace;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct URLTypeOption {
@ -45,7 +47,46 @@ impl From<URLTypeOption> for TypeOptionData {
}
}
impl TypeOptionTransform for URLTypeOption {}
#[async_trait]
impl TypeOptionTransform for URLTypeOption {
async fn transform_type_option(
&mut self,
view_id: &str,
field_id: &str,
old_type_option_field_type: FieldType,
_old_type_option_data: TypeOptionData,
_new_type_option_field_type: FieldType,
database: &mut Database,
) {
match old_type_option_field_type {
FieldType::RichText => {
let rows = database
.get_cells_for_field(view_id, field_id)
.await
.into_iter()
.filter_map(|row| row.cell.map(|cell| (row.row_id, cell)))
.collect::<Vec<_>>();
trace!(
"Transforming RichText to URLTypeOption, updating {} row's cell content",
rows.len()
);
for (row_id, cell_data) in rows {
database
.update_row(row_id, |row| {
row.update_cells(|cell| {
cell.insert(field_id, Self::CellData::from(&cell_data));
});
})
.await;
}
},
_ => {
// Do nothing
},
}
}
}
impl TypeOptionCellDataSerde for URLTypeOption {
fn protobuf_encode(

View File

@ -109,6 +109,10 @@ impl FilterController {
}
}
pub async fn has_filters(&self) -> bool {
!self.filters.read().await.is_empty()
}
pub async fn close(&self) {
if let Ok(mut task_scheduler) = self.task_scheduler.try_write() {
task_scheduler.unregister_handler(&self.handler_id).await;

View File

@ -84,6 +84,10 @@ impl SortController {
}
}
pub async fn has_sorts(&self) -> bool {
!self.sorts.is_empty()
}
pub async fn did_receive_row_changed(&self, row_id: RowId) {
if !self.sorts.is_empty() {
self