fix: tauri folder display (#2176)

* fix: tauri folder display

* refactor: rename layout type
This commit is contained in:
Nathan.fooo 2023-04-04 14:08:50 +08:00 committed by GitHub
parent e1c8135f5d
commit ddd3fbb178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 288 additions and 532 deletions

2
.gitignore vendored
View File

@ -35,3 +35,5 @@ pubspec.lock
.githooks/gitlint .githooks/gitlint
.githooks/gitlint.exe .githooks/gitlint.exe
.fvm/ .fvm/
**/AppFlowy-Collab/

View File

@ -79,7 +79,7 @@ class DatabaseController {
final DatabaseViewBackendService _databaseViewBackendSvc; final DatabaseViewBackendService _databaseViewBackendSvc;
final FieldController fieldController; final FieldController fieldController;
late DatabaseViewCache _viewCache; late DatabaseViewCache _viewCache;
final LayoutTypePB layoutType; final DatabaseLayoutPB layoutType;
// Callbacks // Callbacks
DatabaseCallbacks? _databaseCallbacks; DatabaseCallbacks? _databaseCallbacks;
@ -110,7 +110,7 @@ class DatabaseController {
_listenOnFieldsChanged(); _listenOnFieldsChanged();
_listenOnGroupChanged(); _listenOnGroupChanged();
_listenOnLayoutChanged(); _listenOnLayoutChanged();
if (layoutType == LayoutTypePB.Calendar) { if (layoutType == DatabaseLayoutPB.Calendar) {
_listenOnCalendarLayoutChanged(); _listenOnCalendarLayoutChanged();
} }
} }

View File

@ -86,7 +86,7 @@ class DatabaseViewBackendService {
} }
Future<Either<LayoutSettingPB, FlowyError>> getLayoutSetting( Future<Either<LayoutSettingPB, FlowyError>> getLayoutSetting(
LayoutTypePB layoutType) { DatabaseLayoutPB layoutType) {
final payload = DatabaseLayoutIdPB.create() final payload = DatabaseLayoutIdPB.create()
..viewId = viewId ..viewId = viewId
..layout = layoutType; ..layout = layoutType;

View File

@ -30,7 +30,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
BoardBloc({required ViewPB view}) BoardBloc({required ViewPB view})
: _databaseController = DatabaseController( : _databaseController = DatabaseController(
view: view, view: view,
layoutType: LayoutTypePB.Board, layoutType: DatabaseLayoutPB.Board,
), ),
super(BoardState.initial(view.id)) { super(BoardState.initial(view.id)) {
boardController = AppFlowyBoardController( boardController = AppFlowyBoardController(

View File

@ -29,7 +29,7 @@ class BoardPluginBuilder implements PluginBuilder {
PluginType get pluginType => PluginType.board; PluginType get pluginType => PluginType.board;
@override @override
ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Board; ViewLayoutPB? get layoutType => ViewLayoutPB.Board;
} }
class BoardPluginConfig implements PluginConfig { class BoardPluginConfig implements PluginConfig {

View File

@ -28,7 +28,7 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {
CalendarBloc({required ViewPB view}) CalendarBloc({required ViewPB view})
: _databaseController = DatabaseController( : _databaseController = DatabaseController(
view: view, view: view,
layoutType: LayoutTypePB.Calendar, layoutType: DatabaseLayoutPB.Calendar,
), ),
super(CalendarState.initial()) { super(CalendarState.initial()) {
on<CalendarEvent>( on<CalendarEvent>(

View File

@ -29,7 +29,7 @@ class CalendarPluginBuilder extends PluginBuilder {
PluginType get pluginType => PluginType.calendar; PluginType get pluginType => PluginType.calendar;
@override @override
ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Calendar; ViewLayoutPB? get layoutType => ViewLayoutPB.Calendar;
} }
class CalendarPluginConfig implements PluginConfig { class CalendarPluginConfig implements PluginConfig {

View File

@ -29,7 +29,7 @@ class GridPluginBuilder implements PluginBuilder {
PluginType get pluginType => PluginType.grid; PluginType get pluginType => PluginType.grid;
@override @override
ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Grid; ViewLayoutPB? get layoutType => ViewLayoutPB.Grid;
} }
class GridPluginConfig implements PluginConfig { class GridPluginConfig implements PluginConfig {

View File

@ -38,7 +38,7 @@ class GridPage extends StatefulWidget {
Key? key, Key? key,
}) : databaseController = DatabaseController( }) : databaseController = DatabaseController(
view: view, view: view,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
), ),
super(key: key); super(key: key);

View File

@ -34,7 +34,7 @@ class DocumentPluginBuilder extends PluginBuilder {
PluginType get pluginType => PluginType.editor; PluginType get pluginType => PluginType.editor;
@override @override
ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Document; ViewLayoutPB? get layoutType => ViewLayoutPB.Document;
} }
class DocumentPlugin extends Plugin<int> { class DocumentPlugin extends Plugin<int> {

View File

@ -30,9 +30,9 @@ extension InsertPage on EditorState {
String _convertPageType(ViewPB viewPB) { String _convertPageType(ViewPB viewPB) {
switch (viewPB.layout) { switch (viewPB.layout) {
case ViewLayoutTypePB.Grid: case ViewLayoutPB.Grid:
return kGridType; return kGridType;
case ViewLayoutTypePB.Board: case ViewLayoutPB.Board:
return kBoardType; return kBoardType;
default: default:
throw Exception('Unknown layout type'); throw Exception('Unknown layout type');

View File

@ -17,7 +17,7 @@ void showLinkToPageMenu(
EditorState editorState, EditorState editorState,
SelectionMenuService menuService, SelectionMenuService menuService,
BuildContext context, BuildContext context,
ViewLayoutTypePB pageType, ViewLayoutPB pageType,
) { ) {
final alignment = menuService.alignment; final alignment = menuService.alignment;
final offset = menuService.offset; final offset = menuService.offset;
@ -27,10 +27,10 @@ void showLinkToPageMenu(
String hintText = ''; String hintText = '';
switch (pageType) { switch (pageType) {
case ViewLayoutTypePB.Grid: case ViewLayoutPB.Grid:
hintText = LocaleKeys.document_slashMenu_grid_selectAGridToLinkTo.tr(); hintText = LocaleKeys.document_slashMenu_grid_selectAGridToLinkTo.tr();
break; break;
case ViewLayoutTypePB.Board: case ViewLayoutPB.Board:
hintText = LocaleKeys.document_slashMenu_board_selectABoardToLinkTo.tr(); hintText = LocaleKeys.document_slashMenu_board_selectABoardToLinkTo.tr();
break; break;
default: default:
@ -82,7 +82,7 @@ class LinkToPageMenu extends StatefulWidget {
}); });
final EditorState editorState; final EditorState editorState;
final ViewLayoutTypePB layoutType; final ViewLayoutPB layoutType;
final String hintText; final String hintText;
final void Function(ViewPB view, ViewPB childView) onSelected; final void Function(ViewPB view, ViewPB childView) onSelected;
@ -174,9 +174,9 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
String _iconName(ViewPB viewPB) { String _iconName(ViewPB viewPB) {
switch (viewPB.layout) { switch (viewPB.layout) {
case ViewLayoutTypePB.Grid: case ViewLayoutPB.Grid:
return 'editor/grid'; return 'editor/grid';
case ViewLayoutTypePB.Board: case ViewLayoutPB.Board:
return 'editor/board'; return 'editor/board';
default: default:
throw Exception('Unknown layout type'); throw Exception('Unknown layout type');

View File

@ -24,7 +24,7 @@ SelectionMenuItem boardMenuItem = SelectionMenuItem(
editorState, editorState,
menuService, menuService,
context, context,
ViewLayoutTypePB.Board, ViewLayoutPB.Board,
); );
}, },
); );

View File

@ -23,17 +23,17 @@ SelectionMenuItem boardViewMenuItem(DocumentBloc documentBloc) =>
// TODO(a-wallen): Translate keywords. // TODO(a-wallen): Translate keywords.
keywords: ['board', 'kanban'], keywords: ['board', 'kanban'],
handler: (editorState, menuService, context) async { handler: (editorState, menuService, context) async {
if (!documentBloc.view.hasAppId()) { if (!documentBloc.view.hasParentViewId()) {
return; return;
} }
final appId = documentBloc.view.appId; final appId = documentBloc.view.parentViewId;
final service = AppBackendService(); final service = AppBackendService();
final result = (await service.createView( final result = (await service.createView(
appId: appId, appId: appId,
name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(), name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
layoutType: ViewLayoutTypePB.Board, layoutType: ViewLayoutPB.Board,
)) ))
.getLeftOrNull(); .getLeftOrNull();

View File

@ -23,7 +23,7 @@ SelectionMenuItem gridMenuItem = SelectionMenuItem(
editorState, editorState,
menuService, menuService,
context, context,
ViewLayoutTypePB.Grid, ViewLayoutPB.Grid,
); );
}, },
); );

View File

@ -22,17 +22,17 @@ SelectionMenuItem gridViewMenuItem(DocumentBloc documentBloc) =>
}, },
keywords: ['grid'], keywords: ['grid'],
handler: (editorState, menuService, context) async { handler: (editorState, menuService, context) async {
if (!documentBloc.view.hasAppId()) { if (!documentBloc.view.hasParentViewId()) {
return; return;
} }
final appId = documentBloc.view.appId; final appId = documentBloc.view.parentViewId;
final service = AppBackendService(); final service = AppBackendService();
final result = (await service.createView( final result = (await service.createView(
appId: appId, appId: appId,
name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(), name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
layoutType: ViewLayoutTypePB.Grid, layoutType: ViewLayoutPB.Grid,
)) ))
.getLeftOrNull(); .getLeftOrNull();

View File

@ -52,7 +52,7 @@ abstract class PluginBuilder {
PluginType get pluginType; PluginType get pluginType;
ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Document; ViewLayoutPB? get layoutType => ViewLayoutPB.Document;
} }
abstract class PluginConfig { abstract class PluginConfig {

View File

@ -12,7 +12,7 @@ class AppBackendService {
required String appId, required String appId,
required String name, required String name,
String? desc, String? desc,
required ViewLayoutTypePB layoutType, required ViewLayoutPB layoutType,
/// The initial data should be the JSON of the document. /// The initial data should be the JSON of the document.
/// Currently, only support create document with initial data. /// Currently, only support create document with initial data.
@ -90,7 +90,7 @@ class AppBackendService {
} }
Future<List<Tuple2<ViewPB, List<ViewPB>>>> fetchViews( Future<List<Tuple2<ViewPB, List<ViewPB>>>> fetchViews(
ViewLayoutTypePB layoutType) async { ViewLayoutPB layoutType) async {
final result = <Tuple2<ViewPB, List<ViewPB>>>[]; final result = <Tuple2<ViewPB, List<ViewPB>>>[];
return FolderEventReadCurrentWorkspace().send().then((value) async { return FolderEventReadCurrentWorkspace().send().then((value) async {
final workspaces = value.getLeftOrNull<WorkspaceSettingPB>(); final workspaces = value.getLeftOrNull<WorkspaceSettingPB>();

View File

@ -42,13 +42,13 @@ extension ViewExtension on ViewPB {
PluginType get pluginType { PluginType get pluginType {
switch (layout) { switch (layout) {
case ViewLayoutTypePB.Board: case ViewLayoutPB.Board:
return PluginType.board; return PluginType.board;
case ViewLayoutTypePB.Calendar: case ViewLayoutPB.Calendar:
return PluginType.calendar; return PluginType.calendar;
case ViewLayoutTypePB.Document: case ViewLayoutPB.Document:
return PluginType.editor; return PluginType.editor;
case ViewLayoutTypePB.Grid: case ViewLayoutPB.Grid:
return PluginType.grid; return PluginType.grid;
} }

View File

@ -9,7 +9,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart'
CreateViewPayloadPB, CreateViewPayloadPB,
MoveFolderItemPayloadPB, MoveFolderItemPayloadPB,
MoveFolderItemType, MoveFolderItemType,
ViewLayoutTypePB, ViewLayoutPB,
ViewPB; ViewPB;
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
@ -26,7 +26,7 @@ class WorkspaceService {
..belongToId = workspaceId ..belongToId = workspaceId
..name = name ..name = name
..desc = desc ?? "" ..desc = desc ?? ""
..layout = ViewLayoutTypePB.Document; ..layout = ViewLayoutPB.Document;
return FolderEventCreateView(payload).send(); return FolderEventCreateView(payload).send();
} }

View File

@ -261,7 +261,7 @@ class HomeScreenStackAdaptor extends HomeStackDelegate {
@override @override
void didDeleteStackWidget(ViewPB view, int? index) { void didDeleteStackWidget(ViewPB view, int? index) {
final homeService = HomeService(); final homeService = HomeService();
homeService.readApp(appId: view.appId).then((result) { homeService.readApp(appId: view.parentViewId).then((result) {
result.fold( result.fold(
(parentView) { (parentView) {
final List<ViewPB> views = parentView.belongings; final List<ViewPB> views = parentView.belongings;

View File

@ -43,7 +43,7 @@ class AppFlowyBoardTest {
view, view,
DatabaseController( DatabaseController(
view: view, view: view,
layoutType: LayoutTypePB.Board, layoutType: DatabaseLayoutPB.Board,
), ),
); );
final result = await context._boardDataController.open(); final result = await context._boardDataController.open();

View File

@ -53,7 +53,7 @@ void main() {
final service = FilterBackendService(viewId: context.gridView.id); final service = FilterBackendService(viewId: context.gridView.id);
final gridController = DatabaseController( final gridController = DatabaseController(
view: context.gridView, view: context.gridView,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
); );
final gridBloc = GridBloc( final gridBloc = GridBloc(
view: context.gridView, view: context.gridView,
@ -77,7 +77,7 @@ void main() {
final service = FilterBackendService(viewId: context.gridView.id); final service = FilterBackendService(viewId: context.gridView.id);
final gridController = DatabaseController( final gridController = DatabaseController(
view: context.gridView, view: context.gridView,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
); );
final gridBloc = GridBloc( final gridBloc = GridBloc(
view: context.gridView, view: context.gridView,
@ -121,7 +121,7 @@ void main() {
final service = FilterBackendService(viewId: context.gridView.id); final service = FilterBackendService(viewId: context.gridView.id);
final gridController = DatabaseController( final gridController = DatabaseController(
view: context.gridView, view: context.gridView,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
); );
final gridBloc = GridBloc( final gridBloc = GridBloc(
view: context.gridView, view: context.gridView,
@ -143,7 +143,7 @@ void main() {
final service = FilterBackendService(viewId: context.gridView.id); final service = FilterBackendService(viewId: context.gridView.id);
final gridController = DatabaseController( final gridController = DatabaseController(
view: context.gridView, view: context.gridView,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
); );
final gridBloc = GridBloc( final gridBloc = GridBloc(
view: context.gridView, view: context.gridView,

View File

@ -21,7 +21,7 @@ Future<GridTestContext> createTestFilterGrid(AppFlowyGridTest gridTest) async {
view, view,
DatabaseController( DatabaseController(
view: view, view: view,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
)); ));
final result = await context.gridController.open(); final result = await context.gridController.open();

View File

@ -23,7 +23,7 @@ void main() {
view: context.gridView, view: context.gridView,
databaseController: DatabaseController( databaseController: DatabaseController(
view: context.gridView, view: context.gridView,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
)) ))
..add(const GridEvent.initial()), ..add(const GridEvent.initial()),
act: (bloc) => bloc.add(const GridEvent.createRow()), act: (bloc) => bloc.add(const GridEvent.createRow()),
@ -39,7 +39,7 @@ void main() {
view: context.gridView, view: context.gridView,
databaseController: DatabaseController( databaseController: DatabaseController(
view: context.gridView, view: context.gridView,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
)) ))
..add(const GridEvent.initial()), ..add(const GridEvent.initial()),
act: (bloc) async { act: (bloc) async {

View File

@ -178,7 +178,7 @@ class AppFlowyGridTest {
view, view,
DatabaseController( DatabaseController(
view: view, view: view,
layoutType: LayoutTypePB.Grid, layoutType: DatabaseLayoutPB.Grid,
)); ));
final result = await context.gridController.open(); final result = await context.gridController.open();
result.fold((l) => null, (r) => throw Exception(r)); result.fold((l) => null, (r) => throw Exception(r));

View File

@ -23,7 +23,7 @@ void main() {
assert(bloc.state.views.length == 1); assert(bloc.state.views.length == 1);
assert(bloc.state.views.last.name == "Test document"); assert(bloc.state.views.last.name == "Test document");
assert(bloc.state.views.last.layout == ViewLayoutTypePB.Document); assert(bloc.state.views.last.layout == ViewLayoutPB.Document);
}); });
test('create a grid', () async { test('create a grid', () async {
@ -36,7 +36,7 @@ void main() {
assert(bloc.state.views.length == 1); assert(bloc.state.views.length == 1);
assert(bloc.state.views.last.name == "Test grid"); assert(bloc.state.views.last.name == "Test grid");
assert(bloc.state.views.last.layout == ViewLayoutTypePB.Grid); assert(bloc.state.views.last.layout == ViewLayoutPB.Grid);
}); });
test('create a kanban', () async { test('create a kanban', () async {
@ -49,7 +49,7 @@ void main() {
assert(bloc.state.views.length == 1); assert(bloc.state.views.length == 1);
assert(bloc.state.views.last.name == "Test board"); assert(bloc.state.views.last.name == "Test board");
assert(bloc.state.views.last.layout == ViewLayoutTypePB.Board); assert(bloc.state.views.last.layout == ViewLayoutPB.Board);
}); });
test('create a calendar', () async { test('create a calendar', () async {
@ -62,6 +62,6 @@ void main() {
assert(bloc.state.views.length == 1); assert(bloc.state.views.length == 1);
assert(bloc.state.views.last.name == "Test calendar"); assert(bloc.state.views.last.name == "Test calendar");
assert(bloc.state.views.last.layout == ViewLayoutTypePB.Calendar); assert(bloc.state.views.last.layout == ViewLayoutPB.Calendar);
}); });
} }

View File

@ -564,7 +564,7 @@ dependencies = [
[[package]] [[package]]
name = "collab" name = "collab"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#9b3f895bb6f8e92830acd90cfb68b69aece83095"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -582,7 +582,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-derive" name = "collab-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#9b3f895bb6f8e92830acd90cfb68b69aece83095"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -594,7 +594,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-folder" name = "collab-folder"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#9b3f895bb6f8e92830acd90cfb68b69aece83095"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"collab", "collab",
@ -612,7 +612,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-persistence" name = "collab-persistence"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#9b3f895bb6f8e92830acd90cfb68b69aece83095"
dependencies = [ dependencies = [
"bincode", "bincode",
"chrono", "chrono",

View File

@ -33,8 +33,13 @@ default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"] custom-protocol = ["tauri/custom-protocol"]
[patch.crates-io] [patch.crates-io]
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f25ce7f" } collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f25ce7f" } collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab" }
collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f25ce7f" } collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab" }
#collab = { path = "../../AppFlowy-Collab/collab" }
#collab-folder = { path = "../../AppFlowy-Collab/collab-folder" }
#collab-persistence = { path = "../../AppFlowy-Collab/collab-persistence" }

View File

@ -5,11 +5,11 @@ import { useAppDispatch } from '$app/stores/store';
import loadField from './loadField'; import loadField from './loadField';
import { FieldInfo } from '$app/stores/effects/database/field/field_controller'; import { FieldInfo } from '$app/stores/effects/database/field/field_controller';
import { RowInfo } from '$app/stores/effects/database/row/row_cache'; import { RowInfo } from '$app/stores/effects/database/row/row_cache';
import { ViewLayoutTypePB } from '@/services/backend'; import { ViewLayoutPB } from '@/services/backend';
import { DatabaseGroupController } from '$app/stores/effects/database/group/group_controller'; import { DatabaseGroupController } from '$app/stores/effects/database/group/group_controller';
import { OnDragEndResponder } from 'react-beautiful-dnd'; import { OnDragEndResponder } from 'react-beautiful-dnd';
export const useDatabase = (viewId: string, type?: ViewLayoutTypePB) => { export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [controller, setController] = useState<DatabaseController>(); const [controller, setController] = useState<DatabaseController>();
const [rows, setRows] = useState<readonly RowInfo[]>([]); const [rows, setRows] = useState<readonly RowInfo[]>([]);
@ -58,7 +58,7 @@ export const useDatabase = (viewId: string, type?: ViewLayoutTypePB) => {
}); });
await controller.open(); await controller.open();
if (type === ViewLayoutTypePB.Board) { if (type === ViewLayoutPB.Board) {
const fieldId = await controller.getGroupByFieldId(); const fieldId = await controller.getGroupByFieldId();
setGroupByFieldId(fieldId.unwrap()); setGroupByFieldId(fieldId.unwrap());
setGroups(controller.groups.value); setGroups(controller.groups.value);

View File

@ -3,17 +3,14 @@ import { SearchInput } from '../_shared/SearchInput';
import { BoardBlock } from './BoardBlock'; import { BoardBlock } from './BoardBlock';
import { NewBoardBlock } from './NewBoardBlock'; import { NewBoardBlock } from './NewBoardBlock';
import { useDatabase } from '../_shared/database-hooks/useDatabase'; import { useDatabase } from '../_shared/database-hooks/useDatabase';
import { ViewLayoutTypePB } from '@/services/backend'; import { ViewLayoutPB } from '@/services/backend';
import { DragDropContext } from 'react-beautiful-dnd'; import { DragDropContext } from 'react-beautiful-dnd';
import { useState } from 'react'; import { useState } from 'react';
import { RowInfo } from '$app/stores/effects/database/row/row_cache'; import { RowInfo } from '$app/stores/effects/database/row/row_cache';
import { EditRow } from '$app/components/_shared/EditRow/EditRow'; import { EditRow } from '$app/components/_shared/EditRow/EditRow';
export const Board = ({ viewId }: { viewId: string }) => { export const Board = ({ viewId }: { viewId: string }) => {
const { controller, rows, groups, groupByFieldId, onNewRowClick, onDragEnd } = useDatabase( const { controller, rows, groups, groupByFieldId, onNewRowClick, onDragEnd } = useDatabase(viewId, ViewLayoutPB.Board);
viewId,
ViewLayoutTypePB.Board
);
const [showBoardRow, setShowBoardRow] = useState(false); const [showBoardRow, setShowBoardRow] = useState(false);
const [boardRowInfo, setBoardRowInfo] = useState<RowInfo>(); const [boardRowInfo, setBoardRowInfo] = useState<RowInfo>();

View File

@ -2,7 +2,7 @@ import { foldersActions, IFolder } from '../../../stores/reducers/folders/slice'
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useAppDispatch, useAppSelector } from '../../../stores/store'; import { useAppDispatch, useAppSelector } from '../../../stores/store';
import { IPage, pagesActions } from '../../../stores/reducers/pages/slice'; import { IPage, pagesActions } from '../../../stores/reducers/pages/slice';
import { AppPB, ViewLayoutTypePB } from '@/services/backend'; import { ViewLayoutPB } from '@/services/backend';
import { AppBackendService } from '../../../stores/effects/folder/app/app_bd_svc'; import { AppBackendService } from '../../../stores/effects/folder/app/app_bd_svc';
import { WorkspaceBackendService } from '../../../stores/effects/folder/workspace/workspace_bd_svc'; import { WorkspaceBackendService } from '../../../stores/effects/folder/workspace/workspace_bd_svc';
import { useError } from '../../error/Error.hooks'; import { useError } from '../../error/Error.hooks';
@ -42,7 +42,7 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
const views = change.val; const views = change.val;
const updatedPages: IPage[] = views.items.map((view) => ({ const updatedPages: IPage[] = views.items.map((view) => ({
id: view.id, id: view.id,
folderId: view.app_id, folderId: view.parent_view_id,
pageType: view.layout, pageType: view.layout,
title: view.name, title: view.name,
})); }));
@ -129,13 +129,13 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
try { try {
const newView = await appBackendService.createView({ const newView = await appBackendService.createView({
name: 'New Document 1', name: 'New Document 1',
layoutType: ViewLayoutTypePB.Document, layoutType: ViewLayoutPB.Document,
}); });
appDispatch( appDispatch(
pagesActions.addPage({ pagesActions.addPage({
folderId: folder.id, folderId: folder.id,
pageType: ViewLayoutTypePB.Document, pageType: ViewLayoutPB.Document,
title: newView.name, title: newView.name,
id: newView.id, id: newView.id,
}) })
@ -154,7 +154,7 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
try { try {
const newView = await appBackendService.createView({ const newView = await appBackendService.createView({
name: 'New Board 1', name: 'New Board 1',
layoutType: ViewLayoutTypePB.Board, layoutType: ViewLayoutPB.Board,
}); });
setShowPages(true); setShowPages(true);
@ -162,7 +162,7 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
appDispatch( appDispatch(
pagesActions.addPage({ pagesActions.addPage({
folderId: folder.id, folderId: folder.id,
pageType: ViewLayoutTypePB.Board, pageType: ViewLayoutPB.Board,
title: newView.name, title: newView.name,
id: newView.id, id: newView.id,
}) })
@ -179,7 +179,7 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
try { try {
const newView = await appBackendService.createView({ const newView = await appBackendService.createView({
name: 'New Grid 1', name: 'New Grid 1',
layoutType: ViewLayoutTypePB.Grid, layoutType: ViewLayoutPB.Grid,
}); });
setShowPages(true); setShowPages(true);
@ -187,7 +187,7 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
appDispatch( appDispatch(
pagesActions.addPage({ pagesActions.addPage({
folderId: folder.id, folderId: folder.id,
pageType: ViewLayoutTypePB.Grid, pageType: ViewLayoutPB.Grid,
title: newView.name, title: newView.name,
id: newView.id, id: newView.id,
}) })

View File

@ -1,7 +1,7 @@
import { useAppSelector } from '../../../stores/store'; import { useAppSelector } from '../../../stores/store';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { IPage } from '../../../stores/reducers/pages/slice'; import { IPage } from '../../../stores/reducers/pages/slice';
import { ViewLayoutTypePB } from '@/services/backend'; import { ViewLayoutPB } from '@/services/backend';
import { useState } from 'react'; import { useState } from 'react';
export const useNavigationPanelHooks = function () { export const useNavigationPanelHooks = function () {
@ -23,12 +23,12 @@ export const useNavigationPanelHooks = function () {
const onPageClick = (page: IPage) => { const onPageClick = (page: IPage) => {
let pageTypeRoute = (() => { let pageTypeRoute = (() => {
switch (page.pageType) { switch (page.pageType) {
case ViewLayoutTypePB.Document: case ViewLayoutPB.Document:
return 'document'; return 'document';
break; break;
case ViewLayoutTypePB.Grid: case ViewLayoutPB.Grid:
return 'grid'; return 'grid';
case ViewLayoutTypePB.Board: case ViewLayoutPB.Board:
return 'board'; return 'board';
default: default:
return 'document'; return 'document';

View File

@ -7,7 +7,7 @@ import { IPage } from '../../../stores/reducers/pages/slice';
import { Button } from '../../_shared/Button'; import { Button } from '../../_shared/Button';
import { usePageEvents } from './PageItem.hooks'; import { usePageEvents } from './PageItem.hooks';
import { RenamePopup } from './RenamePopup'; import { RenamePopup } from './RenamePopup';
import { ViewLayoutTypePB } from '@/services/backend'; import { ViewLayoutPB } from '@/services/backend';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { PAGE_ITEM_HEIGHT } from '../../_shared/constants'; import { PAGE_ITEM_HEIGHT } from '../../_shared/constants';
@ -47,9 +47,9 @@ export const PageItem = ({ page, onPageClick }: { page: IPage; onPageClick: () =
> >
<button className={'flex min-w-0 flex-1 items-center'}> <button className={'flex min-w-0 flex-1 items-center'}>
<i className={'ml-1 mr-1 h-[16px] w-[16px]'}> <i className={'ml-1 mr-1 h-[16px] w-[16px]'}>
{page.pageType === ViewLayoutTypePB.Document && <DocumentSvg></DocumentSvg>} {page.pageType === ViewLayoutPB.Document && <DocumentSvg></DocumentSvg>}
{page.pageType === ViewLayoutTypePB.Board && <BoardSvg></BoardSvg>} {page.pageType === ViewLayoutPB.Board && <BoardSvg></BoardSvg>}
{page.pageType === ViewLayoutTypePB.Grid && <GridSvg></GridSvg>} {page.pageType === ViewLayoutPB.Grid && <GridSvg></GridSvg>}
</i> </i>
<span className={'ml-2 min-w-0 flex-1 overflow-hidden overflow-ellipsis whitespace-nowrap text-left'}> <span className={'ml-2 min-w-0 flex-1 overflow-hidden overflow-ellipsis whitespace-nowrap text-left'}>
{page.title} {page.title}

View File

@ -1,7 +1,7 @@
import { import {
FieldType, FieldType,
SingleSelectTypeOptionPB, SingleSelectTypeOptionPB,
ViewLayoutTypePB, ViewLayoutPB,
ViewPB, ViewPB,
WorkspaceSettingPB, WorkspaceSettingPB,
} from '../../../services/backend'; } from '../../../services/backend';
@ -29,7 +29,7 @@ import { SelectOptionBackendService } from '../../stores/effects/database/cell/s
// Create a database view for specific layout type // Create a database view for specific layout type
// Do not use it production code. Just for testing // Do not use it production code. Just for testing
export async function createTestDatabaseView(layout: ViewLayoutTypePB): Promise<ViewPB> { export async function createTestDatabaseView(layout: ViewLayoutPB): Promise<ViewPB> {
const workspaceSetting: WorkspaceSettingPB = await FolderEventReadCurrentWorkspace().then((result) => result.unwrap()); const workspaceSetting: WorkspaceSettingPB = await FolderEventReadCurrentWorkspace().then((result) => result.unwrap());
const app = workspaceSetting.workspace.views[0]; const app = workspaceSetting.workspace.views[0];
const appService = new AppBackendService(app.id); const appService = new AppBackendService(app.id);

View File

@ -1,4 +1,4 @@
import { ViewLayoutTypePB, WorkspaceSettingPB } from '@/services/backend'; import { ViewLayoutPB, WorkspaceSettingPB } from '@/services/backend';
import { FolderEventReadCurrentWorkspace } from '@/services/backend/events/flowy-folder2'; import { FolderEventReadCurrentWorkspace } from '@/services/backend/events/flowy-folder2';
import { AppBackendService } from '$app/stores/effects/folder/app/app_bd_svc'; import { AppBackendService } from '$app/stores/effects/folder/app/app_bd_svc';
@ -6,5 +6,5 @@ export async function createTestDocument() {
const workspaceSetting: WorkspaceSettingPB = await FolderEventReadCurrentWorkspace().then((result) => result.unwrap()); const workspaceSetting: WorkspaceSettingPB = await FolderEventReadCurrentWorkspace().then((result) => result.unwrap());
const app = workspaceSetting.workspace.views[0]; const app = workspaceSetting.workspace.views[0];
const appService = new AppBackendService(app.id); const appService = new AppBackendService(app.id);
return await appService.createView({ name: 'New Document', layoutType: ViewLayoutTypePB.Document }); return await appService.createView({ name: 'New Document', layoutType: ViewLayoutPB.Document });
} }

View File

@ -1,11 +1,5 @@
import React from 'react'; import React from 'react';
import { import { FieldType, NumberFormat, NumberTypeOptionPB, SelectOptionCellDataPB, ViewLayoutPB } from '@/services/backend';
FieldType,
NumberFormat,
NumberTypeOptionPB,
SelectOptionCellDataPB,
ViewLayoutTypePB,
} from '@/services/backend';
import { Log } from '$app/utils/log'; import { Log } from '$app/utils/log';
import { import {
assert, assert,
@ -60,7 +54,7 @@ export const RunAllGridTests = () => {
}; };
async function createBuildInGrid() { async function createBuildInGrid() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
databaseController.subscribe({ databaseController.subscribe({
onViewChanged: (databasePB) => { onViewChanged: (databasePB) => {
@ -82,7 +76,7 @@ async function createBuildInGrid() {
} }
async function testEditGridCell() { async function testEditGridCell() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -95,7 +89,7 @@ async function testEditGridCell() {
} }
async function testEditTextCell() { async function testEditTextCell() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -117,7 +111,7 @@ async function testEditTextCell() {
} }
async function testEditURLCell() { async function testEditURLCell() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -144,7 +138,7 @@ async function testEditURLCell() {
} }
async function testEditDateCell() { async function testEditDateCell() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -169,7 +163,7 @@ async function testEditDateCell() {
} }
async function testCheckboxCell() { async function testCheckboxCell() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -195,7 +189,7 @@ async function testCheckboxCell() {
} }
async function testCreateRow() { async function testCreateRow() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
await assertNumberOfRows(view.id, 3); await assertNumberOfRows(view.id, 3);
@ -207,7 +201,7 @@ async function testCreateRow() {
} }
async function testDeleteRow() { async function testDeleteRow() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -226,7 +220,7 @@ async function testDeleteRow() {
} }
async function testCreateOptionInCell() { async function testCreateOptionInCell() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
for (const [index, row] of databaseController.databaseViewCache.rowInfos.entries()) { for (const [index, row] of databaseController.databaseViewCache.rowInfos.entries()) {
@ -253,7 +247,7 @@ async function testCreateOptionInCell() {
} }
async function testMoveField() { async function testMoveField() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -271,7 +265,7 @@ async function testMoveField() {
} }
async function testGetSingleSelectFieldData() { async function testGetSingleSelectFieldData() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -296,7 +290,7 @@ async function testGetSingleSelectFieldData() {
} }
async function testSwitchFromSingleSelectToNumber() { async function testSwitchFromSingleSelectToNumber() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -322,7 +316,7 @@ async function testSwitchFromSingleSelectToNumber() {
} }
async function testSwitchFromMultiSelectToRichText() { async function testSwitchFromMultiSelectToRichText() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -372,7 +366,7 @@ async function testSwitchFromMultiSelectToRichText() {
} }
async function testEditField() { async function testEditField() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
const fieldInfos = databaseController.fieldController.fieldInfos; const fieldInfos = databaseController.fieldController.fieldInfos;
@ -390,7 +384,7 @@ async function testEditField() {
} }
async function testCreateNewField() { async function testCreateNewField() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
await assertNumberOfFields(view.id, 3); await assertNumberOfFields(view.id, 3);
@ -403,7 +397,7 @@ async function testCreateNewField() {
} }
async function testDeleteField() { async function testDeleteField() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid); const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());

View File

@ -5,7 +5,7 @@ import {
createTestDatabaseView, createTestDatabaseView,
openTestDatabase, openTestDatabase,
} from './DatabaseTestHelper'; } from './DatabaseTestHelper';
import { FieldType, ViewLayoutTypePB } from '../../../services/backend'; import { FieldType, ViewLayoutPB } from '../../../services/backend';
import React from 'react'; import React from 'react';
export const TestAllKanbanTests = () => { export const TestAllKanbanTests = () => {
@ -29,7 +29,7 @@ export const TestAllKanbanTests = () => {
}; };
async function createBuildInBoard() { async function createBuildInBoard() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Board); const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
databaseController.subscribe({ databaseController.subscribe({
onGroupByField: (groups) => { onGroupByField: (groups) => {
@ -49,7 +49,7 @@ async function createBuildInBoard() {
} }
async function createKanbanBoardRow() { async function createKanbanBoardRow() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Board); const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -62,7 +62,7 @@ async function createKanbanBoardRow() {
} }
async function moveKanbanBoardRow() { async function moveKanbanBoardRow() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Board); const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -113,7 +113,7 @@ async function moveKanbanBoardRow() {
} }
async function createKanbanBoardColumn() { async function createKanbanBoardColumn() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Board); const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());
@ -128,7 +128,7 @@ async function createKanbanBoardColumn() {
} }
async function createColumnInBoard() { async function createColumnInBoard() {
const view = await createTestDatabaseView(ViewLayoutTypePB.Board); const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id); const databaseController = await openTestDatabase(view.id);
await databaseController.open().then((result) => result.unwrap()); await databaseController.open().then((result) => result.unwrap());

View File

@ -4,7 +4,7 @@ import {
FolderEventMoveItem, FolderEventMoveItem,
FolderEventReadView, FolderEventReadView,
FolderEventUpdateView, FolderEventUpdateView,
ViewLayoutTypePB, ViewLayoutPB,
} from '@/services/backend/events/flowy-folder2'; } from '@/services/backend/events/flowy-folder2';
import { import {
CreateViewPayloadPB, CreateViewPayloadPB,
@ -29,7 +29,7 @@ export class AppBackendService {
createView = async (params: { createView = async (params: {
name: string; name: string;
desc?: string; desc?: string;
layoutType: ViewLayoutTypePB; layoutType: ViewLayoutPB;
/// The initial data should be the JSON of the document /// The initial data should be the JSON of the document
/// For example: {"document":{"type":"editor","children":[]}} /// For example: {"document":{"type":"editor","children":[]}}
initialData?: string; initialData?: string;

View File

@ -1,5 +1,5 @@
import { Ok, Result } from 'ts-results'; import { Ok, Result } from 'ts-results';
import { AppPB, FlowyError, FolderNotification, RepeatedViewPB } from '@/services/backend'; import { FlowyError, FolderNotification, RepeatedViewPB } from '@/services/backend';
import { ChangeNotifier } from '$app/utils/change_notifier'; import { ChangeNotifier } from '$app/utils/change_notifier';
import { FolderNotificationObserver } from '../notifications/observer'; import { FolderNotificationObserver } from '../notifications/observer';

View File

@ -9,7 +9,7 @@ import {
CreateViewPayloadPB, CreateViewPayloadPB,
FlowyError, FlowyError,
MoveFolderItemPayloadPB, MoveFolderItemPayloadPB,
ViewLayoutTypePB, ViewLayoutPB,
WorkspaceIdPB, WorkspaceIdPB,
} from '@/services/backend'; } from '@/services/backend';
import assert from 'assert'; import assert from 'assert';
@ -22,7 +22,7 @@ export class WorkspaceBackendService {
belong_to_id: this.workspaceId, belong_to_id: this.workspaceId,
name: params.name, name: params.name,
desc: params.desc || '', desc: params.desc || '',
layout: ViewLayoutTypePB.Document, layout: ViewLayoutPB.Document,
}); });
const result = await FolderEventCreateView(payload); const result = await FolderEventCreateView(payload);

View File

@ -1,13 +1,5 @@
import { Ok, Result } from 'ts-results'; import { Ok, Result } from 'ts-results';
import { import { FolderNotification, WorkspacePB, FlowyError, RepeatedViewPB, ViewPB } from '@/services/backend';
AppPB,
FolderNotification,
RepeatedAppPB,
WorkspacePB,
FlowyError,
RepeatedViewPB,
ViewPB,
} from '@/services/backend';
import { ChangeNotifier } from '$app/utils/change_notifier'; import { ChangeNotifier } from '$app/utils/change_notifier';
import { FolderNotificationObserver } from '../notifications/observer'; import { FolderNotificationObserver } from '../notifications/observer';

View File

@ -1,10 +1,10 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { ViewLayoutTypePB } from '@/services/backend'; import { ViewLayoutPB } from '@/services/backend';
export interface IPage { export interface IPage {
id: string; id: string;
title: string; title: string;
pageType: ViewLayoutTypePB; pageType: ViewLayoutPB;
folderId: string; folderId: string;
} }

View File

@ -13,3 +13,4 @@ bin/
**/src/protobuf **/src/protobuf
**/resources/proto **/resources/proto
.idea/ .idea/
AppFlowy-Collab/

View File

@ -491,7 +491,7 @@ dependencies = [
[[package]] [[package]]
name = "collab" name = "collab"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#306f27e56481eb2a998da4cb9f13763699dade76"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -509,7 +509,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-derive" name = "collab-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#306f27e56481eb2a998da4cb9f13763699dade76"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -521,7 +521,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-folder" name = "collab-folder"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#306f27e56481eb2a998da4cb9f13763699dade76"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"collab", "collab",
@ -539,7 +539,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-persistence" name = "collab-persistence"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f25ce7f#f25ce7f71ef3f0a2a35260ebdf74d75534bfad45" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab#306f27e56481eb2a998da4cb9f13763699dade76"
dependencies = [ dependencies = [
"bincode", "bincode",
"chrono", "chrono",

View File

@ -8,7 +8,7 @@ members = [
"flowy-user", "flowy-user",
"flowy-test", "flowy-test",
"flowy-sqlite", "flowy-sqlite",
# "flowy-folder", # "flowy-folder",r
"flowy-folder2", "flowy-folder2",
"flowy-notification", "flowy-notification",
"flowy-document", "flowy-document",
@ -37,8 +37,10 @@ opt-level = 3
## the amount of IO and the size of ./target, which make caching less effective. ## the amount of IO and the size of ./target, which make caching less effective.
incremental = false incremental = false
[patch.crates-io] [patch.crates-io]
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f25ce7f" } collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f25ce7f" } collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab" }
collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f25ce7f" } collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab" }
#collab = { path = "../AppFlowy-Collab/collab" }
#collab-folder = { path = "../AppFlowy-Collab/collab-folder" }
#collab-persistence = { path = "../AppFlowy-Collab/collab-persistence" }

View File

@ -46,7 +46,7 @@ use_bunyan = ["lib-log/use_bunyan"]
dart = [ dart = [
"flowy-user/dart", "flowy-user/dart",
"flowy-net/dart", "flowy-net/dart",
"flowy-folder/dart", # "flowy-folder/dart",
"flowy-folder2/dart", "flowy-folder2/dart",
"flowy-database/dart", "flowy-database/dart",
"flowy-document/dart", "flowy-document/dart",
@ -54,7 +54,7 @@ dart = [
ts = [ ts = [
"flowy-user/ts", "flowy-user/ts",
"flowy-net/ts", "flowy-net/ts",
"flowy-folder/ts", # "flowy-folder/ts",
"flowy-folder2/ts", "flowy-folder2/ts",
"flowy-database/ts", "flowy-database/ts",
"flowy-document/ts", "flowy-document/ts",

View File

@ -1,13 +1,14 @@
use bytes::Bytes; use bytes::Bytes;
use collab_persistence::CollabKV; use collab_persistence::CollabKV;
use database_model::BuildDatabaseContext; use database_model::BuildDatabaseContext;
use flowy_database::entities::LayoutTypePB; use flowy_database::entities::DatabaseLayoutPB;
use flowy_database::manager::{create_new_database, link_existing_database, DatabaseManager}; use flowy_database::manager::{create_new_database, link_existing_database, DatabaseManager};
use flowy_database::util::{make_default_board, make_default_calendar, make_default_grid}; use flowy_database::util::{make_default_board, make_default_calendar, make_default_grid};
use flowy_document::editor::make_transaction_from_document_content; use flowy_document::editor::make_transaction_from_document_content;
use flowy_document::DocumentManager; use flowy_document::DocumentManager;
use flowy_error::FlowyError; use flowy_error::FlowyError;
use flowy_folder2::entities::ViewLayoutPB;
use flowy_folder2::manager::{Folder2Manager, FolderUser}; use flowy_folder2::manager::{Folder2Manager, FolderUser};
use flowy_folder2::view_ext::{ViewDataProcessor, ViewDataProcessorMap}; use flowy_folder2::view_ext::{ViewDataProcessor, ViewDataProcessorMap};
use flowy_folder2::ViewLayout; use flowy_folder2::ViewLayout;
@ -183,9 +184,9 @@ impl ViewDataProcessor for DatabaseViewDataProcessor {
match DatabaseExtParams::from_map(ext).map(|params| params.database_id) { match DatabaseExtParams::from_map(ext).map(|params| params.database_id) {
None => { None => {
let (build_context, layout) = match layout { let (build_context, layout) = match layout {
ViewLayout::Grid => (make_default_grid(), LayoutTypePB::Grid), ViewLayout::Grid => (make_default_grid(), DatabaseLayoutPB::Grid),
ViewLayout::Board => (make_default_board(), LayoutTypePB::Board), ViewLayout::Board => (make_default_board(), DatabaseLayoutPB::Board),
ViewLayout::Calendar => (make_default_calendar(), LayoutTypePB::Calendar), ViewLayout::Calendar => (make_default_calendar(), DatabaseLayoutPB::Calendar),
ViewLayout::Document => { ViewLayout::Document => {
return FutureResult::new(async move { return FutureResult::new(async move {
Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout))) Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
@ -197,7 +198,7 @@ impl ViewDataProcessor for DatabaseViewDataProcessor {
}) })
}, },
Some(database_id) => { Some(database_id) => {
let layout = layout_type_from_view_layout(layout); let layout = layout_type_from_view_layout(layout.into());
FutureResult::new(async move { FutureResult::new(async move {
link_existing_database(&view_id, name, &database_id, layout, database_manager).await link_existing_database(&view_id, name, &database_id, layout, database_manager).await
}) })
@ -220,7 +221,7 @@ impl ViewDataProcessor for DatabaseViewDataProcessor {
) -> FutureResult<(), FlowyError> { ) -> FutureResult<(), FlowyError> {
let view_id = view_id.to_string(); let view_id = view_id.to_string();
let database_manager = self.0.clone(); let database_manager = self.0.clone();
let layout = layout_type_from_view_layout(layout); let layout = layout_type_from_view_layout(layout.into());
let name = name.to_string(); let name = name.to_string();
match DatabaseExtParams::from_map(ext).map(|params| params.database_id) { match DatabaseExtParams::from_map(ext).map(|params| params.database_id) {
None => FutureResult::new(async move { None => FutureResult::new(async move {
@ -248,11 +249,11 @@ impl DatabaseExtParams {
} }
} }
pub fn layout_type_from_view_layout(layout: ViewLayout) -> LayoutTypePB { pub fn layout_type_from_view_layout(layout: ViewLayoutPB) -> DatabaseLayoutPB {
match layout { match layout {
ViewLayout::Grid => LayoutTypePB::Grid, ViewLayoutPB::Grid => DatabaseLayoutPB::Grid,
ViewLayout::Board => LayoutTypePB::Board, ViewLayoutPB::Board => DatabaseLayoutPB::Board,
ViewLayout::Calendar => LayoutTypePB::Calendar, ViewLayoutPB::Calendar => DatabaseLayoutPB::Calendar,
ViewLayout::Document => LayoutTypePB::Grid, ViewLayoutPB::Document => DatabaseLayoutPB::Grid,
} }
} }

View File

@ -3,7 +3,7 @@ pub mod module;
use crate::deps_resolve::*; use crate::deps_resolve::*;
use flowy_client_ws::{listen_on_websocket, FlowyWebSocketConnect, NetworkType}; use flowy_client_ws::{listen_on_websocket, FlowyWebSocketConnect, NetworkType};
use flowy_database::entities::LayoutTypePB; use flowy_database::entities::DatabaseLayoutPB;
use flowy_database::manager::DatabaseManager; use flowy_database::manager::DatabaseManager;
use flowy_document::entities::DocumentVersionPB; use flowy_document::entities::DocumentVersionPB;
use flowy_document::{DocumentConfig, DocumentManager}; use flowy_document::{DocumentConfig, DocumentManager};
@ -320,7 +320,7 @@ impl UserStatusListener {
layout_type_from_view_layout(view.layout), layout_type_from_view_layout(view.layout),
) )
}) })
.collect::<Vec<(String, String, LayoutTypePB)>>() .collect::<Vec<(String, String, DatabaseLayoutPB)>>()
}); });
self self
.database_manager .database_manager

View File

@ -1,5 +1,5 @@
use crate::entities::parser::NotEmptyStr; use crate::entities::parser::NotEmptyStr;
use crate::entities::{FieldIdPB, LayoutTypePB, RowPB}; use crate::entities::{DatabaseLayoutPB, FieldIdPB, RowPB};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode; use flowy_error::ErrorCode;
@ -201,5 +201,5 @@ pub struct DatabaseLayoutIdPB {
pub view_id: String, pub view_id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub layout: LayoutTypePB, pub layout: DatabaseLayoutPB,
} }

View File

@ -15,7 +15,7 @@ use strum_macros::EnumIter;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct DatabaseViewSettingPB { pub struct DatabaseViewSettingPB {
#[pb(index = 1)] #[pb(index = 1)]
pub current_layout: LayoutTypePB, pub current_layout: DatabaseLayoutPB,
#[pb(index = 2)] #[pb(index = 2)]
pub layout_setting: LayoutSettingPB, pub layout_setting: LayoutSettingPB,
@ -32,34 +32,34 @@ pub struct DatabaseViewSettingPB {
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)] #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
#[repr(u8)] #[repr(u8)]
pub enum LayoutTypePB { pub enum DatabaseLayoutPB {
Grid = 0, Grid = 0,
Board = 1, Board = 1,
Calendar = 2, Calendar = 2,
} }
impl std::default::Default for LayoutTypePB { impl std::default::Default for DatabaseLayoutPB {
fn default() -> Self { fn default() -> Self {
LayoutTypePB::Grid DatabaseLayoutPB::Grid
} }
} }
impl std::convert::From<LayoutRevision> for LayoutTypePB { impl std::convert::From<LayoutRevision> for DatabaseLayoutPB {
fn from(rev: LayoutRevision) -> Self { fn from(rev: LayoutRevision) -> Self {
match rev { match rev {
LayoutRevision::Grid => LayoutTypePB::Grid, LayoutRevision::Grid => DatabaseLayoutPB::Grid,
LayoutRevision::Board => LayoutTypePB::Board, LayoutRevision::Board => DatabaseLayoutPB::Board,
LayoutRevision::Calendar => LayoutTypePB::Calendar, LayoutRevision::Calendar => DatabaseLayoutPB::Calendar,
} }
} }
} }
impl std::convert::From<LayoutTypePB> for LayoutRevision { impl std::convert::From<DatabaseLayoutPB> for LayoutRevision {
fn from(layout: LayoutTypePB) -> Self { fn from(layout: DatabaseLayoutPB) -> Self {
match layout { match layout {
LayoutTypePB::Grid => LayoutRevision::Grid, DatabaseLayoutPB::Grid => LayoutRevision::Grid,
LayoutTypePB::Board => LayoutRevision::Board, DatabaseLayoutPB::Board => LayoutRevision::Board,
LayoutTypePB::Calendar => LayoutRevision::Calendar, DatabaseLayoutPB::Calendar => LayoutRevision::Calendar,
} }
} }
} }
@ -70,7 +70,7 @@ pub struct DatabaseSettingChangesetPB {
pub view_id: String, pub view_id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub layout_type: LayoutTypePB, pub layout_type: DatabaseLayoutPB,
#[pb(index = 3, one_of)] #[pb(index = 3, one_of)]
pub alter_filter: Option<AlterFilterPayloadPB>, pub alter_filter: Option<AlterFilterPayloadPB>,

View File

@ -1,4 +1,4 @@
use crate::entities::LayoutTypePB; use crate::entities::DatabaseLayoutPB;
use crate::services::database::{ use crate::services::database::{
make_database_block_rev_manager, DatabaseEditor, DatabaseRefIndexerQuery, make_database_block_rev_manager, DatabaseEditor, DatabaseRefIndexerQuery,
DatabaseRevisionCloudService, DatabaseRevisionMergeable, DatabaseRevisionSerde, DatabaseRevisionCloudService, DatabaseRevisionMergeable, DatabaseRevisionSerde,
@ -83,7 +83,7 @@ impl DatabaseManager {
&self, &self,
user_id: i64, user_id: i64,
_token: &str, _token: &str,
get_views_fn: Fut<Vec<(String, String, LayoutTypePB)>>, get_views_fn: Fut<Vec<(String, String, DatabaseLayoutPB)>>,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
self.migration.run(user_id, get_views_fn).await?; self.migration.run(user_id, get_views_fn).await?;
Ok(()) Ok(())
@ -327,7 +327,7 @@ pub async fn link_existing_database(
view_id: &str, view_id: &str,
name: String, name: String,
database_id: &str, database_id: &str,
layout: LayoutTypePB, layout: DatabaseLayoutPB,
database_manager: Arc<DatabaseManager>, database_manager: Arc<DatabaseManager>,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
tracing::trace!( tracing::trace!(
@ -358,7 +358,7 @@ pub async fn link_existing_database(
pub async fn create_new_database( pub async fn create_new_database(
view_id: &str, view_id: &str,
name: String, name: String,
layout: LayoutTypePB, layout: DatabaseLayoutPB,
database_manager: Arc<DatabaseManager>, database_manager: Arc<DatabaseManager>,
build_context: BuildDatabaseContext, build_context: BuildDatabaseContext,
) -> FlowyResult<()> { ) -> FlowyResult<()> {

View File

@ -1,6 +1,6 @@
mod database_migration; mod database_migration;
mod database_view_migration; mod database_view_migration;
use crate::entities::LayoutTypePB; use crate::entities::DatabaseLayoutPB;
use crate::manager::DatabaseUser; use crate::manager::DatabaseUser;
use crate::services::persistence::database_ref::DatabaseRefs; use crate::services::persistence::database_ref::DatabaseRefs;
use crate::services::persistence::migration::database_migration::{ use crate::services::persistence::migration::database_migration::{
@ -31,7 +31,7 @@ impl DatabaseMigration {
pub async fn run( pub async fn run(
&self, &self,
user_id: i64, user_id: i64,
get_views_fn: Fut<Vec<(String, String, LayoutTypePB)>>, get_views_fn: Fut<Vec<(String, String, DatabaseLayoutPB)>>,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
let pool = self.user.db_pool()?; let pool = self.user.db_pool()?;

View File

@ -1,5 +1,5 @@
use crate::entities::{ use crate::entities::{
AlterFilterParams, DatabaseSettingChangesetParams, DeleteFilterParams, LayoutTypePB, AlterFilterParams, DatabaseLayoutPB, DatabaseSettingChangesetParams, DeleteFilterParams,
}; };
pub struct GridSettingChangesetBuilder { pub struct GridSettingChangesetBuilder {
@ -7,7 +7,7 @@ pub struct GridSettingChangesetBuilder {
} }
impl GridSettingChangesetBuilder { impl GridSettingChangesetBuilder {
pub fn new(grid_id: &str, layout_type: &LayoutTypePB) -> Self { pub fn new(grid_id: &str, layout_type: &DatabaseLayoutPB) -> Self {
let params = DatabaseSettingChangesetParams { let params = DatabaseSettingChangesetParams {
view_id: grid_id.to_string(), view_id: grid_id.to_string(),
layout_type: layout_type.clone().into(), layout_type: layout_type.clone().into(),

View File

@ -26,32 +26,32 @@ pub struct DatabaseEditorTest {
impl DatabaseEditorTest { impl DatabaseEditorTest {
pub async fn new_grid() -> Self { pub async fn new_grid() -> Self {
Self::new(LayoutTypePB::Grid).await Self::new(DatabaseLayoutPB::Grid).await
} }
pub async fn new_board() -> Self { pub async fn new_board() -> Self {
Self::new(LayoutTypePB::Board).await Self::new(DatabaseLayoutPB::Board).await
} }
pub async fn new_calendar() -> Self { pub async fn new_calendar() -> Self {
Self::new(LayoutTypePB::Calendar).await Self::new(DatabaseLayoutPB::Calendar).await
} }
pub async fn new(layout: LayoutTypePB) -> Self { pub async fn new(layout: DatabaseLayoutPB) -> Self {
let sdk = FlowySDKTest::default(); let sdk = FlowySDKTest::default();
let _ = sdk.init_user().await; let _ = sdk.init_user().await;
let test = match layout { let test = match layout {
LayoutTypePB::Grid => { DatabaseLayoutPB::Grid => {
let build_context = make_test_grid(); let build_context = make_test_grid();
let view_data: Bytes = build_context.into(); let view_data: Bytes = build_context.into();
ViewTest::new_grid_view(&sdk, view_data.to_vec()).await ViewTest::new_grid_view(&sdk, view_data.to_vec()).await
}, },
LayoutTypePB::Board => { DatabaseLayoutPB::Board => {
let build_context = make_test_board(); let build_context = make_test_board();
let view_data: Bytes = build_context.into(); let view_data: Bytes = build_context.into();
ViewTest::new_board_view(&sdk, view_data.to_vec()).await ViewTest::new_board_view(&sdk, view_data.to_vec()).await
}, },
LayoutTypePB::Calendar => { DatabaseLayoutPB::Calendar => {
let build_context = make_test_calendar(); let build_context = make_test_calendar();
let view_data: Bytes = build_context.into(); let view_data: Bytes = build_context.into();
ViewTest::new_calendar_view(&sdk, view_data.to_vec()).await ViewTest::new_calendar_view(&sdk, view_data.to_vec()).await

View File

@ -7,7 +7,7 @@ use std::time::Duration;
use bytes::Bytes; use bytes::Bytes;
use futures::TryFutureExt; use futures::TryFutureExt;
use tokio::sync::broadcast::Receiver; use tokio::sync::broadcast::Receiver;
use flowy_database::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, LayoutTypePB, DatabaseSettingChangesetParams, DatabaseViewSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB}; use flowy_database::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, DatabaseLayoutPB, DatabaseSettingChangesetParams, DatabaseViewSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB};
use flowy_database::services::field::{SelectOptionCellChangeset, SelectOptionIds}; use flowy_database::services::field::{SelectOptionCellChangeset, SelectOptionIds};
use flowy_database::services::setting::GridSettingChangesetBuilder; use flowy_database::services::setting::GridSettingChangesetBuilder;
use database_model::{FieldRevision, FieldTypeRevision}; use database_model::{FieldRevision, FieldTypeRevision};

View File

@ -1,183 +0,0 @@
use crate::entities::parser::app::{AppColorStyle, AppIdentify, AppName};
use crate::entities::parser::workspace::WorkspaceIdentify;
use crate::entities::RepeatedViewPB;
use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode;
use std::convert::TryInto;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct AppPB {
#[pb(index = 1)]
pub id: String,
#[pb(index = 2)]
pub workspace_id: String,
#[pb(index = 3)]
pub name: String,
#[pb(index = 4)]
pub belongings: RepeatedViewPB,
#[pb(index = 5)]
pub create_time: i64,
}
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
pub struct RepeatedAppPB {
#[pb(index = 1)]
pub items: Vec<AppPB>,
}
#[derive(ProtoBuf, Default)]
pub struct CreateAppPayloadPB {
#[pb(index = 1)]
pub workspace_id: String,
#[pb(index = 2)]
pub name: String,
#[pb(index = 3)]
pub desc: String,
#[pb(index = 4)]
pub color_style: ColorStylePB,
}
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct ColorStylePB {
#[pb(index = 1)]
pub theme_color: String,
}
#[derive(Debug)]
pub struct CreateAppParams {
pub workspace_id: String,
pub name: String,
pub desc: String,
pub color_style: ColorStylePB,
}
impl TryInto<CreateAppParams> for CreateAppPayloadPB {
type Error = ErrorCode;
fn try_into(self) -> Result<CreateAppParams, Self::Error> {
let name = AppName::parse(self.name)?;
let id = WorkspaceIdentify::parse(self.workspace_id)?;
let color_style = AppColorStyle::parse(self.color_style.theme_color.clone())?;
Ok(CreateAppParams {
workspace_id: id.0,
name: name.0,
desc: self.desc,
color_style: color_style.into(),
})
}
}
impl std::convert::From<AppColorStyle> for ColorStylePB {
fn from(data: AppColorStyle) -> Self {
ColorStylePB {
theme_color: data.theme_color,
}
}
}
#[derive(ProtoBuf, Default, Clone, Debug)]
pub struct AppIdPB {
#[pb(index = 1)]
pub value: String,
}
impl AppIdPB {
pub fn new(app_id: &str) -> Self {
Self {
value: app_id.to_string(),
}
}
}
#[derive(ProtoBuf, Default)]
pub struct UpdateAppPayloadPB {
#[pb(index = 1)]
pub app_id: String,
#[pb(index = 2, one_of)]
pub name: Option<String>,
#[pb(index = 3, one_of)]
pub desc: Option<String>,
#[pb(index = 4, one_of)]
pub color_style: Option<ColorStylePB>,
#[pb(index = 5, one_of)]
pub is_trash: Option<bool>,
}
#[derive(Debug, Clone)]
pub struct UpdateAppParams {
pub app_id: String,
pub name: Option<String>,
pub desc: Option<String>,
pub color_style: Option<ColorStylePB>,
pub is_trash: Option<bool>,
}
impl UpdateAppParams {
pub fn new(app_id: &str) -> Self {
Self {
app_id: app_id.to_string(),
name: None,
desc: None,
color_style: None,
is_trash: None,
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn desc(mut self, desc: &str) -> Self {
self.desc = Some(desc.to_string());
self
}
pub fn trash(mut self) -> Self {
self.is_trash = Some(true);
self
}
}
impl TryInto<UpdateAppParams> for UpdateAppPayloadPB {
type Error = ErrorCode;
fn try_into(self) -> Result<UpdateAppParams, Self::Error> {
let app_id = AppIdentify::parse(self.app_id)?.0;
let name = match self.name {
None => None,
Some(name) => Some(AppName::parse(name)?.0),
};
let color_style = match self.color_style {
None => None,
Some(color_style) => Some(AppColorStyle::parse(color_style.theme_color)?.into()),
};
Ok(UpdateAppParams {
app_id,
name,
desc: self.desc,
color_style,
is_trash: self.is_trash,
})
}
}

View File

@ -1,10 +1,8 @@
pub mod app;
mod parser; mod parser;
pub mod trash; pub mod trash;
pub mod view; pub mod view;
pub mod workspace; pub mod workspace;
pub use app::*;
pub use trash::*; pub use trash::*;
pub use view::*; pub use view::*;
pub use workspace::*; pub use workspace::*;

View File

@ -1,13 +0,0 @@
use flowy_error::ErrorCode;
#[derive(Debug)]
pub struct AppColorStyle {
pub theme_color: String,
}
impl AppColorStyle {
pub fn parse(theme_color: String) -> Result<AppColorStyle, ErrorCode> {
// TODO: verify the color style format
Ok(AppColorStyle { theme_color })
}
}

View File

@ -1,20 +0,0 @@
use unicode_segmentation::UnicodeSegmentation;
#[derive(Debug)]
pub struct AppDesc(pub String);
impl AppDesc {
#[allow(dead_code)]
pub fn parse(s: String) -> Result<AppDesc, String> {
if s.graphemes(true).count() > 1024 {
return Err("Workspace description too long".to_string());
}
Ok(Self(s))
}
}
impl AsRef<str> for AppDesc {
fn as_ref(&self) -> &str {
&self.0
}
}

View File

@ -1,20 +0,0 @@
use flowy_error::ErrorCode;
#[derive(Debug)]
pub struct AppIdentify(pub String);
impl AppIdentify {
pub fn parse(s: String) -> Result<AppIdentify, ErrorCode> {
if s.trim().is_empty() {
return Err(ErrorCode::AppIdInvalid);
}
Ok(Self(s))
}
}
impl AsRef<str> for AppIdentify {
fn as_ref(&self) -> &str {
&self.0
}
}

View File

@ -1,20 +0,0 @@
use flowy_error::ErrorCode;
#[derive(Debug)]
pub struct AppName(pub String);
impl AppName {
pub fn parse(s: String) -> Result<AppName, ErrorCode> {
if s.trim().is_empty() {
return Err(ErrorCode::AppNameInvalid);
}
Ok(Self(s))
}
}
impl AsRef<str> for AppName {
fn as_ref(&self) -> &str {
&self.0
}
}

View File

@ -1,9 +0,0 @@
mod app_color_style;
mod app_desc;
mod app_id;
mod app_name;
pub use app_color_style::*;
pub use app_desc::*;
pub use app_id::*;
pub use app_name::*;

View File

@ -1,4 +1,4 @@
pub mod app; // pub mod app;
pub mod trash; pub mod trash;
pub mod view; pub mod view;
pub mod workspace; pub mod workspace;

View File

@ -1,7 +1,4 @@
use crate::entities::parser::{ use crate::entities::parser::view::{ViewDesc, ViewIdentify, ViewName, ViewThumbnail};
app::AppIdentify,
view::{ViewDesc, ViewIdentify, ViewName, ViewThumbnail},
};
use crate::view_ext::gen_view_id; use crate::view_ext::gen_view_id;
use collab_folder::core::{View, ViewLayout}; use collab_folder::core::{View, ViewLayout};
use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
@ -16,7 +13,7 @@ pub struct ViewPB {
pub id: String, pub id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub app_id: String, pub parent_view_id: String,
#[pb(index = 3)] #[pb(index = 3)]
pub name: String, pub name: String,
@ -28,14 +25,14 @@ pub struct ViewPB {
pub belongings: Vec<ViewPB>, pub belongings: Vec<ViewPB>,
#[pb(index = 6)] #[pb(index = 6)]
pub layout: ViewLayoutTypePB, pub layout: ViewLayoutPB,
} }
impl std::convert::From<View> for ViewPB { impl std::convert::From<View> for ViewPB {
fn from(view: View) -> Self { fn from(view: View) -> Self {
ViewPB { ViewPB {
id: view.id, id: view.id,
app_id: view.bid, parent_view_id: view.bid,
name: view.name, name: view.name,
create_time: view.created_at, create_time: view.created_at,
belongings: Default::default(), belongings: Default::default(),
@ -45,26 +42,35 @@ impl std::convert::From<View> for ViewPB {
} }
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)] #[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
pub enum ViewLayoutTypePB { pub enum ViewLayoutPB {
Document = 0, Document = 0,
Grid = 3, Grid = 3,
Board = 4, Board = 4,
Calendar = 5, Calendar = 5,
} }
impl std::default::Default for ViewLayoutTypePB { impl std::default::Default for ViewLayoutPB {
fn default() -> Self { fn default() -> Self {
ViewLayoutTypePB::Grid ViewLayoutPB::Grid
} }
} }
impl std::convert::From<ViewLayout> for ViewLayoutTypePB { impl ViewLayoutPB {
pub fn is_database(&self) -> bool {
matches!(
self,
ViewLayoutPB::Grid | ViewLayoutPB::Board | ViewLayoutPB::Calendar
)
}
}
impl std::convert::From<ViewLayout> for ViewLayoutPB {
fn from(rev: ViewLayout) -> Self { fn from(rev: ViewLayout) -> Self {
match rev { match rev {
ViewLayout::Grid => ViewLayoutTypePB::Grid, ViewLayout::Grid => ViewLayoutPB::Grid,
ViewLayout::Board => ViewLayoutTypePB::Board, ViewLayout::Board => ViewLayoutPB::Board,
ViewLayout::Document => ViewLayoutTypePB::Document, ViewLayout::Document => ViewLayoutPB::Document,
ViewLayout::Calendar => ViewLayoutTypePB::Calendar, ViewLayout::Calendar => ViewLayoutPB::Calendar,
} }
} }
} }
@ -75,12 +81,8 @@ pub struct RepeatedViewPB {
pub items: Vec<ViewPB>, pub items: Vec<ViewPB>,
} }
impl std::convert::From<Vec<View>> for RepeatedViewPB { impl std::convert::From<Vec<ViewPB>> for RepeatedViewPB {
fn from(views: Vec<View>) -> Self { fn from(items: Vec<ViewPB>) -> Self {
let items = views
.into_iter()
.map(|value| value.into())
.collect::<Vec<ViewPB>>();
RepeatedViewPB { items } RepeatedViewPB { items }
} }
} }
@ -120,7 +122,7 @@ pub struct CreateViewPayloadPB {
pub thumbnail: Option<String>, pub thumbnail: Option<String>,
#[pb(index = 5)] #[pb(index = 5)]
pub layout: ViewLayoutTypePB, pub layout: ViewLayoutPB,
#[pb(index = 6)] #[pb(index = 6)]
pub initial_data: Vec<u8>, pub initial_data: Vec<u8>,
@ -134,7 +136,7 @@ pub struct CreateViewParams {
pub belong_to_id: String, pub belong_to_id: String,
pub name: String, pub name: String,
pub desc: String, pub desc: String,
pub layout: ViewLayoutTypePB, pub layout: ViewLayoutPB,
pub view_id: String, pub view_id: String,
pub initial_data: Vec<u8>, pub initial_data: Vec<u8>,
pub ext: HashMap<String, String>, pub ext: HashMap<String, String>,
@ -145,7 +147,7 @@ impl TryInto<CreateViewParams> for CreateViewPayloadPB {
fn try_into(self) -> Result<CreateViewParams, Self::Error> { fn try_into(self) -> Result<CreateViewParams, Self::Error> {
let name = ViewName::parse(self.name)?.0; let name = ViewName::parse(self.name)?.0;
let belong_to_id = AppIdentify::parse(self.belong_to_id)?.0; let belong_to_id = ViewIdentify::parse(self.belong_to_id)?.0;
let view_id = gen_view_id(); let view_id = gen_view_id();
Ok(CreateViewParams { Ok(CreateViewParams {

View File

@ -22,6 +22,18 @@ pub struct WorkspacePB {
pub create_time: i64, pub create_time: i64,
} }
impl std::convert::From<(Workspace, Vec<ViewPB>)> for WorkspacePB {
fn from(params: (Workspace, Vec<ViewPB>)) -> Self {
let (workspace, views) = params;
WorkspacePB {
id: workspace.id,
name: workspace.name,
views,
create_time: workspace.created_at,
}
}
}
impl std::convert::From<Workspace> for WorkspacePB { impl std::convert::From<Workspace> for WorkspacePB {
fn from(workspace: Workspace) -> Self { fn from(workspace: Workspace) -> Self {
WorkspacePB { WorkspacePB {

View File

@ -39,7 +39,8 @@ pub(crate) async fn open_workspace_handler(
None => Err(FlowyError::workspace_id().context("workspace id should not be empty")), None => Err(FlowyError::workspace_id().context("workspace id should not be empty")),
Some(workspace_id) => { Some(workspace_id) => {
let workspace = folder.open_workspace(&workspace_id).await?; let workspace = folder.open_workspace(&workspace_id).await?;
let workspace_pb: WorkspacePB = workspace.into(); let views = folder.get_workspace_views(&workspace_id).await?;
let workspace_pb: WorkspacePB = (workspace, views).into();
data_result_ok(workspace_pb) data_result_ok(workspace_pb)
}, },
} }
@ -67,7 +68,9 @@ pub(crate) async fn read_workspaces_handler(
pub async fn read_cur_workspace_setting_handler( pub async fn read_cur_workspace_setting_handler(
folder: AFPluginState<Arc<Folder2Manager>>, folder: AFPluginState<Arc<Folder2Manager>>,
) -> DataResult<WorkspaceSettingPB, FlowyError> { ) -> DataResult<WorkspaceSettingPB, FlowyError> {
let workspace: WorkspacePB = folder.get_current_workspace().await?.into(); let workspace = folder.get_current_workspace().await?;
let views = folder.get_workspace_views(&workspace.id).await?;
let workspace: WorkspacePB = (workspace, views).into();
let latest_view: Option<ViewPB> = folder.get_current_view().await; let latest_view: Option<ViewPB> = folder.get_current_view().await;
data_result_ok(WorkspaceSettingPB { data_result_ok(WorkspaceSettingPB {
workspace, workspace,

View File

@ -63,41 +63,28 @@ impl Folder2Manager {
} }
} }
pub async fn get_current_workspace_views(&self) -> FlowyResult<Vec<View>> { pub async fn get_current_workspace_views(&self) -> FlowyResult<Vec<ViewPB>> {
let views = self.with_folder(vec![], |folder| { let workspace_id = self
let trash_ids = folder .folder
.trash .lock()
.get_all_trash() .as_ref()
.into_iter() .map(|folder| folder.get_current_workspace_id());
.map(|trash| trash.id)
.collect::<Vec<String>>();
let mut views = folder.get_views_belong_to_current_workspace(); if let Some(Some(workspace_id)) = workspace_id {
views.retain(|view| !trash_ids.contains(&view.id)); self.get_workspace_views(&workspace_id).await
views } else {
Ok(vec![])
}
}
pub async fn get_workspace_views(&self, workspace_id: &str) -> FlowyResult<Vec<ViewPB>> {
let views = self.with_folder(vec![], |folder| {
get_workspace_view_pbs(workspace_id, folder)
}); });
Ok(views) Ok(views)
} }
pub async fn get_workspace_views<F>(
&self,
workspace_id: &str,
filter: F,
) -> FlowyResult<Vec<View>>
where
F: Fn(&ViewLayout) -> bool,
{
Ok(self.with_folder(vec![], |folder| {
folder
.views
.get_views_belong_to(workspace_id)
.into_iter()
.filter(|view| filter(&view.layout))
.collect::<Vec<_>>()
}))
}
/// Called immediately after the application launched with the user sign in/sign up. /// Called immediately after the application launched with the user sign in/sign up.
#[tracing::instrument(level = "trace", skip(self), err)] #[tracing::instrument(level = "trace", skip(self), err)]
pub async fn initialize(&self, user_id: i64) -> FlowyResult<()> { pub async fn initialize(&self, user_id: i64) -> FlowyResult<()> {
@ -532,6 +519,34 @@ fn listen_on_trash_change(mut rx: TrashChangeReceiver, folder: Folder) {
}); });
} }
fn get_workspace_view_pbs(workspace_id: &str, folder: &InnerFolder) -> Vec<ViewPB> {
let trash_ids = folder
.trash
.get_all_trash()
.into_iter()
.map(|trash| trash.id)
.collect::<Vec<String>>();
let mut views = folder.get_workspace_views(workspace_id);
views.retain(|view| !trash_ids.contains(&view.id));
views
.into_iter()
.map(|view| {
let mut parent_view: ViewPB = view.into();
// Get child views
parent_view.belongings = folder
.views
.get_views_belong_to(&parent_view.id)
.into_iter()
.map(|view| view.into())
.collect();
parent_view
})
.collect()
}
#[tracing::instrument(level = "debug", skip(folder, parent_view_ids))] #[tracing::instrument(level = "debug", skip(folder, parent_view_ids))]
fn notify_parent_view_did_change<T: AsRef<str>>( fn notify_parent_view_did_change<T: AsRef<str>>(
folder: Folder, folder: Folder,
@ -553,9 +568,7 @@ fn notify_parent_view_did_change<T: AsRef<str>>(
// if the view's bid is equal to workspace id. Then it will fetch the current // if the view's bid is equal to workspace id. Then it will fetch the current
// workspace views. Because the the workspace is not a view stored in the views map. // workspace views. Because the the workspace is not a view stored in the views map.
if parent_view_id == workspace_id { if parent_view_id == workspace_id {
let mut child_views = folder.get_views_belong_to_current_workspace(); let repeated_view: RepeatedViewPB = get_workspace_view_pbs(&workspace_id, folder).into();
child_views.retain(|view| !trash_ids.contains(&view.id));
let repeated_view: RepeatedViewPB = child_views.into();
send_notification(&workspace_id, FolderNotification::DidUpdateWorkspaceViews) send_notification(&workspace_id, FolderNotification::DidUpdateWorkspaceViews)
.payload(repeated_view) .payload(repeated_view)
.send(); .send();

View File

@ -1,4 +1,4 @@
use crate::entities::{CreateViewParams, ViewLayoutTypePB}; use crate::entities::{CreateViewParams, ViewLayoutPB};
use crate::manager::Folder2Manager; use crate::manager::Folder2Manager;
use crate::view_ext::gen_view_id; use crate::view_ext::gen_view_id;
use std::collections::HashMap; use std::collections::HashMap;
@ -12,7 +12,7 @@ impl Folder2Manager {
ext: HashMap<String, String>, ext: HashMap<String, String>,
) -> String { ) -> String {
self self
.create_test_view(app_id, name, ViewLayoutTypePB::Grid, ext) .create_test_view(app_id, name, ViewLayoutPB::Grid, ext)
.await .await
} }
@ -23,7 +23,7 @@ impl Folder2Manager {
ext: HashMap<String, String>, ext: HashMap<String, String>,
) -> String { ) -> String {
self self
.create_test_view(app_id, name, ViewLayoutTypePB::Board, ext) .create_test_view(app_id, name, ViewLayoutPB::Board, ext)
.await .await
} }
@ -31,7 +31,7 @@ impl Folder2Manager {
&self, &self,
app_id: &str, app_id: &str,
name: &str, name: &str,
layout: ViewLayoutTypePB, layout: ViewLayoutPB,
ext: HashMap<String, String>, ext: HashMap<String, String>,
) -> String { ) -> String {
let view_id = gen_view_id(); let view_id = gen_view_id();

View File

@ -1,4 +1,4 @@
use crate::entities::{CreateViewParams, ViewLayoutTypePB}; use crate::entities::{CreateViewParams, ViewLayoutPB};
use bytes::Bytes; use bytes::Bytes;
use collab_folder::core::{View, ViewLayout}; use collab_folder::core::{View, ViewLayout};
use flowy_error::FlowyError; use flowy_error::FlowyError;
@ -43,13 +43,13 @@ pub trait ViewDataProcessor {
pub type ViewDataProcessorMap = Arc<HashMap<ViewLayout, Arc<dyn ViewDataProcessor + Send + Sync>>>; pub type ViewDataProcessorMap = Arc<HashMap<ViewLayout, Arc<dyn ViewDataProcessor + Send + Sync>>>;
impl From<ViewLayoutTypePB> for ViewLayout { impl From<ViewLayoutPB> for ViewLayout {
fn from(pb: ViewLayoutTypePB) -> Self { fn from(pb: ViewLayoutPB) -> Self {
match pb { match pb {
ViewLayoutTypePB::Document => ViewLayout::Document, ViewLayoutPB::Document => ViewLayout::Document,
ViewLayoutTypePB::Grid => ViewLayout::Grid, ViewLayoutPB::Grid => ViewLayout::Grid,
ViewLayoutTypePB::Board => ViewLayout::Board, ViewLayoutPB::Board => ViewLayout::Board,
ViewLayoutTypePB::Calendar => ViewLayout::Calendar, ViewLayoutPB::Calendar => ViewLayout::Calendar,
} }
} }
} }

View File

@ -1,7 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
use flowy_folder2::entities::{ use flowy_folder2::entities::{
CreateViewPayloadPB, CreateWorkspacePayloadPB, ViewLayoutTypePB, ViewPB, WorkspaceIdPB, CreateViewPayloadPB, CreateWorkspacePayloadPB, ViewLayoutPB, ViewPB, WorkspaceIdPB, WorkspacePB,
WorkspacePB,
}; };
use flowy_folder2::event_map::FolderEvent::{CreateView, CreateWorkspace, OpenWorkspace}; use flowy_folder2::event_map::FolderEvent::{CreateView, CreateWorkspace, OpenWorkspace};
use flowy_user::{ use flowy_user::{
@ -21,7 +20,7 @@ pub struct ViewTest {
impl ViewTest { impl ViewTest {
#[allow(dead_code)] #[allow(dead_code)]
pub async fn new(sdk: &FlowySDKTest, layout: ViewLayoutTypePB, data: Vec<u8>) -> Self { pub async fn new(sdk: &FlowySDKTest, layout: ViewLayoutPB, data: Vec<u8>) -> Self {
let workspace = create_workspace(sdk, "Workspace", "").await; let workspace = create_workspace(sdk, "Workspace", "").await;
open_workspace(sdk, &workspace.id).await; open_workspace(sdk, &workspace.id).await;
let app = create_app(sdk, "App", "AppFlowy GitHub Project", &workspace.id).await; let app = create_app(sdk, "App", "AppFlowy GitHub Project", &workspace.id).await;
@ -35,19 +34,19 @@ impl ViewTest {
} }
pub async fn new_grid_view(sdk: &FlowySDKTest, data: Vec<u8>) -> Self { pub async fn new_grid_view(sdk: &FlowySDKTest, data: Vec<u8>) -> Self {
Self::new(sdk, ViewLayoutTypePB::Grid, data).await Self::new(sdk, ViewLayoutPB::Grid, data).await
} }
pub async fn new_board_view(sdk: &FlowySDKTest, data: Vec<u8>) -> Self { pub async fn new_board_view(sdk: &FlowySDKTest, data: Vec<u8>) -> Self {
Self::new(sdk, ViewLayoutTypePB::Board, data).await Self::new(sdk, ViewLayoutPB::Board, data).await
} }
pub async fn new_calendar_view(sdk: &FlowySDKTest, data: Vec<u8>) -> Self { pub async fn new_calendar_view(sdk: &FlowySDKTest, data: Vec<u8>) -> Self {
Self::new(sdk, ViewLayoutTypePB::Calendar, data).await Self::new(sdk, ViewLayoutPB::Calendar, data).await
} }
pub async fn new_document_view(sdk: &FlowySDKTest) -> Self { pub async fn new_document_view(sdk: &FlowySDKTest) -> Self {
Self::new(sdk, ViewLayoutTypePB::Document, vec![]).await Self::new(sdk, ViewLayoutPB::Document, vec![]).await
} }
} }
@ -82,7 +81,7 @@ async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &s
name: name.to_string(), name: name.to_string(),
desc: desc.to_string(), desc: desc.to_string(),
thumbnail: None, thumbnail: None,
layout: ViewLayoutTypePB::Document, layout: ViewLayoutPB::Document,
initial_data: vec![], initial_data: vec![],
ext: Default::default(), ext: Default::default(),
}; };
@ -98,7 +97,7 @@ async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &s
async fn create_view( async fn create_view(
sdk: &FlowySDKTest, sdk: &FlowySDKTest,
app_id: &str, app_id: &str,
layout: ViewLayoutTypePB, layout: ViewLayoutPB,
data: Vec<u8>, data: Vec<u8>,
) -> ViewPB { ) -> ViewPB {
let payload = CreateViewPayloadPB { let payload = CreateViewPayloadPB {