Skip to content

Commit 0ee773d

Browse files
committed
chore: imple type option cell
1 parent 2e4bfd8 commit 0ee773d

File tree

10 files changed

+75
-0
lines changed

10 files changed

+75
-0
lines changed

collab-database/src/fields/type_option/date_type_option.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use serde::{Deserialize, Serialize};
1414
use std::fmt;
1515

1616
use crate::template::time_parse::TimeCellData;
17+
use crate::template::util::TypeOptionCellData;
1718
use serde_json::{json, Value};
1819
use std::str::FromStr;
1920
pub use strum::IntoEnumIterator;
@@ -351,6 +352,11 @@ pub struct DateCellData {
351352
pub is_range: bool,
352353
pub reminder_id: String,
353354
}
355+
impl TypeOptionCellData for DateCellData {
356+
fn is_empty(&self) -> bool {
357+
self.timestamp.is_none()
358+
}
359+
}
354360

355361
impl DateCellData {
356362
pub fn new(timestamp: i64, include_time: bool, is_range: bool, reminder_id: String) -> Self {

collab-database/src/fields/type_option/media_type_option.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::fields::{
44
TypeOptionCellReader, TypeOptionCellWriter, TypeOptionData, TypeOptionDataBuilder,
55
};
66
use crate::rows::{new_cell_builder, Cell};
7+
78
use crate::template::entity::CELL_DATA;
9+
use crate::template::util::TypeOptionCellData;
810
use collab::util::AnyMapExt;
911
use serde::{Deserialize, Deserializer, Serialize};
1012
use serde_json::{json, Value};
@@ -79,6 +81,12 @@ pub struct MediaCellData {
7981
pub files: Vec<MediaFile>,
8082
}
8183

84+
impl TypeOptionCellData for MediaCellData {
85+
fn is_empty(&self) -> bool {
86+
self.files.is_empty()
87+
}
88+
}
89+
8290
impl From<MediaCellData> for Any {
8391
fn from(data: MediaCellData) -> Self {
8492
Any::Array(Arc::from(

collab-database/src/fields/type_option/select_type_option.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::fields::{
77
};
88
use crate::rows::{new_cell_builder, Cell};
99
use crate::template::entity::CELL_DATA;
10+
11+
use crate::template::util::TypeOptionCellData;
1012
use collab::util::AnyMapExt;
1113
use serde::{Deserialize, Serialize};
1214
use serde_json::{json, Value};
@@ -290,6 +292,12 @@ impl SelectOptionIds {
290292
}
291293
}
292294

295+
impl TypeOptionCellData for SelectOptionIds {
296+
fn is_empty(&self) -> bool {
297+
self.0.is_empty()
298+
}
299+
}
300+
293301
pub const SELECTION_IDS_SEPARATOR: &str = ",";
294302

295303
impl std::convert::From<Vec<String>> for SelectOptionIds {

collab-database/src/fields/type_option/url_type_option.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::fields::{
55
};
66
use crate::rows::{new_cell_builder, Cell};
77
use crate::template::entity::CELL_DATA;
8+
use crate::template::util::TypeOptionCellData;
89
use collab::preclude::Any;
910
use collab::util::AnyMapExt;
1011
use serde::{Deserialize, Serialize};
@@ -62,6 +63,12 @@ pub struct URLCellData {
6263
pub data: String,
6364
}
6465

66+
impl TypeOptionCellData for URLCellData {
67+
fn is_empty(&self) -> bool {
68+
self.data.is_empty()
69+
}
70+
}
71+
6572
impl AsRef<str> for URLCellData {
6673
fn as_ref(&self) -> &str {
6774
&self.data

collab-database/src/template/check_list_parse.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::database::gen_option_id;
22
use crate::fields::select_type_option::{SelectOption, SelectOptionColor};
3+
use crate::template::util::TypeOptionCellData;
34
use serde::{Deserialize, Serialize};
45

56
#[derive(Default, Clone, Serialize, Deserialize)]
@@ -9,6 +10,12 @@ pub struct ChecklistCellData {
910
pub selected_option_ids: Vec<String>,
1011
}
1112

13+
impl TypeOptionCellData for ChecklistCellData {
14+
fn is_empty(&self) -> bool {
15+
self.options.is_empty()
16+
}
17+
}
18+
1219
impl From<(Vec<String>, Vec<String>)> for ChecklistCellData {
1320
fn from((names, selected_names): (Vec<String>, Vec<String>)) -> Self {
1421
let options: Vec<SelectOption> = names

collab-database/src/template/relation_parse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::entity::FieldType;
2+
23
use crate::rows::{new_cell_builder, Cell, RowId};
34
use crate::template::entity::CELL_DATA;
5+
use crate::template::util::TypeOptionCellData;
46
use serde::{Deserialize, Serialize};
57
use std::sync::Arc;
68
use yrs::Any;
@@ -10,6 +12,12 @@ pub struct RelationCellData {
1012
pub row_ids: Vec<RowId>,
1113
}
1214

15+
impl TypeOptionCellData for RelationCellData {
16+
fn is_empty(&self) -> bool {
17+
self.row_ids.is_empty()
18+
}
19+
}
20+
1321
impl From<&Cell> for RelationCellData {
1422
fn from(value: &Cell) -> Self {
1523
let row_ids = match value.get(CELL_DATA) {

collab-database/src/template/summary_parse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
use crate::entity::FieldType;
22
use crate::rows::{new_cell_builder, Cell};
33
use crate::template::entity::CELL_DATA;
4+
use crate::template::util::TypeOptionCellData;
45
use collab::util::AnyMapExt;
56
use serde::{Deserialize, Serialize};
67

78
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
89
pub struct SummaryCellData(pub String);
10+
11+
impl TypeOptionCellData for SummaryCellData {
12+
fn is_empty(&self) -> bool {
13+
self.0.is_empty()
14+
}
15+
}
16+
917
impl std::ops::Deref for SummaryCellData {
1018
type Target = String;
1119

collab-database/src/template/timestamp_parse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::entity::FieldType;
22
use crate::rows::{new_cell_builder, Cell};
33
use crate::template::entity::CELL_DATA;
4+
5+
use crate::template::util::TypeOptionCellData;
46
use collab::util::AnyMapExt;
57
use serde::{Deserialize, Serialize};
68

@@ -9,6 +11,12 @@ pub struct TimestampCellData {
911
pub timestamp: Option<i64>,
1012
}
1113

14+
impl TypeOptionCellData for TimestampCellData {
15+
fn is_empty(&self) -> bool {
16+
self.timestamp.is_none()
17+
}
18+
}
19+
1220
impl TimestampCellData {
1321
pub fn new<T: Into<Option<i64>>>(timestamp: T) -> Self {
1422
Self {

collab-database/src/template/translate_parse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
use crate::entity::FieldType;
22
use crate::rows::{new_cell_builder, Cell};
33
use crate::template::entity::CELL_DATA;
4+
use crate::template::util::TypeOptionCellData;
45
use collab::util::AnyMapExt;
56
use serde::{Deserialize, Serialize};
67

78
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
89
pub struct TranslateCellData(pub String);
10+
11+
impl TypeOptionCellData for TranslateCellData {
12+
fn is_empty(&self) -> bool {
13+
self.0.is_empty()
14+
}
15+
}
16+
917
impl std::ops::Deref for TranslateCellData {
1018
type Target = String;
1119

collab-database/src/template/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ use crate::template::entity::DatabaseTemplate;
77
use crate::workspace_database::NoPersistenceDatabaseCollabService;
88
use std::sync::Arc;
99

10+
/// This trait that provides methods to extend the [TypeOption::CellData] functionalities.
11+
pub trait TypeOptionCellData {
12+
/// Checks if the cell content is considered empty based on certain criteria. e.g. empty text,
13+
/// no date selected, no selected options
14+
fn is_empty(&self) -> bool;
15+
}
16+
1017
pub async fn database_from_template(template: DatabaseTemplate) -> Result<Database, DatabaseError> {
1118
let params = create_database_params_from_template(template);
1219
let context = DatabaseContext {

0 commit comments

Comments
 (0)