Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: reorder sort precedence (#4592)
Richard Shiuea515715543e1
diff --git a/frontend/appflowy_flutter/integration_test/database/database_sort_test.dart b/frontend/appflowy_flutter/integration_test/database/database_sort_test.dartindex 633f77a3ef..6b4d53d5bc 100644--- a/frontend/appflowy_flutter/integration_test/database/database_sort_test.dart+++ b/frontend/appflowy_flutter/integration_test/database/database_sort_test.dart@@ -86,7 +86,7 @@ void main() {testWidgets('add checkbox sort', (tester) async {await tester.openV020database();- // create a filter+ // create a sortawait tester.tapDatabaseSortButton();await tester.tapCreateSortByFieldType(FieldType.Checkbox, 'Done');@@ -136,7 +136,7 @@ void main() {testWidgets('add number sort', (tester) async {await tester.openV020database();- // create a filter+ // create a sortawait tester.tapDatabaseSortButton();await tester.tapCreateSortByFieldType(FieldType.Number, 'number');@@ -188,7 +188,7 @@ void main() {testWidgets('add checkbox and number sort', (tester) async {await tester.openV020database();- // create a filter+ // create a sortawait tester.tapDatabaseSortButton();await tester.tapCreateSortByFieldType(FieldType.Checkbox, 'Done');@@ -264,5 +264,111 @@ void main() {await tester.pumpAndSettle();});++ testWidgets('reorder sort', (tester) async {+ await tester.openV020database();+ // create a sort+ await tester.tapDatabaseSortButton();+ await tester.tapCreateSortByFieldType(FieldType.Checkbox, 'Done');++ // open the sort menu and sort checkbox by descending+ await tester.tapSortMenuInSettingBar();+ await tester.tapSortButtonByName('Done');+ await tester.tapSortByDescending();++ // add another sort, this time by number descending+ await tester.tapSortMenuInSettingBar();+ await tester.tapCreateSortByFieldTypeInSortMenu(+ FieldType.Number,+ 'number',+ );+ await tester.tapSortButtonByName('number');+ await tester.tapSortByDescending();++ // check checkbox cell order+ for (final (index, content) in <bool>[+ true,+ true,+ true,+ true,+ true,+ false,+ false,+ false,+ false,+ false,+ ].indexed) {+ await tester.assertCheckboxCell(+ rowIndex: index,+ isSelected: content,+ );+ }++ // check number cell order+ for (final (index, content) in <String>[+ '1',+ '0.2',+ '0.1',+ '-1',+ '-2',+ '12',+ '11',+ '10',+ '2',+ '',+ ].indexed) {+ tester.assertCellContent(+ rowIndex: index,+ fieldType: FieldType.Number,+ content: content,+ );+ }++ // reorder sort+ await tester.tapSortMenuInSettingBar();+ await tester.reorderSort(+ (FieldType.Number, 'number'),+ (FieldType.Checkbox, 'Done'),+ );++ // check checkbox cell order+ for (final (index, content) in <bool>[+ false,+ false,+ false,+ false,+ true,+ true,+ true,+ true,+ true,+ false,+ ].indexed) {+ await tester.assertCheckboxCell(+ rowIndex: index,+ isSelected: content,+ );+ }++ // check the number cell order+ for (final (index, content) in <String>[+ '12',+ '11',+ '10',+ '2',+ '1',+ '0.2',+ '0.1',+ '-1',+ '-2',+ '',+ ].indexed) {+ tester.assertCellContent(+ rowIndex: index,+ fieldType: FieldType.Number,+ content: content,+ );+ }+ });});}diff --git a/frontend/appflowy_flutter/integration_test/util/database_test_op.dart b/frontend/appflowy_flutter/integration_test/util/database_test_op.dartindex cb997738c6..12722ebe1b 100644--- a/frontend/appflowy_flutter/integration_test/util/database_test_op.dart+++ b/frontend/appflowy_flutter/integration_test/util/database_test_op.dart@@ -1070,6 +1070,34 @@ extension AppFlowyDatabaseTest on WidgetTester {await tapButton(findSortItem);}+ /// Must call [tapSortMenuInSettingBar] first.+ Future<void> reorderSort(+ (FieldType, String) from,+ (FieldType, String) to,+ ) async {+ final fromSortItem = find.byWidgetPredicate(+ (widget) =>+ widget is DatabaseSortItem &&+ widget.sortInfo.fieldInfo.fieldType == from.$1 &&+ widget.sortInfo.fieldInfo.name == from.$2,+ );+ final toSortItem = find.byWidgetPredicate(+ (widget) =>+ widget is DatabaseSortItem &&+ widget.sortInfo.fieldInfo.fieldType == to.$1 &&+ widget.sortInfo.fieldInfo.name == to.$2,+ );+ final dragElement = find.descendant(+ of: fromSortItem,+ matching: find.byType(ReorderableDragStartListener),+ );+ await drag(+ dragElement,+ getCenter(toSortItem) - getCenter(fromSortItem),+ );+ await pumpAndSettle(const Duration(milliseconds: 200));+ }+/// Must call [tapSortButtonByName] first.Future<void> tapSortByDescending() async {await tapButton(diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart b/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dartindex 3be14cec47..60d1037b10 100644--- a/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart@@ -282,16 +282,19 @@ class FieldController {) {for (final newSortPB in changeset.insertSorts) {final sortIndex = newSortInfos- .indexWhere((element) => element.sortId == newSortPB.id);+ .indexWhere((element) => element.sortId == newSortPB.sort.id);if (sortIndex == -1) {final fieldInfo = _findFieldInfo(fieldInfos: fieldInfos,- fieldId: newSortPB.fieldId,- fieldType: newSortPB.fieldType,+ fieldId: newSortPB.sort.fieldId,+ fieldType: newSortPB.sort.fieldType,);if (fieldInfo != null) {- newSortInfos.add(SortInfo(sortPB: newSortPB, fieldInfo: fieldInfo));+ newSortInfos.insert(+ newSortPB.index,+ SortInfo(sortPB: newSortPB.sort, fieldInfo: fieldInfo),+ );}}}diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/sort/sort_service.dart b/frontend/appflowy_flutter/lib/plugins/database/application/sort/sort_service.dartindex e0b9e591e5..21260c4f3d 100644--- a/frontend/appflowy_flutter/lib/plugins/database/application/sort/sort_service.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/application/sort/sort_service.dart@@ -75,6 +75,20 @@ class SortBackendService {});}+ Future<Either<Unit, FlowyError>> reorderSort({+ required String fromSortId,+ required String toSortId,+ }) {+ final payload = DatabaseSettingChangesetPB()+ ..viewId = viewId+ ..reorderSort = (ReorderSortPayloadPB()+ ..viewId = viewId+ ..fromSortId = fromSortId+ ..toSortId = toSortId);++ return DatabaseEventUpdateDatabaseSetting(payload).send();+ }+Future<Either<Unit, FlowyError>> deleteSort({required String fieldId,required String sortId,diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/sort/sort_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/sort/sort_editor_bloc.dartindex 003052b14b..0eb2b9c6c8 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/sort/sort_editor_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/sort/sort_editor_bloc.dart@@ -71,6 +71,23 @@ class SortEditorBloc extends Bloc<SortEditorEvent, SortEditorState> {);result.fold((l) => null, (err) => Log.error(err));},+ reorderSort: (fromIndex, toIndex) async {+ if (fromIndex < toIndex) {+ toIndex--;+ }++ final fromId = state.sortInfos[fromIndex].sortId;+ final toId = state.sortInfos[toIndex].sortId;++ final newSorts = [...state.sortInfos];+ newSorts.insert(toIndex, newSorts.removeAt(fromIndex));+ emit(state.copyWith(sortInfos: newSorts));+ final result = await _sortBackendSvc.reorderSort(+ fromSortId: fromId,+ toSortId: toId,+ );+ result.fold((l) => null, (err) => Log.error(err));+ },);},);@@ -113,6 +130,8 @@ class SortEditorEvent with _$SortEditorEvent {) = _SetCondition;const factory SortEditorEvent.deleteSort(SortInfo sortInfo) = _DeleteSort;const factory SortEditorEvent.deleteAllSorts() = _DeleteAllSorts;+ const factory SortEditorEvent.reorderSort(int oldIndex, int newIndex) =+ _ReorderSort;}@freezeddiff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_editor.dartindex b3efb32b96..9dfaa03d3f 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_editor.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_editor.dart@@ -1,3 +1,5 @@+import 'dart:io';+import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/plugins/database/application/field/field_controller.dart';@@ -48,33 +50,58 @@ class _SortEditorState extends State<SortEditor> {)..add(const SortEditorEvent.initial()),child: BlocBuilder<SortEditorBloc, SortEditorState>(builder: (context, state) {- return Column(- children: [- ...state.sortInfos.map(- (info) => Padding(- padding: const EdgeInsets.symmetric(vertical: 6),- child: DatabaseSortItem(- sortInfo: info,- popoverMutex: popoverMutex,- ),- ),+ final sortInfos = state.sortInfos;++ return ReorderableListView.builder(+ onReorder: (oldIndex, newIndex) => context+ .read<SortEditorBloc>()+ .add(SortEditorEvent.reorderSort(oldIndex, newIndex)),+ itemCount: state.sortInfos.length,+ itemBuilder: (context, index) => Padding(+ key: ValueKey(sortInfos[index].sortId),+ padding: const EdgeInsets.symmetric(vertical: 6),+ child: DatabaseSortItem(+ index: index,+ sortInfo: sortInfos[index],+ popoverMutex: popoverMutex,),- Row(+ ),+ proxyDecorator: (child, index, animation) => Material(+ color: Colors.transparent,+ child: Stack(children: [- Flexible(- child: DatabaseAddSortButton(- viewId: widget.viewId,- fieldController: widget.fieldController,- popoverMutex: popoverMutex,- ),+ BlocProvider.value(+ value: context.read<SortEditorBloc>(),+ child: child,),- const HSpace(6),- Flexible(- child: DatabaseDeleteSortButton(popoverMutex: popoverMutex),+ MouseRegion(+ cursor: Platform.isWindows+ ? SystemMouseCursors.click+ : SystemMouseCursors.grabbing,+ child: const SizedBox.expand(),),],),- ],+ ),+ shrinkWrap: true,+ buildDefaultDragHandles: false,+ footer: Row(+ children: [+ Flexible(+ child: DatabaseAddSortButton(+ viewId: widget.viewId,+ fieldController: widget.fieldController,+ popoverMutex: popoverMutex,+ ),+ ),+ const HSpace(6),+ Flexible(+ child: DatabaseDeleteSortButton(+ popoverMutex: popoverMutex,+ ),+ ),+ ],+ ),);},),@@ -85,10 +112,12 @@ class _SortEditorState extends State<SortEditor> {class DatabaseSortItem extends StatelessWidget {const DatabaseSortItem({super.key,+ required this.index,required this.popoverMutex,required this.sortInfo,});+ final int index;final PopoverMutex popoverMutex;final SortInfo sortInfo;@@ -107,6 +136,23 @@ class DatabaseSortItem extends StatelessWidget {return Row(children: [+ ReorderableDragStartListener(+ index: index,+ child: MouseRegion(+ cursor: Platform.isWindows+ ? SystemMouseCursors.click+ : SystemMouseCursors.grab,+ child: SizedBox(+ width: 14,+ height: 14,+ child: FlowySvg(+ FlowySvgs.drag_element_s,+ color: Theme.of(context).iconTheme.color,+ ),+ ),+ ),+ ),+ const HSpace(6),SizedBox(height: 26,child: SortChoiceButton(@@ -122,8 +168,8 @@ class DatabaseSortItem extends StatelessWidget {popoverMutex: popoverMutex,),),- const HSpace(6),const Spacer(),+ const HSpace(6),deleteButton,],);diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_menu.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_menu.dartindex f7663cf470..30fe44f101 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_menu.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/sort/sort_menu.dart@@ -31,27 +31,25 @@ class SortMenu extends StatelessWidget {)..add(const SortMenuEvent.initial()),child: BlocBuilder<SortMenuBloc, SortMenuState>(builder: (context, state) {- if (state.sortInfos.isNotEmpty) {- return AppFlowyPopover(- controller: PopoverController(),- constraints: BoxConstraints.loose(const Size(320, 200)),- direction: PopoverDirection.bottomWithLeftAligned,- offset: const Offset(0, 5),- popupBuilder: (BuildContext popoverContext) {- return SingleChildScrollView(- child: SortEditor(- viewId: state.viewId,- fieldController:- context.read<SortMenuBloc>().fieldController,- sortInfos: state.sortInfos,- ),- );- },- child: SortChoiceChip(sortInfos: state.sortInfos),- );+ if (state.sortInfos.isEmpty) {+ return const SizedBox.shrink();}- return const SizedBox.shrink();+ return AppFlowyPopover(+ controller: PopoverController(),+ constraints: BoxConstraints.loose(const Size(320, 200)),+ direction: PopoverDirection.bottomWithLeftAligned,+ offset: const Offset(0, 5),+ margin: const EdgeInsets.fromLTRB(6.0, 0.0, 6.0, 6.0),+ popupBuilder: (BuildContext popoverContext) {+ return SortEditor(+ viewId: state.viewId,+ fieldController: context.read<SortMenuBloc>().fieldController,+ sortInfos: state.sortInfos,+ );+ },+ child: SortChoiceChip(sortInfos: state.sortInfos),+ );},),);diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dartindex 3e94429489..fd8958cea6 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dart@@ -169,6 +169,7 @@ class _DatabasePropertyCellState extends State<DatabasePropertyCell> {FlowySvg(widget.fieldInfo.fieldType.svgData,color: Theme.of(context).iconTheme.color,+ size: const Size.square(16),),],),diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lockindex 734d7b474a..d37cc705e2 100644--- a/frontend/appflowy_tauri/src-tauri/Cargo.lock+++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock@@ -816,7 +816,7 @@ dependencies = [[[package]]name = "collab"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","async-trait",@@ -838,7 +838,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","async-trait",@@ -867,7 +867,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","collab",@@ -886,7 +886,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","bytes",@@ -901,7 +901,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","chrono",@@ -938,7 +938,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","async-stream",@@ -977,7 +977,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","collab",diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.tomlindex d46b59109c..370d1edc57 100644--- a/frontend/appflowy_tauri/src-tauri/Cargo.toml+++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml@@ -34,18 +34,38 @@ lru = "0.12.0"[dependencies]serde_json.workspace = trueserde.workspace = true-tauri = { version = "1.5", features = ["clipboard-all", "fs-all", "shell-open"] }+tauri = { version = "1.5", features = [+ "clipboard-all",+ "fs-all",+ "shell-open",+] }tauri-utils = "1.5.2"bytes.workspace = truetracing.workspace = true-lib-dispatch = { path = "../../rust-lib/lib-dispatch", features = ["use_serde"] }-flowy-core = { path = "../../rust-lib/flowy-core", features = ["rev-sqlite", "ts"] }+lib-dispatch = { path = "../../rust-lib/lib-dispatch", features = [+ "use_serde",+] }+flowy-core = { path = "../../rust-lib/flowy-core", features = [+ "rev-sqlite",+ "ts",+] }flowy-user = { path = "../../rust-lib/flowy-user", features = ["tauri_ts"] }flowy-config = { path = "../../rust-lib/flowy-config", features = ["tauri_ts"] }flowy-date = { path = "../../rust-lib/flowy-date", features = ["tauri_ts"] }-flowy-error = { path = "../../rust-lib/flowy-error", features = ["impl_from_sqlite", "impl_from_dispatch_error", "impl_from_appflowy_cloud", "impl_from_reqwest", "impl_from_serde", "tauri_ts"] }-flowy-document = { path = "../../rust-lib/flowy-document", features = ["tauri_ts"] }-flowy-notification = { path = "../../rust-lib/flowy-notification", features = ["tauri_ts"] }+flowy-error = { path = "../../rust-lib/flowy-error", features = [+ "impl_from_sqlite",+ "impl_from_dispatch_error",+ "impl_from_appflowy_cloud",+ "impl_from_reqwest",+ "impl_from_serde",+ "tauri_ts",+] }+flowy-document = { path = "../../rust-lib/flowy-document", features = [+ "tauri_ts",+] }+flowy-notification = { path = "../../rust-lib/flowy-notification", features = [+ "tauri_ts",+] }uuid = "1.5.0"[features]@@ -72,10 +92,10 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "d23# To switch to the local path, run:# scripts/tool/update_collab_source.sh# ⚠️⚠️⚠️️-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }diff --git a/frontend/appflowy_tauri/src/appflowy_app/application/database/sort/sort_listeners.ts b/frontend/appflowy_tauri/src/appflowy_app/application/database/sort/sort_listeners.tsindex 377dfec2f5..808c62e0d2 100644--- a/frontend/appflowy_tauri/src/appflowy_app/application/database/sort/sort_listeners.ts+++ b/frontend/appflowy_tauri/src/appflowy_app/application/database/sort/sort_listeners.ts@@ -12,7 +12,7 @@ const deleteSortsFromChange = (database: Database, changeset: SortChangesetNotifconst insertSortsFromChange = (database: Database, changeset: SortChangesetNotificationPB) => {changeset.insert_sorts.forEach(sortPB => {- database.sorts.push(pbToSort(sortPB));+ database.sorts.push(pbToSort(sortPB.sort));});};diff --git a/frontend/appflowy_web/wasm-libs/Cargo.toml b/frontend/appflowy_web/wasm-libs/Cargo.tomlindex 9c333f6133..24ddff37be 100644--- a/frontend/appflowy_web/wasm-libs/Cargo.toml+++ b/frontend/appflowy_web/wasm-libs/Cargo.toml@@ -1,9 +1,5 @@[workspace]-members = [- "af-wasm",- "af-user",- "af-persistence",-]+members = ["af-wasm", "af-user", "af-persistence"]resolver = "2"[workspace.dependencies]@@ -15,7 +11,7 @@ parking_lot = { version = "0.12.1" }tracing = { version = "0.1.22" }serde = { version = "1.0.194", features = ["derive"] }serde_json = "1.0"-collab-integrate = { path = "../../rust-lib/collab-integrate"}+collab-integrate = { path = "../../rust-lib/collab-integrate" }flowy-notification = { path = "../../rust-lib/flowy-notification" }flowy-user-pub = { path = "../../rust-lib/flowy-user-pub" }flowy-server = { path = "../../rust-lib/flowy-server" }@@ -42,7 +38,6 @@ wasm-bindgen-futures = "0.4.40"serde-wasm-bindgen = "0.4"-[profile.dev]opt-level = 0lto = false@@ -70,10 +65,10 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "d23# To switch to the local path, run:# scripts/tool/update_collab_source.sh# ⚠️⚠️⚠️️-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex 1030d588b2..494c8af709 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -744,7 +744,7 @@ dependencies = [[[package]]name = "collab"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","async-trait",@@ -766,7 +766,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","async-trait",@@ -795,7 +795,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","collab",@@ -814,7 +814,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","bytes",@@ -829,7 +829,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","chrono",@@ -866,7 +866,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","async-stream",@@ -905,7 +905,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a6b0932581b4544a0800a0451b9522e6caab5570#a6b0932581b4544a0800a0451b9522e6caab5570"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=2ce95b948accd6d14b97ee886f4416295acd9c65#2ce95b948accd6d14b97ee886f4416295acd9c65"dependencies = ["anyhow","collab",diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex fdf144fe66..48ae3727f1 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -115,10 +115,10 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "d23# To switch to the local path, run:# scripts/tool/update_collab_source.sh# ⚠️⚠️⚠️️-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }-collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a6b0932581b4544a0800a0451b9522e6caab5570" }+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }+collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2ce95b948accd6d14b97ee886f4416295acd9c65" }diff --git a/frontend/rust-lib/flowy-database2/src/entities/filter_entities/util.rs b/frontend/rust-lib/flowy-database2/src/entities/filter_entities/util.rsindex d12706b81f..4d2d9283c7 100644--- a/frontend/rust-lib/flowy-database2/src/entities/filter_entities/util.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/filter_entities/util.rs@@ -84,7 +84,7 @@ pub struct DeleteFilterPayloadPB {pub field_type: FieldType,#[pb(index = 3)]- #[validate(custom = "lib_infra::validator_fn::required_not_empty_str")]+ #[validate(custom = "crate::entities::utils::validate_filter_id")]pub filter_id: String,#[pb(index = 4)]@@ -103,7 +103,7 @@ pub struct UpdateFilterPayloadPB {/// Create a new filter if the filter_id is None#[pb(index = 3, one_of)]- #[validate(custom = "lib_infra::validator_fn::required_not_empty_str")]+ #[validate(custom = "crate::entities::utils::validate_filter_id")]pub filter_id: Option<String>,#[pb(index = 4)]diff --git a/frontend/rust-lib/flowy-database2/src/entities/mod.rs b/frontend/rust-lib/flowy-database2/src/entities/mod.rsindex 63fd455832..6bacbd0539 100644--- a/frontend/rust-lib/flowy-database2/src/entities/mod.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/mod.rs@@ -35,3 +35,25 @@ pub use share_entities::*;pub use sort_entities::*;pub use type_option_entities::*;pub use view_entities::*;++mod utils {+ use fancy_regex::Regex;+ use lib_infra::impl_regex_validator;+ use validator::ValidationError;++ impl_regex_validator!(+ validate_filter_id,+ Regex::new(r"^[A-Za-z0-9_-]{6}$").unwrap(),+ "invalid filter_id"+ );+ impl_regex_validator!(+ validate_sort_id,+ Regex::new(r"^s:[A-Za-z0-9_-]{6}$").unwrap(),+ "invalid sort_id"+ );+ impl_regex_validator!(+ validate_group_id,+ Regex::new(r"^g:[A-Za-z0-9_-]{6}$").unwrap(),+ "invalid group_id"+ );+}diff --git a/frontend/rust-lib/flowy-database2/src/entities/setting_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/setting_entities.rsindex 1305986ffb..e1cefc07cc 100644--- a/frontend/rust-lib/flowy-database2/src/entities/setting_entities.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/setting_entities.rs@@ -15,7 +15,7 @@ use crate::entities::{};use crate::services::setting::{BoardLayoutSetting, CalendarLayoutSetting};-use super::BoardLayoutSettingPB;+use super::{BoardLayoutSettingPB, ReorderSortPayloadPB};/// [DatabaseViewSettingPB] defines the setting options for the grid. Such as the filter, group, and sort.#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]@@ -39,9 +39,8 @@ pub struct DatabaseViewSettingPB {pub field_settings: RepeatedFieldSettingsPB,}-#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]+#[derive(Debug, Default, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]#[repr(u8)]-#[derive(Default)]pub enum DatabaseLayoutPB {#[default]Grid = 0,@@ -96,6 +95,10 @@ pub struct DatabaseSettingChangesetPB {#[pb(index = 7, one_of)]#[validate]+ pub reorder_sort: Option<ReorderSortPayloadPB>,++ #[pb(index = 8, one_of)]+ #[validate]pub delete_sort: Option<DeleteSortPayloadPB>,}diff --git a/frontend/rust-lib/flowy-database2/src/entities/sort_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/sort_entities.rsindex 4814a89792..e7c6eb762c 100644--- a/frontend/rust-lib/flowy-database2/src/entities/sort_entities.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/sort_entities.rs@@ -41,6 +41,15 @@ impl std::convert::From<Sort> for SortPB {}}+#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]+pub struct SortWithIndexPB {+ #[pb(index = 1)]+ pub index: u32,++ #[pb(index = 2)]+ pub sort: SortPB,+}+#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]pub struct RepeatedSortPB {#[pb(index = 1)]@@ -105,12 +114,28 @@ pub struct UpdateSortPayloadPB {/// Create a new sort if the sort_id is None#[pb(index = 4, one_of)]+ #[validate(custom = "super::utils::validate_sort_id")]pub sort_id: Option<String>,#[pb(index = 5)]pub condition: SortConditionPB,}+#[derive(Debug, Default, Clone, Validate, ProtoBuf)]+pub struct ReorderSortPayloadPB {+ #[pb(index = 1)]+ #[validate(custom = "lib_infra::validator_fn::required_not_empty_str")]+ pub view_id: String,++ #[pb(index = 2)]+ #[validate(custom = "super::utils::validate_sort_id")]+ pub from_sort_id: String,++ #[pb(index = 3)]+ #[validate(custom = "super::utils::validate_sort_id")]+ pub to_sort_id: String,+}+#[derive(ProtoBuf, Debug, Default, Clone, Validate)]pub struct DeleteSortPayloadPB {#[pb(index = 1)]@@ -118,7 +143,7 @@ pub struct DeleteSortPayloadPB {pub view_id: String,#[pb(index = 2)]- #[validate(custom = "lib_infra::validator_fn::required_not_empty_str")]+ #[validate(custom = "super::utils::validate_sort_id")]pub sort_id: String,}@@ -128,7 +153,7 @@ pub struct SortChangesetNotificationPB {pub view_id: String,#[pb(index = 2)]- pub insert_sorts: Vec<SortPB>,+ pub insert_sorts: Vec<SortWithIndexPB>,#[pb(index = 3)]pub delete_sorts: Vec<SortPB>,diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rsindex 7c25519d52..72dde97929 100644--- a/frontend/rust-lib/flowy-database2/src/event_handler.rs+++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs@@ -88,28 +88,32 @@ pub(crate) async fn update_database_setting_handler() -> Result<(), FlowyError> {let manager = upgrade_manager(manager)?;let params = data.try_into_inner()?;- let editor = manager.get_database_with_view_id(¶ms.view_id).await?;+ let database_editor = manager.get_database_with_view_id(¶ms.view_id).await?;if let Some(update_filter) = params.update_filter {- editor+ database_editor.create_or_update_filter(update_filter.try_into()?).await?;}if let Some(delete_filter) = params.delete_filter {- editor.delete_filter(delete_filter).await?;+ database_editor.delete_filter(delete_filter).await?;}if let Some(update_sort) = params.update_sort {- let _ = editor.create_or_update_sort(update_sort).await?;+ let _ = database_editor.create_or_update_sort(update_sort).await?;+ }++ if let Some(reorder_sort) = params.reorder_sort {+ database_editor.reorder_sort(reorder_sort).await?;}if let Some(delete_sort) = params.delete_sort {- editor.delete_sort(delete_sort).await?;+ database_editor.delete_sort(delete_sort).await?;}if let Some(layout_type) = params.layout_type {- editor+ database_editor.update_view_layout(¶ms.view_id, layout_type.into()).await?;}diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rsindex 4c6f2e757a..e2e8823919 100644--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs@@ -228,10 +228,16 @@ impl DatabaseEditor {pub async fn create_or_update_sort(&self, params: UpdateSortPayloadPB) -> FlowyResult<Sort> {let view_editor = self.database_views.get_view_editor(¶ms.view_id).await?;- let sort = view_editor.insert_or_update_sort(params).await?;+ let sort = view_editor.v_create_or_update_sort(params).await?;Ok(sort)}+ pub async fn reorder_sort(&self, params: ReorderSortPayloadPB) -> FlowyResult<()> {+ let view_editor = self.database_views.get_view_editor(¶ms.view_id).await?;+ view_editor.v_reorder_sort(params).await?;+ Ok(())+ }+pub async fn delete_sort(&self, params: DeleteSortPayloadPB) -> FlowyResult<()> {let view_editor = self.database_views.get_view_editor(¶ms.view_id).await?;view_editor.v_delete_sort(params).await?;@@ -1459,6 +1465,13 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl {self.database.lock().insert_sort(view_id, sort);}+ fn move_sort(&self, view_id: &str, from_sort_id: &str, to_sort_id: &str) {+ self+ .database+ .lock()+ .move_sort(view_id, from_sort_id, to_sort_id);+ }+fn remove_sort(&self, view_id: &str, sort_id: &str) {self.database.lock().remove_sort(view_id, sort_id);}diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rsindex 35ce867674..04e68c3b23 100644--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs@@ -17,8 +17,8 @@ use lib_dispatch::prelude::af_spawn;use crate::entities::{CalendarEventPB, DatabaseLayoutMetaPB, DatabaseLayoutSettingPB, DeleteFilterPayloadPB,DeleteSortPayloadPB, FieldType, FieldVisibility, GroupChangesPB, GroupPB, InsertedRowPB,- LayoutSettingChangeset, LayoutSettingParams, RemoveCalculationChangesetPB, RowMetaPB,- RowsChangePB, SortChangesetNotificationPB, SortPB, UpdateCalculationChangesetPB,+ LayoutSettingChangeset, LayoutSettingParams, RemoveCalculationChangesetPB, ReorderSortPayloadPB,+ RowMetaPB, RowsChangePB, SortChangesetNotificationPB, SortPB, UpdateCalculationChangesetPB,UpdateFilterParams, UpdateSortPayloadPB,};use crate::notification::{send_notification, DatabaseNotification};@@ -499,7 +499,7 @@ impl DatabaseViewEditor {}#[tracing::instrument(level = "trace", skip(self), err)]- pub async fn insert_or_update_sort(&self, params: UpdateSortPayloadPB) -> FlowyResult<Sort> {+ pub async fn v_create_or_update_sort(&self, params: UpdateSortPayloadPB) -> FlowyResult<Sort> {let is_exist = params.sort_id.is_some();let sort_id = match params.sort_id {None => gen_database_sort_id(),@@ -513,9 +513,11 @@ impl DatabaseViewEditor {condition: params.condition.into(),};- let mut sort_controller = self.sort_controller.write().await;self.delegate.insert_sort(&self.view_id, sort.clone());- let changeset = if is_exist {++ let mut sort_controller = self.sort_controller.write().await;++ let notification = if is_exist {sort_controller.apply_changeset(SortChangeset::from_update(sort.clone())).await@@ -525,10 +527,29 @@ impl DatabaseViewEditor {.await};drop(sort_controller);- notify_did_update_sort(changeset).await;+ notify_did_update_sort(notification).await;Ok(sort)}+ pub async fn v_reorder_sort(&self, params: ReorderSortPayloadPB) -> FlowyResult<()> {+ self+ .delegate+ .move_sort(&self.view_id, ¶ms.from_sort_id, ¶ms.to_sort_id);++ let notification = self+ .sort_controller+ .write()+ .await+ .apply_changeset(SortChangeset::from_reorder(+ params.from_sort_id,+ params.to_sort_id,+ ))+ .await;++ notify_did_update_sort(notification).await;+ Ok(())+ }+pub async fn v_delete_sort(&self, params: DeleteSortPayloadPB) -> FlowyResult<()> {let notification = self.sort_controllerdiff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rsindex 291f98ac03..40ad9778b5 100644--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs@@ -75,6 +75,8 @@ pub trait DatabaseViewOperation: Send + Sync + 'static {fn insert_sort(&self, view_id: &str, sort: Sort);+ fn move_sort(&self, view_id: &str, from_sort_id: &str, to_sort_id: &str);+fn remove_sort(&self, view_id: &str, sort_id: &str);fn get_all_sorts(&self, view_id: &str) -> Vec<Sort>;diff --git a/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs b/frontend/rust-lib/flowy-database2/src/services/sort/controller.rsindex 88f2440b46..599a67303c 100644--- a/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs+++ b/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs@@ -13,8 +13,8 @@ use flowy_error::FlowyResult;use lib_infra::future::Fut;use lib_infra::priority_task::{QualityOfService, Task, TaskContent, TaskDispatcher};-use crate::entities::FieldType;use crate::entities::SortChangesetNotificationPB;+use crate::entities::{FieldType, SortWithIndexPB};use crate::services::cell::CellCache;use crate::services::database_view::{DatabaseViewChanged, DatabaseViewChangedNotifier};use crate::services::field::{default_order, TypeOptionCellExt};@@ -184,7 +184,10 @@ impl SortController {if let Some(insert_sort) = changeset.insert_sort {if let Some(sort) = self.delegate.get_sort(&self.view_id, &insert_sort.id).await {- notification.insert_sorts.push(sort.as_ref().into());+ notification.insert_sorts.push(SortWithIndexPB {+ index: self.sorts.len() as u32,+ sort: sort.as_ref().into(),+ });self.sorts.push(sort);}}@@ -209,6 +212,23 @@ impl SortController {}}+ if let Some((from_id, to_id)) = changeset.reorder_sort {+ let moved_sort = self.delegate.get_sort(&self.view_id, &from_id).await;+ let from_index = self.sorts.iter().position(|sort| sort.id == from_id);+ let to_index = self.sorts.iter().position(|sort| sort.id == to_id);++ if let (Some(sort), Some(from_index), Some(to_index)) = (moved_sort, from_index, to_index) {+ self.sorts.remove(from_index);+ self.sorts.insert(to_index, sort.clone());++ notification.delete_sorts.push(sort.as_ref().into());+ notification.insert_sorts.push(SortWithIndexPB {+ index: to_index as u32,+ sort: sort.as_ref().into(),+ });+ }+ }+if !notification.is_empty() {self.gen_task(SortEvent::SortDidChanged, QualityOfService::UserInteractive)diff --git a/frontend/rust-lib/flowy-database2/src/services/sort/entities.rs b/frontend/rust-lib/flowy-database2/src/services/sort/entities.rsindex fe262877d5..15cb7d4c2a 100644--- a/frontend/rust-lib/flowy-database2/src/services/sort/entities.rs+++ b/frontend/rust-lib/flowy-database2/src/services/sort/entities.rs@@ -126,6 +126,7 @@ pub struct SortChangeset {pub(crate) insert_sort: Option<Sort>,pub(crate) update_sort: Option<Sort>,pub(crate) delete_sort: Option<String>,+ pub(crate) reorder_sort: Option<(String, String)>,}impl SortChangeset {@@ -134,6 +135,7 @@ impl SortChangeset {insert_sort: Some(sort),update_sort: None,delete_sort: None,+ reorder_sort: None,}}@@ -142,6 +144,7 @@ impl SortChangeset {insert_sort: None,update_sort: Some(sort),delete_sort: None,+ reorder_sort: None,}}@@ -150,6 +153,16 @@ impl SortChangeset {insert_sort: None,update_sort: None,delete_sort: Some(sort_id),+ reorder_sort: None,+ }+ }++ pub fn from_reorder(from_sort_id: String, to_sort_id: String) -> Self {+ Self {+ insert_sort: None,+ update_sort: None,+ delete_sort: None,+ reorder_sort: Some((from_sort_id, to_sort_id)),}}}diff --git a/frontend/rust-lib/flowy-database2/tests/database/sort_test/multi_sort_test.rs b/frontend/rust-lib/flowy-database2/tests/database/sort_test/multi_sort_test.rsindex bd9ff68d47..7fe1874984 100644--- a/frontend/rust-lib/flowy-database2/tests/database/sort_test/multi_sort_test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/sort_test/multi_sort_test.rs@@ -47,3 +47,55 @@ async fn sort_checkbox_and_then_text_by_descending_test() {];test.run_scripts(scripts).await;}++#[tokio::test]+async fn reorder_sort_test() {+ let mut test = DatabaseSortTest::new().await;+ let checkbox_field = test.get_first_field(FieldType::Checkbox);+ let text_field = test.get_first_field(FieldType::RichText);+ // Use the same sort set up as above+ let scripts = vec![+ AssertCellContentOrder {+ field_id: checkbox_field.id.clone(),+ orders: vec!["Yes", "Yes", "No", "No", "No", "Yes", ""],+ },+ AssertCellContentOrder {+ field_id: text_field.id.clone(),+ orders: vec!["A", "", "C", "DA", "AE", "AE", "CB"],+ },+ InsertSort {+ field: checkbox_field.clone(),+ condition: SortCondition::Descending,+ },+ InsertSort {+ field: text_field.clone(),+ condition: SortCondition::Ascending,+ },+ AssertCellContentOrder {+ field_id: checkbox_field.id.clone(),+ orders: vec!["Yes", "Yes", "Yes", "No", "No", "", "No"],+ },+ AssertCellContentOrder {+ field_id: text_field.id.clone(),+ orders: vec!["A", "AE", "", "AE", "C", "CB", "DA"],+ },+ ];+ test.run_scripts(scripts).await;++ let sorts = test.editor.get_all_sorts(&test.view_id).await.items;+ let scripts = vec![+ ReorderSort {+ from_sort_id: sorts[1].id.clone(),+ to_sort_id: sorts[0].id.clone(),+ },+ AssertCellContentOrder {+ field_id: checkbox_field.id.clone(),+ orders: vec!["Yes", "Yes", "No", "No", "", "No", "Yes"],+ },+ AssertCellContentOrder {+ field_id: text_field.id.clone(),+ orders: vec!["A", "AE", "AE", "C", "CB", "DA", ""],+ },+ ];+ test.run_scripts(scripts).await;+}diff --git a/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rsindex 21d7f0557d..7e12235fe1 100644--- a/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs@@ -7,10 +7,12 @@ use collab_database::rows::RowId;use futures::stream::StreamExt;use tokio::sync::broadcast::Receiver;-use flowy_database2::entities::{DeleteSortPayloadPB, FieldType, UpdateSortPayloadPB};+use flowy_database2::entities::{+ DeleteSortPayloadPB, FieldType, ReorderSortPayloadPB, UpdateSortPayloadPB,+};use flowy_database2::services::cell::stringify_cell_data;use flowy_database2::services::database_view::DatabaseViewChanged;-use flowy_database2::services::sort::{Sort, SortCondition};+use flowy_database2::services::sort::SortCondition;use crate::database::database_editor::DatabaseEditorTest;@@ -19,6 +21,10 @@ pub enum SortScript {field: Field,condition: SortCondition,},+ ReorderSort {+ from_sort_id: String,+ to_sort_id: String,+ },DeleteSort {sort_id: String,},@@ -41,7 +47,6 @@ pub enum SortScript {pub struct DatabaseSortTest {inner: DatabaseEditorTest,- pub current_sort_rev: Option<Sort>,recv: Option<Receiver<DatabaseViewChanged>>,}@@ -50,7 +55,6 @@ impl DatabaseSortTest {let editor_test = DatabaseEditorTest::new_grid().await;Self {inner: editor_test,- current_sort_rev: None,recv: None,}}@@ -77,8 +81,25 @@ impl DatabaseSortTest {field_type: FieldType::from(field.field_type),condition: condition.into(),};- let sort_rev = self.editor.create_or_update_sort(params).await.unwrap();- self.current_sort_rev = Some(sort_rev);+ let _ = self.editor.create_or_update_sort(params).await.unwrap();+ },+ SortScript::ReorderSort {+ from_sort_id,+ to_sort_id,+ } => {+ self.recv = Some(+ self+ .editor+ .subscribe_view_changed(&self.view_id)+ .await+ .unwrap(),+ );+ let params = ReorderSortPayloadPB {+ view_id: self.view_id.clone(),+ from_sort_id,+ to_sort_id,+ };+ self.editor.reorder_sort(params).await.unwrap();},SortScript::DeleteSort { sort_id } => {self.recv = Some(@@ -93,7 +114,6 @@ impl DatabaseSortTest {sort_id,};self.editor.delete_sort(params).await.unwrap();- self.current_sort_rev = None;},SortScript::AssertCellContentOrder { field_id, orders } => {let mut cells = vec![];diff --git a/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rs b/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rsindex a3eac1db8d..2620c3149b 100644--- a/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rs@@ -85,16 +85,21 @@ async fn sort_change_notification_by_update_text_test() {async fn sort_text_by_ascending_and_delete_sort_test() {let mut test = DatabaseSortTest::new().await;let text_field = test.get_first_field(FieldType::RichText).clone();- let scripts = vec![InsertSort {- field: text_field.clone(),- condition: SortCondition::Ascending,- }];- test.run_scripts(scripts).await;- let sort = test.current_sort_rev.as_ref().unwrap();let scripts = vec![- DeleteSort {- sort_id: sort.id.clone(),+ InsertSort {+ field: text_field.clone(),+ condition: SortCondition::Ascending,+ },+ AssertCellContentOrder {+ field_id: text_field.id.clone(),+ orders: vec!["A", "AE", "AE", "C", "CB", "DA", ""],},+ ];+ test.run_scripts(scripts).await;++ let sort = test.editor.get_all_sorts(&test.view_id).await.items[0].clone();+ let scripts = vec![+ DeleteSort { sort_id: sort.id },AssertCellContentOrder {field_id: text_field.id.clone(),orders: vec!["A", "", "C", "DA", "AE", "AE", "CB"],diff --git a/frontend/rust-lib/lib-infra/src/validator_fn.rs b/frontend/rust-lib/lib-infra/src/validator_fn.rsindex feaa55292f..6d7a034b0c 100644--- a/frontend/rust-lib/lib-infra/src/validator_fn.rs+++ b/frontend/rust-lib/lib-infra/src/validator_fn.rs@@ -15,3 +15,28 @@ pub fn required_valid_path(s: &str) -> Result<(), ValidationError> {(_, _) => Err(ValidationError::new("invalid_path")),}}++#[macro_export]+/// Macro to implement a custom validator function for a regex expression.+/// This is intended to replace `validator` crate's own regex validator, which+/// isn't compatible with `fancy_regex`.+///+/// # Arguments:+///+/// - name of the validator function+/// - the `fancy_regex::Regex` object+/// - error message of the `ValidationError`+///+macro_rules! impl_regex_validator {+ ($validator: ident, $regex: expr, $error: expr) => {+ pub(crate) fn $validator(arg: &str) -> Result<(), ValidationError> {+ let check = $regex.is_match(arg).unwrap();++ if check {+ Ok(())+ } else {+ Err(ValidationError::new($error))+ }+ }+ };+}