mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: update typeOption data
This commit is contained in:
@ -70,6 +70,19 @@ pub(crate) async fn insert_field_handler(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn update_field_type_option_handler(
|
||||
data: Data<UpdateFieldTypeOptionPayload>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateFieldTypeOptionParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let _ = editor
|
||||
.update_field_type_option(¶ms.grid_id, ¶ms.field_id, params.type_option_data)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn delete_field_handler(
|
||||
data: Data<FieldIdentifierPayload>,
|
||||
|
@ -14,6 +14,7 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
|
||||
.event(GridEvent::GetFields, get_fields_handler)
|
||||
.event(GridEvent::UpdateField, update_field_handler)
|
||||
.event(GridEvent::InsertField, insert_field_handler)
|
||||
.event(GridEvent::UpdateFieldTypeOption, update_field_type_option_handler)
|
||||
.event(GridEvent::DeleteField, delete_field_handler)
|
||||
.event(GridEvent::SwitchToField, switch_to_field_handler)
|
||||
.event(GridEvent::DuplicateField, duplicate_field_handler)
|
||||
@ -52,26 +53,29 @@ pub enum GridEvent {
|
||||
#[event(input = "FieldChangesetPayload")]
|
||||
UpdateField = 11,
|
||||
|
||||
#[event(input = "UpdateFieldTypeOptionPayload")]
|
||||
UpdateFieldTypeOption = 12,
|
||||
|
||||
#[event(input = "InsertFieldPayload")]
|
||||
InsertField = 12,
|
||||
InsertField = 13,
|
||||
|
||||
#[event(input = "FieldIdentifierPayload")]
|
||||
DeleteField = 13,
|
||||
DeleteField = 14,
|
||||
|
||||
#[event(input = "EditFieldPayload", output = "EditFieldContext")]
|
||||
SwitchToField = 14,
|
||||
SwitchToField = 20,
|
||||
|
||||
#[event(input = "FieldIdentifierPayload")]
|
||||
DuplicateField = 15,
|
||||
DuplicateField = 21,
|
||||
|
||||
#[event(input = "EditFieldPayload", output = "EditFieldContext")]
|
||||
GetEditFieldContext = 16,
|
||||
GetEditFieldContext = 22,
|
||||
|
||||
#[event(input = "MoveItemPayload")]
|
||||
MoveItem = 17,
|
||||
MoveItem = 23,
|
||||
|
||||
#[event(input = "EditFieldPayload", output = "FieldTypeOptionData")]
|
||||
GetFieldTypeOption = 18,
|
||||
GetFieldTypeOption = 24,
|
||||
|
||||
#[event(input = "CreateSelectOptionPayload", output = "SelectOption")]
|
||||
NewSelectOption = 30,
|
||||
|
@ -29,13 +29,14 @@ pub enum GridEvent {
|
||||
GetGridBlocks = 1,
|
||||
GetFields = 10,
|
||||
UpdateField = 11,
|
||||
InsertField = 12,
|
||||
DeleteField = 13,
|
||||
SwitchToField = 14,
|
||||
DuplicateField = 15,
|
||||
GetEditFieldContext = 16,
|
||||
MoveItem = 17,
|
||||
GetFieldTypeOption = 18,
|
||||
UpdateFieldTypeOption = 12,
|
||||
InsertField = 13,
|
||||
DeleteField = 14,
|
||||
SwitchToField = 20,
|
||||
DuplicateField = 21,
|
||||
GetEditFieldContext = 22,
|
||||
MoveItem = 23,
|
||||
GetFieldTypeOption = 24,
|
||||
NewSelectOption = 30,
|
||||
GetSelectOptionContext = 31,
|
||||
UpdateSelectOption = 32,
|
||||
@ -59,13 +60,14 @@ impl ::protobuf::ProtobufEnum for GridEvent {
|
||||
1 => ::std::option::Option::Some(GridEvent::GetGridBlocks),
|
||||
10 => ::std::option::Option::Some(GridEvent::GetFields),
|
||||
11 => ::std::option::Option::Some(GridEvent::UpdateField),
|
||||
12 => ::std::option::Option::Some(GridEvent::InsertField),
|
||||
13 => ::std::option::Option::Some(GridEvent::DeleteField),
|
||||
14 => ::std::option::Option::Some(GridEvent::SwitchToField),
|
||||
15 => ::std::option::Option::Some(GridEvent::DuplicateField),
|
||||
16 => ::std::option::Option::Some(GridEvent::GetEditFieldContext),
|
||||
17 => ::std::option::Option::Some(GridEvent::MoveItem),
|
||||
18 => ::std::option::Option::Some(GridEvent::GetFieldTypeOption),
|
||||
12 => ::std::option::Option::Some(GridEvent::UpdateFieldTypeOption),
|
||||
13 => ::std::option::Option::Some(GridEvent::InsertField),
|
||||
14 => ::std::option::Option::Some(GridEvent::DeleteField),
|
||||
20 => ::std::option::Option::Some(GridEvent::SwitchToField),
|
||||
21 => ::std::option::Option::Some(GridEvent::DuplicateField),
|
||||
22 => ::std::option::Option::Some(GridEvent::GetEditFieldContext),
|
||||
23 => ::std::option::Option::Some(GridEvent::MoveItem),
|
||||
24 => ::std::option::Option::Some(GridEvent::GetFieldTypeOption),
|
||||
30 => ::std::option::Option::Some(GridEvent::NewSelectOption),
|
||||
31 => ::std::option::Option::Some(GridEvent::GetSelectOptionContext),
|
||||
32 => ::std::option::Option::Some(GridEvent::UpdateSelectOption),
|
||||
@ -86,6 +88,7 @@ impl ::protobuf::ProtobufEnum for GridEvent {
|
||||
GridEvent::GetGridBlocks,
|
||||
GridEvent::GetFields,
|
||||
GridEvent::UpdateField,
|
||||
GridEvent::UpdateFieldTypeOption,
|
||||
GridEvent::InsertField,
|
||||
GridEvent::DeleteField,
|
||||
GridEvent::SwitchToField,
|
||||
@ -131,17 +134,17 @@ impl ::protobuf::reflect::ProtobufValue for GridEvent {
|
||||
}
|
||||
|
||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\n\x0fevent_map.proto*\x95\x03\n\tGridEvent\x12\x0f\n\x0bGetGridData\x10\
|
||||
\n\x0fevent_map.proto*\xb0\x03\n\tGridEvent\x12\x0f\n\x0bGetGridData\x10\
|
||||
\0\x12\x11\n\rGetGridBlocks\x10\x01\x12\r\n\tGetFields\x10\n\x12\x0f\n\
|
||||
\x0bUpdateField\x10\x0b\x12\x0f\n\x0bInsertField\x10\x0c\x12\x0f\n\x0bDe\
|
||||
leteField\x10\r\x12\x11\n\rSwitchToField\x10\x0e\x12\x12\n\x0eDuplicateF\
|
||||
ield\x10\x0f\x12\x17\n\x13GetEditFieldContext\x10\x10\x12\x0c\n\x08MoveI\
|
||||
tem\x10\x11\x12\x16\n\x12GetFieldTypeOption\x10\x12\x12\x13\n\x0fNewSele\
|
||||
ctOption\x10\x1e\x12\x1a\n\x16GetSelectOptionContext\x10\x1f\x12\x16\n\
|
||||
\x12UpdateSelectOption\x10\x20\x12\r\n\tCreateRow\x102\x12\n\n\x06GetRow\
|
||||
\x103\x12\r\n\tDeleteRow\x104\x12\x10\n\x0cDuplicateRow\x105\x12\x0b\n\
|
||||
\x07GetCell\x10F\x12\x0e\n\nUpdateCell\x10G\x12\x1a\n\x16UpdateCellSelec\
|
||||
tOption\x10Hb\x06proto3\
|
||||
\x0bUpdateField\x10\x0b\x12\x19\n\x15UpdateFieldTypeOption\x10\x0c\x12\
|
||||
\x0f\n\x0bInsertField\x10\r\x12\x0f\n\x0bDeleteField\x10\x0e\x12\x11\n\r\
|
||||
SwitchToField\x10\x14\x12\x12\n\x0eDuplicateField\x10\x15\x12\x17\n\x13G\
|
||||
etEditFieldContext\x10\x16\x12\x0c\n\x08MoveItem\x10\x17\x12\x16\n\x12Ge\
|
||||
tFieldTypeOption\x10\x18\x12\x13\n\x0fNewSelectOption\x10\x1e\x12\x1a\n\
|
||||
\x16GetSelectOptionContext\x10\x1f\x12\x16\n\x12UpdateSelectOption\x10\
|
||||
\x20\x12\r\n\tCreateRow\x102\x12\n\n\x06GetRow\x103\x12\r\n\tDeleteRow\
|
||||
\x104\x12\x10\n\x0cDuplicateRow\x105\x12\x0b\n\x07GetCell\x10F\x12\x0e\n\
|
||||
\nUpdateCell\x10G\x12\x1a\n\x16UpdateCellSelectOption\x10Hb\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
@ -5,13 +5,14 @@ enum GridEvent {
|
||||
GetGridBlocks = 1;
|
||||
GetFields = 10;
|
||||
UpdateField = 11;
|
||||
InsertField = 12;
|
||||
DeleteField = 13;
|
||||
SwitchToField = 14;
|
||||
DuplicateField = 15;
|
||||
GetEditFieldContext = 16;
|
||||
MoveItem = 17;
|
||||
GetFieldTypeOption = 18;
|
||||
UpdateFieldTypeOption = 12;
|
||||
InsertField = 13;
|
||||
DeleteField = 14;
|
||||
SwitchToField = 20;
|
||||
DuplicateField = 21;
|
||||
GetEditFieldContext = 22;
|
||||
MoveItem = 23;
|
||||
GetFieldTypeOption = 24;
|
||||
NewSelectOption = 30;
|
||||
GetSelectOptionContext = 31;
|
||||
UpdateSelectOption = 32;
|
||||
|
@ -93,6 +93,34 @@ impl ClientGridEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_field_type_option(
|
||||
&self,
|
||||
grid_id: &str,
|
||||
field_id: &str,
|
||||
type_option_data: Vec<u8>,
|
||||
) -> FlowyResult<()> {
|
||||
let result = self.get_field_meta(field_id).await;
|
||||
if result.is_none() {
|
||||
tracing::warn!("Can't find the field with id: {}", field_id);
|
||||
return Ok(());
|
||||
}
|
||||
let field_meta = result.unwrap();
|
||||
let _ = self
|
||||
.modify(|grid| {
|
||||
let deserializer = TypeOptionJsonDeserializer(field_meta.field_type.clone());
|
||||
let changeset = FieldChangesetParams {
|
||||
field_id: field_id.to_owned(),
|
||||
grid_id: grid_id.to_owned(),
|
||||
type_option_data: Some(type_option_data),
|
||||
..Default::default()
|
||||
};
|
||||
Ok(grid.update_field_meta(changeset, deserializer)?)
|
||||
})
|
||||
.await?;
|
||||
let _ = self.notify_did_update_grid_field(&field_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_next_field_meta(&self, field_type: &FieldType) -> FlowyResult<FieldMeta> {
|
||||
let name = format!("Property {}", self.grid_pad.read().await.fields().len() + 1);
|
||||
let field_meta = FieldBuilder::from_field_type(field_type).name(&name).build();
|
||||
|
Reference in New Issue
Block a user