Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: get all calendar events not fetching empty ones (#6508)
Richard Shiue93885bad7b0e
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dartindex e0bcc071ed..4b5ab8e201 100644--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dart@@ -42,7 +42,7 @@ class UnscheduleEventsBlocstate.copyWith(allEvents: events,unscheduleEvents:- events.where((element) => !element.isScheduled).toList(),+ events.where((element) => !element.hasTimestamp()).toList(),),);},@@ -55,7 +55,7 @@ class UnscheduleEventsBlocstate.copyWith(allEvents: events,unscheduleEvents:- events.where((element) => !element.isScheduled).toList(),+ events.where((element) => !element.hasTimestamp()).toList(),),);},@@ -65,7 +65,7 @@ class UnscheduleEventsBlocstate.copyWith(allEvents: events,unscheduleEvents:- events.where((element) => !element.isScheduled).toList(),+ events.where((element) => !element.hasTimestamp()).toList(),),);},diff --git a/frontend/rust-lib/flowy-database2/src/entities/calendar_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/calendar_entities.rsindex e757ce4407..6ab424a230 100644--- a/frontend/rust-lib/flowy-database2/src/entities/calendar_entities.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/calendar_entities.rs@@ -108,11 +108,8 @@ pub struct CalendarEventPB {#[pb(index = 3)]pub title: String,- #[pb(index = 4)]- pub timestamp: i64,-- #[pb(index = 5)]- pub is_scheduled: bool,+ #[pb(index = 4, one_of)]+ pub timestamp: Option<i64>,}#[derive(Debug, Clone, Default, ProtoBuf)]diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rsindex fa6a53939f..998f57c6e9 100644--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs@@ -18,9 +18,7 @@ use crate::services::cell::{CellBuilder, CellCache};use crate::services::database::{database_view_setting_pb_from_view, DatabaseRowEvent, UpdatedRow};use crate::services::database_view::view_calculations::make_calculations_controller;use crate::services::database_view::view_filter::make_filter_controller;-use crate::services::database_view::view_group::{- get_cell_for_row, get_cells_for_field, new_group_controller,-};+use crate::services::database_view::view_group::{get_cell_for_row, new_group_controller};use crate::services::database_view::view_operation::DatabaseViewOperation;use crate::services::database_view::view_sort::make_sort_controller;use crate::services::database_view::{@@ -1029,16 +1027,15 @@ impl DatabaseViewEditor {let timestamp = date_cell.into_date_field_cell_data().unwrap_or_default()- .timestamp- .unwrap_or_default();+ .timestamp;let (_, row_detail) = self.delegate.get_row_detail(&self.view_id, &row_id).await?;+Some(CalendarEventPB {row_meta: RowMetaPB::from(row_detail.as_ref().clone()),date_field_id: date_field.id.clone(),title,timestamp,- is_scheduled: timestamp != 0,})}@@ -1056,53 +1053,34 @@ impl DatabaseViewEditor {Some(calendar_setting) => calendar_setting,};- // Textlet primary_field = self.delegate.get_primary_field().await?;- let mut primary_cells =- get_cells_for_field(self.delegate.clone(), &self.view_id, &primary_field.id).await;-- // Date- let timestamp_cells = get_cells_for_field(- self.delegate.clone(),- &self.view_id,- &calendar_setting.field_id,- )- .await;let mut events: Vec<CalendarEventPB> = vec![];- for timestamp_cell in timestamp_cells {- let row_id = timestamp_cell.row_id.clone();- let index = primary_cells- .iter()- .position(|text_cell| text_cell.row_id == row_id);++ let rows = self.v_get_all_rows().await;++ for row in rows {+ let primary_cell = get_cell_for_row(self.delegate.clone(), &primary_field.id, &row.id).await;+ let timestamp_cell =+ get_cell_for_row(self.delegate.clone(), &calendar_setting.field_id, &row.id).await;let timestamp = timestamp_cell- .into_date_field_cell_data()- .map(|date_cell_data| date_cell_data.timestamp.unwrap_or_default())- .unwrap_or_default();+ .and_then(|cell| cell.into_date_field_cell_data())+ .and_then(|cell_data| cell_data.timestamp);- // The cell for given primary field might be empty.- // If yes, return empty string- // If not, return the text for the cell- let title = match index {- None => "".to_string(),- Some(index) => {- let text_cell = primary_cells.remove(index);- text_cell- .into_text_field_cell_data()- .unwrap_or_default()- .into()- },- };+ let title = primary_cell+ .and_then(|cell| cell.into_text_field_cell_data())+ .map(|cell_data| cell_data.into())+ .unwrap_or_default();- let (_, row_detail) = self.delegate.get_row_detail(&self.view_id, &row_id).await?;+ let (_, row_detail) = self.delegate.get_row_detail(&self.view_id, &row.id).await?;let event = CalendarEventPB {row_meta: RowMetaPB::from(row_detail.as_ref().clone()),date_field_id: calendar_setting.field_id.clone(),title,timestamp,- is_scheduled: timestamp != 0,};+events.push(event);}diff --git a/frontend/rust-lib/flowy-database2/tests/database/layout_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/layout_test/script.rsindex 57f17b9870..6da423d371 100644--- a/frontend/rust-lib/flowy-database2/tests/database/layout_test/script.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/layout_test/script.rs@@ -132,20 +132,20 @@ impl DatabaseLayoutTest {for (index, event) in events.into_iter().enumerate() {if index == 0 {assert_eq!(event.title, "A");- assert_eq!(event.timestamp, 1678090778);+ assert_eq!(event.timestamp, Some(1678090778));}if index == 1 {assert_eq!(event.title, "B");- assert_eq!(event.timestamp, 1677917978);+ assert_eq!(event.timestamp, Some(1677917978));}if index == 2 {assert_eq!(event.title, "C");- assert_eq!(event.timestamp, 1679213978);+ assert_eq!(event.timestamp, Some(1679213978));}if index == 4 {assert_eq!(event.title, "E");- assert_eq!(event.timestamp, 1678695578);+ assert_eq!(event.timestamp, Some(1678695578));}}},diff --git a/frontend/rust-lib/flowy-database2/tests/database/layout_test/test.rs b/frontend/rust-lib/flowy-database2/tests/database/layout_test/test.rsindex 0812dcc1a2..41f2f88d0e 100644--- a/frontend/rust-lib/flowy-database2/tests/database/layout_test/test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/layout_test/test.rs@@ -52,7 +52,7 @@ async fn grid_to_calendar_layout_test() {UpdateDatabaseLayout {layout: DatabaseLayout::Calendar,},- AssertAllCalendarEventsCount { expected: 0 },+ AssertAllCalendarEventsCount { expected: 3 },];test.run_scripts(scripts).await;}