Merge pull request #950 from AppFlowy-IO/fix/no_status_record

chore: save move to no status card
This commit is contained in:
Nathan.fooo 2022-08-31 14:54:56 +08:00 committed by GitHub
commit 93f4d4377a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 53 deletions

View File

@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
const DART_LOG = "Dart_LOG";
class Log {
static const enableLog = true;
static const enableLog = false;
static void info(String? message) {
if (enableLog) {

View File

@ -155,11 +155,12 @@ pub fn select_option_color_from_index(index: usize) -> SelectOptionColorPB {
}
}
#[derive(Default)]
pub struct SelectOptionIds(Vec<String>);
impl SelectOptionIds {
pub fn new() -> Self {
Self(vec![])
Self::default()
}
pub fn into_inner(self) -> Vec<String> {
self.0

View File

@ -134,7 +134,7 @@ impl GridViewManager {
row_rev: Arc<RowRevision>,
to_group_id: String,
to_row_id: Option<String>,
with_row_changeset: impl FnOnce(RowChangeset) -> AFFuture<()>,
recv_row_changeset: impl FnOnce(RowChangeset) -> AFFuture<()>,
) -> FlowyResult<()> {
let mut row_changeset = RowChangeset::new(row_rev.id.clone());
let view_editor = self.get_default_view_editor().await?;
@ -143,7 +143,7 @@ impl GridViewManager {
.await;
if !row_changeset.is_empty() {
with_row_changeset(row_changeset).await;
recv_row_changeset(row_changeset).await;
}
for group_changeset in group_changesets {

View File

@ -93,16 +93,47 @@ where
})
}
pub(crate) fn groups(&self) -> Vec<&Group> {
/// Returns the groups without the default group
pub(crate) fn concrete_groups(&self) -> Vec<&Group> {
self.groups_map.values().collect()
}
/// Returns the all the groups that contain the default group.
pub(crate) fn clone_groups(&self) -> Vec<Group> {
let mut groups: Vec<Group> = self.groups_map.values().cloned().collect();
groups.push(self.default_group.clone());
groups
}
/// Iterate mut the groups. The default group will be the last one that get mutated.
pub(crate) fn iter_mut_groups(&mut self, mut each: impl FnMut(&mut Group)) {
self.groups_map.iter_mut().for_each(|(_, group)| {
each(group);
});
each(&mut self.default_group);
}
pub(crate) fn move_group(&mut self, from_id: &str, to_id: &str) -> FlowyResult<()> {
let from_index = self.groups_map.get_index_of(from_id);
let to_index = self.groups_map.get_index_of(to_id);
match (from_index, to_index) {
(Some(from_index), Some(to_index)) => {
self.groups_map.swap_indices(from_index, to_index);
self.mut_configuration(|configuration| {
let from_index = configuration.groups.iter().position(|group| group.id == from_id);
let to_index = configuration.groups.iter().position(|group| group.id == to_id);
if let (Some(from), Some(to)) = (from_index, to_index) {
configuration.groups.swap(from, to);
}
true
})?;
Ok(())
}
_ => Err(FlowyError::out_of_bounds()),
}
}
pub(crate) fn merge_groups(&mut self, groups: Vec<Group>) -> FlowyResult<Option<GroupViewChangesetPB>> {
let MergeGroupResult {
groups,
@ -154,7 +185,7 @@ where
#[allow(dead_code)]
pub(crate) async fn hide_group(&mut self, group_id: &str) -> FlowyResult<()> {
self.mut_configuration_group(group_id, |group_rev| {
self.mut_group_rev(group_id, |group_rev| {
group_rev.visible = false;
})?;
Ok(())
@ -162,45 +193,18 @@ where
#[allow(dead_code)]
pub(crate) async fn show_group(&mut self, group_id: &str) -> FlowyResult<()> {
self.mut_configuration_group(group_id, |group_rev| {
self.mut_group_rev(group_id, |group_rev| {
group_rev.visible = true;
})?;
Ok(())
}
pub(crate) fn iter_mut_groups(&mut self, mut each: impl FnMut(&mut Group)) {
self.groups_map.iter_mut().for_each(|(_, group)| {
each(group);
})
}
pub(crate) fn get_mut_group(&mut self, group_id: &str) -> Option<&mut Group> {
self.groups_map.get_mut(group_id)
}
pub(crate) fn get_mut_default_group(&mut self) -> &mut Group {
&mut self.default_group
}
pub(crate) fn move_group(&mut self, from_id: &str, to_id: &str) -> FlowyResult<()> {
let from_index = self.groups_map.get_index_of(from_id);
let to_index = self.groups_map.get_index_of(to_id);
match (from_index, to_index) {
(Some(from_index), Some(to_index)) => {
self.groups_map.swap_indices(from_index, to_index);
self.mut_configuration(|configuration| {
let from_index = configuration.groups.iter().position(|group| group.id == from_id);
let to_index = configuration.groups.iter().position(|group| group.id == to_id);
if let (Some(from), Some(to)) = (from_index, to_index) {
configuration.groups.swap(from, to);
}
true
})?;
Ok(())
}
_ => Err(FlowyError::out_of_bounds()),
}
pub(crate) fn get_mut_group(&mut self, group_id: &str) -> Option<&mut Group> {
self.groups_map.get_mut(group_id)
}
// Returns the index and group specified by the group_id
@ -231,22 +235,6 @@ where
Ok(())
}
fn mut_configuration_group(
&mut self,
group_id: &str,
mut_groups_fn: impl Fn(&mut GroupRevision),
) -> FlowyResult<()> {
self.mut_configuration(|configuration| {
match configuration.groups.iter_mut().find(|group| group.id == group_id) {
None => false,
Some(group_rev) => {
mut_groups_fn(group_rev);
true
}
}
})
}
fn mut_configuration(
&mut self,
mut_configuration_fn: impl FnOnce(&mut GroupConfigurationRevision) -> bool,
@ -258,6 +246,18 @@ where
}
Ok(())
}
fn mut_group_rev(&mut self, group_id: &str, mut_groups_fn: impl Fn(&mut GroupRevision)) -> FlowyResult<()> {
self.mut_configuration(|configuration| {
match configuration.groups.iter_mut().find(|group| group.id == group_id) {
None => false,
Some(group_rev) => {
mut_groups_fn(group_rev);
true
}
}
})
}
}
fn merge_groups(old_groups: &[GroupRevision], groups: Vec<Group>) -> MergeGroupResult {

View File

@ -195,7 +195,7 @@ where
let mut grouped_rows: Vec<GroupedRow> = vec![];
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev);
let cell_data = cell_bytes.parser::<P>()?;
for group in self.configuration.groups() {
for group in self.configuration.concrete_groups() {
if self.can_group(&group.content, &cell_data) {
grouped_rows.push(GroupedRow {
row: row_rev.into(),