Skip to content

Commit

Permalink
fix: merge main problems
Browse files Browse the repository at this point in the history
  • Loading branch information
zoli committed Sep 8, 2024
1 parent 31f4214 commit 0877e41
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 86 deletions.
13 changes: 13 additions & 0 deletions frontend/rust-lib/flowy-database2/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ pub(crate) async fn get_row_handler(
data_result_ok(OptionalRowPB { row })
}

pub(crate) async fn init_row_handler(
data: AFPluginData<DatabaseViewRowIdPB>,
manager: AFPluginState<Weak<DatabaseManager>>,
) -> Result<(), FlowyError> {
let manager = upgrade_manager(manager)?;
let params: RowIdParams = data.into_inner().try_into()?;
let database_editor = manager
.get_database_editor_with_view_id(&params.view_id)
.await?;
database_editor.init_database_row(&params.row_id).await?;
Ok(())
}

pub(crate) async fn get_row_meta_handler(
data: AFPluginData<DatabaseViewRowIdPB>,
manager: AFPluginState<Weak<DatabaseManager>>,
Expand Down
169 changes: 85 additions & 84 deletions frontend/rust-lib/flowy-database2/src/event_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,91 @@ pub fn init(database_manager: Weak<DatabaseManager>) -> AFPlugin {
.name(env!("CARGO_PKG_NAME"))
.state(database_manager);
plugin
.event(DatabaseEvent::GetDatabase, get_database_data_handler)
.event(DatabaseEvent::GetDatabaseData, get_database_data_handler)
.event(DatabaseEvent::GetDatabaseId, get_database_id_handler)
.event(DatabaseEvent::GetDatabaseSetting, get_database_setting_handler)
.event(DatabaseEvent::UpdateDatabaseSetting, update_database_setting_handler)
.event(DatabaseEvent::GetAllFilters, get_all_filters_handler)
.event(DatabaseEvent::GetAllSorts, get_all_sorts_handler)
.event(DatabaseEvent::DeleteAllSorts, delete_all_sorts_handler)
// Field
.event(DatabaseEvent::GetFields, get_fields_handler)
.event(DatabaseEvent::GetPrimaryField, get_primary_field_handler)
.event(DatabaseEvent::UpdateField, update_field_handler)
.event(DatabaseEvent::UpdateFieldTypeOption, update_field_type_option_handler)
.event(DatabaseEvent::DeleteField, delete_field_handler)
.event(DatabaseEvent::ClearField, clear_field_handler)
.event(DatabaseEvent::UpdateFieldType, switch_to_field_handler)
.event(DatabaseEvent::DuplicateField, duplicate_field_handler)
.event(DatabaseEvent::MoveField, move_field_handler)
.event(DatabaseEvent::CreateField, create_field_handler)
// Row
.event(DatabaseEvent::CreateRow, create_row_handler)
.event(DatabaseEvent::GetRow, get_row_handler)
.event(DatabaseEvent::GetRowMeta, get_row_meta_handler)
.event(DatabaseEvent::UpdateRowMeta, update_row_meta_handler)
.event(DatabaseEvent::DeleteRows, delete_rows_handler)
.event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
.event(DatabaseEvent::MoveRow, move_row_handler)
// Cell
.event(DatabaseEvent::GetCell, get_cell_handler)
.event(DatabaseEvent::UpdateCell, update_cell_handler)
// SelectOption
.event(DatabaseEvent::CreateSelectOption, new_select_option_handler)
.event(DatabaseEvent::InsertOrUpdateSelectOption, insert_or_update_select_option_handler)
.event(DatabaseEvent::DeleteSelectOption, delete_select_option_handler)
.event(DatabaseEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
// Checklist
.event(DatabaseEvent::UpdateChecklistCell, update_checklist_cell_handler)
// Date
.event(DatabaseEvent::UpdateDateCell, update_date_cell_handler)
// Group
.event(DatabaseEvent::SetGroupByField, set_group_by_field_handler)
.event(DatabaseEvent::MoveGroup, move_group_handler)
.event(DatabaseEvent::MoveGroupRow, move_group_row_handler)
.event(DatabaseEvent::GetGroups, get_groups_handler)
.event(DatabaseEvent::GetGroup, get_group_handler)
.event(DatabaseEvent::UpdateGroup, update_group_handler)
.event(DatabaseEvent::CreateGroup, create_group_handler)
.event(DatabaseEvent::DeleteGroup, delete_group_handler)
// Database
.event(DatabaseEvent::GetDatabaseMeta, get_database_meta_handler)
.event(DatabaseEvent::GetDatabases, get_databases_handler)
// Calendar
.event(DatabaseEvent::GetAllCalendarEvents, get_calendar_events_handler)
.event(DatabaseEvent::GetNoDateCalendarEvents, get_no_date_calendar_events_handler)
.event(DatabaseEvent::GetCalendarEvent, get_calendar_event_handler)
.event(DatabaseEvent::MoveCalendarEvent, move_calendar_event_handler)
// Layout setting
.event(DatabaseEvent::SetLayoutSetting, set_layout_setting_handler)
.event(DatabaseEvent::GetLayoutSetting, get_layout_setting_handler)
.event(DatabaseEvent::CreateDatabaseView, create_database_view)
// Export
.event(DatabaseEvent::ExportCSV, export_csv_handler)
.event(DatabaseEvent::GetDatabaseSnapshots, get_snapshots_handler)
// Field settings
.event(DatabaseEvent::GetFieldSettings, get_field_settings_handler)
.event(DatabaseEvent::GetAllFieldSettings, get_all_field_settings_handler)
.event(DatabaseEvent::UpdateFieldSettings, update_field_settings_handler)
// Calculations
.event(DatabaseEvent::GetAllCalculations, get_all_calculations_handler)
.event(DatabaseEvent::UpdateCalculation, update_calculation_handler)
.event(DatabaseEvent::RemoveCalculation, remove_calculation_handler)
// Relation
.event(DatabaseEvent::GetRelatedDatabaseIds, get_related_database_ids_handler)
.event(DatabaseEvent::UpdateRelationCell, update_relation_cell_handler)
.event(DatabaseEvent::GetRelatedRowDatas, get_related_row_datas_handler)
.event(DatabaseEvent::GetRelatedDatabaseRows, get_related_database_rows_handler)
// AI
.event(DatabaseEvent::SummarizeRow, summarize_row_handler)
.event(DatabaseEvent::TranslateRow, translate_row_handler)
// Time field
.event(DatabaseEvent::UpdateTimeCell, update_time_cell_handler)
// Media
.event(DatabaseEvent::UpdateMediaCell, update_media_cell_handler)
.event(DatabaseEvent::RenameMediaFile, rename_media_cell_file_handler)
.event(DatabaseEvent::GetDatabase, get_database_data_handler)
.event(DatabaseEvent::GetDatabaseData, get_database_data_handler)
.event(DatabaseEvent::GetDatabaseId, get_database_id_handler)
.event(DatabaseEvent::GetDatabaseSetting, get_database_setting_handler)
.event(DatabaseEvent::UpdateDatabaseSetting, update_database_setting_handler)
.event(DatabaseEvent::GetAllFilters, get_all_filters_handler)
.event(DatabaseEvent::GetAllSorts, get_all_sorts_handler)
.event(DatabaseEvent::DeleteAllSorts, delete_all_sorts_handler)
// Field
.event(DatabaseEvent::GetFields, get_fields_handler)
.event(DatabaseEvent::GetPrimaryField, get_primary_field_handler)
.event(DatabaseEvent::UpdateField, update_field_handler)
.event(DatabaseEvent::UpdateFieldTypeOption, update_field_type_option_handler)
.event(DatabaseEvent::DeleteField, delete_field_handler)
.event(DatabaseEvent::ClearField, clear_field_handler)
.event(DatabaseEvent::UpdateFieldType, switch_to_field_handler)
.event(DatabaseEvent::DuplicateField, duplicate_field_handler)
.event(DatabaseEvent::MoveField, move_field_handler)
.event(DatabaseEvent::CreateField, create_field_handler)
// Row
.event(DatabaseEvent::CreateRow, create_row_handler)
.event(DatabaseEvent::GetRow, get_row_handler)
.event(DatabaseEvent::InitRow, init_row_handler)
.event(DatabaseEvent::GetRowMeta, get_row_meta_handler)
.event(DatabaseEvent::UpdateRowMeta, update_row_meta_handler)
.event(DatabaseEvent::DeleteRows, delete_rows_handler)
.event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
.event(DatabaseEvent::MoveRow, move_row_handler)
// Cell
.event(DatabaseEvent::GetCell, get_cell_handler)
.event(DatabaseEvent::UpdateCell, update_cell_handler)
// SelectOption
.event(DatabaseEvent::CreateSelectOption, new_select_option_handler)
.event(DatabaseEvent::InsertOrUpdateSelectOption, insert_or_update_select_option_handler)
.event(DatabaseEvent::DeleteSelectOption, delete_select_option_handler)
.event(DatabaseEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
// Checklist
.event(DatabaseEvent::UpdateChecklistCell, update_checklist_cell_handler)
// Date
.event(DatabaseEvent::UpdateDateCell, update_date_cell_handler)
// Group
.event(DatabaseEvent::SetGroupByField, set_group_by_field_handler)
.event(DatabaseEvent::MoveGroup, move_group_handler)
.event(DatabaseEvent::MoveGroupRow, move_group_row_handler)
.event(DatabaseEvent::GetGroups, get_groups_handler)
.event(DatabaseEvent::GetGroup, get_group_handler)
.event(DatabaseEvent::UpdateGroup, update_group_handler)
.event(DatabaseEvent::CreateGroup, create_group_handler)
.event(DatabaseEvent::DeleteGroup, delete_group_handler)
// Database
.event(DatabaseEvent::GetDatabaseMeta, get_database_meta_handler)
.event(DatabaseEvent::GetDatabases, get_databases_handler)
// Calendar
.event(DatabaseEvent::GetAllCalendarEvents, get_calendar_events_handler)
.event(DatabaseEvent::GetNoDateCalendarEvents, get_no_date_calendar_events_handler)
.event(DatabaseEvent::GetCalendarEvent, get_calendar_event_handler)
.event(DatabaseEvent::MoveCalendarEvent, move_calendar_event_handler)
// Layout setting
.event(DatabaseEvent::SetLayoutSetting, set_layout_setting_handler)
.event(DatabaseEvent::GetLayoutSetting, get_layout_setting_handler)
.event(DatabaseEvent::CreateDatabaseView, create_database_view)
// Export
.event(DatabaseEvent::ExportCSV, export_csv_handler)
.event(DatabaseEvent::GetDatabaseSnapshots, get_snapshots_handler)
// Field settings
.event(DatabaseEvent::GetFieldSettings, get_field_settings_handler)
.event(DatabaseEvent::GetAllFieldSettings, get_all_field_settings_handler)
.event(DatabaseEvent::UpdateFieldSettings, update_field_settings_handler)
// Calculations
.event(DatabaseEvent::GetAllCalculations, get_all_calculations_handler)
.event(DatabaseEvent::UpdateCalculation, update_calculation_handler)
.event(DatabaseEvent::RemoveCalculation, remove_calculation_handler)
// Relation
.event(DatabaseEvent::GetRelatedDatabaseIds, get_related_database_ids_handler)
.event(DatabaseEvent::UpdateRelationCell, update_relation_cell_handler)
.event(DatabaseEvent::GetRelatedRowDatas, get_related_row_datas_handler)
.event(DatabaseEvent::GetRelatedDatabaseRows, get_related_database_rows_handler)
// AI
.event(DatabaseEvent::SummarizeRow, summarize_row_handler)
.event(DatabaseEvent::TranslateRow, translate_row_handler)
// Time field
.event(DatabaseEvent::UpdateTimeCell, update_time_cell_handler)
// Media
.event(DatabaseEvent::UpdateMediaCell, update_media_cell_handler)
.event(DatabaseEvent::RenameMediaFile, rename_media_cell_file_handler)
}

/// [DatabaseEvent] defines events that are used to interact with the Grid. You could check [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/backend/protobuf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ const TIMER_START: &str = "timer_start";

impl From<&Cell> for TimeCellData {
fn from(cell: &Cell) -> Self {
let time = cell.get_as::<i64>(CELL_DATA);
let timer_start = cell.get_as::<i64>(TIMER_START);
let time = cell
.get_as::<String>(CELL_DATA)
.and_then(|data| data.parse::<i64>().ok());
let timer_start = cell
.get_as::<String>(TIMER_START)
.and_then(|data| data.parse::<i64>().ok());
let time_tracks = cell
.get_as::<String>(TIME_TRACKS)
.map(|data| serde_json::from_str::<Vec<TimeTrack>>(&data).unwrap_or_default())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ async fn update_updated_at_field_on_other_cell_update() {
async fn time_cell_data_test() {
let test = DatabaseCellTest::new().await;
let time_field = test.get_first_field(FieldType::Time).await;
println!("{:?}", time_field);
let cells = test
.editor
.get_cells_for_field(&test.view_id, &time_field.id)
.await;

assert!(cells[0].cell.as_ref().is_some());
let cell = TimeCellData::from(cells[0].cell.as_ref().unwrap());
println!("{:?}", cell);

assert!(cell.time.is_some());
assert_eq!(cell.time.unwrap(), 75);
Expand Down

0 comments on commit 0877e41

Please sign in to comment.