mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add create card notification
This commit is contained in:
parent
43eaa2748d
commit
24ca8da8c8
@ -11,6 +11,7 @@ pub enum GridNotification {
|
||||
DidUpdateRow = 30,
|
||||
DidUpdateCell = 40,
|
||||
DidUpdateField = 50,
|
||||
DidUpdateBoard = 60,
|
||||
}
|
||||
|
||||
impl std::default::Default for GridNotification {
|
||||
|
@ -232,10 +232,7 @@ pub(crate) async fn get_row_handler(
|
||||
) -> DataResult<OptionalRowPB, FlowyError> {
|
||||
let params: RowIdParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let row = editor
|
||||
.get_row_rev(¶ms.row_id)
|
||||
.await?
|
||||
.and_then(|row_rev| Some(make_row_from_row_rev(row_rev)));
|
||||
let row = editor.get_row_rev(¶ms.row_id).await?.map(make_row_from_row_rev);
|
||||
|
||||
data_result(OptionalRowPB { row })
|
||||
}
|
||||
|
@ -161,31 +161,26 @@ impl GridBlockManager {
|
||||
Ok(changesets)
|
||||
}
|
||||
|
||||
pub(crate) async fn move_row(&self, row_id: &str, from: usize, to: usize) -> FlowyResult<()> {
|
||||
let editor = self.get_editor_from_row_id(row_id).await?;
|
||||
let _ = editor.move_row(row_id, from, to).await?;
|
||||
pub(crate) async fn move_row(&self, row_rev: Arc<RowRevision>, from: usize, to: usize) -> FlowyResult<()> {
|
||||
let editor = self.get_editor_from_row_id(&row_rev.id).await?;
|
||||
let _ = editor.move_row(&row_rev.id, from, to).await?;
|
||||
|
||||
match editor.get_row_revs(Some(vec![Cow::Borrowed(row_id)])).await?.pop() {
|
||||
None => {}
|
||||
Some(row_rev) => {
|
||||
let delete_row_id = row_rev.id.clone();
|
||||
let insert_row = InsertedRowPB {
|
||||
index: Some(to as i32),
|
||||
row: make_row_from_row_rev(row_rev),
|
||||
};
|
||||
let delete_row_id = row_rev.id.clone();
|
||||
let insert_row = InsertedRowPB {
|
||||
index: Some(to as i32),
|
||||
row: make_row_from_row_rev(row_rev),
|
||||
};
|
||||
|
||||
let notified_changeset = GridBlockChangesetPB {
|
||||
block_id: editor.block_id.clone(),
|
||||
inserted_rows: vec![insert_row],
|
||||
deleted_rows: vec![delete_row_id],
|
||||
..Default::default()
|
||||
};
|
||||
let notified_changeset = GridBlockChangesetPB {
|
||||
block_id: editor.block_id.clone(),
|
||||
inserted_rows: vec![insert_row],
|
||||
deleted_rows: vec![delete_row_id],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let _ = self
|
||||
.notify_did_update_block(&editor.block_id, notified_changeset)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
let _ = self
|
||||
.notify_did_update_block(&editor.block_id, notified_changeset)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -326,6 +326,7 @@ impl GridRevisionEditor {
|
||||
|
||||
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
|
||||
let _ = self.block_manager.delete_row(row_id).await?;
|
||||
self.group_service.read().await.did_delete_card(row_id.to_owned()).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -517,10 +518,22 @@ impl GridRevisionEditor {
|
||||
}
|
||||
|
||||
pub async fn move_row(&self, row_id: &str, from: i32, to: i32) -> FlowyResult<()> {
|
||||
let _ = self.block_manager.move_row(row_id, from as usize, to as usize).await?;
|
||||
match self.block_manager.get_row_rev(row_id).await? {
|
||||
None => tracing::warn!("Move row failed, can not find the row:{}", row_id),
|
||||
Some(row_rev) => {
|
||||
let _ = self
|
||||
.block_manager
|
||||
.move_row(row_rev.clone(), from as usize, to as usize)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn move_board_card(&self, group_id: &str, from: i32, to: i32) -> FlowyResult<()> {
|
||||
self.group_service.write().await.move_card(group_id, from, to).await;
|
||||
Ok(())
|
||||
}
|
||||
pub async fn delta_bytes(&self) -> Bytes {
|
||||
self.grid_pad.read().await.delta_bytes()
|
||||
}
|
||||
@ -558,10 +571,12 @@ impl GridRevisionEditor {
|
||||
.group_service
|
||||
.write()
|
||||
.await
|
||||
.create_board_card(&mut row_rev, group_id)
|
||||
.update_board_card(&mut row_rev, group_id)
|
||||
.await;
|
||||
|
||||
self.create_row_pb(row_rev, None).await
|
||||
let row_pb = self.create_row_pb(row_rev, None).await?;
|
||||
self.group_service.read().await.did_create_card(group_id, &row_pb).await;
|
||||
Ok(row_pb)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
@ -579,7 +594,6 @@ impl GridRevisionEditor {
|
||||
Ok(row_rev)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
async fn create_row_pb(&self, row_rev: RowRevision, start_row_id: Option<String>) -> FlowyResult<RowPB> {
|
||||
let row_pb = RowPB::from(&row_rev);
|
||||
let block_id = row_rev.block_id.clone();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{CheckboxGroupConfigurationPB, RowPB};
|
||||
use crate::entities::CheckboxGroupConfigurationPB;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{FieldRevision, RowRevision};
|
||||
use std::sync::Arc;
|
||||
@ -32,7 +32,7 @@ impl GroupActionHandler for CheckboxGroupController {
|
||||
self.handle_rows(row_revs, field_rev)
|
||||
}
|
||||
|
||||
fn create_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
fn update_card(&self, _row_rev: &mut RowRevision, _field_rev: &FieldRevision, _group_id: &str) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::entities::{GroupPB, RowPB};
|
||||
use crate::services::cell::{decode_any_cell_data, CellBytesParser};
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{
|
||||
FieldRevision, GroupConfigurationRevision, RowRevision, TypeOptionDataDeserializer,
|
||||
};
|
||||
use futures::future::BoxFuture;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use lib_infra::future::{BoxResultFuture, FutureResult};
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -39,7 +39,7 @@ pub trait GroupActionHandler: Send + Sync {
|
||||
fn field_id(&self) -> &str;
|
||||
fn get_groups(&self) -> Vec<Group>;
|
||||
fn group_rows(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<()>;
|
||||
fn create_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
|
||||
fn update_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
|
||||
}
|
||||
|
||||
pub trait GroupActionHandler2: Send + Sync {
|
||||
@ -141,7 +141,7 @@ where
|
||||
for row in rows {
|
||||
if let Some(cell_rev) = row.cells.get(&self.field_id) {
|
||||
let mut records: Vec<GroupRecord> = vec![];
|
||||
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), &field_rev);
|
||||
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev);
|
||||
let cell_data = cell_bytes.parser::<P>()?;
|
||||
for group in self.groups_map.values() {
|
||||
if self.can_group(&group.content, &cell_data) {
|
||||
@ -168,13 +168,6 @@ where
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn group_rows(&mut self, rows: &[Arc<RowRevision>]) -> FlowyResult<()> {
|
||||
for row in rows {
|
||||
// let _ = self.handle_row(row)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct GroupRecord {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::entities::{RowPB, SelectOptionGroupConfigurationPB};
|
||||
use crate::entities::SelectOptionGroupConfigurationPB;
|
||||
use crate::services::cell::insert_select_option_cell;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{FieldRevision, RowRevision};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::services::field::{
|
||||
@ -40,7 +40,7 @@ impl GroupActionHandler for SingleSelectGroupController {
|
||||
self.handle_rows(row_revs, field_rev)
|
||||
}
|
||||
|
||||
fn create_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
fn update_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
let group: Option<&Group> = self.groups_map.get(group_id);
|
||||
match group {
|
||||
None => {}
|
||||
@ -105,7 +105,7 @@ impl GroupActionHandler for MultiSelectGroupController {
|
||||
self.handle_rows(row_revs, field_rev)
|
||||
}
|
||||
|
||||
fn create_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
fn update_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
let group: Option<&Group> = self.groups_map.get(group_id);
|
||||
match group {
|
||||
None => tracing::warn!("Can not find the group: {}", group_id),
|
||||
|
@ -1,20 +1,21 @@
|
||||
use crate::services::block_manager::GridBlockManager;
|
||||
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
||||
use crate::services::group::{
|
||||
CheckboxGroupController, Group, GroupActionHandler, GroupCellContentProvider, MultiSelectGroupController,
|
||||
SingleSelectGroupController,
|
||||
};
|
||||
|
||||
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||
use crate::entities::{
|
||||
CheckboxGroupConfigurationPB, CreateBoardCardParams, DateGroupConfigurationPB, FieldType, GroupPB,
|
||||
BoardCardChangesetPB, CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, GroupPB,
|
||||
NumberGroupConfigurationPB, RowPB, SelectOptionGroupConfigurationPB, TextGroupConfigurationPB,
|
||||
UrlGroupConfigurationPB,
|
||||
};
|
||||
use crate::services::block_manager::GridBlockManager;
|
||||
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
||||
use crate::services::group::{
|
||||
CheckboxGroupController, GroupActionHandler, GroupCellContentProvider, MultiSelectGroupController,
|
||||
SingleSelectGroupController,
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{gen_grid_group_id, FieldRevision, GroupConfigurationRevision, RowRevision};
|
||||
use flowy_sync::client_grid::GridRevisionPad;
|
||||
use futures::future::BoxFuture;
|
||||
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
@ -63,21 +64,17 @@ impl GridGroupService {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, row_rev))]
|
||||
pub(crate) async fn create_board_card(&self, row_rev: &mut RowRevision, group_id: &str) {
|
||||
pub(crate) async fn update_board_card(&self, row_rev: &mut RowRevision, group_id: &str) {
|
||||
if let Some(group_action_handler) = self.group_action_handler.as_ref() {
|
||||
match self
|
||||
.grid_pad
|
||||
.read()
|
||||
.await
|
||||
.get_field_rev(group_action_handler.read().await.field_id())
|
||||
{
|
||||
let field_id = group_action_handler.read().await.field_id().to_owned();
|
||||
|
||||
match self.grid_pad.read().await.get_field_rev(&field_id) {
|
||||
None => tracing::warn!("Fail to create card because the field does not exist"),
|
||||
Some((_, field_rev)) => {
|
||||
tracing::trace!("Create card");
|
||||
group_action_handler
|
||||
.write()
|
||||
.await
|
||||
.create_card(row_rev, field_rev, group_id);
|
||||
.update_card(row_rev, field_rev, group_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,6 +94,37 @@ impl GridGroupService {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn move_card(&self, _group_id: &str, _from: i32, _to: i32) {
|
||||
// BoardCardChangesetPB {
|
||||
// group_id: "".to_string(),
|
||||
// inserted_cards: vec![],
|
||||
// deleted_cards: vec![],
|
||||
// updated_cards: vec![]
|
||||
// }
|
||||
// let row_pb = make_row_from_row_rev(row_rev);
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn did_delete_card(&self, _row_id: String) {
|
||||
// let changeset = BoardCardChangesetPB::delete(group_id.to_owned(), vec![row_id]);
|
||||
// self.notify_did_update_board(changeset).await;
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn did_create_card(&self, group_id: &str, row_pb: &RowPB) {
|
||||
let changeset = BoardCardChangesetPB::insert(group_id.to_owned(), vec![row_pb.clone()]);
|
||||
self.notify_did_update_board(changeset).await;
|
||||
}
|
||||
|
||||
pub async fn notify_did_update_board(&self, changeset: BoardCardChangesetPB) {
|
||||
if self.group_action_handler.is_none() {
|
||||
return;
|
||||
}
|
||||
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateBoard)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
async fn build_groups(
|
||||
&mut self,
|
||||
@ -158,7 +186,7 @@ fn find_group_field(field_revs: &[Arc<FieldRevision>]) -> Option<Arc<FieldRevisi
|
||||
impl GroupCellContentProvider for Arc<RwLock<GridRevisionPad>> {}
|
||||
|
||||
fn default_group_configuration(field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
||||
let field_type: FieldType = field_rev.field_type_rev.clone().into();
|
||||
let field_type: FieldType = field_rev.field_type_rev.into();
|
||||
let bytes: Bytes = match field_type {
|
||||
FieldType::RichText => TextGroupConfigurationPB::default().try_into().unwrap(),
|
||||
FieldType::Number => NumberGroupConfigurationPB::default().try_into().unwrap(),
|
||||
@ -171,7 +199,7 @@ fn default_group_configuration(field_rev: &FieldRevision) -> GroupConfigurationR
|
||||
GroupConfigurationRevision {
|
||||
id: gen_grid_group_id(),
|
||||
field_id: field_rev.id.clone(),
|
||||
field_type_rev: field_rev.field_type_rev.clone(),
|
||||
field_type_rev: field_rev.field_type_rev,
|
||||
content: Some(bytes.to_vec()),
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::services::cell::{
|
||||
apply_cell_data_changeset, insert_checkbox_cell, insert_date_cell, insert_number_cell, insert_select_option_cell,
|
||||
insert_text_cell, insert_url_cell,
|
||||
insert_checkbox_cell, insert_date_cell, insert_number_cell, insert_select_option_cell, insert_text_cell,
|
||||
insert_url_cell,
|
||||
};
|
||||
use crate::services::field::{DateCellChangesetPB, SelectOptionCellChangeset};
|
||||
|
||||
use flowy_grid_data_model::revision::{gen_row_id, CellRevision, FieldRevision, RowRevision, DEFAULT_ROW_HEIGHT};
|
||||
use indexmap::IndexMap;
|
||||
use std::collections::HashMap;
|
||||
|
@ -76,7 +76,7 @@ pub fn make_default_board() -> BuildGridContext {
|
||||
let multi_select_type_option = MultiSelectTypeOptionBuilder::default()
|
||||
.add_option(banana_option.clone())
|
||||
.add_option(apple_option.clone())
|
||||
.add_option(pear_option.clone());
|
||||
.add_option(pear_option);
|
||||
let multi_select_field = FieldBuilder::new(multi_select_type_option)
|
||||
.name("Fruit")
|
||||
.visibility(true)
|
||||
|
Loading…
Reference in New Issue
Block a user