mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add suffix PB to rust struct
This commit is contained in:
parent
3a0b8bbd74
commit
1bf0f0f875
@ -9,7 +9,7 @@ import 'block_listener.dart';
|
||||
/// Read https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid for more information
|
||||
class GridBlockCache {
|
||||
final String gridId;
|
||||
final GridBlock block;
|
||||
final GridBlockPB block;
|
||||
late GridRowCache _rowCache;
|
||||
late GridBlockListener _listener;
|
||||
|
||||
|
@ -21,10 +21,10 @@ class FieldService {
|
||||
FieldService({required this.gridId, required this.fieldId});
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveField(int fromIndex, int toIndex) {
|
||||
final payload = MoveItemPayload.create()
|
||||
final payload = MoveItemPayloadPB.create()
|
||||
..gridId = gridId
|
||||
..itemId = fieldId
|
||||
..ty = MoveItemType.MoveField
|
||||
..ty = MoveItemTypePB.MoveField
|
||||
..fromIndex = fromIndex
|
||||
..toIndex = toIndex;
|
||||
|
||||
|
@ -19,10 +19,10 @@ class GridService {
|
||||
required this.gridId,
|
||||
});
|
||||
|
||||
Future<Either<Grid, FlowyError>> loadGrid() async {
|
||||
Future<Either<GridPB, FlowyError>> loadGrid() async {
|
||||
await FolderEventSetLatestView(ViewId(value: gridId)).send();
|
||||
|
||||
final payload = GridId(value: gridId);
|
||||
final payload = GridIdPB(value: gridId);
|
||||
return GridEventGetGrid(payload).send();
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class GridService {
|
||||
return GridEventCreateRow(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<RepeatedField, FlowyError>> getFields({required List<GridField> fieldOrders}) {
|
||||
Future<Either<RepeatedField, FlowyError>> getFields({required List<GridFieldPB> fieldOrders}) {
|
||||
final payload = QueryFieldPayload.create()
|
||||
..gridId = gridId
|
||||
..fieldOrders = RepeatedFieldOrder(items: fieldOrders);
|
||||
@ -141,12 +141,12 @@ class GridFieldCache {
|
||||
}
|
||||
}
|
||||
|
||||
void _deleteFields(List<GridField> deletedFields) {
|
||||
void _deleteFields(List<GridFieldPB> deletedFields) {
|
||||
if (deletedFields.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final List<Field> newFields = fields;
|
||||
final Map<String, GridField> deletedFieldMap = {
|
||||
final Map<String, GridFieldPB> deletedFieldMap = {
|
||||
for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder
|
||||
};
|
||||
|
||||
|
@ -5,16 +5,16 @@ use flowy_grid_data_model::revision::RowRevision;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct GridBlock {
|
||||
pub struct GridBlockPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub rows: Vec<Row>,
|
||||
pub rows: Vec<GridRowPB>,
|
||||
}
|
||||
|
||||
impl GridBlock {
|
||||
pub fn new(block_id: &str, rows: Vec<Row>) -> Self {
|
||||
impl GridBlockPB {
|
||||
pub fn new(block_id: &str, rows: Vec<GridRowPB>) -> Self {
|
||||
Self {
|
||||
id: block_id.to_owned(),
|
||||
rows,
|
||||
@ -23,7 +23,7 @@ impl GridBlock {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, ProtoBuf)]
|
||||
pub struct Row {
|
||||
pub struct GridRowPB {
|
||||
#[pb(index = 1)]
|
||||
pub block_id: String,
|
||||
|
||||
@ -34,7 +34,7 @@ pub struct Row {
|
||||
pub height: i32,
|
||||
}
|
||||
|
||||
impl Row {
|
||||
impl GridRowPB {
|
||||
pub fn row_id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
@ -44,7 +44,7 @@ impl Row {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&RowRevision> for Row {
|
||||
impl std::convert::From<&RowRevision> for GridRowPB {
|
||||
fn from(rev: &RowRevision) -> Self {
|
||||
Self {
|
||||
block_id: rev.block_id.clone(),
|
||||
@ -54,7 +54,7 @@ impl std::convert::From<&RowRevision> for Row {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&Arc<RowRevision>> for Row {
|
||||
impl std::convert::From<&Arc<RowRevision>> for GridRowPB {
|
||||
fn from(rev: &Arc<RowRevision>) -> Self {
|
||||
Self {
|
||||
block_id: rev.block_id.clone(),
|
||||
@ -65,36 +65,36 @@ impl std::convert::From<&Arc<RowRevision>> for Row {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct OptionalRow {
|
||||
pub struct OptionalRowPB {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub row: Option<Row>,
|
||||
pub row: Option<GridRowPB>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct RepeatedRow {
|
||||
pub struct RepeatedRowPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<Row>,
|
||||
pub items: Vec<GridRowPB>,
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<Row>> for RepeatedRow {
|
||||
fn from(items: Vec<Row>) -> Self {
|
||||
impl std::convert::From<Vec<GridRowPB>> for RepeatedRowPB {
|
||||
fn from(items: Vec<GridRowPB>) -> Self {
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct RepeatedGridBlock {
|
||||
pub struct RepeatedGridBlockPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<GridBlock>,
|
||||
pub items: Vec<GridBlockPB>,
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<GridBlock>> for RepeatedGridBlock {
|
||||
fn from(items: Vec<GridBlock>) -> Self {
|
||||
impl std::convert::From<Vec<GridBlockPB>> for RepeatedGridBlockPB {
|
||||
fn from(items: Vec<GridBlockPB>) -> Self {
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct InsertedRow {
|
||||
pub struct InsertedRowPB {
|
||||
#[pb(index = 1)]
|
||||
pub block_id: String,
|
||||
|
||||
@ -109,7 +109,7 @@ pub struct InsertedRow {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct UpdatedRow {
|
||||
pub struct UpdatedRowPB {
|
||||
#[pb(index = 1)]
|
||||
pub block_id: String,
|
||||
|
||||
@ -117,11 +117,11 @@ pub struct UpdatedRow {
|
||||
pub row_id: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub row: Row,
|
||||
pub row: GridRowPB,
|
||||
}
|
||||
|
||||
impl UpdatedRow {
|
||||
pub fn new(row_rev: &RowRevision, row: Row) -> Self {
|
||||
impl UpdatedRowPB {
|
||||
pub fn new(row_rev: &RowRevision, row: GridRowPB) -> Self {
|
||||
Self {
|
||||
row_id: row_rev.id.clone(),
|
||||
block_id: row_rev.block_id.clone(),
|
||||
@ -130,8 +130,8 @@ impl UpdatedRow {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Row> for InsertedRow {
|
||||
fn from(row_info: Row) -> Self {
|
||||
impl std::convert::From<GridRowPB> for InsertedRowPB {
|
||||
fn from(row_info: GridRowPB) -> Self {
|
||||
Self {
|
||||
row_id: row_info.id,
|
||||
block_id: row_info.block_id,
|
||||
@ -141,26 +141,26 @@ impl std::convert::From<Row> for InsertedRow {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&RowRevision> for InsertedRow {
|
||||
impl std::convert::From<&RowRevision> for InsertedRowPB {
|
||||
fn from(row: &RowRevision) -> Self {
|
||||
let row_order = Row::from(row);
|
||||
let row_order = GridRowPB::from(row);
|
||||
Self::from(row_order)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct GridBlockChangeset {
|
||||
pub struct GridBlockChangesetPB {
|
||||
#[pb(index = 1)]
|
||||
pub block_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub inserted_rows: Vec<InsertedRow>,
|
||||
pub inserted_rows: Vec<InsertedRowPB>,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub deleted_rows: Vec<String>,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub updated_rows: Vec<UpdatedRow>,
|
||||
pub updated_rows: Vec<UpdatedRowPB>,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub visible_rows: Vec<String>,
|
||||
@ -168,8 +168,8 @@ pub struct GridBlockChangeset {
|
||||
#[pb(index = 6)]
|
||||
pub hide_rows: Vec<String>,
|
||||
}
|
||||
impl GridBlockChangeset {
|
||||
pub fn insert(block_id: &str, inserted_rows: Vec<InsertedRow>) -> Self {
|
||||
impl GridBlockChangesetPB {
|
||||
pub fn insert(block_id: &str, inserted_rows: Vec<InsertedRowPB>) -> Self {
|
||||
Self {
|
||||
block_id: block_id.to_owned(),
|
||||
inserted_rows,
|
||||
@ -185,7 +185,7 @@ impl GridBlockChangeset {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(block_id: &str, updated_rows: Vec<UpdatedRow>) -> Self {
|
||||
pub fn update(block_id: &str, updated_rows: Vec<UpdatedRowPB>) -> Self {
|
||||
Self {
|
||||
block_id: block_id.to_owned(),
|
||||
updated_rows,
|
||||
@ -195,7 +195,7 @@ impl GridBlockChangeset {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct QueryGridBlocksPayload {
|
||||
pub struct QueryGridBlocksPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -208,7 +208,7 @@ pub struct QueryGridBlocksParams {
|
||||
pub block_ids: Vec<String>,
|
||||
}
|
||||
|
||||
impl TryInto<QueryGridBlocksParams> for QueryGridBlocksPayload {
|
||||
impl TryInto<QueryGridBlocksParams> for QueryGridBlocksPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<QueryGridBlocksParams, Self::Error> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{FieldIdentifier, FieldIdentifierPayload};
|
||||
use crate::entities::{FieldIdentifier, FieldIdentifierPayloadPB};
|
||||
use flowy_derive::ProtoBuf;
|
||||
use flowy_error::ErrorCode;
|
||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
@ -8,7 +8,7 @@ use std::collections::HashMap;
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct CreateSelectOptionPayload {
|
||||
#[pb(index = 1)]
|
||||
pub field_identifier: FieldIdentifierPayload,
|
||||
pub field_identifier: FieldIdentifierPayloadPB,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub option_name: String,
|
||||
|
@ -9,7 +9,7 @@ use std::sync::Arc;
|
||||
use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString};
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct Field {
|
||||
pub struct FieldPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -35,7 +35,7 @@ pub struct Field {
|
||||
pub is_primary: bool,
|
||||
}
|
||||
|
||||
impl std::convert::From<FieldRevision> for Field {
|
||||
impl std::convert::From<FieldRevision> for FieldPB {
|
||||
fn from(field_rev: FieldRevision) -> Self {
|
||||
Self {
|
||||
id: field_rev.id,
|
||||
@ -50,31 +50,31 @@ impl std::convert::From<FieldRevision> for Field {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Arc<FieldRevision>> for Field {
|
||||
impl std::convert::From<Arc<FieldRevision>> for FieldPB {
|
||||
fn from(field_rev: Arc<FieldRevision>) -> Self {
|
||||
let field_rev = field_rev.as_ref().clone();
|
||||
Field::from(field_rev)
|
||||
FieldPB::from(field_rev)
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct GridField {
|
||||
pub struct GridFieldPB {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
}
|
||||
|
||||
impl std::convert::From<&str> for GridField {
|
||||
impl std::convert::From<&str> for GridFieldPB {
|
||||
fn from(s: &str) -> Self {
|
||||
GridField { field_id: s.to_owned() }
|
||||
GridFieldPB { field_id: s.to_owned() }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<String> for GridField {
|
||||
impl std::convert::From<String> for GridFieldPB {
|
||||
fn from(s: String) -> Self {
|
||||
GridField { field_id: s }
|
||||
GridFieldPB { field_id: s }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&Arc<FieldRevision>> for GridField {
|
||||
impl std::convert::From<&Arc<FieldRevision>> for GridFieldPB {
|
||||
fn from(field_rev: &Arc<FieldRevision>) -> Self {
|
||||
Self {
|
||||
field_id: field_rev.id.clone(),
|
||||
@ -82,22 +82,22 @@ impl std::convert::From<&Arc<FieldRevision>> for GridField {
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct GridFieldChangeset {
|
||||
pub struct GridFieldChangesetPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub inserted_fields: Vec<IndexField>,
|
||||
pub inserted_fields: Vec<IndexFieldPB>,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub deleted_fields: Vec<GridField>,
|
||||
pub deleted_fields: Vec<GridFieldPB>,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub updated_fields: Vec<Field>,
|
||||
pub updated_fields: Vec<FieldPB>,
|
||||
}
|
||||
|
||||
impl GridFieldChangeset {
|
||||
pub fn insert(grid_id: &str, inserted_fields: Vec<IndexField>) -> Self {
|
||||
impl GridFieldChangesetPB {
|
||||
pub fn insert(grid_id: &str, inserted_fields: Vec<IndexFieldPB>) -> Self {
|
||||
Self {
|
||||
grid_id: grid_id.to_owned(),
|
||||
inserted_fields,
|
||||
@ -106,7 +106,7 @@ impl GridFieldChangeset {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete(grid_id: &str, deleted_fields: Vec<GridField>) -> Self {
|
||||
pub fn delete(grid_id: &str, deleted_fields: Vec<GridFieldPB>) -> Self {
|
||||
Self {
|
||||
grid_id: grid_id.to_string(),
|
||||
inserted_fields: vec![],
|
||||
@ -115,7 +115,7 @@ impl GridFieldChangeset {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(grid_id: &str, updated_fields: Vec<Field>) -> Self {
|
||||
pub fn update(grid_id: &str, updated_fields: Vec<FieldPB>) -> Self {
|
||||
Self {
|
||||
grid_id: grid_id.to_string(),
|
||||
inserted_fields: vec![],
|
||||
@ -126,25 +126,25 @@ impl GridFieldChangeset {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct IndexField {
|
||||
pub struct IndexFieldPB {
|
||||
#[pb(index = 1)]
|
||||
pub field: Field,
|
||||
pub field: FieldPB,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub index: i32,
|
||||
}
|
||||
|
||||
impl IndexField {
|
||||
impl IndexFieldPB {
|
||||
pub fn from_field_rev(field_rev: &Arc<FieldRevision>, index: usize) -> Self {
|
||||
Self {
|
||||
field: Field::from(field_rev.as_ref().clone()),
|
||||
field: FieldPB::from(field_rev.as_ref().clone()),
|
||||
index: index as i32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct GetEditFieldContextPayload {
|
||||
pub struct GetEditFieldContextPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -156,7 +156,7 @@ pub struct GetEditFieldContextPayload {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct EditFieldPayload {
|
||||
pub struct EditFieldPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -176,7 +176,7 @@ pub struct EditFieldParams {
|
||||
pub field_type: FieldType,
|
||||
}
|
||||
|
||||
impl TryInto<EditFieldParams> for EditFieldPayload {
|
||||
impl TryInto<EditFieldParams> for EditFieldPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<EditFieldParams, Self::Error> {
|
||||
@ -195,7 +195,7 @@ pub struct CreateFieldParams {
|
||||
pub field_type: FieldType,
|
||||
}
|
||||
|
||||
impl TryInto<CreateFieldParams> for EditFieldPayload {
|
||||
impl TryInto<CreateFieldParams> for EditFieldPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateFieldParams, Self::Error> {
|
||||
@ -209,87 +209,75 @@ impl TryInto<CreateFieldParams> for EditFieldPayload {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct FieldTypeOptionContext {
|
||||
pub struct FieldTypeOptionDataPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub grid_field: Field,
|
||||
pub field: FieldPB,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub type_option_data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct FieldTypeOptionData {
|
||||
pub struct RepeatedFieldPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub field: Field,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub type_option_data: Vec<u8>,
|
||||
pub items: Vec<FieldPB>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct RepeatedField {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<Field>,
|
||||
}
|
||||
impl std::ops::Deref for RepeatedField {
|
||||
type Target = Vec<Field>;
|
||||
impl std::ops::Deref for RepeatedFieldPB {
|
||||
type Target = Vec<FieldPB>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.items
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for RepeatedField {
|
||||
impl std::ops::DerefMut for RepeatedFieldPB {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.items
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<Field>> for RepeatedField {
|
||||
fn from(items: Vec<Field>) -> Self {
|
||||
impl std::convert::From<Vec<FieldPB>> for RepeatedFieldPB {
|
||||
fn from(items: Vec<FieldPB>) -> Self {
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct RepeatedFieldOrder {
|
||||
pub struct RepeatedGridFieldPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<GridField>,
|
||||
pub items: Vec<GridFieldPB>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for RepeatedFieldOrder {
|
||||
type Target = Vec<GridField>;
|
||||
impl std::ops::Deref for RepeatedGridFieldPB {
|
||||
type Target = Vec<GridFieldPB>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.items
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<GridField>> for RepeatedFieldOrder {
|
||||
fn from(field_orders: Vec<GridField>) -> Self {
|
||||
RepeatedFieldOrder { items: field_orders }
|
||||
impl std::convert::From<Vec<GridFieldPB>> for RepeatedGridFieldPB {
|
||||
fn from(field_orders: Vec<GridFieldPB>) -> Self {
|
||||
RepeatedGridFieldPB { items: field_orders }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<String> for RepeatedFieldOrder {
|
||||
impl std::convert::From<String> for RepeatedGridFieldPB {
|
||||
fn from(s: String) -> Self {
|
||||
RepeatedFieldOrder {
|
||||
items: vec![GridField::from(s)],
|
||||
RepeatedGridFieldPB {
|
||||
items: vec![GridFieldPB::from(s)],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct InsertFieldPayload {
|
||||
pub struct InsertFieldPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub field: Field,
|
||||
pub field: FieldPB,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub type_option_data: Vec<u8>,
|
||||
@ -301,12 +289,12 @@ pub struct InsertFieldPayload {
|
||||
#[derive(Clone)]
|
||||
pub struct InsertFieldParams {
|
||||
pub grid_id: String,
|
||||
pub field: Field,
|
||||
pub field: FieldPB,
|
||||
pub type_option_data: Vec<u8>,
|
||||
pub start_field_id: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<InsertFieldParams> for InsertFieldPayload {
|
||||
impl TryInto<InsertFieldParams> for InsertFieldPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<InsertFieldParams, Self::Error> {
|
||||
@ -328,7 +316,7 @@ impl TryInto<InsertFieldParams> for InsertFieldPayload {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct UpdateFieldTypeOptionPayload {
|
||||
pub struct UpdateFieldTypeOptionPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -346,7 +334,7 @@ pub struct UpdateFieldTypeOptionParams {
|
||||
pub type_option_data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl TryInto<UpdateFieldTypeOptionParams> for UpdateFieldTypeOptionPayload {
|
||||
impl TryInto<UpdateFieldTypeOptionParams> for UpdateFieldTypeOptionPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<UpdateFieldTypeOptionParams, Self::Error> {
|
||||
@ -362,20 +350,20 @@ impl TryInto<UpdateFieldTypeOptionParams> for UpdateFieldTypeOptionPayload {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct QueryFieldPayload {
|
||||
pub struct QueryFieldPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub field_orders: RepeatedFieldOrder,
|
||||
pub field_orders: RepeatedGridFieldPB,
|
||||
}
|
||||
|
||||
pub struct QueryFieldParams {
|
||||
pub grid_id: String,
|
||||
pub field_orders: RepeatedFieldOrder,
|
||||
pub field_orders: RepeatedGridFieldPB,
|
||||
}
|
||||
|
||||
impl TryInto<QueryFieldParams> for QueryFieldPayload {
|
||||
impl TryInto<QueryFieldParams> for QueryFieldPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<QueryFieldParams, Self::Error> {
|
||||
@ -388,7 +376,7 @@ impl TryInto<QueryFieldParams> for QueryFieldPayload {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct FieldChangesetPayload {
|
||||
pub struct FieldChangesetPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
@ -417,7 +405,7 @@ pub struct FieldChangesetPayload {
|
||||
pub type_option_data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl TryInto<FieldChangesetParams> for FieldChangesetPayload {
|
||||
impl TryInto<FieldChangesetParams> for FieldChangesetPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<FieldChangesetParams, Self::Error> {
|
||||
@ -569,7 +557,7 @@ impl std::convert::From<FieldTypeRevision> for FieldType {
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct FieldIdentifierPayload {
|
||||
pub struct FieldIdentifierPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
@ -582,7 +570,7 @@ pub struct FieldIdentifier {
|
||||
pub grid_id: String,
|
||||
}
|
||||
|
||||
impl TryInto<FieldIdentifier> for FieldIdentifierPayload {
|
||||
impl TryInto<FieldIdentifier> for FieldIdentifierPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<FieldIdentifier, Self::Error> {
|
||||
|
@ -17,7 +17,7 @@ pub struct GridFilter {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct RepeatedGridFilter {
|
||||
pub struct RepeatedGridFilterPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<GridFilter>,
|
||||
}
|
||||
@ -28,22 +28,22 @@ impl std::convert::From<&GridFilterRevision> for GridFilter {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<Arc<GridFilterRevision>>> for RepeatedGridFilter {
|
||||
impl std::convert::From<Vec<Arc<GridFilterRevision>>> for RepeatedGridFilterPB {
|
||||
fn from(revs: Vec<Arc<GridFilterRevision>>) -> Self {
|
||||
RepeatedGridFilter {
|
||||
RepeatedGridFilterPB {
|
||||
items: revs.into_iter().map(|rev| rev.as_ref().into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<GridFilter>> for RepeatedGridFilter {
|
||||
impl std::convert::From<Vec<GridFilter>> for RepeatedGridFilterPB {
|
||||
fn from(items: Vec<GridFilter>) -> Self {
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct DeleteFilterPayload {
|
||||
pub struct DeleteFilterPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
@ -54,7 +54,7 @@ pub struct DeleteFilterPayload {
|
||||
pub field_type: FieldType,
|
||||
}
|
||||
|
||||
impl TryInto<DeleteFilterParams> for DeleteFilterPayload {
|
||||
impl TryInto<DeleteFilterParams> for DeleteFilterPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<DeleteFilterParams, Self::Error> {
|
||||
@ -73,7 +73,7 @@ impl TryInto<DeleteFilterParams> for DeleteFilterPayload {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct CreateGridFilterPayload {
|
||||
pub struct CreateGridFilterPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
@ -87,7 +87,7 @@ pub struct CreateGridFilterPayload {
|
||||
pub content: Option<String>,
|
||||
}
|
||||
|
||||
impl CreateGridFilterPayload {
|
||||
impl CreateGridFilterPayloadPB {
|
||||
#[allow(dead_code)]
|
||||
pub fn new<T: Into<i32>>(field_rev: &FieldRevision, condition: T, content: Option<String>) -> Self {
|
||||
Self {
|
||||
@ -99,7 +99,7 @@ impl CreateGridFilterPayload {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<CreateGridFilterParams> for CreateGridFilterPayload {
|
||||
impl TryInto<CreateGridFilterParams> for CreateGridFilterPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateGridFilterParams, Self::Error> {
|
||||
|
@ -1,69 +1,69 @@
|
||||
use crate::entities::{GridBlock, GridField};
|
||||
use crate::entities::{GridBlockPB, GridFieldPB};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::ErrorCode;
|
||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct Grid {
|
||||
pub struct GridPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub fields: Vec<GridField>,
|
||||
pub fields: Vec<GridFieldPB>,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub blocks: Vec<GridBlock>,
|
||||
pub blocks: Vec<GridBlockPB>,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct CreateGridPayload {
|
||||
pub struct CreateGridPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, ProtoBuf, Default, Debug)]
|
||||
pub struct GridId {
|
||||
pub struct GridIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl AsRef<str> for GridId {
|
||||
impl AsRef<str> for GridIdPB {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, ProtoBuf, Default, Debug)]
|
||||
pub struct GridBlockId {
|
||||
pub struct GridBlockIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl AsRef<str> for GridBlockId {
|
||||
impl AsRef<str> for GridBlockIdPB {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&str> for GridBlockId {
|
||||
impl std::convert::From<&str> for GridBlockIdPB {
|
||||
fn from(s: &str) -> Self {
|
||||
GridBlockId { value: s.to_owned() }
|
||||
GridBlockIdPB { value: s.to_owned() }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, ProtoBuf_Enum)]
|
||||
pub enum MoveItemType {
|
||||
pub enum MoveItemTypePB {
|
||||
MoveField = 0,
|
||||
MoveRow = 1,
|
||||
}
|
||||
|
||||
impl std::default::Default for MoveItemType {
|
||||
impl std::default::Default for MoveItemTypePB {
|
||||
fn default() -> Self {
|
||||
MoveItemType::MoveField
|
||||
MoveItemTypePB::MoveField
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
pub struct MoveItemPayload {
|
||||
pub struct MoveItemPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -77,7 +77,7 @@ pub struct MoveItemPayload {
|
||||
pub to_index: i32,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub ty: MoveItemType,
|
||||
pub ty: MoveItemTypePB,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -86,10 +86,10 @@ pub struct MoveItemParams {
|
||||
pub item_id: String,
|
||||
pub from_index: i32,
|
||||
pub to_index: i32,
|
||||
pub ty: MoveItemType,
|
||||
pub ty: MoveItemTypePB,
|
||||
}
|
||||
|
||||
impl TryInto<MoveItemParams> for MoveItemPayload {
|
||||
impl TryInto<MoveItemParams> for MoveItemPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<MoveItemParams, Self::Error> {
|
||||
|
@ -7,7 +7,7 @@ use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridGroup {
|
||||
pub struct GridGroupPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -18,9 +18,9 @@ pub struct GridGroup {
|
||||
pub sub_group_field_id: Option<String>,
|
||||
}
|
||||
|
||||
impl std::convert::From<&GridGroupRevision> for GridGroup {
|
||||
impl std::convert::From<&GridGroupRevision> for GridGroupPB {
|
||||
fn from(rev: &GridGroupRevision) -> Self {
|
||||
GridGroup {
|
||||
GridGroupPB {
|
||||
id: rev.id.clone(),
|
||||
group_field_id: rev.field_id.clone(),
|
||||
sub_group_field_id: rev.sub_field_id.clone(),
|
||||
@ -29,27 +29,27 @@ impl std::convert::From<&GridGroupRevision> for GridGroup {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct RepeatedGridGroup {
|
||||
pub struct RepeatedGridGroupPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<GridGroup>,
|
||||
pub items: Vec<GridGroupPB>,
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<GridGroup>> for RepeatedGridGroup {
|
||||
fn from(items: Vec<GridGroup>) -> Self {
|
||||
impl std::convert::From<Vec<GridGroupPB>> for RepeatedGridGroupPB {
|
||||
fn from(items: Vec<GridGroupPB>) -> Self {
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<Arc<GridGroupRevision>>> for RepeatedGridGroup {
|
||||
impl std::convert::From<Vec<Arc<GridGroupRevision>>> for RepeatedGridGroupPB {
|
||||
fn from(revs: Vec<Arc<GridGroupRevision>>) -> Self {
|
||||
RepeatedGridGroup {
|
||||
RepeatedGridGroupPB {
|
||||
items: revs.iter().map(|rev| rev.as_ref().into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct CreateGridGroupPayload {
|
||||
pub struct CreateGridGroupPayloadPB {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub field_id: Option<String>,
|
||||
|
||||
@ -57,7 +57,7 @@ pub struct CreateGridGroupPayload {
|
||||
pub sub_field_id: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<CreateGridGroupParams> for CreateGridGroupPayload {
|
||||
impl TryInto<CreateGridGroupParams> for CreateGridGroupPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateGridGroupParams, Self::Error> {
|
||||
|
@ -3,7 +3,7 @@ use flowy_error::ErrorCode;
|
||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct GridRowIdPayload {
|
||||
pub struct GridRowIdPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -15,7 +15,7 @@ pub struct GridRowIdPayload {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, ProtoBuf)]
|
||||
pub struct GridRowId {
|
||||
pub struct GridRowIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -26,15 +26,15 @@ pub struct GridRowId {
|
||||
pub row_id: String,
|
||||
}
|
||||
|
||||
impl TryInto<GridRowId> for GridRowIdPayload {
|
||||
impl TryInto<GridRowIdPB> for GridRowIdPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<GridRowId, Self::Error> {
|
||||
fn try_into(self) -> Result<GridRowIdPB, Self::Error> {
|
||||
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
||||
let block_id = NotEmptyStr::parse(self.block_id).map_err(|_| ErrorCode::BlockIdIsEmpty)?;
|
||||
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
||||
|
||||
Ok(GridRowId {
|
||||
Ok(GridRowIdPB {
|
||||
grid_id: grid_id.0,
|
||||
block_id: block_id.0,
|
||||
row_id: row_id.0,
|
||||
@ -43,7 +43,7 @@ impl TryInto<GridRowId> for GridRowIdPayload {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, ProtoBuf)]
|
||||
pub struct BlockRowId {
|
||||
pub struct BlockRowIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub block_id: String,
|
||||
|
||||
@ -52,7 +52,7 @@ pub struct BlockRowId {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct CreateRowPayload {
|
||||
pub struct CreateRowPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -66,7 +66,7 @@ pub struct CreateRowParams {
|
||||
pub start_row_id: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<CreateRowParams> for CreateRowPayload {
|
||||
impl TryInto<CreateRowParams> for CreateRowPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::entities::{
|
||||
CreateGridFilterPayload, CreateGridGroupPayload, CreateGridSortPayload, DeleteFilterPayload, RepeatedGridFilter,
|
||||
RepeatedGridGroup, RepeatedGridSort,
|
||||
CreateGridFilterPayloadPB, CreateGridGroupPayloadPB, CreateGridSortPayloadPB, DeleteFilterPayloadPB,
|
||||
RepeatedGridFilterPB, RepeatedGridGroupPB, RepeatedGridSortPB,
|
||||
};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::ErrorCode;
|
||||
@ -13,34 +13,34 @@ use strum::IntoEnumIterator;
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridSetting {
|
||||
pub struct GridSettingPB {
|
||||
#[pb(index = 1)]
|
||||
pub layouts: Vec<GridLayout>,
|
||||
pub layouts: Vec<GridLayoutPB>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub current_layout_type: GridLayoutType,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub filters_by_field_id: HashMap<String, RepeatedGridFilter>,
|
||||
pub filters_by_field_id: HashMap<String, RepeatedGridFilterPB>,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub groups_by_field_id: HashMap<String, RepeatedGridGroup>,
|
||||
pub groups_by_field_id: HashMap<String, RepeatedGridGroupPB>,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub sorts_by_field_id: HashMap<String, RepeatedGridSort>,
|
||||
pub sorts_by_field_id: HashMap<String, RepeatedGridSortPB>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridLayout {
|
||||
pub struct GridLayoutPB {
|
||||
#[pb(index = 1)]
|
||||
ty: GridLayoutType,
|
||||
}
|
||||
|
||||
impl GridLayout {
|
||||
pub fn all() -> Vec<GridLayout> {
|
||||
impl GridLayoutPB {
|
||||
pub fn all() -> Vec<GridLayoutPB> {
|
||||
let mut layouts = vec![];
|
||||
for layout_ty in GridLayoutType::iter() {
|
||||
layouts.push(GridLayout { ty: layout_ty })
|
||||
layouts.push(GridLayoutPB { ty: layout_ty })
|
||||
}
|
||||
|
||||
layouts
|
||||
@ -79,7 +79,7 @@ impl std::convert::From<GridLayoutType> for GridLayoutRevision {
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct GridSettingChangesetPayload {
|
||||
pub struct GridSettingChangesetPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
@ -87,25 +87,25 @@ pub struct GridSettingChangesetPayload {
|
||||
pub layout_type: GridLayoutType,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub insert_filter: Option<CreateGridFilterPayload>,
|
||||
pub insert_filter: Option<CreateGridFilterPayloadPB>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub delete_filter: Option<DeleteFilterPayload>,
|
||||
pub delete_filter: Option<DeleteFilterPayloadPB>,
|
||||
|
||||
#[pb(index = 5, one_of)]
|
||||
pub insert_group: Option<CreateGridGroupPayload>,
|
||||
pub insert_group: Option<CreateGridGroupPayloadPB>,
|
||||
|
||||
#[pb(index = 6, one_of)]
|
||||
pub delete_group: Option<String>,
|
||||
|
||||
#[pb(index = 7, one_of)]
|
||||
pub insert_sort: Option<CreateGridSortPayload>,
|
||||
pub insert_sort: Option<CreateGridSortPayloadPB>,
|
||||
|
||||
#[pb(index = 8, one_of)]
|
||||
pub delete_sort: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<GridSettingChangesetParams> for GridSettingChangesetPayload {
|
||||
impl TryInto<GridSettingChangesetParams> for GridSettingChangesetPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<GridSettingChangesetParams, Self::Error> {
|
||||
|
@ -26,32 +26,32 @@ impl std::convert::From<&GridSortRevision> for GridSort {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct RepeatedGridSort {
|
||||
pub struct RepeatedGridSortPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<GridSort>,
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<Arc<GridSortRevision>>> for RepeatedGridSort {
|
||||
impl std::convert::From<Vec<Arc<GridSortRevision>>> for RepeatedGridSortPB {
|
||||
fn from(revs: Vec<Arc<GridSortRevision>>) -> Self {
|
||||
RepeatedGridSort {
|
||||
RepeatedGridSortPB {
|
||||
items: revs.into_iter().map(|rev| rev.as_ref().into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<GridSort>> for RepeatedGridSort {
|
||||
impl std::convert::From<Vec<GridSort>> for RepeatedGridSortPB {
|
||||
fn from(items: Vec<GridSort>) -> Self {
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct CreateGridSortPayload {
|
||||
pub struct CreateGridSortPayloadPB {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub field_id: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<CreateGridSortParams> for CreateGridSortPayload {
|
||||
impl TryInto<CreateGridSortParams> for CreateGridSortPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateGridSortParams, Self::Error> {
|
||||
|
@ -3,9 +3,9 @@ use crate::manager::GridManager;
|
||||
use crate::services::cell::AnyCellData;
|
||||
use crate::services::field::{
|
||||
default_type_option_builder_from_type, select_option_operation, type_option_builder_from_json_str,
|
||||
DateChangesetParams, DateChangesetPayload, SelectOption, SelectOptionCellChangeset,
|
||||
SelectOptionCellChangesetParams, SelectOptionCellChangesetPayload, SelectOptionCellData, SelectOptionChangeset,
|
||||
SelectOptionChangesetPayload,
|
||||
DateChangesetParams, DateChangesetPayloadPB, SelectOptionPB, SelectOptionCellChangeset,
|
||||
SelectOptionCellChangesetParams, SelectOptionCellChangesetPayloadPB, SelectOptionCellDataPB, SelectOptionChangeset,
|
||||
SelectOptionChangesetPayloadPB,
|
||||
};
|
||||
use crate::services::row::make_row_from_row_rev;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
@ -16,10 +16,10 @@ use std::sync::Arc;
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn get_grid_handler(
|
||||
data: Data<GridId>,
|
||||
data: Data<GridIdPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<Grid, FlowyError> {
|
||||
let grid_id: GridId = data.into_inner();
|
||||
) -> DataResult<GridPB, FlowyError> {
|
||||
let grid_id: GridIdPB = data.into_inner();
|
||||
let editor = manager.open_grid(grid_id).await?;
|
||||
let grid = editor.get_grid_data().await?;
|
||||
data_result(grid)
|
||||
@ -27,10 +27,10 @@ pub(crate) async fn get_grid_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn get_grid_setting_handler(
|
||||
data: Data<GridId>,
|
||||
data: Data<GridIdPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<GridSetting, FlowyError> {
|
||||
let grid_id: GridId = data.into_inner();
|
||||
) -> DataResult<GridSettingPB, FlowyError> {
|
||||
let grid_id: GridIdPB = data.into_inner();
|
||||
let editor = manager.open_grid(grid_id).await?;
|
||||
let grid_setting = editor.get_grid_setting().await?;
|
||||
data_result(grid_setting)
|
||||
@ -38,7 +38,7 @@ pub(crate) async fn get_grid_setting_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn update_grid_setting_handler(
|
||||
data: Data<GridSettingChangesetPayload>,
|
||||
data: Data<GridSettingChangesetPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: GridSettingChangesetParams = data.into_inner().try_into()?;
|
||||
@ -49,9 +49,9 @@ pub(crate) async fn update_grid_setting_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn get_grid_blocks_handler(
|
||||
data: Data<QueryGridBlocksPayload>,
|
||||
data: Data<QueryGridBlocksPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<RepeatedGridBlock, FlowyError> {
|
||||
) -> DataResult<RepeatedGridBlockPB, FlowyError> {
|
||||
let params: QueryGridBlocksParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let repeated_grid_block = editor.get_blocks(Some(params.block_ids)).await?;
|
||||
@ -60,9 +60,9 @@ pub(crate) async fn get_grid_blocks_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn get_fields_handler(
|
||||
data: Data<QueryFieldPayload>,
|
||||
data: Data<QueryFieldPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<RepeatedField, FlowyError> {
|
||||
) -> DataResult<RepeatedFieldPB, FlowyError> {
|
||||
let params: QueryFieldParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let field_orders = params
|
||||
@ -72,13 +72,13 @@ pub(crate) async fn get_fields_handler(
|
||||
.map(|field_order| field_order.field_id)
|
||||
.collect();
|
||||
let field_revs = editor.get_field_revs(Some(field_orders)).await?;
|
||||
let repeated_field: RepeatedField = field_revs.into_iter().map(Field::from).collect::<Vec<_>>().into();
|
||||
let repeated_field: RepeatedFieldPB = field_revs.into_iter().map(FieldPB::from).collect::<Vec<_>>().into();
|
||||
data_result(repeated_field)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn update_field_handler(
|
||||
data: Data<FieldChangesetPayload>,
|
||||
data: Data<FieldChangesetPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let changeset: FieldChangesetParams = data.into_inner().try_into()?;
|
||||
@ -89,7 +89,7 @@ pub(crate) async fn update_field_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn insert_field_handler(
|
||||
data: Data<InsertFieldPayload>,
|
||||
data: Data<InsertFieldPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: InsertFieldParams = data.into_inner().try_into()?;
|
||||
@ -100,7 +100,7 @@ pub(crate) async fn insert_field_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn update_field_type_option_handler(
|
||||
data: Data<UpdateFieldTypeOptionPayload>,
|
||||
data: Data<UpdateFieldTypeOptionPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateFieldTypeOptionParams = data.into_inner().try_into()?;
|
||||
@ -113,7 +113,7 @@ pub(crate) async fn update_field_type_option_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn delete_field_handler(
|
||||
data: Data<FieldIdentifierPayload>,
|
||||
data: Data<FieldIdentifierPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: FieldIdentifier = data.into_inner().try_into()?;
|
||||
@ -124,9 +124,9 @@ pub(crate) async fn delete_field_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn switch_to_field_handler(
|
||||
data: Data<EditFieldPayload>,
|
||||
data: Data<EditFieldPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<FieldTypeOptionData, FlowyError> {
|
||||
) -> DataResult<FieldTypeOptionDataPB, FlowyError> {
|
||||
let params: EditFieldParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
editor
|
||||
@ -140,7 +140,7 @@ pub(crate) async fn switch_to_field_handler(
|
||||
.unwrap_or(Arc::new(editor.next_field_rev(¶ms.field_type).await?));
|
||||
|
||||
let type_option_data = get_type_option_data(&field_rev, ¶ms.field_type).await?;
|
||||
let data = FieldTypeOptionData {
|
||||
let data = FieldTypeOptionDataPB {
|
||||
grid_id: params.grid_id,
|
||||
field: field_rev.into(),
|
||||
type_option_data,
|
||||
@ -151,7 +151,7 @@ pub(crate) async fn switch_to_field_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn duplicate_field_handler(
|
||||
data: Data<FieldIdentifierPayload>,
|
||||
data: Data<FieldIdentifierPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: FieldIdentifier = data.into_inner().try_into()?;
|
||||
@ -163,9 +163,9 @@ pub(crate) async fn duplicate_field_handler(
|
||||
/// Return the FieldTypeOptionData if the Field exists otherwise return record not found error.
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn get_field_type_option_data_handler(
|
||||
data: Data<EditFieldPayload>,
|
||||
data: Data<EditFieldPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<FieldTypeOptionData, FlowyError> {
|
||||
) -> DataResult<FieldTypeOptionDataPB, FlowyError> {
|
||||
let params: EditFieldParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
match editor.get_field_rev(¶ms.field_id).await {
|
||||
@ -173,7 +173,7 @@ pub(crate) async fn get_field_type_option_data_handler(
|
||||
Some(field_rev) => {
|
||||
let field_type = field_rev.field_type_rev.into();
|
||||
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
||||
let data = FieldTypeOptionData {
|
||||
let data = FieldTypeOptionDataPB {
|
||||
grid_id: params.grid_id,
|
||||
field: field_rev.into(),
|
||||
type_option_data,
|
||||
@ -186,16 +186,16 @@ pub(crate) async fn get_field_type_option_data_handler(
|
||||
/// Create FieldMeta and save it. Return the FieldTypeOptionData.
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn create_field_type_option_data_handler(
|
||||
data: Data<EditFieldPayload>,
|
||||
data: Data<EditFieldPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<FieldTypeOptionData, FlowyError> {
|
||||
) -> DataResult<FieldTypeOptionDataPB, FlowyError> {
|
||||
let params: CreateFieldParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let field_rev = editor.create_next_field_rev(¶ms.field_type).await?;
|
||||
let field_type: FieldType = field_rev.field_type_rev.into();
|
||||
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
||||
|
||||
data_result(FieldTypeOptionData {
|
||||
data_result(FieldTypeOptionDataPB {
|
||||
grid_id: params.grid_id,
|
||||
field: field_rev.into(),
|
||||
type_option_data,
|
||||
@ -204,7 +204,7 @@ pub(crate) async fn create_field_type_option_data_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn move_item_handler(
|
||||
data: Data<MoveItemPayload>,
|
||||
data: Data<MoveItemPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: MoveItemParams = data.into_inner().try_into()?;
|
||||
@ -227,25 +227,25 @@ async fn get_type_option_data(field_rev: &FieldRevision, field_type: &FieldType)
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn get_row_handler(
|
||||
data: Data<GridRowIdPayload>,
|
||||
data: Data<GridRowIdPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<OptionalRow, FlowyError> {
|
||||
let params: GridRowId = data.into_inner().try_into()?;
|
||||
) -> DataResult<OptionalRowPB, FlowyError> {
|
||||
let params: GridRowIdPB = 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(make_row_from_row_rev);
|
||||
|
||||
data_result(OptionalRow { row })
|
||||
data_result(OptionalRowPB { row })
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn delete_row_handler(
|
||||
data: Data<GridRowIdPayload>,
|
||||
data: Data<GridRowIdPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: GridRowId = data.into_inner().try_into()?;
|
||||
let params: GridRowIdPB = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let _ = editor.delete_row(¶ms.row_id).await?;
|
||||
Ok(())
|
||||
@ -253,10 +253,10 @@ pub(crate) async fn delete_row_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn duplicate_row_handler(
|
||||
data: Data<GridRowIdPayload>,
|
||||
data: Data<GridRowIdPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: GridRowId = data.into_inner().try_into()?;
|
||||
let params: GridRowIdPB = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let _ = editor.duplicate_row(¶ms.row_id).await?;
|
||||
Ok(())
|
||||
@ -264,7 +264,7 @@ pub(crate) async fn duplicate_row_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn create_row_handler(
|
||||
data: Data<CreateRowPayload>,
|
||||
data: Data<CreateRowPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: CreateRowParams = data.into_inner().try_into()?;
|
||||
@ -301,7 +301,7 @@ pub(crate) async fn update_cell_handler(
|
||||
pub(crate) async fn new_select_option_handler(
|
||||
data: Data<CreateSelectOptionPayload>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<SelectOption, FlowyError> {
|
||||
) -> DataResult<SelectOptionPB, FlowyError> {
|
||||
let params: CreateSelectOptionParams = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
match editor.get_field_rev(¶ms.field_id).await {
|
||||
@ -316,7 +316,7 @@ pub(crate) async fn new_select_option_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) async fn update_select_option_handler(
|
||||
data: Data<SelectOptionChangesetPayload>,
|
||||
data: Data<SelectOptionChangesetPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let changeset: SelectOptionChangeset = data.into_inner().try_into()?;
|
||||
@ -359,13 +359,13 @@ pub(crate) async fn update_select_option_handler(
|
||||
pub(crate) async fn get_select_option_handler(
|
||||
data: Data<CellIdentifierPayload>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<SelectOptionCellData, FlowyError> {
|
||||
) -> DataResult<SelectOptionCellDataPB, FlowyError> {
|
||||
let params: CellIdentifier = data.into_inner().try_into()?;
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
match editor.get_field_rev(¶ms.field_id).await {
|
||||
None => {
|
||||
tracing::error!("Can't find the select option field with id: {}", params.field_id);
|
||||
data_result(SelectOptionCellData::default())
|
||||
data_result(SelectOptionCellDataPB::default())
|
||||
}
|
||||
Some(field_rev) => {
|
||||
//
|
||||
@ -386,7 +386,7 @@ pub(crate) async fn get_select_option_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) async fn update_select_option_cell_handler(
|
||||
data: Data<SelectOptionCellChangesetPayload>,
|
||||
data: Data<SelectOptionCellChangesetPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: SelectOptionCellChangesetParams = data.into_inner().try_into()?;
|
||||
@ -397,7 +397,7 @@ pub(crate) async fn update_select_option_cell_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) async fn update_date_cell_handler(
|
||||
data: Data<DateChangesetPayload>,
|
||||
data: Data<DateChangesetPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: DateChangesetParams = data.into_inner().try_into()?;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||
use crate::entities::{CellChangeset, GridBlockChangeset, InsertedRow, Row, UpdatedRow};
|
||||
use crate::entities::{CellChangeset, GridBlockChangesetPB, GridRowPB, InsertedRowPB, UpdatedRowPB};
|
||||
use crate::manager::GridUser;
|
||||
use crate::services::block_revision_editor::GridBlockRevisionEditor;
|
||||
use crate::services::persistence::block_index::BlockIndexCache;
|
||||
@ -71,12 +71,12 @@ impl GridBlockManager {
|
||||
let _ = self.persistence.insert(&row_rev.block_id, &row_rev.id)?;
|
||||
let editor = self.get_editor(&row_rev.block_id).await?;
|
||||
|
||||
let mut index_row_order = InsertedRow::from(&row_rev);
|
||||
let mut index_row_order = InsertedRowPB::from(&row_rev);
|
||||
let (row_count, row_index) = editor.create_row(row_rev, start_row_id).await?;
|
||||
index_row_order.index = row_index;
|
||||
|
||||
let _ = self
|
||||
.notify_did_update_block(block_id, GridBlockChangeset::insert(block_id, vec![index_row_order]))
|
||||
.notify_did_update_block(block_id, GridBlockChangesetPB::insert(block_id, vec![index_row_order]))
|
||||
.await?;
|
||||
Ok(row_count)
|
||||
}
|
||||
@ -92,7 +92,7 @@ impl GridBlockManager {
|
||||
let mut row_count = 0;
|
||||
for row in row_revs {
|
||||
let _ = self.persistence.insert(&row.block_id, &row.id)?;
|
||||
let mut row_order = InsertedRow::from(&row);
|
||||
let mut row_order = InsertedRowPB::from(&row);
|
||||
let (count, index) = editor.create_row(row, None).await?;
|
||||
row_count = count;
|
||||
row_order.index = index;
|
||||
@ -101,7 +101,7 @@ impl GridBlockManager {
|
||||
changesets.push(GridBlockMetaRevisionChangeset::from_row_count(&block_id, row_count));
|
||||
|
||||
let _ = self
|
||||
.notify_did_update_block(&block_id, GridBlockChangeset::insert(&block_id, inserted_row_orders))
|
||||
.notify_did_update_block(&block_id, GridBlockChangesetPB::insert(&block_id, inserted_row_orders))
|
||||
.await?;
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ impl GridBlockManager {
|
||||
|
||||
pub async fn update_row<F>(&self, changeset: RowMetaChangeset, row_builder: F) -> FlowyResult<()>
|
||||
where
|
||||
F: FnOnce(Arc<RowRevision>) -> Option<Row>,
|
||||
F: FnOnce(Arc<RowRevision>) -> Option<GridRowPB>,
|
||||
{
|
||||
let editor = self.get_editor_from_row_id(&changeset.row_id).await?;
|
||||
let _ = editor.update_row(changeset.clone()).await?;
|
||||
@ -118,8 +118,8 @@ impl GridBlockManager {
|
||||
None => tracing::error!("Internal error: can't find the row with id: {}", changeset.row_id),
|
||||
Some(row_rev) => {
|
||||
if let Some(row) = row_builder(row_rev.clone()) {
|
||||
let row_order = UpdatedRow::new(&row_rev, row);
|
||||
let block_order_changeset = GridBlockChangeset::update(&editor.block_id, vec![row_order]);
|
||||
let row_order = UpdatedRowPB::new(&row_rev, row);
|
||||
let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_order]);
|
||||
let _ = self
|
||||
.notify_did_update_block(&editor.block_id, block_order_changeset)
|
||||
.await?;
|
||||
@ -138,7 +138,7 @@ impl GridBlockManager {
|
||||
Some(row_info) => {
|
||||
let _ = editor.delete_rows(vec![Cow::Borrowed(&row_id)]).await?;
|
||||
let _ = self
|
||||
.notify_did_update_block(&block_id, GridBlockChangeset::delete(&block_id, vec![row_info.id]))
|
||||
.notify_did_update_block(&block_id, GridBlockChangesetPB::delete(&block_id, vec![row_info.id]))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,10 @@ impl GridBlockManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_rows(&self, row_orders: Vec<Row>) -> FlowyResult<Vec<GridBlockMetaRevisionChangeset>> {
|
||||
pub(crate) async fn delete_rows(
|
||||
&self,
|
||||
row_orders: Vec<GridRowPB>,
|
||||
) -> FlowyResult<Vec<GridBlockMetaRevisionChangeset>> {
|
||||
let mut changesets = vec![];
|
||||
for grid_block in block_from_row_orders(row_orders) {
|
||||
let editor = self.get_editor(&grid_block.id).await?;
|
||||
@ -170,14 +173,14 @@ impl GridBlockManager {
|
||||
match editor.get_row_revs(Some(vec![Cow::Borrowed(row_id)])).await?.pop() {
|
||||
None => {}
|
||||
Some(row_rev) => {
|
||||
let insert_row = InsertedRow {
|
||||
let insert_row = InsertedRowPB {
|
||||
block_id: row_rev.block_id.clone(),
|
||||
row_id: row_rev.id.clone(),
|
||||
index: Some(to as i32),
|
||||
height: row_rev.height,
|
||||
};
|
||||
|
||||
let notified_changeset = GridBlockChangeset {
|
||||
let notified_changeset = GridBlockChangesetPB {
|
||||
block_id: editor.block_id.clone(),
|
||||
inserted_rows: vec![insert_row],
|
||||
deleted_rows: vec![row_rev.id.clone()],
|
||||
@ -195,7 +198,7 @@ impl GridBlockManager {
|
||||
|
||||
pub async fn update_cell<F>(&self, changeset: CellChangeset, row_builder: F) -> FlowyResult<()>
|
||||
where
|
||||
F: FnOnce(Arc<RowRevision>) -> Option<Row>,
|
||||
F: FnOnce(Arc<RowRevision>) -> Option<GridRowPB>,
|
||||
{
|
||||
let row_changeset: RowMetaChangeset = changeset.clone().into();
|
||||
let _ = self.update_row(row_changeset, row_builder).await?;
|
||||
@ -214,7 +217,7 @@ impl GridBlockManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_row_orders(&self, block_id: &str) -> FlowyResult<Vec<Row>> {
|
||||
pub async fn get_row_orders(&self, block_id: &str) -> FlowyResult<Vec<GridRowPB>> {
|
||||
let editor = self.get_editor(block_id).await?;
|
||||
editor.get_row_infos::<&str>(None).await
|
||||
}
|
||||
@ -244,7 +247,7 @@ impl GridBlockManager {
|
||||
Ok(snapshots)
|
||||
}
|
||||
|
||||
async fn notify_did_update_block(&self, block_id: &str, changeset: GridBlockChangeset) -> FlowyResult<()> {
|
||||
async fn notify_did_update_block(&self, block_id: &str, changeset: GridBlockChangesetPB) -> FlowyResult<()> {
|
||||
send_dart_notification(block_id, GridNotification::DidUpdateGridBlock)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::Row;
|
||||
use crate::entities::GridRowPB;
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::{CellRevision, GridBlockRevision, RowMetaChangeset, RowRevision};
|
||||
@ -123,12 +123,12 @@ impl GridBlockRevisionEditor {
|
||||
Ok(cell_revs)
|
||||
}
|
||||
|
||||
pub async fn get_row_info(&self, row_id: &str) -> FlowyResult<Option<Row>> {
|
||||
pub async fn get_row_info(&self, row_id: &str) -> FlowyResult<Option<GridRowPB>> {
|
||||
let row_ids = Some(vec![Cow::Borrowed(row_id)]);
|
||||
Ok(self.get_row_infos(row_ids).await?.pop())
|
||||
}
|
||||
|
||||
pub async fn get_row_infos<T>(&self, row_ids: Option<Vec<Cow<'_, T>>>) -> FlowyResult<Vec<Row>>
|
||||
pub async fn get_row_infos<T>(&self, row_ids: Option<Vec<Cow<'_, T>>>) -> FlowyResult<Vec<GridRowPB>>
|
||||
where
|
||||
T: AsRef<str> + ToOwned + ?Sized,
|
||||
{
|
||||
@ -138,8 +138,8 @@ impl GridBlockRevisionEditor {
|
||||
.await
|
||||
.get_row_revs(row_ids)?
|
||||
.iter()
|
||||
.map(Row::from)
|
||||
.collect::<Vec<Row>>();
|
||||
.map(GridRowPB::from)
|
||||
.collect::<Vec<GridRowPB>>();
|
||||
Ok(row_infos)
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,9 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>(
|
||||
FieldType::RichText => RichTextTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
FieldType::Number => NumberTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
FieldType::DateTime => DateTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
FieldType::SingleSelect => SingleSelectTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
FieldType::SingleSelect => {
|
||||
SingleSelectTypeOptionPB::from(field_rev).apply_changeset(changeset.into(), cell_rev)
|
||||
}
|
||||
FieldType::MultiSelect => MultiSelectTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
FieldType::Checkbox => CheckboxTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
FieldType::URL => URLTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev),
|
||||
@ -104,7 +106,7 @@ pub fn try_decode_cell_data(
|
||||
.get_type_option_entry::<DateTypeOption>(field_type)?
|
||||
.decode_cell_data(cell_data.into(), s_field_type, field_rev),
|
||||
FieldType::SingleSelect => field_rev
|
||||
.get_type_option_entry::<SingleSelectTypeOption>(field_type)?
|
||||
.get_type_option_entry::<SingleSelectTypeOptionPB>(field_type)?
|
||||
.decode_cell_data(cell_data.into(), s_field_type, field_rev),
|
||||
FieldType::MultiSelect => field_rev
|
||||
.get_type_option_entry::<MultiSelectTypeOption>(field_type)?
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{Field, FieldType};
|
||||
use crate::entities::{FieldPB, FieldType};
|
||||
use crate::services::field::type_options::*;
|
||||
use bytes::Bytes;
|
||||
use flowy_grid_data_model::revision::{FieldRevision, TypeOptionDataEntry};
|
||||
@ -28,7 +28,7 @@ impl FieldBuilder {
|
||||
Self::new(type_option_builder)
|
||||
}
|
||||
|
||||
pub fn from_field(field: Field, type_option_builder: Box<dyn TypeOptionBuilder>) -> Self {
|
||||
pub fn from_field(field: FieldPB, type_option_builder: Box<dyn TypeOptionBuilder>) -> Self {
|
||||
let field_rev = FieldRevision {
|
||||
id: field.id,
|
||||
name: field.name,
|
||||
@ -93,7 +93,7 @@ pub fn default_type_option_builder_from_type(field_type: &FieldType) -> Box<dyn
|
||||
FieldType::RichText => RichTextTypeOption::default().into(),
|
||||
FieldType::Number => NumberTypeOption::default().into(),
|
||||
FieldType::DateTime => DateTypeOption::default().into(),
|
||||
FieldType::SingleSelect => SingleSelectTypeOption::default().into(),
|
||||
FieldType::SingleSelect => SingleSelectTypeOptionPB::default().into(),
|
||||
FieldType::MultiSelect => MultiSelectTypeOption::default().into(),
|
||||
FieldType::Checkbox => CheckboxTypeOption::default().into(),
|
||||
FieldType::URL => URLTypeOption::default().into(),
|
||||
|
@ -14,7 +14,7 @@ mod tests {
|
||||
let field_rev = FieldBuilder::from_field_type(&field_type).build();
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some("1e".to_string()),
|
||||
time: Some("23:00".to_owned()),
|
||||
},
|
||||
@ -60,7 +60,7 @@ mod tests {
|
||||
TimeFormat::TwentyFourHour => {
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(1653609600.to_string()),
|
||||
time: None,
|
||||
},
|
||||
@ -70,7 +70,7 @@ mod tests {
|
||||
);
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(1653609600.to_string()),
|
||||
time: Some("23:00".to_owned()),
|
||||
},
|
||||
@ -82,7 +82,7 @@ mod tests {
|
||||
TimeFormat::TwelveHour => {
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(1653609600.to_string()),
|
||||
time: None,
|
||||
},
|
||||
@ -93,7 +93,7 @@ mod tests {
|
||||
//
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(1653609600.to_string()),
|
||||
time: Some("".to_owned()),
|
||||
},
|
||||
@ -104,7 +104,7 @@ mod tests {
|
||||
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(1653609600.to_string()),
|
||||
time: Some("11:23 pm".to_owned()),
|
||||
},
|
||||
@ -126,7 +126,7 @@ mod tests {
|
||||
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp.clone()),
|
||||
time: None,
|
||||
},
|
||||
@ -138,7 +138,7 @@ mod tests {
|
||||
type_option.include_time = true;
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp.clone()),
|
||||
time: None,
|
||||
},
|
||||
@ -149,7 +149,7 @@ mod tests {
|
||||
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp.clone()),
|
||||
time: Some("1:00".to_owned()),
|
||||
},
|
||||
@ -161,7 +161,7 @@ mod tests {
|
||||
type_option.time_format = TimeFormat::TwelveHour;
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp),
|
||||
time: Some("1:00 am".to_owned()),
|
||||
},
|
||||
@ -181,7 +181,7 @@ mod tests {
|
||||
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp.clone()),
|
||||
time: Some("1:".to_owned()),
|
||||
},
|
||||
@ -192,7 +192,7 @@ mod tests {
|
||||
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp),
|
||||
time: Some("1:00".to_owned()),
|
||||
},
|
||||
@ -212,7 +212,7 @@ mod tests {
|
||||
|
||||
assert_changeset_result(
|
||||
&type_option,
|
||||
DateCellChangeset {
|
||||
DateCellChangesetPB {
|
||||
date: Some(date_timestamp),
|
||||
time: Some("1:00 am".to_owned()),
|
||||
},
|
||||
@ -224,7 +224,7 @@ mod tests {
|
||||
|
||||
fn assert_changeset_result(
|
||||
type_option: &DateTypeOption,
|
||||
changeset: DateCellChangeset,
|
||||
changeset: DateCellChangesetPB,
|
||||
_field_type: &FieldType,
|
||||
field_rev: &FieldRevision,
|
||||
expected: &str,
|
||||
@ -243,7 +243,7 @@ mod tests {
|
||||
field_rev: &FieldRevision,
|
||||
expected: &str,
|
||||
) {
|
||||
let s = serde_json::to_string(&DateCellChangeset {
|
||||
let s = serde_json::to_string(&DateCellChangesetPB {
|
||||
date: Some(timestamp.to_string()),
|
||||
time: None,
|
||||
})
|
||||
|
@ -2,7 +2,7 @@ use crate::entities::FieldType;
|
||||
use crate::impl_type_option;
|
||||
use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable};
|
||||
use crate::services::field::{
|
||||
BoxTypeOptionBuilder, DateCellChangeset, DateCellData, DateFormat, DateTimestamp, TimeFormat, TypeOptionBuilder,
|
||||
BoxTypeOptionBuilder, DateCellChangesetPB, DateCellDataPB, DateFormat, DateTimestamp, TimeFormat, TypeOptionBuilder,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use chrono::format::strftime::StrftimeItems;
|
||||
@ -32,15 +32,15 @@ impl DateTypeOption {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn today_desc_from_timestamp<T: AsRef<i64>>(&self, timestamp: T) -> DateCellData {
|
||||
fn today_desc_from_timestamp<T: AsRef<i64>>(&self, timestamp: T) -> DateCellDataPB {
|
||||
let timestamp = *timestamp.as_ref();
|
||||
let native = chrono::NaiveDateTime::from_timestamp(timestamp, 0);
|
||||
self.date_from_native(native)
|
||||
}
|
||||
|
||||
fn date_from_native(&self, native: chrono::NaiveDateTime) -> DateCellData {
|
||||
fn date_from_native(&self, native: chrono::NaiveDateTime) -> DateCellDataPB {
|
||||
if native.timestamp() == 0 {
|
||||
return DateCellData::default();
|
||||
return DateCellDataPB::default();
|
||||
}
|
||||
|
||||
let time = native.time();
|
||||
@ -57,7 +57,7 @@ impl DateTypeOption {
|
||||
}
|
||||
|
||||
let timestamp = native.timestamp();
|
||||
DateCellData { date, time, timestamp }
|
||||
DateCellDataPB { date, time, timestamp }
|
||||
}
|
||||
|
||||
fn date_fmt(&self, time: &Option<String>) -> String {
|
||||
@ -129,7 +129,7 @@ impl CellDisplayable<DateTimestamp> for DateTypeOption {
|
||||
}
|
||||
}
|
||||
|
||||
impl CellDataOperation<DateTimestamp, DateCellChangeset> for DateTypeOption {
|
||||
impl CellDataOperation<DateTimestamp, DateCellChangesetPB> for DateTypeOption {
|
||||
fn decode_cell_data(
|
||||
&self,
|
||||
cell_data: CellData<DateTimestamp>,
|
||||
@ -148,7 +148,7 @@ impl CellDataOperation<DateTimestamp, DateCellChangeset> for DateTypeOption {
|
||||
|
||||
fn apply_changeset(
|
||||
&self,
|
||||
changeset: CellDataChangeset<DateCellChangeset>,
|
||||
changeset: CellDataChangeset<DateCellChangesetPB>,
|
||||
_cell_rev: Option<CellRevision>,
|
||||
) -> Result<String, FlowyError> {
|
||||
let changeset = changeset.try_into_inner()?;
|
||||
|
@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||
pub struct DateCellData {
|
||||
pub struct DateCellDataPB {
|
||||
#[pb(index = 1)]
|
||||
pub date: String,
|
||||
|
||||
@ -22,7 +22,7 @@ pub struct DateCellData {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||
pub struct DateChangesetPayload {
|
||||
pub struct DateChangesetPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub cell_identifier: CellIdentifierPayload,
|
||||
|
||||
@ -39,7 +39,7 @@ pub struct DateChangesetParams {
|
||||
pub time: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<DateChangesetParams> for DateChangesetPayload {
|
||||
impl TryInto<DateChangesetParams> for DateChangesetPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<DateChangesetParams, Self::Error> {
|
||||
@ -54,7 +54,7 @@ impl TryInto<DateChangesetParams> for DateChangesetPayload {
|
||||
|
||||
impl std::convert::From<DateChangesetParams> for CellChangeset {
|
||||
fn from(params: DateChangesetParams) -> Self {
|
||||
let changeset = DateCellChangeset {
|
||||
let changeset = DateCellChangesetPB {
|
||||
date: params.date,
|
||||
time: params.time,
|
||||
};
|
||||
@ -69,12 +69,12 @@ impl std::convert::From<DateChangesetParams> for CellChangeset {
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct DateCellChangeset {
|
||||
pub struct DateCellChangesetPB {
|
||||
pub date: Option<String>,
|
||||
pub time: Option<String>,
|
||||
}
|
||||
|
||||
impl DateCellChangeset {
|
||||
impl DateCellChangesetPB {
|
||||
pub fn date_timestamp(&self) -> Option<i64> {
|
||||
if let Some(date) = &self.date {
|
||||
match date.parse::<i64>() {
|
||||
@ -87,12 +87,12 @@ impl DateCellChangeset {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCellChangeset for DateCellChangeset {
|
||||
impl FromCellChangeset for DateCellChangesetPB {
|
||||
fn from_changeset(changeset: String) -> FlowyResult<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
serde_json::from_str::<DateCellChangeset>(&changeset).map_err(internal_error)
|
||||
serde_json::from_str::<DateCellChangesetPB>(&changeset).map_err(internal_error)
|
||||
}
|
||||
}
|
||||
pub struct DateTimestamp(i64);
|
||||
@ -202,9 +202,9 @@ impl std::default::Default for TimeFormat {
|
||||
|
||||
pub struct DateCellDataParser();
|
||||
impl CellBytesParser for DateCellDataParser {
|
||||
type Object = DateCellData;
|
||||
type Object = DateCellDataPB;
|
||||
|
||||
fn parse(&self, bytes: &Bytes) -> FlowyResult<Self::Object> {
|
||||
DateCellData::try_from(bytes.as_ref()).map_err(internal_error)
|
||||
DateCellDataPB::try_from(bytes.as_ref()).map_err(internal_error)
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ use crate::impl_type_option;
|
||||
use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable};
|
||||
use crate::services::field::type_options::util::get_cell_data;
|
||||
use crate::services::field::{
|
||||
make_selected_select_options, BoxTypeOptionBuilder, SelectOption, SelectOptionCellChangeset, SelectOptionCellData,
|
||||
SelectOptionIds, SelectOptionOperation, TypeOptionBuilder, SELECTION_IDS_SEPARATOR,
|
||||
make_selected_select_options, BoxTypeOptionBuilder, SelectOptionCellChangeset, SelectOptionCellDataPB,
|
||||
SelectOptionIds, SelectOptionOperation, SelectOptionPB, TypeOptionBuilder, SELECTION_IDS_SEPARATOR,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::ProtoBuf;
|
||||
@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)]
|
||||
pub struct MultiSelectTypeOption {
|
||||
#[pb(index = 1)]
|
||||
pub options: Vec<SelectOption>,
|
||||
pub options: Vec<SelectOptionPB>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub disable_color: bool,
|
||||
@ -24,19 +24,19 @@ pub struct MultiSelectTypeOption {
|
||||
impl_type_option!(MultiSelectTypeOption, FieldType::MultiSelect);
|
||||
|
||||
impl SelectOptionOperation for MultiSelectTypeOption {
|
||||
fn selected_select_option(&self, cell_data: CellData<SelectOptionIds>) -> SelectOptionCellData {
|
||||
fn selected_select_option(&self, cell_data: CellData<SelectOptionIds>) -> SelectOptionCellDataPB {
|
||||
let select_options = make_selected_select_options(cell_data, &self.options);
|
||||
SelectOptionCellData {
|
||||
SelectOptionCellDataPB {
|
||||
options: self.options.clone(),
|
||||
select_options,
|
||||
}
|
||||
}
|
||||
|
||||
fn options(&self) -> &Vec<SelectOption> {
|
||||
fn options(&self) -> &Vec<SelectOptionPB> {
|
||||
&self.options
|
||||
}
|
||||
|
||||
fn mut_options(&mut self) -> &mut Vec<SelectOption> {
|
||||
fn mut_options(&mut self) -> &mut Vec<SelectOptionPB> {
|
||||
&mut self.options
|
||||
}
|
||||
}
|
||||
@ -97,7 +97,7 @@ pub struct MultiSelectTypeOptionBuilder(MultiSelectTypeOption);
|
||||
impl_into_box_type_option_builder!(MultiSelectTypeOptionBuilder);
|
||||
impl_builder_from_json_str_and_from_bytes!(MultiSelectTypeOptionBuilder, MultiSelectTypeOption);
|
||||
impl MultiSelectTypeOptionBuilder {
|
||||
pub fn option(mut self, opt: SelectOption) -> Self {
|
||||
pub fn option(mut self, opt: SelectOptionPB) -> Self {
|
||||
self.0.options.push(opt);
|
||||
self
|
||||
}
|
||||
@ -123,9 +123,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn multi_select_test() {
|
||||
let google_option = SelectOption::new("Google");
|
||||
let facebook_option = SelectOption::new("Facebook");
|
||||
let twitter_option = SelectOption::new("Twitter");
|
||||
let google_option = SelectOptionPB::new("Google");
|
||||
let facebook_option = SelectOptionPB::new("Facebook");
|
||||
let twitter_option = SelectOptionPB::new("Twitter");
|
||||
let multi_select = MultiSelectTypeOptionBuilder::default()
|
||||
.option(google_option.clone())
|
||||
.option(facebook_option.clone())
|
||||
@ -172,7 +172,7 @@ mod tests {
|
||||
cell_data: String,
|
||||
type_option: &MultiSelectTypeOption,
|
||||
field_rev: &FieldRevision,
|
||||
expected: Vec<SelectOption>,
|
||||
expected: Vec<SelectOptionPB>,
|
||||
) {
|
||||
let field_type: FieldType = field_rev.field_type_rev.into();
|
||||
assert_eq!(
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::entities::{CellChangeset, CellIdentifier, CellIdentifierPayload, FieldType};
|
||||
use crate::services::cell::{CellBytes, CellBytesParser, CellData, CellDisplayable, FromCellChangeset, FromCellString};
|
||||
use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOption};
|
||||
use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB};
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::{internal_error, ErrorCode, FlowyResult};
|
||||
@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub const SELECTION_IDS_SEPARATOR: &str = ",";
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ProtoBuf)]
|
||||
pub struct SelectOption {
|
||||
pub struct SelectOptionPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -20,20 +20,20 @@ pub struct SelectOption {
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub color: SelectOptionColor,
|
||||
pub color: SelectOptionColorPB,
|
||||
}
|
||||
|
||||
impl SelectOption {
|
||||
impl SelectOptionPB {
|
||||
pub fn new(name: &str) -> Self {
|
||||
SelectOption {
|
||||
SelectOptionPB {
|
||||
id: nanoid!(4),
|
||||
name: name.to_owned(),
|
||||
color: SelectOptionColor::default(),
|
||||
color: SelectOptionColorPB::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_color(name: &str, color: SelectOptionColor) -> Self {
|
||||
SelectOption {
|
||||
pub fn with_color(name: &str, color: SelectOptionColorPB) -> Self {
|
||||
SelectOptionPB {
|
||||
id: nanoid!(4),
|
||||
name: name.to_owned(),
|
||||
color,
|
||||
@ -43,7 +43,7 @@ impl SelectOption {
|
||||
|
||||
#[derive(ProtoBuf_Enum, PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
||||
#[repr(u8)]
|
||||
pub enum SelectOptionColor {
|
||||
pub enum SelectOptionColorPB {
|
||||
Purple = 0,
|
||||
Pink = 1,
|
||||
LightPink = 2,
|
||||
@ -55,16 +55,16 @@ pub enum SelectOptionColor {
|
||||
Blue = 8,
|
||||
}
|
||||
|
||||
impl std::default::Default for SelectOptionColor {
|
||||
impl std::default::Default for SelectOptionColorPB {
|
||||
fn default() -> Self {
|
||||
SelectOptionColor::Purple
|
||||
SelectOptionColorPB::Purple
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_selected_select_options(
|
||||
cell_data: CellData<SelectOptionIds>,
|
||||
options: &[SelectOption],
|
||||
) -> Vec<SelectOption> {
|
||||
options: &[SelectOptionPB],
|
||||
) -> Vec<SelectOptionPB> {
|
||||
if let Ok(ids) = cell_data.try_into_inner() {
|
||||
ids.iter()
|
||||
.flat_map(|option_id| options.iter().find(|option| &option.id == option_id).cloned())
|
||||
@ -75,7 +75,7 @@ pub fn make_selected_select_options(
|
||||
}
|
||||
|
||||
pub trait SelectOptionOperation: TypeOptionDataEntry + Send + Sync {
|
||||
fn insert_option(&mut self, new_option: SelectOption) {
|
||||
fn insert_option(&mut self, new_option: SelectOptionPB) {
|
||||
let options = self.mut_options();
|
||||
if let Some(index) = options
|
||||
.iter()
|
||||
@ -88,23 +88,23 @@ pub trait SelectOptionOperation: TypeOptionDataEntry + Send + Sync {
|
||||
}
|
||||
}
|
||||
|
||||
fn delete_option(&mut self, delete_option: SelectOption) {
|
||||
fn delete_option(&mut self, delete_option: SelectOptionPB) {
|
||||
let options = self.mut_options();
|
||||
if let Some(index) = options.iter().position(|option| option.id == delete_option.id) {
|
||||
options.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_option(&self, name: &str) -> SelectOption {
|
||||
fn create_option(&self, name: &str) -> SelectOptionPB {
|
||||
let color = select_option_color_from_index(self.options().len());
|
||||
SelectOption::with_color(name, color)
|
||||
SelectOptionPB::with_color(name, color)
|
||||
}
|
||||
|
||||
fn selected_select_option(&self, cell_data: CellData<SelectOptionIds>) -> SelectOptionCellData;
|
||||
fn selected_select_option(&self, cell_data: CellData<SelectOptionIds>) -> SelectOptionCellDataPB;
|
||||
|
||||
fn options(&self) -> &Vec<SelectOption>;
|
||||
fn options(&self) -> &Vec<SelectOptionPB>;
|
||||
|
||||
fn mut_options(&mut self) -> &mut Vec<SelectOption>;
|
||||
fn mut_options(&mut self) -> &mut Vec<SelectOptionPB>;
|
||||
}
|
||||
|
||||
impl<T> CellDisplayable<SelectOptionIds> for T
|
||||
@ -125,7 +125,7 @@ pub fn select_option_operation(field_rev: &FieldRevision) -> FlowyResult<Box<dyn
|
||||
let field_type: FieldType = field_rev.field_type_rev.into();
|
||||
match &field_type {
|
||||
FieldType::SingleSelect => {
|
||||
let type_option = SingleSelectTypeOption::from(field_rev);
|
||||
let type_option = SingleSelectTypeOptionPB::from(field_rev);
|
||||
Ok(Box::new(type_option))
|
||||
}
|
||||
FieldType::MultiSelect => {
|
||||
@ -139,18 +139,18 @@ pub fn select_option_operation(field_rev: &FieldRevision) -> FlowyResult<Box<dyn
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_option_color_from_index(index: usize) -> SelectOptionColor {
|
||||
pub fn select_option_color_from_index(index: usize) -> SelectOptionColorPB {
|
||||
match index % 8 {
|
||||
0 => SelectOptionColor::Purple,
|
||||
1 => SelectOptionColor::Pink,
|
||||
2 => SelectOptionColor::LightPink,
|
||||
3 => SelectOptionColor::Orange,
|
||||
4 => SelectOptionColor::Yellow,
|
||||
5 => SelectOptionColor::Lime,
|
||||
6 => SelectOptionColor::Green,
|
||||
7 => SelectOptionColor::Aqua,
|
||||
8 => SelectOptionColor::Blue,
|
||||
_ => SelectOptionColor::Purple,
|
||||
0 => SelectOptionColorPB::Purple,
|
||||
1 => SelectOptionColorPB::Pink,
|
||||
2 => SelectOptionColorPB::LightPink,
|
||||
3 => SelectOptionColorPB::Orange,
|
||||
4 => SelectOptionColorPB::Yellow,
|
||||
5 => SelectOptionColorPB::Lime,
|
||||
6 => SelectOptionColorPB::Green,
|
||||
7 => SelectOptionColorPB::Aqua,
|
||||
8 => SelectOptionColorPB::Blue,
|
||||
_ => SelectOptionColorPB::Purple,
|
||||
}
|
||||
}
|
||||
pub struct SelectOptionIds(Vec<String>);
|
||||
@ -215,15 +215,15 @@ impl CellBytesParser for SelectOptionIdsParser {
|
||||
|
||||
pub struct SelectOptionCellDataParser();
|
||||
impl CellBytesParser for SelectOptionCellDataParser {
|
||||
type Object = SelectOptionCellData;
|
||||
type Object = SelectOptionCellDataPB;
|
||||
|
||||
fn parse(&self, bytes: &Bytes) -> FlowyResult<Self::Object> {
|
||||
SelectOptionCellData::try_from(bytes.as_ref()).map_err(internal_error)
|
||||
SelectOptionCellDataPB::try_from(bytes.as_ref()).map_err(internal_error)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||
pub struct SelectOptionCellChangesetPayload {
|
||||
pub struct SelectOptionCellChangesetPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub cell_identifier: CellIdentifierPayload,
|
||||
|
||||
@ -256,7 +256,7 @@ impl std::convert::From<SelectOptionCellChangesetParams> for CellChangeset {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<SelectOptionCellChangesetParams> for SelectOptionCellChangesetPayload {
|
||||
impl TryInto<SelectOptionCellChangesetParams> for SelectOptionCellChangesetPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<SelectOptionCellChangesetParams, Self::Error> {
|
||||
@ -323,37 +323,37 @@ impl SelectOptionCellChangeset {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)]
|
||||
pub struct SelectOptionCellData {
|
||||
pub struct SelectOptionCellDataPB {
|
||||
#[pb(index = 1)]
|
||||
pub options: Vec<SelectOption>,
|
||||
pub options: Vec<SelectOptionPB>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub select_options: Vec<SelectOption>,
|
||||
pub select_options: Vec<SelectOptionPB>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||
pub struct SelectOptionChangesetPayload {
|
||||
pub struct SelectOptionChangesetPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub cell_identifier: CellIdentifierPayload,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub insert_option: Option<SelectOption>,
|
||||
pub insert_option: Option<SelectOptionPB>,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub update_option: Option<SelectOption>,
|
||||
pub update_option: Option<SelectOptionPB>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub delete_option: Option<SelectOption>,
|
||||
pub delete_option: Option<SelectOptionPB>,
|
||||
}
|
||||
|
||||
pub struct SelectOptionChangeset {
|
||||
pub cell_identifier: CellIdentifier,
|
||||
pub insert_option: Option<SelectOption>,
|
||||
pub update_option: Option<SelectOption>,
|
||||
pub delete_option: Option<SelectOption>,
|
||||
pub insert_option: Option<SelectOptionPB>,
|
||||
pub update_option: Option<SelectOptionPB>,
|
||||
pub delete_option: Option<SelectOptionPB>,
|
||||
}
|
||||
|
||||
impl TryInto<SelectOptionChangeset> for SelectOptionChangesetPayload {
|
||||
impl TryInto<SelectOptionChangeset> for SelectOptionChangesetPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<SelectOptionChangeset, Self::Error> {
|
||||
@ -368,11 +368,11 @@ impl TryInto<SelectOptionChangeset> for SelectOptionChangesetPayload {
|
||||
}
|
||||
|
||||
pub struct SelectedSelectOptions {
|
||||
pub(crate) options: Vec<SelectOption>,
|
||||
pub(crate) options: Vec<SelectOptionPB>,
|
||||
}
|
||||
|
||||
impl std::convert::From<SelectOptionCellData> for SelectedSelectOptions {
|
||||
fn from(data: SelectOptionCellData) -> Self {
|
||||
impl std::convert::From<SelectOptionCellDataPB> for SelectedSelectOptions {
|
||||
fn from(data: SelectOptionCellDataPB) -> Self {
|
||||
Self {
|
||||
options: data.select_options,
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ use crate::entities::FieldType;
|
||||
use crate::impl_type_option;
|
||||
use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable};
|
||||
use crate::services::field::{
|
||||
make_selected_select_options, SelectOption, SelectOptionCellChangeset, SelectOptionCellData, SelectOptionIds,
|
||||
SelectOptionOperation,
|
||||
make_selected_select_options, SelectOptionCellChangeset, SelectOptionCellDataPB, SelectOptionIds,
|
||||
SelectOptionOperation, SelectOptionPB,
|
||||
};
|
||||
use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder};
|
||||
use bytes::Bytes;
|
||||
@ -14,36 +14,36 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
// Single select
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)]
|
||||
pub struct SingleSelectTypeOption {
|
||||
pub struct SingleSelectTypeOptionPB {
|
||||
#[pb(index = 1)]
|
||||
pub options: Vec<SelectOption>,
|
||||
pub options: Vec<SelectOptionPB>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub disable_color: bool,
|
||||
}
|
||||
impl_type_option!(SingleSelectTypeOption, FieldType::SingleSelect);
|
||||
impl_type_option!(SingleSelectTypeOptionPB, FieldType::SingleSelect);
|
||||
|
||||
impl SelectOptionOperation for SingleSelectTypeOption {
|
||||
fn selected_select_option(&self, cell_data: CellData<SelectOptionIds>) -> SelectOptionCellData {
|
||||
impl SelectOptionOperation for SingleSelectTypeOptionPB {
|
||||
fn selected_select_option(&self, cell_data: CellData<SelectOptionIds>) -> SelectOptionCellDataPB {
|
||||
let mut select_options = make_selected_select_options(cell_data, &self.options);
|
||||
// only keep option in single select
|
||||
select_options.truncate(1);
|
||||
SelectOptionCellData {
|
||||
SelectOptionCellDataPB {
|
||||
options: self.options.clone(),
|
||||
select_options,
|
||||
}
|
||||
}
|
||||
|
||||
fn options(&self) -> &Vec<SelectOption> {
|
||||
fn options(&self) -> &Vec<SelectOptionPB> {
|
||||
&self.options
|
||||
}
|
||||
|
||||
fn mut_options(&mut self) -> &mut Vec<SelectOption> {
|
||||
fn mut_options(&mut self) -> &mut Vec<SelectOptionPB> {
|
||||
&mut self.options
|
||||
}
|
||||
}
|
||||
|
||||
impl CellDataOperation<SelectOptionIds, SelectOptionCellChangeset> for SingleSelectTypeOption {
|
||||
impl CellDataOperation<SelectOptionIds, SelectOptionCellChangeset> for SingleSelectTypeOptionPB {
|
||||
fn decode_cell_data(
|
||||
&self,
|
||||
cell_data: CellData<SelectOptionIds>,
|
||||
@ -77,12 +77,12 @@ impl CellDataOperation<SelectOptionIds, SelectOptionCellChangeset> for SingleSel
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SingleSelectTypeOptionBuilder(SingleSelectTypeOption);
|
||||
pub struct SingleSelectTypeOptionBuilder(SingleSelectTypeOptionPB);
|
||||
impl_into_box_type_option_builder!(SingleSelectTypeOptionBuilder);
|
||||
impl_builder_from_json_str_and_from_bytes!(SingleSelectTypeOptionBuilder, SingleSelectTypeOption);
|
||||
impl_builder_from_json_str_and_from_bytes!(SingleSelectTypeOptionBuilder, SingleSelectTypeOptionPB);
|
||||
|
||||
impl SingleSelectTypeOptionBuilder {
|
||||
pub fn option(mut self, opt: SelectOption) -> Self {
|
||||
pub fn option(mut self, opt: SelectOptionPB) -> Self {
|
||||
self.0.options.push(opt);
|
||||
self
|
||||
}
|
||||
@ -109,9 +109,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn single_select_test() {
|
||||
let google_option = SelectOption::new("Google");
|
||||
let facebook_option = SelectOption::new("Facebook");
|
||||
let twitter_option = SelectOption::new("Twitter");
|
||||
let google_option = SelectOptionPB::new("Google");
|
||||
let facebook_option = SelectOptionPB::new("Facebook");
|
||||
let twitter_option = SelectOptionPB::new("Twitter");
|
||||
let single_select = SingleSelectTypeOptionBuilder::default()
|
||||
.option(google_option.clone())
|
||||
.option(facebook_option.clone())
|
||||
@ -122,7 +122,7 @@ mod tests {
|
||||
.visibility(true)
|
||||
.build();
|
||||
|
||||
let type_option = SingleSelectTypeOption::from(&field_rev);
|
||||
let type_option = SingleSelectTypeOptionPB::from(&field_rev);
|
||||
|
||||
let option_ids = vec![google_option.id.clone(), facebook_option.id].join(SELECTION_IDS_SEPARATOR);
|
||||
let data = SelectOptionCellChangeset::from_insert(&option_ids).to_str();
|
||||
@ -152,9 +152,9 @@ mod tests {
|
||||
|
||||
fn assert_single_select_options(
|
||||
cell_data: String,
|
||||
type_option: &SingleSelectTypeOption,
|
||||
type_option: &SingleSelectTypeOptionPB,
|
||||
field_rev: &FieldRevision,
|
||||
expected: Vec<SelectOption>,
|
||||
expected: Vec<SelectOptionPB>,
|
||||
) {
|
||||
let field_type: FieldType = field_rev.field_type_rev.into();
|
||||
assert_eq!(
|
||||
|
@ -131,7 +131,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// Single select
|
||||
let done_option = SelectOption::new("Done");
|
||||
let done_option = SelectOptionPB::new("Done");
|
||||
let done_option_id = done_option.id.clone();
|
||||
let single_select = SingleSelectTypeOptionBuilder::default().option(done_option.clone());
|
||||
let single_select_field_rev = FieldBuilder::new(single_select).build();
|
||||
@ -151,8 +151,8 @@ mod tests {
|
||||
);
|
||||
|
||||
// Multiple select
|
||||
let google_option = SelectOption::new("Google");
|
||||
let facebook_option = SelectOption::new("Facebook");
|
||||
let google_option = SelectOptionPB::new("Google");
|
||||
let facebook_option = SelectOptionPB::new("Facebook");
|
||||
let ids = vec![google_option.id.clone(), facebook_option.id.clone()].join(SELECTION_IDS_SEPARATOR);
|
||||
let cell_data_changeset = SelectOptionCellChangeset::from_insert(&ids).to_str();
|
||||
let multi_select = MultiSelectTypeOptionBuilder::default()
|
||||
|
@ -3,7 +3,7 @@ mod tests {
|
||||
use crate::entities::FieldType;
|
||||
use crate::services::cell::{CellData, CellDataOperation};
|
||||
use crate::services::field::{FieldBuilder, URLCellDataParser};
|
||||
use crate::services::field::{URLCellData, URLTypeOption};
|
||||
use crate::services::field::{URLCellDataPB, URLTypeOption};
|
||||
use flowy_grid_data_model::revision::FieldRevision;
|
||||
|
||||
#[test]
|
||||
@ -52,12 +52,12 @@ mod tests {
|
||||
assert_eq!(expected_url.to_owned(), decode_cell_data.url);
|
||||
}
|
||||
|
||||
fn decode_cell_data<T: Into<CellData<URLCellData>>>(
|
||||
fn decode_cell_data<T: Into<CellData<URLCellDataPB>>>(
|
||||
encoded_data: T,
|
||||
type_option: &URLTypeOption,
|
||||
field_rev: &FieldRevision,
|
||||
field_type: &FieldType,
|
||||
) -> URLCellData {
|
||||
) -> URLCellDataPB {
|
||||
type_option
|
||||
.decode_cell_data(encoded_data.into(), field_type, field_rev)
|
||||
.unwrap()
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::entities::FieldType;
|
||||
use crate::impl_type_option;
|
||||
use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable};
|
||||
use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder, URLCellData};
|
||||
use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder, URLCellDataPB};
|
||||
use bytes::Bytes;
|
||||
use fancy_regex::Regex;
|
||||
use flowy_derive::ProtoBuf;
|
||||
@ -32,22 +32,22 @@ pub struct URLTypeOption {
|
||||
}
|
||||
impl_type_option!(URLTypeOption, FieldType::URL);
|
||||
|
||||
impl CellDisplayable<URLCellData> for URLTypeOption {
|
||||
impl CellDisplayable<URLCellDataPB> for URLTypeOption {
|
||||
fn display_data(
|
||||
&self,
|
||||
cell_data: CellData<URLCellData>,
|
||||
cell_data: CellData<URLCellDataPB>,
|
||||
_decoded_field_type: &FieldType,
|
||||
_field_rev: &FieldRevision,
|
||||
) -> FlowyResult<CellBytes> {
|
||||
let cell_data: URLCellData = cell_data.try_into_inner()?;
|
||||
let cell_data: URLCellDataPB = cell_data.try_into_inner()?;
|
||||
CellBytes::from(cell_data)
|
||||
}
|
||||
}
|
||||
|
||||
impl CellDataOperation<URLCellData, String> for URLTypeOption {
|
||||
impl CellDataOperation<URLCellDataPB, String> for URLTypeOption {
|
||||
fn decode_cell_data(
|
||||
&self,
|
||||
cell_data: CellData<URLCellData>,
|
||||
cell_data: CellData<URLCellDataPB>,
|
||||
decoded_field_type: &FieldType,
|
||||
field_rev: &FieldRevision,
|
||||
) -> FlowyResult<CellBytes> {
|
||||
@ -67,7 +67,7 @@ impl CellDataOperation<URLCellData, String> for URLTypeOption {
|
||||
if let Ok(Some(m)) = URL_REGEX.find(&content) {
|
||||
url = auto_append_scheme(m.as_str());
|
||||
}
|
||||
URLCellData { url, content }.to_json()
|
||||
URLCellDataPB { url, content }.to_json()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ use flowy_error::{internal_error, FlowyResult};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)]
|
||||
pub struct URLCellData {
|
||||
pub struct URLCellDataPB {
|
||||
#[pb(index = 1)]
|
||||
pub url: String,
|
||||
|
||||
@ -13,7 +13,7 @@ pub struct URLCellData {
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
impl URLCellData {
|
||||
impl URLCellDataPB {
|
||||
pub fn new(s: &str) -> Self {
|
||||
Self {
|
||||
url: "".to_string(),
|
||||
@ -28,15 +28,15 @@ impl URLCellData {
|
||||
|
||||
pub struct URLCellDataParser();
|
||||
impl CellBytesParser for URLCellDataParser {
|
||||
type Object = URLCellData;
|
||||
type Object = URLCellDataPB;
|
||||
|
||||
fn parse(&self, bytes: &Bytes) -> FlowyResult<Self::Object> {
|
||||
URLCellData::try_from(bytes.as_ref()).map_err(internal_error)
|
||||
URLCellDataPB::try_from(bytes.as_ref()).map_err(internal_error)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCellString for URLCellData {
|
||||
impl FromCellString for URLCellDataPB {
|
||||
fn from_cell_str(s: &str) -> FlowyResult<Self> {
|
||||
serde_json::from_str::<URLCellData>(s).map_err(internal_error)
|
||||
serde_json::from_str::<URLCellDataPB>(s).map_err(internal_error)
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||
use crate::entities::{FieldType, GridBlockChangeset};
|
||||
use crate::entities::{FieldType, GridBlockChangesetPB};
|
||||
use crate::services::block_manager::GridBlockManager;
|
||||
use crate::services::cell::{AnyCellData, CellFilterOperation};
|
||||
use crate::services::field::{
|
||||
CheckboxTypeOption, DateTypeOption, MultiSelectTypeOption, NumberTypeOption, RichTextTypeOption,
|
||||
SingleSelectTypeOption, URLTypeOption,
|
||||
SingleSelectTypeOptionPB, URLTypeOption,
|
||||
};
|
||||
use crate::services::filter::filter_cache::{
|
||||
refresh_filter_cache, FilterCache, FilterId, FilterResult, FilterResultCache,
|
||||
@ -90,7 +90,7 @@ impl GridFilterService {
|
||||
}
|
||||
}
|
||||
|
||||
let changeset = GridBlockChangeset {
|
||||
let changeset = GridBlockChangesetPB {
|
||||
block_id: block.block_id,
|
||||
hide_rows,
|
||||
visible_rows,
|
||||
@ -137,7 +137,7 @@ impl GridFilterService {
|
||||
}
|
||||
}
|
||||
|
||||
async fn notify(&self, changesets: Vec<GridBlockChangeset>) {
|
||||
async fn notify(&self, changesets: Vec<GridBlockChangesetPB>) {
|
||||
for changeset in changesets {
|
||||
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridBlock)
|
||||
.payload(changeset)
|
||||
@ -213,7 +213,7 @@ fn filter_cell(
|
||||
FieldType::SingleSelect => filter_cache.select_option_filter.get(&filter_id).and_then(|filter| {
|
||||
Some(
|
||||
field_rev
|
||||
.get_type_option_entry::<SingleSelectTypeOption>(field_type_rev)?
|
||||
.get_type_option_entry::<SingleSelectTypeOptionPB>(field_type_rev)?
|
||||
.apply_filter(any_cell_data, filter.value())
|
||||
.ok(),
|
||||
)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::entities::{GridSelectOptionFilter, SelectOptionCondition};
|
||||
use crate::services::cell::{AnyCellData, CellFilterOperation};
|
||||
use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOption};
|
||||
use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB};
|
||||
use crate::services::field::{SelectOptionOperation, SelectedSelectOptions};
|
||||
use flowy_error::FlowyResult;
|
||||
|
||||
@ -50,7 +50,7 @@ impl CellFilterOperation<GridSelectOptionFilter> for MultiSelectTypeOption {
|
||||
}
|
||||
}
|
||||
|
||||
impl CellFilterOperation<GridSelectOptionFilter> for SingleSelectTypeOption {
|
||||
impl CellFilterOperation<GridSelectOptionFilter> for SingleSelectTypeOptionPB {
|
||||
fn apply_filter(&self, any_cell_data: AnyCellData, filter: &GridSelectOptionFilter) -> FlowyResult<bool> {
|
||||
if !any_cell_data.is_single_select() {
|
||||
return Ok(true);
|
||||
@ -64,13 +64,13 @@ impl CellFilterOperation<GridSelectOptionFilter> for SingleSelectTypeOption {
|
||||
mod tests {
|
||||
#![allow(clippy::all)]
|
||||
use crate::entities::{GridSelectOptionFilter, SelectOptionCondition};
|
||||
use crate::services::field::selection_type_option::{SelectOption, SelectedSelectOptions};
|
||||
use crate::services::field::selection_type_option::{SelectOptionPB, SelectedSelectOptions};
|
||||
|
||||
#[test]
|
||||
fn select_option_filter_is_test() {
|
||||
let option_1 = SelectOption::new("A");
|
||||
let option_2 = SelectOption::new("B");
|
||||
let option_3 = SelectOption::new("C");
|
||||
let option_1 = SelectOptionPB::new("A");
|
||||
let option_2 = SelectOptionPB::new("B");
|
||||
let option_3 = SelectOptionPB::new("C");
|
||||
|
||||
let filter_1 = GridSelectOptionFilter {
|
||||
condition: SelectOptionCondition::OptionIs,
|
||||
|
@ -188,8 +188,8 @@ impl GridRevisionEditor {
|
||||
|
||||
pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||
let _ = self.modify(|grid_pad| Ok(grid_pad.delete_field_rev(field_id)?)).await?;
|
||||
let field_order = GridField::from(field_id);
|
||||
let notified_changeset = GridFieldChangeset::delete(&self.grid_id, vec![field_order]);
|
||||
let field_order = GridFieldPB::from(field_id);
|
||||
let notified_changeset = GridFieldChangesetPB::delete(&self.grid_id, vec![field_order]);
|
||||
let _ = self.notify_did_update_grid(notified_changeset).await?;
|
||||
Ok(())
|
||||
}
|
||||
@ -268,13 +268,13 @@ impl GridRevisionEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_row(&self, start_row_id: Option<String>) -> FlowyResult<Row> {
|
||||
pub async fn create_row(&self, start_row_id: Option<String>) -> FlowyResult<GridRowPB> {
|
||||
let field_revs = self.grid_pad.read().await.get_field_revs(None)?;
|
||||
let block_id = self.block_id().await?;
|
||||
|
||||
// insert empty row below the row whose id is upper_row_id
|
||||
let row_rev = RowRevisionBuilder::new(&field_revs).build(&block_id);
|
||||
let row_order = Row::from(&row_rev);
|
||||
let row_order = GridRowPB::from(&row_rev);
|
||||
|
||||
// insert the row
|
||||
let row_count = self.block_manager.create_row(&block_id, row_rev, start_row_id).await?;
|
||||
@ -285,12 +285,12 @@ impl GridRevisionEditor {
|
||||
Ok(row_order)
|
||||
}
|
||||
|
||||
pub async fn insert_rows(&self, row_revs: Vec<RowRevision>) -> FlowyResult<Vec<Row>> {
|
||||
pub async fn insert_rows(&self, row_revs: Vec<RowRevision>) -> FlowyResult<Vec<GridRowPB>> {
|
||||
let block_id = self.block_id().await?;
|
||||
let mut rows_by_block_id: HashMap<String, Vec<RowRevision>> = HashMap::new();
|
||||
let mut row_orders = vec![];
|
||||
for row_rev in row_revs {
|
||||
row_orders.push(Row::from(&row_rev));
|
||||
row_orders.push(GridRowPB::from(&row_rev));
|
||||
rows_by_block_id
|
||||
.entry(block_id.clone())
|
||||
.or_insert_with(Vec::new)
|
||||
@ -307,7 +307,7 @@ impl GridRevisionEditor {
|
||||
self.block_manager.update_row(changeset, make_row_from_row_rev).await
|
||||
}
|
||||
|
||||
pub async fn get_rows(&self, block_id: &str) -> FlowyResult<RepeatedRow> {
|
||||
pub async fn get_rows(&self, block_id: &str) -> FlowyResult<RepeatedRowPB> {
|
||||
let block_ids = vec![block_id.to_owned()];
|
||||
let mut grid_block_snapshot = self.grid_block_snapshots(Some(block_ids)).await?;
|
||||
|
||||
@ -402,7 +402,7 @@ impl GridRevisionEditor {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_blocks(&self, block_ids: Option<Vec<String>>) -> FlowyResult<RepeatedGridBlock> {
|
||||
pub async fn get_blocks(&self, block_ids: Option<Vec<String>>) -> FlowyResult<RepeatedGridBlockPB> {
|
||||
let block_snapshots = self.grid_block_snapshots(block_ids.clone()).await?;
|
||||
make_grid_blocks(block_ids, block_snapshots)
|
||||
}
|
||||
@ -412,7 +412,7 @@ impl GridRevisionEditor {
|
||||
Ok(block_meta_revs)
|
||||
}
|
||||
|
||||
pub async fn delete_rows(&self, row_orders: Vec<Row>) -> FlowyResult<()> {
|
||||
pub async fn delete_rows(&self, row_orders: Vec<GridRowPB>) -> FlowyResult<()> {
|
||||
let changesets = self.block_manager.delete_rows(row_orders).await?;
|
||||
for changeset in changesets {
|
||||
let _ = self.update_block(changeset).await?;
|
||||
@ -420,31 +420,31 @@ impl GridRevisionEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_grid_data(&self) -> FlowyResult<Grid> {
|
||||
pub async fn get_grid_data(&self) -> FlowyResult<GridPB> {
|
||||
let pad_read_guard = self.grid_pad.read().await;
|
||||
let field_orders = pad_read_guard
|
||||
.get_field_revs(None)?
|
||||
.iter()
|
||||
.map(GridField::from)
|
||||
.map(GridFieldPB::from)
|
||||
.collect();
|
||||
let mut block_orders = vec![];
|
||||
for block_rev in pad_read_guard.get_block_meta_revs() {
|
||||
let row_orders = self.block_manager.get_row_orders(&block_rev.block_id).await?;
|
||||
let block_order = GridBlock {
|
||||
let block_order = GridBlockPB {
|
||||
id: block_rev.block_id.clone(),
|
||||
rows: row_orders,
|
||||
};
|
||||
block_orders.push(block_order);
|
||||
}
|
||||
|
||||
Ok(Grid {
|
||||
Ok(GridPB {
|
||||
id: self.grid_id.clone(),
|
||||
fields: field_orders,
|
||||
blocks: block_orders,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn get_grid_setting(&self) -> FlowyResult<GridSetting> {
|
||||
pub async fn get_grid_setting(&self) -> FlowyResult<GridSettingPB> {
|
||||
let read_guard = self.grid_pad.read().await;
|
||||
let grid_setting_rev = read_guard.get_grid_setting_rev();
|
||||
let field_revs = read_guard.get_field_revs(None)?;
|
||||
@ -495,11 +495,11 @@ impl GridRevisionEditor {
|
||||
|
||||
pub async fn move_item(&self, params: MoveItemParams) -> FlowyResult<()> {
|
||||
match params.ty {
|
||||
MoveItemType::MoveField => {
|
||||
MoveItemTypePB::MoveField => {
|
||||
self.move_field(¶ms.item_id, params.from_index, params.to_index)
|
||||
.await
|
||||
}
|
||||
MoveItemType::MoveRow => self.move_row(¶ms.item_id, params.from_index, params.to_index).await,
|
||||
MoveItemTypePB::MoveRow => self.move_row(¶ms.item_id, params.from_index, params.to_index).await,
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,9 +508,9 @@ impl GridRevisionEditor {
|
||||
.modify(|grid_pad| Ok(grid_pad.move_field(field_id, from as usize, to as usize)?))
|
||||
.await?;
|
||||
if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(field_id) {
|
||||
let delete_field_order = GridField::from(field_id);
|
||||
let insert_field = IndexField::from_field_rev(field_rev, index);
|
||||
let notified_changeset = GridFieldChangeset {
|
||||
let delete_field_order = GridFieldPB::from(field_id);
|
||||
let insert_field = IndexFieldPB::from_field_rev(field_rev, index);
|
||||
let notified_changeset = GridFieldChangesetPB {
|
||||
grid_id: self.grid_id.clone(),
|
||||
inserted_fields: vec![insert_field],
|
||||
deleted_fields: vec![delete_field_order],
|
||||
@ -599,8 +599,8 @@ impl GridRevisionEditor {
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
async fn notify_did_insert_grid_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||
if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(field_id) {
|
||||
let index_field = IndexField::from_field_rev(field_rev, index);
|
||||
let notified_changeset = GridFieldChangeset::insert(&self.grid_id, vec![index_field]);
|
||||
let index_field = IndexFieldPB::from_field_rev(field_rev, index);
|
||||
let notified_changeset = GridFieldChangesetPB::insert(&self.grid_id, vec![index_field]);
|
||||
let _ = self.notify_did_update_grid(notified_changeset).await?;
|
||||
}
|
||||
Ok(())
|
||||
@ -615,8 +615,8 @@ impl GridRevisionEditor {
|
||||
.get_field_rev(field_id)
|
||||
.map(|(index, field)| (index, field.clone()))
|
||||
{
|
||||
let updated_field = Field::from(field_rev);
|
||||
let notified_changeset = GridFieldChangeset::update(&self.grid_id, vec![updated_field.clone()]);
|
||||
let updated_field = FieldPB::from(field_rev);
|
||||
let notified_changeset = GridFieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]);
|
||||
let _ = self.notify_did_update_grid(notified_changeset).await?;
|
||||
|
||||
send_dart_notification(field_id, GridNotification::DidUpdateField)
|
||||
@ -627,7 +627,7 @@ impl GridRevisionEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn notify_did_update_grid(&self, changeset: GridFieldChangeset) -> FlowyResult<()> {
|
||||
async fn notify_did_update_grid(&self, changeset: GridFieldChangesetPB) -> FlowyResult<()> {
|
||||
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridField)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{GridBlock, RepeatedGridBlock, Row};
|
||||
use crate::entities::{GridBlockPB, GridRowPB, RepeatedGridBlockPB};
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::RowRevision;
|
||||
use std::collections::HashMap;
|
||||
@ -9,14 +9,14 @@ pub struct GridBlockSnapshot {
|
||||
pub row_revs: Vec<Arc<RowRevision>>,
|
||||
}
|
||||
|
||||
pub(crate) fn block_from_row_orders(row_orders: Vec<Row>) -> Vec<GridBlock> {
|
||||
let mut map: HashMap<String, GridBlock> = HashMap::new();
|
||||
pub(crate) fn block_from_row_orders(row_orders: Vec<GridRowPB>) -> Vec<GridBlockPB> {
|
||||
let mut map: HashMap<String, GridBlockPB> = HashMap::new();
|
||||
row_orders.into_iter().for_each(|row_info| {
|
||||
// Memory Optimization: escape clone block_id
|
||||
let block_id = row_info.block_id().to_owned();
|
||||
let cloned_block_id = block_id.clone();
|
||||
map.entry(block_id)
|
||||
.or_insert_with(|| GridBlock::new(&cloned_block_id, vec![]))
|
||||
.or_insert_with(|| GridBlockPB::new(&cloned_block_id, vec![]))
|
||||
.rows
|
||||
.push(row_info);
|
||||
});
|
||||
@ -35,16 +35,16 @@ pub(crate) fn block_from_row_orders(row_orders: Vec<Row>) -> Vec<GridBlock> {
|
||||
// Some((field_id, cell))
|
||||
// }
|
||||
|
||||
pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc<RowRevision>]) -> Vec<Row> {
|
||||
row_revs.iter().map(Row::from).collect::<Vec<_>>()
|
||||
pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc<RowRevision>]) -> Vec<GridRowPB> {
|
||||
row_revs.iter().map(GridRowPB::from).collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub(crate) fn make_row_from_row_rev(row_rev: Arc<RowRevision>) -> Option<Row> {
|
||||
pub(crate) fn make_row_from_row_rev(row_rev: Arc<RowRevision>) -> Option<GridRowPB> {
|
||||
make_rows_from_row_revs(&[row_rev]).pop()
|
||||
}
|
||||
|
||||
pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc<RowRevision>]) -> Vec<Row> {
|
||||
let make_row = |row_rev: &Arc<RowRevision>| Row {
|
||||
pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc<RowRevision>]) -> Vec<GridRowPB> {
|
||||
let make_row = |row_rev: &Arc<RowRevision>| GridRowPB {
|
||||
block_id: row_rev.block_id.clone(),
|
||||
id: row_rev.id.clone(),
|
||||
height: row_rev.height,
|
||||
@ -56,15 +56,15 @@ pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc<RowRevision>]) -> Vec<Row>
|
||||
pub(crate) fn make_grid_blocks(
|
||||
block_ids: Option<Vec<String>>,
|
||||
block_snapshots: Vec<GridBlockSnapshot>,
|
||||
) -> FlowyResult<RepeatedGridBlock> {
|
||||
) -> FlowyResult<RepeatedGridBlockPB> {
|
||||
match block_ids {
|
||||
None => Ok(block_snapshots
|
||||
.into_iter()
|
||||
.map(|snapshot| {
|
||||
let row_orders = make_row_orders_from_row_revs(&snapshot.row_revs);
|
||||
GridBlock::new(&snapshot.block_id, row_orders)
|
||||
GridBlockPB::new(&snapshot.block_id, row_orders)
|
||||
})
|
||||
.collect::<Vec<GridBlock>>()
|
||||
.collect::<Vec<GridBlockPB>>()
|
||||
.into()),
|
||||
Some(block_ids) => {
|
||||
let block_meta_data_map: HashMap<&String, &Vec<Arc<RowRevision>>> = block_snapshots
|
||||
@ -78,7 +78,7 @@ pub(crate) fn make_grid_blocks(
|
||||
None => {}
|
||||
Some(row_revs) => {
|
||||
let row_orders = make_row_orders_from_row_revs(row_revs);
|
||||
grid_blocks.push(GridBlock::new(&block_id, row_orders));
|
||||
grid_blocks.push(GridBlockPB::new(&block_id, row_orders));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
GridLayout, GridLayoutType, GridSetting, RepeatedGridFilter, RepeatedGridGroup, RepeatedGridSort,
|
||||
GridLayoutPB, GridLayoutType, GridSettingPB, RepeatedGridFilterPB, RepeatedGridGroupPB, RepeatedGridSortPB,
|
||||
};
|
||||
use flowy_grid_data_model::revision::{FieldRevision, GridSettingRevision};
|
||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
||||
@ -40,7 +40,7 @@ impl GridSettingChangesetBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[Arc<FieldRevision>]) -> GridSetting {
|
||||
pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[Arc<FieldRevision>]) -> GridSettingPB {
|
||||
let current_layout_type: GridLayoutType = grid_setting_rev.layout.clone().into();
|
||||
let filters_by_field_id = grid_setting_rev
|
||||
.get_all_filter(field_revs)
|
||||
@ -48,7 +48,7 @@ pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[A
|
||||
filters_by_field_id
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into()))
|
||||
.collect::<HashMap<String, RepeatedGridFilter>>()
|
||||
.collect::<HashMap<String, RepeatedGridFilterPB>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let groups_by_field_id = grid_setting_rev
|
||||
@ -57,7 +57,7 @@ pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[A
|
||||
groups_by_field_id
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into()))
|
||||
.collect::<HashMap<String, RepeatedGridGroup>>()
|
||||
.collect::<HashMap<String, RepeatedGridGroupPB>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let sorts_by_field_id = grid_setting_rev
|
||||
@ -66,12 +66,12 @@ pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[A
|
||||
sorts_by_field_id
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into()))
|
||||
.collect::<HashMap<String, RepeatedGridSort>>()
|
||||
.collect::<HashMap<String, RepeatedGridSortPB>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
GridSetting {
|
||||
layouts: GridLayout::all(),
|
||||
GridSettingPB {
|
||||
layouts: GridLayoutPB::all(),
|
||||
current_layout_type,
|
||||
filters_by_field_id,
|
||||
groups_by_field_id,
|
||||
|
@ -2,7 +2,7 @@ use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
|
||||
use crate::grid::block_test::util::GridRowTestBuilder;
|
||||
use crate::grid::grid_editor::GridEditorTest;
|
||||
|
||||
use flowy_grid::entities::{CellIdentifier, FieldType, Row};
|
||||
use flowy_grid::entities::{CellIdentifier, FieldType, GridRowPB};
|
||||
use flowy_grid::services::field::*;
|
||||
use flowy_grid_data_model::revision::{
|
||||
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
|
||||
@ -97,7 +97,7 @@ impl GridRowTest {
|
||||
let row_orders = row_ids
|
||||
.into_iter()
|
||||
.map(|row_id| self.row_order_by_row_id.get(&row_id).unwrap().clone())
|
||||
.collect::<Vec<Row>>();
|
||||
.collect::<Vec<GridRowPB>>();
|
||||
|
||||
self.editor.delete_rows(row_orders).await.unwrap();
|
||||
self.row_revs = self.get_row_revs().await;
|
||||
@ -289,7 +289,7 @@ impl<'a> CreateRowScriptBuilder<'a> {
|
||||
|
||||
pub fn insert_single_select_cell<F>(&mut self, f: F, expected: &str)
|
||||
where
|
||||
F: Fn(Vec<SelectOption>) -> SelectOption,
|
||||
F: Fn(Vec<SelectOptionPB>) -> SelectOptionPB,
|
||||
{
|
||||
let field_id = self.builder.insert_single_select_cell(f);
|
||||
self.output_by_field_type.insert(
|
||||
@ -303,7 +303,7 @@ impl<'a> CreateRowScriptBuilder<'a> {
|
||||
|
||||
pub fn insert_multi_select_cell<F>(&mut self, f: F, expected: &str)
|
||||
where
|
||||
F: Fn(Vec<SelectOption>) -> Vec<SelectOption>,
|
||||
F: Fn(Vec<SelectOptionPB>) -> Vec<SelectOptionPB>,
|
||||
{
|
||||
let field_id = self.builder.insert_multi_select_cell(f);
|
||||
self.output_by_field_type.insert(
|
||||
|
@ -2,7 +2,7 @@ use flowy_grid::entities::FieldType;
|
||||
use std::sync::Arc;
|
||||
|
||||
use flowy_grid::services::field::{
|
||||
DateCellChangeset, MultiSelectTypeOption, SelectOption, SingleSelectTypeOption, SELECTION_IDS_SEPARATOR,
|
||||
DateCellChangesetPB, MultiSelectTypeOption, SelectOptionPB, SingleSelectTypeOptionPB, SELECTION_IDS_SEPARATOR,
|
||||
};
|
||||
use flowy_grid::services::row::RowRevisionBuilder;
|
||||
use flowy_grid_data_model::revision::{FieldRevision, RowRevision};
|
||||
@ -44,7 +44,7 @@ impl<'a> GridRowTestBuilder<'a> {
|
||||
}
|
||||
|
||||
pub fn insert_date_cell(&mut self, data: &str) -> String {
|
||||
let value = serde_json::to_string(&DateCellChangeset {
|
||||
let value = serde_json::to_string(&DateCellChangesetPB {
|
||||
date: Some(data.to_string()),
|
||||
time: None,
|
||||
})
|
||||
@ -71,10 +71,10 @@ impl<'a> GridRowTestBuilder<'a> {
|
||||
|
||||
pub fn insert_single_select_cell<F>(&mut self, f: F) -> String
|
||||
where
|
||||
F: Fn(Vec<SelectOption>) -> SelectOption,
|
||||
F: Fn(Vec<SelectOptionPB>) -> SelectOptionPB,
|
||||
{
|
||||
let single_select_field = self.field_rev_with_type(&FieldType::SingleSelect);
|
||||
let type_option = SingleSelectTypeOption::from(&single_select_field);
|
||||
let type_option = SingleSelectTypeOptionPB::from(&single_select_field);
|
||||
let option = f(type_option.options);
|
||||
self.inner_builder
|
||||
.insert_select_option_cell(&single_select_field.id, option.id)
|
||||
@ -85,7 +85,7 @@ impl<'a> GridRowTestBuilder<'a> {
|
||||
|
||||
pub fn insert_multi_select_cell<F>(&mut self, f: F) -> String
|
||||
where
|
||||
F: Fn(Vec<SelectOption>) -> Vec<SelectOption>,
|
||||
F: Fn(Vec<SelectOptionPB>) -> Vec<SelectOptionPB>,
|
||||
{
|
||||
let multi_select_field = self.field_rev_with_type(&FieldType::MultiSelect);
|
||||
let type_option = MultiSelectTypeOption::from(&multi_select_field);
|
||||
|
@ -3,7 +3,7 @@ use crate::grid::cell_test::script::GridCellTest;
|
||||
use crate::grid::field_test::util::make_date_cell_string;
|
||||
use flowy_grid::entities::{CellChangeset, FieldType};
|
||||
use flowy_grid::services::field::selection_type_option::SelectOptionCellChangeset;
|
||||
use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOption};
|
||||
use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB};
|
||||
|
||||
#[tokio::test]
|
||||
async fn grid_cell_update() {
|
||||
@ -24,7 +24,7 @@ async fn grid_cell_update() {
|
||||
FieldType::Number => "123".to_string(),
|
||||
FieldType::DateTime => make_date_cell_string("123"),
|
||||
FieldType::SingleSelect => {
|
||||
let type_option = SingleSelectTypeOption::from(field_rev);
|
||||
let type_option = SingleSelectTypeOptionPB::from(field_rev);
|
||||
SelectOptionCellChangeset::from_insert(&type_option.options.first().unwrap().id).to_str()
|
||||
}
|
||||
FieldType::MultiSelect => {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::grid::field_test::script::FieldScript::*;
|
||||
use crate::grid::field_test::script::GridFieldTest;
|
||||
use crate::grid::field_test::util::*;
|
||||
use flowy_grid::services::field::selection_type_option::SelectOption;
|
||||
use flowy_grid::services::field::SingleSelectTypeOption;
|
||||
use flowy_grid::services::field::selection_type_option::SelectOptionPB;
|
||||
use flowy_grid::services::field::SingleSelectTypeOptionPB;
|
||||
use flowy_grid_data_model::revision::TypeOptionDataEntry;
|
||||
use flowy_sync::entities::grid::FieldChangesetParams;
|
||||
|
||||
@ -71,8 +71,8 @@ async fn grid_update_field() {
|
||||
let mut test = GridFieldTest::new().await;
|
||||
let (params, single_select_field) = create_single_select_field(&test.grid_id());
|
||||
|
||||
let mut single_select_type_option = SingleSelectTypeOption::from(&single_select_field);
|
||||
single_select_type_option.options.push(SelectOption::new("Unknown"));
|
||||
let mut single_select_type_option = SingleSelectTypeOptionPB::from(&single_select_field);
|
||||
single_select_type_option.options.push(SelectOptionPB::new("Unknown"));
|
||||
let changeset = FieldChangesetParams {
|
||||
field_id: single_select_field.id.clone(),
|
||||
grid_id: test.grid_id(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use flowy_grid::entities::*;
|
||||
use flowy_grid::services::field::selection_type_option::SelectOption;
|
||||
use flowy_grid::services::field::selection_type_option::SelectOptionPB;
|
||||
use flowy_grid::services::field::*;
|
||||
use flowy_grid_data_model::revision::*;
|
||||
|
||||
@ -17,7 +17,7 @@ pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) {
|
||||
.protobuf_bytes()
|
||||
.to_vec();
|
||||
|
||||
let field = Field {
|
||||
let field = FieldPB {
|
||||
id: field_rev.id,
|
||||
name: field_rev.name,
|
||||
desc: field_rev.desc,
|
||||
@ -39,18 +39,18 @@ pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) {
|
||||
|
||||
pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) {
|
||||
let single_select = SingleSelectTypeOptionBuilder::default()
|
||||
.option(SelectOption::new("Done"))
|
||||
.option(SelectOption::new("Progress"));
|
||||
.option(SelectOptionPB::new("Done"))
|
||||
.option(SelectOptionPB::new("Progress"));
|
||||
|
||||
let field_rev = FieldBuilder::new(single_select).name("Name").visibility(true).build();
|
||||
let cloned_field_rev = field_rev.clone();
|
||||
let type_option_data = field_rev
|
||||
.get_type_option_entry::<SingleSelectTypeOption>(field_rev.field_type_rev)
|
||||
.get_type_option_entry::<SingleSelectTypeOptionPB>(field_rev.field_type_rev)
|
||||
.unwrap()
|
||||
.protobuf_bytes()
|
||||
.to_vec();
|
||||
|
||||
let field = Field {
|
||||
let field = FieldPB {
|
||||
id: field_rev.id,
|
||||
name: field_rev.name,
|
||||
desc: field_rev.desc,
|
||||
@ -73,7 +73,7 @@ pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldRev
|
||||
// The grid will contains all existing field types and there are three empty rows in this grid.
|
||||
|
||||
pub fn make_date_cell_string(s: &str) -> String {
|
||||
serde_json::to_string(&DateCellChangeset {
|
||||
serde_json::to_string(&DateCellChangesetPB {
|
||||
date: Some(s.to_string()),
|
||||
time: None,
|
||||
})
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use flowy_grid::entities::{CreateGridFilterPayload, GridLayoutType, GridSetting};
|
||||
use flowy_grid::entities::{CreateGridFilterPayloadPB, GridLayoutType, GridSettingPB};
|
||||
use flowy_grid::services::setting::GridSettingChangesetBuilder;
|
||||
use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision};
|
||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
||||
@ -15,7 +15,7 @@ pub enum FilterScript {
|
||||
params: GridSettingChangesetParams,
|
||||
},
|
||||
InsertGridTableFilter {
|
||||
payload: CreateGridFilterPayload,
|
||||
payload: CreateGridFilterPayloadPB,
|
||||
},
|
||||
AssertTableFilterCount {
|
||||
count: i32,
|
||||
@ -26,7 +26,7 @@ pub enum FilterScript {
|
||||
},
|
||||
#[allow(dead_code)]
|
||||
AssertGridSetting {
|
||||
expected_setting: GridSetting,
|
||||
expected_setting: GridSettingPB,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::grid::filter_test::script::FilterScript::*;
|
||||
use crate::grid::filter_test::script::*;
|
||||
use flowy_grid::entities::{CreateGridFilterPayload, FieldType, TextFilterCondition};
|
||||
use flowy_grid::entities::{CreateGridFilterPayloadPB, FieldType, TextFilterCondition};
|
||||
use flowy_grid_data_model::revision::FieldRevision;
|
||||
|
||||
#[tokio::test]
|
||||
async fn grid_filter_create_test() {
|
||||
let mut test = GridFilterTest::new().await;
|
||||
let field_rev = test.get_field_rev(FieldType::RichText);
|
||||
let payload = CreateGridFilterPayload::new(field_rev, TextFilterCondition::TextIsEmpty, Some("abc".to_owned()));
|
||||
let payload = CreateGridFilterPayloadPB::new(field_rev, TextFilterCondition::TextIsEmpty, Some("abc".to_owned()));
|
||||
let scripts = vec![InsertGridTableFilter { payload }, AssertTableFilterCount { count: 1 }];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
@ -19,7 +19,7 @@ async fn grid_filter_invalid_condition_panic_test() {
|
||||
let field_rev = test.get_field_rev(FieldType::RichText).clone();
|
||||
|
||||
// 100 is not a valid condition, so this test should be panic.
|
||||
let payload = CreateGridFilterPayload::new(&field_rev, 100, Some("".to_owned()));
|
||||
let payload = CreateGridFilterPayloadPB::new(&field_rev, 100, Some("".to_owned()));
|
||||
let scripts = vec![InsertGridTableFilter { payload }];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
@ -46,6 +46,6 @@ async fn grid_filter_delete_test() {
|
||||
#[tokio::test]
|
||||
async fn grid_filter_get_rows_test() {}
|
||||
|
||||
fn create_filter(field_rev: &FieldRevision, condition: TextFilterCondition, s: &str) -> CreateGridFilterPayload {
|
||||
CreateGridFilterPayload::new(field_rev, condition, Some(s.to_owned()))
|
||||
fn create_filter(field_rev: &FieldRevision, condition: TextFilterCondition, s: &str) -> CreateGridFilterPayloadPB {
|
||||
CreateGridFilterPayloadPB::new(field_rev, condition, Some(s.to_owned()))
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
use crate::grid::block_test::util::GridRowTestBuilder;
|
||||
use bytes::Bytes;
|
||||
use flowy_grid::entities::*;
|
||||
use flowy_grid::services::field::SelectOption;
|
||||
use flowy_grid::services::field::SelectOptionPB;
|
||||
use flowy_grid::services::field::*;
|
||||
use flowy_grid::services::grid_editor::{GridPadBuilder, GridRevisionEditor};
|
||||
use flowy_grid::services::row::{CreateRowRevisionPayload, RowRevisionBuilder};
|
||||
@ -32,7 +32,7 @@ pub struct GridEditorTest {
|
||||
pub block_meta_revs: Vec<Arc<GridBlockMetaRevision>>,
|
||||
pub row_revs: Vec<Arc<RowRevision>>,
|
||||
pub field_count: usize,
|
||||
pub row_order_by_row_id: HashMap<String, Row>,
|
||||
pub row_order_by_row_id: HashMap<String, GridRowPB>,
|
||||
}
|
||||
|
||||
impl GridEditorTest {
|
||||
@ -138,18 +138,18 @@ fn make_test_grid() -> BuildGridContext {
|
||||
FieldType::SingleSelect => {
|
||||
// Single Select
|
||||
let single_select = SingleSelectTypeOptionBuilder::default()
|
||||
.option(SelectOption::new(COMPLETED))
|
||||
.option(SelectOption::new(PLANNED))
|
||||
.option(SelectOption::new(PAUSED));
|
||||
.option(SelectOptionPB::new(COMPLETED))
|
||||
.option(SelectOptionPB::new(PLANNED))
|
||||
.option(SelectOptionPB::new(PAUSED));
|
||||
let single_select_field = FieldBuilder::new(single_select).name("Status").visibility(true).build();
|
||||
grid_builder.add_field(single_select_field);
|
||||
}
|
||||
FieldType::MultiSelect => {
|
||||
// MultiSelect
|
||||
let multi_select = MultiSelectTypeOptionBuilder::default()
|
||||
.option(SelectOption::new(GOOGLE))
|
||||
.option(SelectOption::new(FACEBOOK))
|
||||
.option(SelectOption::new(TWITTER));
|
||||
.option(SelectOptionPB::new(GOOGLE))
|
||||
.option(SelectOptionPB::new(FACEBOOK))
|
||||
.option(SelectOptionPB::new(TWITTER));
|
||||
let multi_select_field = FieldBuilder::new(multi_select)
|
||||
.name("Platform")
|
||||
.visibility(true)
|
||||
|
Loading…
Reference in New Issue
Block a user