mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
1ad08ba59d
* chore: create folders * chore: setup taliwindcss (#1742) * chore: create folders * chore: setup taliwindcss --------- Co-authored-by: nathan <nathan@appflowy.io> Co-authored-by: Nathan.fooo <86001920+appflowy@users.noreply.github.com> * feat: greater to blockquote * fix: local variable 'text' isn't used * feat: #1061 Support markdown to create a blockquote * fix: #1732 the actions of an image look different than the ones of a code block * fix: command of double tilde to strikethrough * feat: callout (#1732) * feat: add callout plugin * refactor: add SelectionMenuItem.node factory makes calloutMenuItem more readable * feat: add color picker * feat: add popover to callout * feat: add emoji to callout * fix: store tint name * fix: remove leading underscores * fix: revert export of editor_entry * refactor: move color tint names to appflowy_editor * fix: #1732 only re-insert text node if it's parent is text node too while deleting * docs: doc comment for SelectionMenuItem.node * fix: disable callout plugin should be re-enabled after #1753 is done * fix: typo --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> * Feat/http server adapt (#1754) * integrate board plugin into document (#1675) * fix: cursor doesn't blink when opening selection menu * feat: add board plugin * feat: integrate board plugin into document * feat: add i10n and fix known bugs * feat: support jump to board page on document * feat: disable editor scroll only when the board plugin is selected * chore: dart fix * chore: remove unused files * fix: dart lint * Feat/database view (#1765) * chore: rename flowy-database to flowy-sqlite * refactor: rename flowy-grid to flowy-database * refactor: rename grid to database * refactor: rename GridEvent to DatabaseEvent * refactor: rename grid_id to database_id * refactor: rename dart code * fix: #1763 [Bug] Mouse unable to click a certain area * fix: potential async errors (#1772) * feat: Skeleton task (#1775) * chore: change tauri dev npm script * chore: setup prettier * chore: add protobuf type * chore: move test calls to separate component * chore: serve assets from app_flowy folder * chore: import poppins font * chore: install eslint, remove errors * placeholder components * chore: import colors from UI kit, footer panel * chore: reorganise components * chore: redux toolkit, navigation folders and files, navigation hooks * fix: on add folder others close * fix: tauri_dev task * fix: restore grid notification * chore: navigation items events (#1784) * chore: change tauri dev npm script * chore: setup prettier * chore: add protobuf type * chore: move test calls to separate component * chore: serve assets from app_flowy folder * chore: import poppins font * chore: install eslint, remove errors * placeholder components * chore: import colors from UI kit, footer panel * chore: reorganise components * chore: redux toolkit, navigation folders and files, navigation hooks * fix: on add folder others close * fix: tauri_dev task * fix: restore grid notification * chore: shared button * chore: folder/file popup, rename/duplicate/delete items * chore: new page types popup * fix: navitem pages padding * fix: page click mishandle * fix: folder click mishandle * chore: add other page types * fix: stop propagating on button click * fix: one alt * fix: renaming change bg * refactor: brake Navigation Panel into smaller components * chore: header panel folder * chore: focus and select all on rename popup * chore: add classname to popup * chore: navigation panel resize * Feat/appflowy tauri (#1831) * feat:grid view structure * feat:add store and refactor grid page * chore: import icons, resize grid items, change grid items style, add field type icons, reorganize grid toolbar * feat: auth screens(login, signup and confirm-account) ui done * chore: add tailwind class sorter and formatted all files * chore: group svgs into single folder * chore: resolve warnings in svg files * fix: use exported fieldType enum * fix: resolve FieldType referances * chore: auth pages fixes, replace links, replace buttons, svg fixes, navigate between pages, navigate to homepage on main button click --------- Co-authored-by: ascarbek <ascarbek@gmail.com> * ci: wanrings --------- Co-authored-by: Mikias Tilahun Abebe <mikiastilahun@gmail.com> Co-authored-by: Andreas Bichinger <andreas.bichinger@gmail.com> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Askarbek Zadauly <ascarbek@gmail.com>
375 lines
13 KiB
Rust
375 lines
13 KiB
Rust
use bytes::Bytes;
|
|
use flowy_client_sync::client_grid::GridBuilder;
|
|
use flowy_database::services::field::*;
|
|
use flowy_database::services::grid_meta_editor::{GridMetaEditor, GridPadBuilder};
|
|
use flowy_database::services::row::CreateRowMetaPayload;
|
|
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
|
use flowy_test::helper::ViewTest;
|
|
use flowy_test::FlowySDKTest;
|
|
use grid_model::entities::{
|
|
BuildGridContext, CellChangeset, Field, FieldChangesetParams, FieldMeta, FieldOrder, FieldType,
|
|
GridBlockInfoChangeset, GridBlockMetaSnapshot, InsertFieldParams, RowMeta, RowMetaChangeset, RowOrder,
|
|
TypeOptionDataFormat,
|
|
};
|
|
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
use strum::EnumCount;
|
|
use tokio::time::sleep;
|
|
|
|
pub enum EditorScript {
|
|
CreateField {
|
|
params: InsertFieldParams,
|
|
},
|
|
UpdateField {
|
|
changeset: FieldChangesetParams,
|
|
},
|
|
DeleteField {
|
|
field_meta: FieldMeta,
|
|
},
|
|
AssertFieldCount(usize),
|
|
AssertFieldEqual {
|
|
field_index: usize,
|
|
field_meta: FieldMeta,
|
|
},
|
|
CreateBlock {
|
|
block: GridBlockMetaSnapshot,
|
|
},
|
|
UpdateBlock {
|
|
changeset: GridBlockInfoChangeset,
|
|
},
|
|
AssertBlockCount(usize),
|
|
AssertBlock {
|
|
block_index: usize,
|
|
row_count: i32,
|
|
start_row_index: i32,
|
|
},
|
|
AssertBlockEqual {
|
|
block_index: usize,
|
|
block: GridBlockMetaSnapshot,
|
|
},
|
|
CreateEmptyRow,
|
|
CreateRow {
|
|
context: CreateRowMetaPayload,
|
|
},
|
|
UpdateRow {
|
|
changeset: RowMetaChangeset,
|
|
},
|
|
AssertRow {
|
|
changeset: RowMetaChangeset,
|
|
},
|
|
DeleteRow {
|
|
row_ids: Vec<String>,
|
|
},
|
|
UpdateCell {
|
|
changeset: CellChangeset,
|
|
is_err: bool,
|
|
},
|
|
AssertRowCount(usize),
|
|
// AssertRowEqual{ row_index: usize, row: RowMeta},
|
|
AssertGridMetaPad,
|
|
}
|
|
|
|
pub struct GridEditorTest {
|
|
pub sdk: FlowySDKTest,
|
|
pub grid_id: String,
|
|
pub editor: Arc<GridMetaEditor>,
|
|
pub field_metas: Vec<FieldMeta>,
|
|
pub grid_blocks: Vec<GridBlockMetaSnapshot>,
|
|
pub row_metas: Vec<Arc<RowMeta>>,
|
|
pub field_count: usize,
|
|
|
|
pub row_order_by_row_id: HashMap<String, RowOrder>,
|
|
}
|
|
|
|
impl GridEditorTest {
|
|
pub async fn new() -> Self {
|
|
let sdk = FlowySDKTest::default();
|
|
let _ = sdk.init_user().await;
|
|
let build_context = make_template_1_grid();
|
|
let view_data: Bytes = build_context.into();
|
|
let test = ViewTest::new_grid_view(&sdk, view_data.to_vec()).await;
|
|
let editor = sdk.grid_manager.open_grid(&test.view.id).await.unwrap();
|
|
let field_metas = editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
|
let grid_blocks = editor.get_block_metas().await.unwrap();
|
|
let row_metas = get_row_metas(&editor).await;
|
|
|
|
let grid_id = test.view.id;
|
|
Self {
|
|
sdk,
|
|
grid_id,
|
|
editor,
|
|
field_metas,
|
|
grid_blocks,
|
|
row_metas,
|
|
field_count: FieldType::COUNT,
|
|
row_order_by_row_id: HashMap::default(),
|
|
}
|
|
}
|
|
|
|
pub async fn run_scripts(&mut self, scripts: Vec<EditorScript>) {
|
|
for script in scripts {
|
|
self.run_script(script).await;
|
|
}
|
|
}
|
|
|
|
pub async fn run_script(&mut self, script: EditorScript) {
|
|
let grid_manager = self.sdk.grid_manager.clone();
|
|
let pool = self.sdk.user_session.db_pool().unwrap();
|
|
let rev_manager = self.editor.rev_manager();
|
|
let _cache = rev_manager.revision_cache().await;
|
|
|
|
match script {
|
|
EditorScript::CreateField { params } => {
|
|
if !self.editor.contain_field(¶ms.field.id).await {
|
|
self.field_count += 1;
|
|
}
|
|
|
|
self.editor.insert_field(params).await.unwrap();
|
|
self.field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
|
assert_eq!(self.field_count, self.field_metas.len());
|
|
}
|
|
EditorScript::UpdateField { changeset: change } => {
|
|
self.editor.update_field(change).await.unwrap();
|
|
self.field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
|
}
|
|
EditorScript::DeleteField { field_meta } => {
|
|
if self.editor.contain_field(&field_meta.id).await {
|
|
self.field_count -= 1;
|
|
}
|
|
|
|
self.editor.delete_field(&field_meta.id).await.unwrap();
|
|
self.field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
|
assert_eq!(self.field_count, self.field_metas.len());
|
|
}
|
|
EditorScript::AssertFieldCount(count) => {
|
|
assert_eq!(
|
|
self.editor.get_field_metas::<FieldOrder>(None).await.unwrap().len(),
|
|
count
|
|
);
|
|
}
|
|
EditorScript::AssertFieldEqual {
|
|
field_index,
|
|
field_meta,
|
|
} => {
|
|
let field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
|
assert_eq!(field_metas[field_index].clone(), field_meta);
|
|
}
|
|
EditorScript::CreateBlock { block } => {
|
|
self.editor.create_block(block).await.unwrap();
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
|
}
|
|
EditorScript::UpdateBlock { changeset: change } => {
|
|
self.editor.update_block(change).await.unwrap();
|
|
}
|
|
EditorScript::AssertBlockCount(count) => {
|
|
assert_eq!(self.editor.get_block_metas().await.unwrap().len(), count);
|
|
}
|
|
EditorScript::AssertBlock {
|
|
block_index,
|
|
row_count,
|
|
start_row_index,
|
|
} => {
|
|
assert_eq!(self.grid_blocks[block_index].row_count, row_count);
|
|
assert_eq!(self.grid_blocks[block_index].start_row_index, start_row_index);
|
|
}
|
|
EditorScript::AssertBlockEqual { block_index, block } => {
|
|
let blocks = self.editor.get_block_metas().await.unwrap();
|
|
let compared_block = blocks[block_index].clone();
|
|
assert_eq!(compared_block, block);
|
|
}
|
|
EditorScript::CreateEmptyRow => {
|
|
let row_order = self.editor.create_row(None).await.unwrap();
|
|
self.row_order_by_row_id.insert(row_order.row_id.clone(), row_order);
|
|
self.row_metas = self.get_row_metas().await;
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
|
}
|
|
EditorScript::CreateRow { context } => {
|
|
let row_orders = self.editor.insert_rows(vec![context]).await.unwrap();
|
|
for row_order in row_orders {
|
|
self.row_order_by_row_id.insert(row_order.row_id.clone(), row_order);
|
|
}
|
|
self.row_metas = self.get_row_metas().await;
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
|
}
|
|
EditorScript::UpdateRow { changeset: change } => self.editor.update_row(change).await.unwrap(),
|
|
EditorScript::DeleteRow { row_ids } => {
|
|
let row_orders = row_ids
|
|
.into_iter()
|
|
.map(|row_id| self.row_order_by_row_id.get(&row_id).unwrap().clone())
|
|
.collect::<Vec<RowOrder>>();
|
|
|
|
self.editor.delete_rows(row_orders).await.unwrap();
|
|
self.row_metas = self.get_row_metas().await;
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
|
}
|
|
EditorScript::AssertRow { changeset } => {
|
|
let row = self.row_metas.iter().find(|row| row.id == changeset.row_id).unwrap();
|
|
|
|
if let Some(visibility) = changeset.visibility {
|
|
assert_eq!(row.visibility, visibility);
|
|
}
|
|
|
|
if let Some(height) = changeset.height {
|
|
assert_eq!(row.height, height);
|
|
}
|
|
}
|
|
EditorScript::UpdateCell { changeset, is_err } => {
|
|
let result = self.editor.update_cell(changeset).await;
|
|
if is_err {
|
|
assert!(result.is_err())
|
|
} else {
|
|
let _ = result.unwrap();
|
|
self.row_metas = self.get_row_metas().await;
|
|
}
|
|
}
|
|
EditorScript::AssertRowCount(count) => {
|
|
assert_eq!(self.row_metas.len(), count);
|
|
}
|
|
EditorScript::AssertGridMetaPad => {
|
|
sleep(Duration::from_millis(2 * REVISION_WRITE_INTERVAL_IN_MILLIS)).await;
|
|
let mut grid_rev_manager = grid_manager.make_grid_rev_manager(&self.grid_id, pool.clone()).unwrap();
|
|
let grid_pad = grid_rev_manager.load::<GridPadBuilder>(None).await.unwrap();
|
|
println!("{}", grid_pad.delta_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
async fn get_row_metas(&self) -> Vec<Arc<RowMeta>> {
|
|
get_row_metas(&self.editor).await
|
|
}
|
|
}
|
|
|
|
async fn get_row_metas(editor: &Arc<GridMetaEditor>) -> Vec<Arc<RowMeta>> {
|
|
editor
|
|
.grid_block_snapshots(None)
|
|
.await
|
|
.unwrap()
|
|
.pop()
|
|
.unwrap()
|
|
.row_metas
|
|
}
|
|
|
|
pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldMeta) {
|
|
let field_meta = FieldBuilder::new(RichTextTypeOptionBuilder::default())
|
|
.name("Name")
|
|
.visibility(true)
|
|
.build();
|
|
|
|
let cloned_field_meta = field_meta.clone();
|
|
|
|
let type_option_data = field_meta
|
|
.get_type_option_entry::<RichTextTypeOptionPB>(&field_meta.field_type)
|
|
.unwrap()
|
|
.protobuf_bytes()
|
|
.to_vec();
|
|
|
|
let field = Field {
|
|
id: field_meta.id,
|
|
name: field_meta.name,
|
|
desc: field_meta.desc,
|
|
field_type: field_meta.field_type,
|
|
frozen: field_meta.frozen,
|
|
visibility: field_meta.visibility,
|
|
width: field_meta.width,
|
|
is_primary: false,
|
|
};
|
|
|
|
let params = InsertFieldParams {
|
|
grid_id: grid_id.to_owned(),
|
|
field,
|
|
type_option_data,
|
|
start_field_id: None,
|
|
};
|
|
(params, cloned_field_meta)
|
|
}
|
|
|
|
pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldMeta) {
|
|
let single_select = SingleSelectTypeOptionBuilder::default()
|
|
.option(SelectOption::new("Done"))
|
|
.option(SelectOption::new("Progress"));
|
|
|
|
let field_meta = FieldBuilder::new(single_select).name("Name").visibility(true).build();
|
|
let cloned_field_meta = field_meta.clone();
|
|
let type_option_data = field_meta
|
|
.get_type_option_entry::<SingleSelectTypeOption>(&field_meta.field_type)
|
|
.unwrap()
|
|
.protobuf_bytes()
|
|
.to_vec();
|
|
|
|
let field = Field {
|
|
id: field_meta.id,
|
|
name: field_meta.name,
|
|
desc: field_meta.desc,
|
|
field_type: field_meta.field_type,
|
|
frozen: field_meta.frozen,
|
|
visibility: field_meta.visibility,
|
|
width: field_meta.width,
|
|
is_primary: false,
|
|
};
|
|
|
|
let params = InsertFieldParams {
|
|
grid_id: grid_id.to_owned(),
|
|
field,
|
|
type_option_data,
|
|
start_field_id: None,
|
|
};
|
|
(params, cloned_field_meta)
|
|
}
|
|
|
|
fn make_template_1_grid() -> BuildGridContext {
|
|
let text_field = FieldBuilder::new(RichTextTypeOptionBuilder::default())
|
|
.name("Name")
|
|
.visibility(true)
|
|
.build();
|
|
|
|
// Single Select
|
|
let single_select = SingleSelectTypeOptionBuilder::default()
|
|
.option(SelectOption::new("Live"))
|
|
.option(SelectOption::new("Completed"))
|
|
.option(SelectOption::new("Planned"))
|
|
.option(SelectOption::new("Paused"));
|
|
let single_select_field = FieldBuilder::new(single_select).name("Status").visibility(true).build();
|
|
|
|
// MultiSelect
|
|
let multi_select = MultiSelectTypeOptionBuilder::default()
|
|
.option(SelectOption::new("Google"))
|
|
.option(SelectOption::new("Facebook"))
|
|
.option(SelectOption::new("Twitter"));
|
|
let multi_select_field = FieldBuilder::new(multi_select)
|
|
.name("Platform")
|
|
.visibility(true)
|
|
.build();
|
|
|
|
// Number
|
|
let number = NumberTypeOptionBuilder::default().set_format(NumberFormat::USD);
|
|
let number_field = FieldBuilder::new(number).name("Price").visibility(true).build();
|
|
|
|
// Date
|
|
let date = DateTypeOptionBuilder::default()
|
|
.date_format(DateFormat::US)
|
|
.time_format(TimeFormat::TwentyFourHour);
|
|
let date_field = FieldBuilder::new(date).name("Time").visibility(true).build();
|
|
|
|
// Checkbox
|
|
let checkbox = CheckboxTypeOptionBuilder::default();
|
|
let checkbox_field = FieldBuilder::new(checkbox).name("is done").visibility(true).build();
|
|
|
|
// URL
|
|
let url = URLTypeOptionBuilder::default();
|
|
let url_field = FieldBuilder::new(url).name("link").visibility(true).build();
|
|
|
|
GridBuilder::default()
|
|
.add_field(text_field)
|
|
.add_field(single_select_field)
|
|
.add_field(multi_select_field)
|
|
.add_field(number_field)
|
|
.add_field(date_field)
|
|
.add_field(checkbox_field)
|
|
.add_field(url_field)
|
|
.add_empty_row()
|
|
.add_empty_row()
|
|
.add_empty_row()
|
|
.build()
|
|
}
|