chore: create board card

This commit is contained in:
appflowy
2022-08-16 17:13:56 +08:00
parent b7d71428be
commit bc346dfd67
20 changed files with 240 additions and 98 deletions

View File

@ -11,7 +11,7 @@ pub enum GridNotification {
DidUpdateRow = 30,
DidUpdateCell = 40,
DidUpdateField = 50,
DidUpdateBoard = 60,
DidUpdateGroup = 60,
}
impl std::default::Default for GridNotification {

View File

@ -1,4 +1,4 @@
use crate::entities::{CreateRowParams, GridLayout, RowPB};
use crate::entities::{CreateRowParams, GridLayout};
use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode;
use flowy_grid_data_model::parser::NotEmptyStr;
@ -26,43 +26,3 @@ impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
})
}
}
#[derive(Debug, Default, ProtoBuf)]
pub struct GroupRowsChangesetPB {
#[pb(index = 1)]
pub group_id: String,
#[pb(index = 2)]
pub inserted_rows: Vec<RowPB>,
#[pb(index = 3)]
pub deleted_rows: Vec<String>,
#[pb(index = 4)]
pub updated_rows: Vec<RowPB>,
}
impl GroupRowsChangesetPB {
pub fn insert(group_id: String, inserted_rows: Vec<RowPB>) -> Self {
Self {
group_id,
inserted_rows,
..Default::default()
}
}
pub fn delete(group_id: String, deleted_rows: Vec<String>) -> Self {
Self {
group_id,
deleted_rows,
..Default::default()
}
}
pub fn update(group_id: String, updated_rows: Vec<RowPB>) -> Self {
Self {
group_id,
updated_rows,
..Default::default()
}
}
}

View File

@ -0,0 +1,43 @@
use crate::entities::{InsertedRowPB, RowPB};
use flowy_derive::ProtoBuf;
#[derive(Debug, Default, ProtoBuf)]
pub struct GroupRowsChangesetPB {
#[pb(index = 1)]
pub group_id: String,
#[pb(index = 2)]
pub inserted_rows: Vec<InsertedRowPB>,
#[pb(index = 3)]
pub deleted_rows: Vec<String>,
#[pb(index = 4)]
pub updated_rows: Vec<RowPB>,
}
impl GroupRowsChangesetPB {
pub fn insert(group_id: String, inserted_rows: Vec<InsertedRowPB>) -> Self {
Self {
group_id,
inserted_rows,
..Default::default()
}
}
pub fn delete(group_id: String, deleted_rows: Vec<String>) -> Self {
Self {
group_id,
deleted_rows,
..Default::default()
}
}
pub fn update(group_id: String, updated_rows: Vec<RowPB>) -> Self {
Self {
group_id,
updated_rows,
..Default::default()
}
}
}

View File

@ -1,7 +1,9 @@
mod board_card;
mod configuration;
mod group;
mod group_changeset;
pub use board_card::*;
pub use configuration::*;
pub use group::*;
pub use group_changeset::*;

View File

@ -1,7 +1,8 @@
use flowy_error::{FlowyError, FlowyResult};
use crate::entities::{
CreateRowParams, GridFilterConfiguration, GridLayout, GridSettingPB, GroupPB, GroupRowsChangesetPB, RowPB,
CreateRowParams, GridFilterConfiguration, GridLayout, GridSettingPB, GroupPB, GroupRowsChangesetPB, InsertedRowPB,
RowPB,
};
use crate::services::grid_editor_task::GridServiceTaskScheduler;
use crate::services::group::{default_group_configuration, Group, GroupConfigurationDelegate, GroupService};
@ -91,8 +92,6 @@ impl GridViewRevisionEditor {
}
},
}
todo!()
}
pub(crate) async fn did_create_row(&self, row_pb: &RowPB, params: &CreateRowParams) {
@ -100,7 +99,11 @@ impl GridViewRevisionEditor {
match params.group_id.as_ref() {
None => {}
Some(group_id) => {
let changeset = GroupRowsChangesetPB::insert(group_id.clone(), vec![row_pb.clone()]);
let inserted_row = InsertedRowPB {
row: row_pb.clone(),
index: None,
};
let changeset = GroupRowsChangesetPB::insert(group_id.clone(), vec![inserted_row]);
self.notify_did_update_group(changeset).await;
}
}
@ -120,7 +123,7 @@ impl GridViewRevisionEditor {
async fn group_id_of_row(&self, row_id: &str) -> Option<String> {
let read_guard = self.groups.read().await;
for group in read_guard.iter() {
if group.rows.iter().find(|row| row.id == row_id).is_some() {
if group.rows.iter().any(|row| row.id == row_id) {
return Some(group.id.clone());
}
}
@ -167,7 +170,7 @@ impl GridViewRevisionEditor {
}
async fn notify_did_update_group(&self, changeset: GroupRowsChangesetPB) {
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateBoard)
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateGroup)
.payload(changeset)
.send();
}

View File

@ -1,8 +1,6 @@
use crate::dart_notification::{send_dart_notification, GridNotification};
use crate::entities::{
CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, GroupPB, GroupRowsChangesetPB,
NumberGroupConfigurationPB, RowPB, SelectOptionGroupConfigurationPB, TextGroupConfigurationPB,
UrlGroupConfigurationPB,
CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, NumberGroupConfigurationPB,
SelectOptionGroupConfigurationPB, TextGroupConfigurationPB, UrlGroupConfigurationPB,
};
use crate::services::group::{
CheckboxGroupController, Group, GroupActionHandler, MultiSelectGroupController, SingleSelectGroupController,