mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Feat/rename views (#2495)
* refactor: rename belongings to child views * test: fix test
This commit is contained in:
parent
bc723f8d0f
commit
2a35787dd1
@ -47,7 +47,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
|
||||
},
|
||||
appDidUpdate: (e) async {
|
||||
final latestCreatedView = state.latestCreatedView;
|
||||
final views = e.app.belongings;
|
||||
final views = e.app.childViews;
|
||||
AppState newState = state.copyWith(
|
||||
views: views,
|
||||
view: e.app,
|
||||
@ -174,7 +174,7 @@ class AppState with _$AppState {
|
||||
|
||||
factory AppState.initial(ViewPB view) => AppState(
|
||||
view: view,
|
||||
views: view.belongings,
|
||||
views: view.childViews,
|
||||
successOrFailure: left(unit),
|
||||
);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class AppBackendService {
|
||||
|
||||
return FolderEventReadView(payload).send().then((result) {
|
||||
return result.fold(
|
||||
(app) => left(app.belongings),
|
||||
(app) => left(app.childViews),
|
||||
(error) => right(error),
|
||||
);
|
||||
});
|
||||
@ -130,7 +130,7 @@ class AppBackendService {
|
||||
return FolderEventReadView(payload).send().then((result) {
|
||||
return result.fold(
|
||||
(app) => left(
|
||||
app.belongings.firstWhere((e) => e.id == childViewID),
|
||||
app.childViews.firstWhere((e) => e.id == childViewID),
|
||||
),
|
||||
(error) => right(error),
|
||||
);
|
||||
|
@ -32,7 +32,7 @@ class SettingsFileExportState {
|
||||
expanded = views.map((e) => true).toList();
|
||||
selectedApps = views.map((e) => true).toList();
|
||||
selectedItems =
|
||||
views.map((e) => e.belongings.map((e) => true).toList()).toList();
|
||||
views.map((e) => e.childViews.map((e) => true).toList()).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ class SettingsFileExporterCubit extends Cubit<SettingsFileExportState> {
|
||||
final ids = <String>[];
|
||||
for (var j = 0; j < selectedItem.length; j++) {
|
||||
if (selectedItem[j]) {
|
||||
ids.add(apps[i].belongings[j].id);
|
||||
ids.add(apps[i].childViews[j].id);
|
||||
}
|
||||
}
|
||||
if (ids.isNotEmpty) {
|
||||
|
@ -275,7 +275,7 @@ class HomeScreenStackAdaptor extends HomeStackDelegate {
|
||||
homeService.readApp(appId: view.parentViewId).then((result) {
|
||||
result.fold(
|
||||
(parentView) {
|
||||
final List<ViewPB> views = parentView.belongings;
|
||||
final List<ViewPB> views = parentView.childViews;
|
||||
if (views.isNotEmpty) {
|
||||
var lastView = views.last;
|
||||
if (index != null && index != 0 && views.length > index - 1) {
|
||||
|
@ -135,7 +135,7 @@ class _ExpandedListState extends State<_ExpandedList> {
|
||||
List<Widget> expandedChildren = [];
|
||||
if (isExpaned) {
|
||||
for (var i = 0; i < selectedItems[index].length; i++) {
|
||||
final name = apps[index].belongings[i].name;
|
||||
final name = apps[index].childViews[i].name;
|
||||
final checkbox = CheckboxListTile(
|
||||
value: selectedItems[index][i],
|
||||
onChanged: (value) {
|
||||
|
@ -43,7 +43,7 @@ class TrashTestContext {
|
||||
);
|
||||
await blocResponseFuture();
|
||||
|
||||
allViews = [...appBloc.state.view.belongings];
|
||||
allViews = [...appBloc.state.view.childViews];
|
||||
assert(allViews.length == 3, 'but receive ${allViews.length}');
|
||||
}
|
||||
}
|
||||
@ -68,17 +68,17 @@ void main() {
|
||||
await blocResponseFuture(millisecond: 200);
|
||||
|
||||
// delete a view
|
||||
final deletedView = context.appBloc.state.view.belongings[0];
|
||||
final deletedView = context.appBloc.state.view.childViews[0];
|
||||
context.appBloc.add(AppEvent.deleteView(deletedView.id));
|
||||
await blocResponseFuture();
|
||||
assert(context.appBloc.state.view.belongings.length == 2);
|
||||
assert(context.appBloc.state.view.childViews.length == 2);
|
||||
assert(trashBloc.state.objects.length == 1);
|
||||
assert(trashBloc.state.objects.first.id == deletedView.id);
|
||||
|
||||
// put back
|
||||
trashBloc.add(TrashEvent.putback(deletedView.id));
|
||||
await blocResponseFuture();
|
||||
assert(context.appBloc.state.view.belongings.length == 3);
|
||||
assert(context.appBloc.state.view.childViews.length == 3);
|
||||
assert(trashBloc.state.objects.isEmpty);
|
||||
|
||||
// delete all views
|
||||
|
@ -23,7 +23,7 @@ export const useWorkspace = () => {
|
||||
for (const app of apps) {
|
||||
appDispatch(foldersActions.addFolder({ id: app.id, title: app.name }));
|
||||
|
||||
const views = app.belongings;
|
||||
const views = app.child_views;
|
||||
for (const view of views) {
|
||||
appDispatch(pagesActions.addPage({ folderId: app.id, id: view.id, pageType: view.layout, title: view.name }));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ export class AppBackendService {
|
||||
getAllViews = (): Promise<Result<ViewPB[], FlowyError>> => {
|
||||
const payload = ViewIdPB.fromObject({ value: this.appId });
|
||||
return FolderEventReadView(payload).then((result) => {
|
||||
return result.map((app) => app.belongings);
|
||||
return result.map((app) => app.child_views);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -171,7 +171,7 @@ mod tests {
|
||||
date: Some("1653609600".to_owned()),
|
||||
time: Some("11:23 pm".to_owned()),
|
||||
include_time: Some(true),
|
||||
timezone_id: Some("Etc/UTC".to_owned()),
|
||||
timezone_id: Some(chrono_tz::Tz::Etc__UTC.to_string()),
|
||||
},
|
||||
None,
|
||||
"May 27, 2022 11:23 PM",
|
||||
|
@ -84,7 +84,7 @@ impl DateTypeOption {
|
||||
let naive = chrono::NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap();
|
||||
let offset = match Tz::from_str(&timezone_id) {
|
||||
Ok(timezone) => timezone.offset_from_utc_datetime(&naive).fix(),
|
||||
Err(_) => Local::now().offset().clone(),
|
||||
Err(_) => *Local::now().offset(),
|
||||
};
|
||||
|
||||
let date_time = DateTime::<Local>::from_utc(naive, offset);
|
||||
@ -206,9 +206,8 @@ impl CellDataChangeset for DateTypeOption {
|
||||
.from_utc_datetime(&NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap())
|
||||
.date_naive(),
|
||||
),
|
||||
None => match previous_datetime {
|
||||
Some(datetime) => Some(timezone.from_utc_datetime(&datetime).date_naive()),
|
||||
None => None,
|
||||
None => {
|
||||
previous_datetime.map(|datetime| timezone.from_utc_datetime(&datetime).date_naive())
|
||||
},
|
||||
};
|
||||
|
||||
@ -231,17 +230,15 @@ impl CellDataChangeset for DateTypeOption {
|
||||
Err(_) => match parsed_time {
|
||||
// same logic as above, but using local time instead of timezone
|
||||
Some(time) => {
|
||||
let offset = Local::now().offset().clone();
|
||||
|
||||
let offset = *Local::now().offset();
|
||||
let local_date = match new_date_timestamp {
|
||||
Some(timestamp) => Some(
|
||||
offset
|
||||
.from_utc_datetime(&NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap())
|
||||
.date_naive(),
|
||||
),
|
||||
None => match previous_datetime {
|
||||
Some(datetime) => Some(offset.from_utc_datetime(&datetime).date_naive()),
|
||||
None => None,
|
||||
None => {
|
||||
previous_datetime.map(|datetime| offset.from_utc_datetime(&datetime).date_naive())
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -64,8 +64,7 @@ impl From<&Cell> for DateCellData {
|
||||
fn from(cell: &Cell) -> Self {
|
||||
let timestamp = cell
|
||||
.get_str_value(CELL_DATE)
|
||||
.map(|data| data.parse::<i64>().ok())
|
||||
.flatten();
|
||||
.and_then(|data| data.parse::<i64>().ok());
|
||||
|
||||
let include_time = cell.get_bool_value("include_time").unwrap_or_default();
|
||||
let timezone_id = cell.get_str_value("timezone_id").unwrap_or_default();
|
||||
|
@ -46,7 +46,8 @@ impl DatabaseCellTest {
|
||||
&changeset.field_id,
|
||||
changeset.cell_changeset,
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
.unwrap();
|
||||
}, // CellScript::AssertGridRevisionPad => {
|
||||
// sleep(Duration::from_millis(2 * REVISION_WRITE_INTERVAL_IN_MILLIS)).await;
|
||||
// let mut grid_rev_manager = grid_manager.make_grid_rev_manager(&self.grid_id, pool.clone()).unwrap();
|
||||
|
@ -12,6 +12,7 @@ use flowy_database2::services::field::{
|
||||
CheckboxTypeOption, ChecklistTypeOption, DateCellChangeset, MultiSelectTypeOption, SelectOption,
|
||||
SelectOptionCellChangeset, SingleSelectTypeOption,
|
||||
};
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_test::helper::ViewTest;
|
||||
use flowy_test::FlowySDKTest;
|
||||
|
||||
@ -172,7 +173,7 @@ impl DatabaseEditorTest {
|
||||
field_id: &str,
|
||||
row_id: RowId,
|
||||
cell_changeset: T,
|
||||
) {
|
||||
) -> FlowyResult<()> {
|
||||
let field = self
|
||||
.editor
|
||||
.get_fields(&self.view_id, None)
|
||||
@ -183,10 +184,10 @@ impl DatabaseEditorTest {
|
||||
self
|
||||
.editor
|
||||
.update_cell_with_changeset(&self.view_id, row_id, &field.id, cell_changeset)
|
||||
.await;
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn update_text_cell(&mut self, row_id: RowId, content: &str) {
|
||||
pub(crate) async fn update_text_cell(&mut self, row_id: RowId, content: &str) -> FlowyResult<()> {
|
||||
let field = self
|
||||
.editor
|
||||
.get_fields(&self.view_id, None)
|
||||
@ -200,10 +201,14 @@ impl DatabaseEditorTest {
|
||||
|
||||
self
|
||||
.update_cell(&field.id, row_id, content.to_string())
|
||||
.await;
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn update_single_select_cell(&mut self, row_id: RowId, option_id: &str) {
|
||||
pub(crate) async fn update_single_select_cell(
|
||||
&mut self,
|
||||
row_id: RowId,
|
||||
option_id: &str,
|
||||
) -> FlowyResult<()> {
|
||||
let field = self
|
||||
.editor
|
||||
.get_fields(&self.view_id, None)
|
||||
@ -216,7 +221,7 @@ impl DatabaseEditorTest {
|
||||
.clone();
|
||||
|
||||
let cell_changeset = SelectOptionCellChangeset::from_insert_option_id(option_id);
|
||||
self.update_cell(&field.id, row_id, cell_changeset).await;
|
||||
self.update_cell(&field.id, row_id, cell_changeset).await
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,12 +258,18 @@ impl TestRowBuilder {
|
||||
number_field.id.clone()
|
||||
}
|
||||
|
||||
pub fn insert_date_cell(&mut self, data: &str) -> String {
|
||||
pub fn insert_date_cell(
|
||||
&mut self,
|
||||
data: &str,
|
||||
time: Option<String>,
|
||||
include_time: Option<bool>,
|
||||
timezone_id: Option<String>,
|
||||
) -> String {
|
||||
let value = serde_json::to_string(&DateCellChangeset {
|
||||
date: Some(data.to_string()),
|
||||
time: None,
|
||||
include_time: Some(false),
|
||||
timezone_id: None,
|
||||
time,
|
||||
include_time,
|
||||
timezone_id,
|
||||
})
|
||||
.unwrap();
|
||||
let date_field = self.field_with_type(&FieldType::DateTime);
|
||||
|
@ -131,12 +131,12 @@ impl DatabaseFilterTest {
|
||||
FilterScript::UpdateTextCell { row_id, text, changed} => {
|
||||
self.recv = Some(self.editor.subscribe_view_changed(&self.view_id()).await.unwrap());
|
||||
self.assert_future_changed(changed).await;
|
||||
self.update_text_cell(row_id, &text).await;
|
||||
self.update_text_cell(row_id, &text).await.unwrap();
|
||||
}
|
||||
FilterScript::UpdateSingleSelectCell { row_id, option_id, changed} => {
|
||||
self.recv = Some(self.editor.subscribe_view_changed(&self.view_id()).await.unwrap());
|
||||
self.assert_future_changed(changed).await;
|
||||
self.update_single_select_cell(row_id, &option_id).await;
|
||||
self.update_single_select_cell(row_id, &option_id).await.unwrap();
|
||||
}
|
||||
FilterScript::InsertFilter { payload } => {
|
||||
self.recv = Some(self.editor.subscribe_view_changed(&self.view_id()).await.unwrap());
|
||||
|
@ -183,7 +183,8 @@ impl DatabaseGroupTest {
|
||||
self
|
||||
.editor
|
||||
.update_cell(&self.view_id, row_id, &field_id, cell)
|
||||
.await;
|
||||
.await
|
||||
.unwrap();
|
||||
},
|
||||
GroupScript::UpdateGroupedCellWithData {
|
||||
from_group_index,
|
||||
@ -205,7 +206,8 @@ impl DatabaseGroupTest {
|
||||
self
|
||||
.editor
|
||||
.update_cell(&self.view_id, row_id, &field_id, cell)
|
||||
.await;
|
||||
.await
|
||||
.unwrap();
|
||||
},
|
||||
GroupScript::MoveGroup {
|
||||
from_group_index,
|
||||
|
@ -119,7 +119,12 @@ pub fn make_test_board() -> DatabaseData {
|
||||
FieldType::RichText => row_builder.insert_text_cell("A"),
|
||||
FieldType::Number => row_builder.insert_number_cell("1"),
|
||||
// 1647251762 => Mar 14,2022
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1647251762",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
},
|
||||
@ -137,7 +142,12 @@ pub fn make_test_board() -> DatabaseData {
|
||||
FieldType::RichText => row_builder.insert_text_cell("B"),
|
||||
FieldType::Number => row_builder.insert_number_cell("2"),
|
||||
// 1647251762 => Mar 14,2022
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1647251762",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
},
|
||||
@ -154,7 +164,12 @@ pub fn make_test_board() -> DatabaseData {
|
||||
FieldType::RichText => row_builder.insert_text_cell("C"),
|
||||
FieldType::Number => row_builder.insert_number_cell("3"),
|
||||
// 1647251762 => Mar 14,2022
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1647251762",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
},
|
||||
@ -174,7 +189,12 @@ pub fn make_test_board() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("DA"),
|
||||
FieldType::Number => row_builder.insert_number_cell("4"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1668704685"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1668704685",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
},
|
||||
@ -189,7 +209,12 @@ pub fn make_test_board() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("AE"),
|
||||
FieldType::Number => row_builder.insert_number_cell(""),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1668359085"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1668359085",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(2))
|
||||
},
|
||||
|
@ -46,7 +46,12 @@ pub fn make_test_calendar() -> DatabaseData {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("A"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1678090778"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1678090778",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
@ -55,7 +60,12 @@ pub fn make_test_calendar() -> DatabaseData {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("B"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1677917978"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1677917978",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
@ -64,7 +74,12 @@ pub fn make_test_calendar() -> DatabaseData {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("C"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1679213978"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1679213978",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
@ -73,7 +88,12 @@ pub fn make_test_calendar() -> DatabaseData {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("D"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1678695578"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1678695578",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
@ -82,7 +102,12 @@ pub fn make_test_calendar() -> DatabaseData {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("E"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1678695578"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1678695578",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
|
@ -118,7 +118,12 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("A"),
|
||||
FieldType::Number => row_builder.insert_number_cell("1"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1647251762",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::MultiSelect => row_builder
|
||||
.insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
|
||||
FieldType::Checklist => row_builder.insert_checklist_cell(|options| options),
|
||||
@ -135,7 +140,12 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell(""),
|
||||
FieldType::Number => row_builder.insert_number_cell("2"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1647251762",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::MultiSelect => row_builder
|
||||
.insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(1)]),
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
|
||||
@ -148,7 +158,12 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("C"),
|
||||
FieldType::Number => row_builder.insert_number_cell("3"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1647251762",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
},
|
||||
@ -165,7 +180,12 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("DA"),
|
||||
FieldType::Number => row_builder.insert_number_cell("4"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1668704685"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1668704685",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
},
|
||||
@ -179,7 +199,12 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("AE"),
|
||||
FieldType::Number => row_builder.insert_number_cell(""),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1668359085"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1668359085",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
},
|
||||
@ -194,7 +219,12 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("AE"),
|
||||
FieldType::Number => row_builder.insert_number_cell("5"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1671938394"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell(
|
||||
"1671938394",
|
||||
None,
|
||||
None,
|
||||
Some(chrono_tz::Tz::Etc__GMTPlus8.to_string()),
|
||||
),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
},
|
||||
|
@ -126,7 +126,7 @@ impl DatabaseSortTest {
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
self.update_text_cell(row_id, &text).await;
|
||||
self.update_text_cell(row_id, &text).await.unwrap();
|
||||
},
|
||||
SortScript::AssertSortChanged {
|
||||
new_row_orders,
|
||||
|
@ -184,7 +184,7 @@ async fn sort_date_by_descending_test() {
|
||||
"2022/03/14",
|
||||
"2022/11/17",
|
||||
"2022/11/13",
|
||||
"2022/12/25",
|
||||
"2022/12/24",
|
||||
],
|
||||
},
|
||||
InsertSort {
|
||||
@ -194,7 +194,7 @@ async fn sort_date_by_descending_test() {
|
||||
AssertCellContentOrder {
|
||||
field_id: date_field.id.clone(),
|
||||
orders: vec![
|
||||
"2022/12/25",
|
||||
"2022/12/24",
|
||||
"2022/11/17",
|
||||
"2022/11/13",
|
||||
"2022/03/14",
|
||||
|
@ -22,22 +22,35 @@ pub struct ViewPB {
|
||||
pub create_time: i64,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub belongings: Vec<ViewPB>,
|
||||
pub child_views: Vec<ViewPB>,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub layout: ViewLayoutPB,
|
||||
}
|
||||
|
||||
impl std::convert::From<View> for ViewPB {
|
||||
fn from(view: View) -> Self {
|
||||
ViewPB {
|
||||
id: view.id,
|
||||
parent_view_id: view.bid,
|
||||
name: view.name,
|
||||
create_time: view.created_at,
|
||||
belongings: Default::default(),
|
||||
layout: view.layout.into(),
|
||||
}
|
||||
pub fn view_pb_without_child_views(view: View) -> ViewPB {
|
||||
ViewPB {
|
||||
id: view.id,
|
||||
parent_view_id: view.bid,
|
||||
name: view.name,
|
||||
create_time: view.created_at,
|
||||
child_views: Default::default(),
|
||||
layout: view.layout.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a ViewPB with child views. Only the first level of child views are included.
|
||||
pub fn view_pb_with_child_views(view: View, child_views: Vec<View>) -> ViewPB {
|
||||
ViewPB {
|
||||
id: view.id,
|
||||
parent_view_id: view.bid,
|
||||
name: view.name,
|
||||
create_time: view.created_at,
|
||||
child_views: child_views
|
||||
.into_iter()
|
||||
.map(view_pb_without_child_views)
|
||||
.collect(),
|
||||
layout: view.layout.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
use crate::entities::{
|
||||
CreateViewParams, CreateViewPayloadPB, CreateWorkspaceParams, CreateWorkspacePayloadPB,
|
||||
MoveFolderItemPayloadPB, MoveViewParams, RepeatedTrashIdPB, RepeatedTrashPB, RepeatedViewIdPB,
|
||||
RepeatedViewPB, RepeatedWorkspacePB, TrashIdPB, UpdateViewParams, UpdateViewPayloadPB, ViewIdPB,
|
||||
ViewPB, WorkspaceIdPB, WorkspacePB, WorkspaceSettingPB,
|
||||
view_pb_without_child_views, CreateViewParams, CreateViewPayloadPB, CreateWorkspaceParams,
|
||||
CreateWorkspacePayloadPB, MoveFolderItemPayloadPB, MoveViewParams, RepeatedTrashIdPB,
|
||||
RepeatedTrashPB, RepeatedViewIdPB, RepeatedViewPB, RepeatedWorkspacePB, TrashIdPB,
|
||||
UpdateViewParams, UpdateViewPayloadPB, ViewIdPB, ViewPB, WorkspaceIdPB, WorkspacePB,
|
||||
WorkspaceSettingPB,
|
||||
};
|
||||
use crate::manager::Folder2Manager;
|
||||
|
||||
@ -85,7 +86,7 @@ pub(crate) async fn create_view_handler(
|
||||
let params: CreateViewParams = data.into_inner().try_into()?;
|
||||
let view = folder.create_view_with_params(params).await?;
|
||||
let _ = folder.set_current_view(&view.id).await;
|
||||
data_result_ok(view.into())
|
||||
data_result_ok(view_pb_without_child_views(view))
|
||||
}
|
||||
|
||||
pub(crate) async fn read_view_handler(
|
||||
@ -103,7 +104,7 @@ pub(crate) async fn update_view_handler(
|
||||
folder: AFPluginState<Arc<Folder2Manager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateViewParams = data.into_inner().try_into()?;
|
||||
let _ = folder.update_view_with_params(params).await?;
|
||||
folder.update_view_with_params(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ use flowy_error::{FlowyError, FlowyResult};
|
||||
use lib_infra::util::timestamp;
|
||||
|
||||
use crate::entities::{
|
||||
CreateViewParams, CreateWorkspaceParams, RepeatedTrashPB, RepeatedViewPB, RepeatedWorkspacePB,
|
||||
UpdateViewParams, ViewPB,
|
||||
view_pb_with_child_views, CreateViewParams, CreateWorkspaceParams, RepeatedTrashPB,
|
||||
RepeatedViewPB, RepeatedWorkspacePB, UpdateViewParams, ViewPB,
|
||||
};
|
||||
use crate::notification::{
|
||||
send_notification, send_workspace_notification, send_workspace_setting_notification,
|
||||
@ -285,14 +285,13 @@ impl Folder2Manager {
|
||||
None => Err(FlowyError::record_not_found()),
|
||||
Some(mut view) => {
|
||||
view.belongings.retain(|b| !trash_ids.contains(&b.id));
|
||||
let mut view_pb: ViewPB = view.into();
|
||||
view_pb.belongings = folder
|
||||
let child_views = folder
|
||||
.views
|
||||
.get_views_belong_to(&view_pb.id)
|
||||
.get_views_belong_to(&view.id)
|
||||
.into_iter()
|
||||
.filter(|view| !trash_ids.contains(&view.id))
|
||||
.map(|view| view.into())
|
||||
.collect::<Vec<ViewPB>>();
|
||||
.collect::<Vec<View>>();
|
||||
let view_pb = view_pb_with_child_views(view, child_views);
|
||||
Ok(view_pb)
|
||||
},
|
||||
}
|
||||
@ -344,8 +343,8 @@ impl Folder2Manager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self), err)]
|
||||
pub async fn update_view_with_params(&self, params: UpdateViewParams) -> FlowyResult<View> {
|
||||
let view = self
|
||||
pub async fn update_view_with_params(&self, params: UpdateViewParams) -> FlowyResult<()> {
|
||||
let _ = self
|
||||
.folder
|
||||
.lock()
|
||||
.as_ref()
|
||||
@ -358,18 +357,13 @@ impl Folder2Manager {
|
||||
.done()
|
||||
});
|
||||
|
||||
match view {
|
||||
None => Err(FlowyError::record_not_found()),
|
||||
Some(view) => {
|
||||
let view_pb: ViewPB = view.clone().into();
|
||||
send_notification(&view.id, FolderNotification::DidUpdateView)
|
||||
.payload(view_pb)
|
||||
.send();
|
||||
|
||||
notify_parent_view_did_change(self.folder.clone(), vec![view.bid.clone()]);
|
||||
Ok(view)
|
||||
},
|
||||
if let Ok(view_pb) = self.get_view(¶ms.view_id).await {
|
||||
send_notification(&view_pb.id, FolderNotification::DidUpdateView)
|
||||
.payload(view_pb)
|
||||
.send();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
||||
@ -536,16 +530,13 @@ fn get_workspace_view_pbs(workspace_id: &str, folder: &InnerFolder) -> Vec<ViewP
|
||||
views
|
||||
.into_iter()
|
||||
.map(|view| {
|
||||
let mut parent_view: ViewPB = view.into();
|
||||
|
||||
// Get child views
|
||||
parent_view.belongings = folder
|
||||
let child_views = folder
|
||||
.views
|
||||
.get_views_belong_to(&parent_view.id)
|
||||
.get_views_belong_to(&view.id)
|
||||
.into_iter()
|
||||
.map(|view| view.into())
|
||||
.collect();
|
||||
parent_view
|
||||
view_pb_with_child_views(view, child_views)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@ -584,11 +575,7 @@ fn notify_parent_view_did_change<T: AsRef<str>>(
|
||||
event!(Level::DEBUG, child_views_count = child_views.len());
|
||||
|
||||
// Post the notification
|
||||
let mut parent_view_pb: ViewPB = parent_view.into();
|
||||
parent_view_pb.belongings = child_views
|
||||
.into_iter()
|
||||
.map(|child_view| child_view.into())
|
||||
.collect::<Vec<ViewPB>>();
|
||||
let parent_view_pb = view_pb_with_child_views(parent_view, child_views);
|
||||
send_notification(parent_view_id, FolderNotification::DidUpdateChildViews)
|
||||
.payload(parent_view_pb)
|
||||
.send();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{ViewPB, WorkspacePB, WorkspaceSettingPB};
|
||||
use crate::entities::{view_pb_without_child_views, WorkspacePB, WorkspaceSettingPB};
|
||||
use collab_folder::core::{View, Workspace};
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
@ -62,7 +62,7 @@ pub(crate) fn send_workspace_setting_notification(
|
||||
current_view: Option<View>,
|
||||
) -> Option<()> {
|
||||
let workspace: WorkspacePB = current_workspace?.into();
|
||||
let latest_view = current_view.map(ViewPB::from);
|
||||
let latest_view = current_view.map(view_pb_without_child_views);
|
||||
let setting = WorkspaceSettingPB {
|
||||
workspace,
|
||||
latest_view,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{ViewPB, WorkspacePB};
|
||||
use crate::entities::{view_pb_with_child_views, WorkspacePB};
|
||||
|
||||
use crate::view_ext::{gen_view_id, ViewDataProcessorMap};
|
||||
use chrono::Utc;
|
||||
@ -92,10 +92,7 @@ fn workspace_pb_from_workspace(
|
||||
view: &View,
|
||||
child_view: &View,
|
||||
) -> WorkspacePB {
|
||||
let child_view_pb: ViewPB = child_view.clone().into();
|
||||
let mut view_pb: ViewPB = view.clone().into();
|
||||
view_pb.belongings.push(child_view_pb);
|
||||
|
||||
let view_pb = view_pb_with_child_views(view.clone(), vec![child_view.clone()]);
|
||||
WorkspacePB {
|
||||
id: workspace.id.clone(),
|
||||
name: workspace.name.clone(),
|
||||
|
@ -149,9 +149,9 @@ async fn app_create_with_view() {
|
||||
.await;
|
||||
|
||||
app = test.parent_view.clone();
|
||||
assert_eq!(app.belongings.len(), 3);
|
||||
assert_eq!(app.belongings[1].name, "View A");
|
||||
assert_eq!(app.belongings[2].name, "Grid")
|
||||
assert_eq!(app.child_views.len(), 3);
|
||||
assert_eq!(app.child_views[1].name, "View A");
|
||||
assert_eq!(app.child_views[2].name, "Grid")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@ -216,13 +216,13 @@ async fn view_delete_all() {
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
test.parent_view.belongings.len(),
|
||||
test.parent_view.child_views.len(),
|
||||
3,
|
||||
"num of belongings should be 3"
|
||||
);
|
||||
let view_ids = test
|
||||
.parent_view
|
||||
.belongings
|
||||
.child_views
|
||||
.iter()
|
||||
.map(|view| view.id.clone())
|
||||
.collect::<Vec<String>>();
|
||||
@ -234,7 +234,7 @@ async fn view_delete_all() {
|
||||
])
|
||||
.await;
|
||||
|
||||
assert_eq!(test.parent_view.belongings.len(), 0);
|
||||
assert_eq!(test.parent_view.child_views.len(), 0);
|
||||
assert_eq!(test.trash.len(), 3);
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ async fn view_delete_all_permanent() {
|
||||
|
||||
let view_ids = test
|
||||
.parent_view
|
||||
.belongings
|
||||
.child_views
|
||||
.iter()
|
||||
.map(|view| view.id.clone())
|
||||
.collect::<Vec<String>>();
|
||||
@ -268,6 +268,6 @@ async fn view_delete_all_permanent() {
|
||||
])
|
||||
.await;
|
||||
|
||||
assert_eq!(test.parent_view.belongings.len(), 0);
|
||||
assert_eq!(test.parent_view.child_views.len(), 0);
|
||||
assert_eq!(test.trash.len(), 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user