Skip to content

Commit

Permalink
feat: custom field icons
Browse files Browse the repository at this point in the history
  • Loading branch information
richardshiue committed Sep 27, 2024
1 parent 44efb82 commit 480e81c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
7 changes: 6 additions & 1 deletion collab-database/src/fields/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Field {
pub id: String,
pub name: String,
pub field_type: i64,
pub icon: String,
pub type_options: TypeOptions,
#[serde(default = "DEFAULT_IS_PRIMARY_VALUE")]
pub is_primary: bool,
Expand All @@ -21,8 +22,8 @@ impl Field {
id,
name,
field_type,
type_options: Default::default(),
is_primary,
..Default::default()
}
}

Expand Down Expand Up @@ -83,6 +84,7 @@ impl<'a, 'b, 'c> FieldUpdate<'a, 'b, 'c> {
}

impl_str_update!(set_name, set_name_if_not_none, FIELD_NAME);
impl_str_update!(set_icon, set_icon_if_not_none, FIELD_ICON);
impl_bool_update!(set_primary, set_primary_if_not_none, FIELD_PRIMARY);
impl_i64_update!(set_field_type, set_field_type_if_not_none, FIELD_TYPE);
impl_i64_update!(set_created_at, set_created_at_if_not_none, CREATED_AT);
Expand Down Expand Up @@ -129,6 +131,7 @@ impl<'a, 'b, 'c> FieldUpdate<'a, 'b, 'c> {

const FIELD_ID: &str = "id";
const FIELD_NAME: &str = "name";
const FIELD_ICON: &str = "icon";
const FIELD_TYPE: &str = "ty";
const FIELD_TYPE_OPTION: &str = "type_option";
const FIELD_PRIMARY: &str = "is_primary";
Expand Down Expand Up @@ -162,6 +165,7 @@ pub fn field_from_value<T: ReadTxn>(value: YrsValue, txn: &T) -> Option<Field> {
pub fn field_from_map_ref<T: ReadTxn>(map_ref: &MapRef, txn: &T) -> Option<Field> {
let id: String = map_ref.get_with_txn(txn, FIELD_ID)?;
let name: String = map_ref.get_with_txn(txn, FIELD_NAME).unwrap_or_default();
let icon: String = map_ref.get_with_txn(txn, FIELD_ICON).unwrap_or_default();

let type_options: TypeOptions = map_ref
.get_with_txn(txn, FIELD_TYPE_OPTION)
Expand All @@ -175,6 +179,7 @@ pub fn field_from_map_ref<T: ReadTxn>(map_ref: &MapRef, txn: &T) -> Option<Field
Some(Field {
id,
name,
icon,
field_type,
type_options,
is_primary,
Expand Down
1 change: 1 addition & 0 deletions collab-database/src/fields/field_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl FieldMap {
.update(|update| {
update
.set_name(field.name)
.set_icon(field.icon)
.set_created_at(timestamp())
.set_last_modified(timestamp())
.set_primary(field.is_primary)
Expand Down
26 changes: 3 additions & 23 deletions collab-database/tests/user_test/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,29 +359,9 @@ pub async fn test_timeout<F: Future>(f: F) -> F::Output {
pub fn make_default_grid(view_id: &str, name: &str) -> CreateDatabaseParams {
let database_id = gen_database_id();

let text_field = Field {
id: gen_field_id(),
name: "Name".to_string(),
field_type: 0,
type_options: Default::default(),
is_primary: true,
};

let single_select_field = Field {
id: gen_field_id(),
name: "Status".to_string(),
field_type: 3,
type_options: Default::default(),
is_primary: false,
};

let checkbox_field = Field {
id: gen_field_id(),
name: "Done".to_string(),
field_type: 4,
type_options: Default::default(),
is_primary: false,
};
let text_field = Field::new(gen_field_id(), "Name".to_string(), 0, true);
let single_select_field = Field::new(gen_field_id(), "Status".to_string(), 3, false);
let checkbox_field = Field::new(gen_field_id(), "Done".to_string(), 4, false);

let field_settings_map = field_settings_for_default_database();

Expand Down
1 change: 0 additions & 1 deletion collab-entity/src/proto/collab.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// This file is @generated by prost-build.
/// Identifier of an active collab document sent over pubsub
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down

0 comments on commit 480e81c

Please sign in to comment.