Feat: rename stack inline (#3781)

* feat: rename stack in-line

* feat: rename stack in-line

* chore: compiler issues

* fix: conflicts and cleaning

* fix: code lost after merge

* test: fix failing rust tests

* fix: tauri localization wrong keys

---------

Co-authored-by: Richard Shiue <71320345+richardshiue@users.noreply.github.com>
This commit is contained in:
Mathias Mogensen
2023-10-26 03:38:37 +02:00
committed by GitHub
parent f40ae9ff25
commit aa27c4e6d4
24 changed files with 516 additions and 221 deletions

View File

@ -145,10 +145,13 @@ pub struct UpdateGroupPB {
#[pb(index = 2)]
pub group_id: String,
#[pb(index = 3, one_of)]
pub name: Option<String>,
#[pb(index = 3)]
pub field_id: String,
#[pb(index = 4, one_of)]
pub name: Option<String>,
#[pb(index = 5, one_of)]
pub visible: Option<bool>,
}
@ -162,10 +165,14 @@ impl TryInto<UpdateGroupParams> for UpdateGroupPB {
let group_id = NotEmptyStr::parse(self.group_id)
.map_err(|_| ErrorCode::GroupIdIsEmpty)?
.0;
let field_id = NotEmptyStr::parse(self.field_id)
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
.0;
Ok(UpdateGroupParams {
view_id,
group_id,
field_id,
name: self.name,
visible: self.visible,
})
@ -175,6 +182,7 @@ impl TryInto<UpdateGroupParams> for UpdateGroupPB {
pub struct UpdateGroupParams {
pub view_id: String,
pub group_id: String,
pub field_id: String,
pub name: Option<String>,
pub visible: Option<bool>,
}
@ -183,6 +191,7 @@ impl From<UpdateGroupParams> for GroupChangeset {
fn from(params: UpdateGroupParams) -> Self {
Self {
group_id: params.group_id,
field_id: params.field_id,
name: params.name,
visible: params.visible,
}

View File

@ -694,12 +694,19 @@ pub(crate) async fn update_group_handler(
let params: UpdateGroupParams = data.into_inner().try_into()?;
let view_id = params.view_id.clone();
let database_editor = manager.get_database_with_view_id(&view_id).await?;
let group_setting_changeset = GroupSettingChangeset {
update_groups: vec![GroupChangeset::from(params)],
};
let group_changeset = GroupChangeset::from(params);
database_editor
.update_group_setting(&view_id, group_setting_changeset)
.update_group(&view_id, group_changeset.clone())
.await?;
database_editor
.update_group_setting(
&view_id,
GroupSettingChangeset {
update_groups: vec![group_changeset],
},
)
.await?;
Ok(())
}

View File

@ -32,7 +32,7 @@ use crate::services::field_settings::{
};
use crate::services::filter::Filter;
use crate::services::group::{
default_group_setting, GroupSetting, GroupSettingChangeset, RowChangeset,
default_group_setting, GroupChangeset, GroupSetting, GroupSettingChangeset, RowChangeset,
};
use crate::services::share::csv::{CSVExport, CSVFormat};
use crate::services::sort::Sort;
@ -188,6 +188,31 @@ impl DatabaseEditor {
Ok(())
}
pub async fn update_group(
&self,
view_id: &str,
group_changeset: GroupChangeset,
) -> FlowyResult<()> {
let view_editor = self.database_views.get_view_editor(view_id).await?;
let type_option = view_editor.update_group(group_changeset.clone()).await?;
if let Some(type_option_data) = type_option {
let field = self.get_field(&group_changeset.field_id);
if field.is_some() {
let _ = self
.update_field_type_option(
view_id,
&group_changeset.field_id,
type_option_data,
field.unwrap(),
)
.await;
}
}
Ok(())
}
#[tracing::instrument(level = "trace", skip_all, err)]
pub async fn create_or_update_filter(&self, params: UpdateFilterParams) -> FlowyResult<()> {
let view_editor = self.database_views.get_view_editor(&params.view_id).await?;

View File

@ -37,7 +37,8 @@ use crate::services::filter::{
Filter, FilterChangeset, FilterController, FilterType, UpdatedFilterType,
};
use crate::services::group::{
GroupController, GroupSetting, GroupSettingChangeset, MoveGroupRowContext, RowChangeset,
GroupChangeset, GroupController, GroupSetting, GroupSettingChangeset, MoveGroupRowContext,
RowChangeset,
};
use crate::services::setting::CalendarLayoutSetting;
use crate::services::sort::{DeletedSortType, Sort, SortChangeset, SortController, SortType};
@ -479,6 +480,27 @@ impl DatabaseViewEditor {
Ok(())
}
pub async fn update_group(
&self,
changeset: GroupChangeset,
) -> FlowyResult<Option<TypeOptionData>> {
match changeset.name {
Some(group_name) => {
let result = self
.mut_group_controller(|controller, _| {
Ok(controller.update_group_name(&changeset.group_id, &group_name))
})
.await;
match result {
Some(r) => Ok(r),
None => Ok(None),
}
},
None => Ok(None),
}
}
pub async fn v_get_all_sorts(&self) -> Vec<Sort> {
self.delegate.get_all_sorts(&self.view_id)
}

View File

@ -39,6 +39,11 @@ pub trait GroupController: GroupControllerOperation + Send + Sync {
/// Called after the row was created.
fn did_create_row(&mut self, row_detail: &RowDetail, group_id: &str);
/// Update group name handler
fn update_group_name(&mut self, _group_id: &str, _group_name: &str) -> Option<TypeOptionData> {
None
}
}
/// The [GroupsBuilder] trait is used to generate the groups for different [FieldType]

View File

@ -1,12 +1,14 @@
use std::sync::Arc;
use collab_database::fields::Field;
use collab_database::fields::{Field, TypeOptionData};
use collab_database::rows::{new_cell_builder, Cell, Cells, Row, RowDetail};
use serde::{Deserialize, Serialize};
use crate::entities::{FieldType, GroupRowsNotificationPB, SelectOptionCellDataPB};
use crate::services::cell::insert_select_option_cell;
use crate::services::field::{MultiSelectTypeOption, SelectOptionCellDataParser};
use crate::services::field::{
MultiSelectTypeOption, SelectOption, SelectOptionCellDataParser, SelectTypeOptionSharedAction,
};
use crate::services::group::action::GroupCustomize;
use crate::services::group::controller::{
BaseGroupController, GroupController, GroupsBuilder, MoveGroupRowContext,
@ -105,6 +107,29 @@ impl GroupController for MultiSelectGroupController {
group.add_row(row_detail.clone())
}
}
fn update_group_name(&mut self, group_id: &str, group_name: &str) -> Option<TypeOptionData> {
match &self.type_option {
Some(type_option) => {
let select_option = type_option
.options
.iter()
.find(|option| option.id == group_id)
.unwrap();
let new_select_option = SelectOption {
name: group_name.to_owned(),
..select_option.to_owned()
};
let mut new_type_option = type_option.clone();
new_type_option.insert_option(new_select_option);
Some(new_type_option.to_type_option_data())
},
None => None,
}
}
}
pub struct MultiSelectGroupGenerator;

View File

@ -1,12 +1,14 @@
use std::sync::Arc;
use collab_database::fields::Field;
use collab_database::fields::{Field, TypeOptionData};
use collab_database::rows::{new_cell_builder, Cell, Cells, Row, RowDetail};
use serde::{Deserialize, Serialize};
use crate::entities::{FieldType, GroupRowsNotificationPB, SelectOptionCellDataPB};
use crate::services::cell::insert_select_option_cell;
use crate::services::field::{SelectOptionCellDataParser, SingleSelectTypeOption};
use crate::services::field::{
SelectOption, SelectOptionCellDataParser, SelectTypeOptionSharedAction, SingleSelectTypeOption,
};
use crate::services::group::action::GroupCustomize;
use crate::services::group::controller::{
BaseGroupController, GroupController, GroupsBuilder, MoveGroupRowContext,
@ -99,11 +101,35 @@ impl GroupController for SingleSelectGroupController {
},
}
}
fn did_create_row(&mut self, row_detail: &RowDetail, group_id: &str) {
if let Some(group) = self.context.get_mut_group(group_id) {
group.add_row(row_detail.clone())
}
}
fn update_group_name(&mut self, group_id: &str, group_name: &str) -> Option<TypeOptionData> {
match &self.type_option {
Some(type_option) => {
let select_option = type_option
.options
.iter()
.find(|option| option.id == group_id)
.unwrap();
let new_select_option = SelectOption {
name: group_name.to_owned(),
..select_option.to_owned()
};
let mut new_type_option = type_option.clone();
new_type_option.insert_option(new_select_option);
Some(new_type_option.to_type_option_data())
},
None => None,
}
}
}
pub struct SingleSelectGroupGenerator();

View File

@ -18,8 +18,10 @@ pub struct GroupSettingChangeset {
pub update_groups: Vec<GroupChangeset>,
}
#[derive(Clone, Default, Debug)]
pub struct GroupChangeset {
pub group_id: String,
pub field_id: String,
pub name: Option<String>,
pub visible: Option<bool>,
}