mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
* feat: add flowy-database2 * chore: config type option data * chore: impl type option * feat: config group * fix: group compile * feat: add sort * chore: setting * chore: insert with specific type * chore: custom group * chore: rename any map * chore: use group setting * chore: update * chore: open database event * chore: update database editor * chore: update * chore: update view editor * chore: update * chore: update view editor * chore: sort feat * chore: update handler * chore: update * chore: config handler event * feat: impl handlers * feat: impl handlers * chore: layout setting * feat: impl handlers * chore: remove flowy-folder ref * chore: integrate flowy-database2 * feat: get cell * chore: create database with data * chore: create view * chore: fix dart compile * fix: some bugs * chore: update * chore: merge develop * chore: fix warning * chore: integrate rocksdb * fix: rocksdb compile errros * fix: update cell * chore: update the bundle identifier * fix: create row * fix: switch to field * fix: duplicate grid * test: migrate tests * test: migrate tests * test: update test * test: migrate tests * chore: add patch
227 lines
5.1 KiB
Rust
227 lines
5.1 KiB
Rust
use collab_database::rows::RowId;
|
|
use collab_database::user::DatabaseRecord;
|
|
use collab_database::views::DatabaseLayout;
|
|
|
|
use flowy_derive::ProtoBuf;
|
|
use flowy_error::ErrorCode;
|
|
|
|
use crate::entities::parser::NotEmptyStr;
|
|
use crate::entities::{DatabaseLayoutPB, FieldIdPB, RowPB};
|
|
|
|
/// [DatabasePB] describes how many fields and blocks the grid has
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
pub struct DatabasePB {
|
|
#[pb(index = 1)]
|
|
pub id: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub fields: Vec<FieldIdPB>,
|
|
|
|
#[pb(index = 3)]
|
|
pub rows: Vec<RowPB>,
|
|
}
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
pub struct CreateDatabasePayloadPB {
|
|
#[pb(index = 1)]
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Clone, ProtoBuf, Default, Debug)]
|
|
pub struct DatabaseViewIdPB {
|
|
#[pb(index = 1)]
|
|
pub value: String,
|
|
}
|
|
|
|
impl AsRef<str> for DatabaseViewIdPB {
|
|
fn as_ref(&self) -> &str {
|
|
&self.value
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
pub struct MoveFieldPayloadPB {
|
|
#[pb(index = 1)]
|
|
pub view_id: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub field_id: String,
|
|
|
|
#[pb(index = 3)]
|
|
pub from_index: i32,
|
|
|
|
#[pb(index = 4)]
|
|
pub to_index: i32,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct MoveFieldParams {
|
|
pub view_id: String,
|
|
pub field_id: String,
|
|
pub from_index: i32,
|
|
pub to_index: i32,
|
|
}
|
|
|
|
impl TryInto<MoveFieldParams> for MoveFieldPayloadPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<MoveFieldParams, Self::Error> {
|
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseViewIdIsEmpty)?;
|
|
let item_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::InvalidData)?;
|
|
Ok(MoveFieldParams {
|
|
view_id: view_id.0,
|
|
field_id: item_id.0,
|
|
from_index: self.from_index,
|
|
to_index: self.to_index,
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
pub struct MoveRowPayloadPB {
|
|
#[pb(index = 1)]
|
|
pub view_id: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub from_row_id: i64,
|
|
|
|
#[pb(index = 3)]
|
|
pub to_row_id: i64,
|
|
}
|
|
|
|
pub struct MoveRowParams {
|
|
pub view_id: String,
|
|
pub from_row_id: RowId,
|
|
pub to_row_id: RowId,
|
|
}
|
|
|
|
impl TryInto<MoveRowParams> for MoveRowPayloadPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<MoveRowParams, Self::Error> {
|
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseViewIdIsEmpty)?;
|
|
|
|
Ok(MoveRowParams {
|
|
view_id: view_id.0,
|
|
from_row_id: RowId::from(self.from_row_id),
|
|
to_row_id: RowId::from(self.to_row_id),
|
|
})
|
|
}
|
|
}
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
pub struct MoveGroupRowPayloadPB {
|
|
#[pb(index = 1)]
|
|
pub view_id: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub from_row_id: i64,
|
|
|
|
#[pb(index = 3)]
|
|
pub to_group_id: String,
|
|
|
|
#[pb(index = 4, one_of)]
|
|
pub to_row_id: Option<i64>,
|
|
}
|
|
|
|
pub struct MoveGroupRowParams {
|
|
pub view_id: String,
|
|
pub from_row_id: RowId,
|
|
pub to_group_id: String,
|
|
pub to_row_id: Option<RowId>,
|
|
}
|
|
|
|
impl TryInto<MoveGroupRowParams> for MoveGroupRowPayloadPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<MoveGroupRowParams, Self::Error> {
|
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseViewIdIsEmpty)?;
|
|
let to_group_id =
|
|
NotEmptyStr::parse(self.to_group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
|
|
|
|
Ok(MoveGroupRowParams {
|
|
view_id: view_id.0,
|
|
to_group_id: to_group_id.0,
|
|
from_row_id: RowId::from(self.from_row_id),
|
|
to_row_id: self.to_row_id.map(RowId::from),
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
pub struct DatabaseDescriptionPB {
|
|
#[pb(index = 1)]
|
|
pub name: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub database_id: String,
|
|
}
|
|
|
|
impl From<DatabaseRecord> for DatabaseDescriptionPB {
|
|
fn from(data: DatabaseRecord) -> Self {
|
|
Self {
|
|
name: data.name,
|
|
database_id: data.database_id,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
pub struct RepeatedDatabaseDescriptionPB {
|
|
#[pb(index = 1)]
|
|
pub items: Vec<DatabaseDescriptionPB>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
pub struct DatabaseGroupIdPB {
|
|
#[pb(index = 1)]
|
|
pub view_id: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub group_id: String,
|
|
}
|
|
|
|
pub struct DatabaseGroupIdParams {
|
|
pub view_id: String,
|
|
pub group_id: String,
|
|
}
|
|
|
|
impl TryInto<DatabaseGroupIdParams> for DatabaseGroupIdPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<DatabaseGroupIdParams, Self::Error> {
|
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseViewIdIsEmpty)?;
|
|
let group_id = NotEmptyStr::parse(self.group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
|
|
Ok(DatabaseGroupIdParams {
|
|
view_id: view_id.0,
|
|
group_id: group_id.0,
|
|
})
|
|
}
|
|
}
|
|
#[derive(Clone, ProtoBuf, Default, Debug)]
|
|
pub struct DatabaseLayoutIdPB {
|
|
#[pb(index = 1)]
|
|
pub view_id: String,
|
|
|
|
#[pb(index = 2)]
|
|
pub layout: DatabaseLayoutPB,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct DatabaseLayoutId {
|
|
pub view_id: String,
|
|
pub layout: DatabaseLayout,
|
|
}
|
|
|
|
impl TryInto<DatabaseLayoutId> for DatabaseLayoutIdPB {
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<DatabaseLayoutId, Self::Error> {
|
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseViewIdIsEmpty)?;
|
|
let layout = self.layout.into();
|
|
Ok(DatabaseLayoutId {
|
|
view_id: view_id.0,
|
|
layout,
|
|
})
|
|
}
|
|
}
|