From 1ac1fabb6eee28cd5600a740da70db5749594065 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 12 Dec 2022 10:52:14 +0800 Subject: [PATCH] chore: add suffix PB to filter structs --- .../filter/checkbox_filter_editor_bloc.dart | 4 +- .../filter/checklist_filter_bloc.dart | 4 +- .../filter/filter_create_bloc.dart | 16 +-- .../application/filter/filter_service.dart | 16 +-- .../filter/select_option_filter_bloc.dart | 4 +- .../filter/text_filter_editor_bloc.dart | 4 +- .../widgets/filter/choicechip/checkbox.dart | 18 +-- .../choicechip/checklist/checklist.dart | 16 +-- .../select_option/condition_list.dart | 24 ++-- .../select_option/select_option.dart | 4 +- .../widgets/filter/choicechip/text.dart | 50 ++++---- .../grid_test/filter/create_filter_test.dart | 14 +-- .../filter/edit_filter_field_test.dart | 2 +- .../grid_test/filter/filter_menu_test.dart | 8 +- .../filter/filter_rows_by_checkbox_test.dart | 4 +- .../filter/filter_rows_by_text_test.dart | 18 +-- .../filter_entities/checkbox_filter.rs | 21 ++-- .../filter_entities/checklist_filter.rs | 22 ++-- .../entities/filter_entities/date_filter.rs | 38 +++--- .../entities/filter_entities/number_filter.rs | 32 ++--- .../filter_entities/select_option_filter.rs | 24 ++-- .../entities/filter_entities/text_filter.rs | 32 ++--- .../src/entities/filter_entities/util.rs | 6 +- .../rust-lib/flowy-grid/src/entities/mod.rs | 2 + .../src/entities/setting_entities.rs | 29 ++++- .../flowy-grid/src/entities/sort_entities.rs | 118 ++++++++++++++++++ .../rust-lib/flowy-grid/src/event_handler.rs | 7 ++ .../checkbox_type_option/checkbox_filter.rs | 12 +- .../date_type_option/date_filter.rs | 32 ++--- .../number_type_option/number_filter.rs | 26 ++-- .../selection_type_option/checklist_filter.rs | 6 +- .../selection_type_option/select_filter.rs | 28 ++--- .../text_type_option/text_filter.rs | 30 ++--- .../flowy-grid/src/services/grid_editor.rs | 8 ++ .../src/services/view_editor/editor.rs | 1 + .../grid/filter_test/checkbox_filter_test.rs | 6 +- .../grid/filter_test/checklist_filter_test.rs | 6 +- .../grid/filter_test/date_filter_test.rs | 12 +- .../grid/filter_test/number_filter_test.rs | 14 +-- .../tests/grid/filter_test/script.rs | 18 +-- .../filter_test/select_option_filter_test.rs | 16 +-- .../grid/filter_test/text_filter_test.rs | 26 ++-- 42 files changed, 470 insertions(+), 308 deletions(-) create mode 100644 frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs diff --git a/frontend/app_flowy/lib/plugins/grid/application/filter/checkbox_filter_editor_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/filter/checkbox_filter_editor_bloc.dart index 399f233361..ed17b3b55b 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/filter/checkbox_filter_editor_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/filter/checkbox_filter_editor_bloc.dart @@ -28,7 +28,7 @@ class CheckboxFilterEditorBloc initial: () async { _startListening(); }, - updateCondition: (CheckboxFilterCondition condition) { + updateCondition: (CheckboxFilterConditionPB condition) { _ffiService.insertCheckboxFilter( filterId: filterInfo.filter.id, fieldId: filterInfo.fieldInfo.id, @@ -79,7 +79,7 @@ class CheckboxFilterEditorEvent with _$CheckboxFilterEditorEvent { const factory CheckboxFilterEditorEvent.didReceiveFilter(FilterPB filter) = _DidReceiveFilter; const factory CheckboxFilterEditorEvent.updateCondition( - CheckboxFilterCondition condition) = _UpdateCondition; + CheckboxFilterConditionPB condition) = _UpdateCondition; const factory CheckboxFilterEditorEvent.delete() = _Delete; } diff --git a/frontend/app_flowy/lib/plugins/grid/application/filter/checklist_filter_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/filter/checklist_filter_bloc.dart index 05e801081a..8050e3bccb 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/filter/checklist_filter_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/filter/checklist_filter_bloc.dart @@ -32,7 +32,7 @@ class ChecklistFilterEditorBloc initial: () async { _startListening(); }, - updateCondition: (ChecklistFilterCondition condition) { + updateCondition: (ChecklistFilterConditionPB condition) { _ffiService.insertChecklistFilter( filterId: filterInfo.filter.id, fieldId: filterInfo.fieldInfo.id, @@ -85,7 +85,7 @@ class ChecklistFilterEditorEvent with _$ChecklistFilterEditorEvent { const factory ChecklistFilterEditorEvent.didReceiveFilter(FilterPB filter) = _DidReceiveFilter; const factory ChecklistFilterEditorEvent.updateCondition( - ChecklistFilterCondition condition) = _UpdateCondition; + ChecklistFilterConditionPB condition) = _UpdateCondition; const factory ChecklistFilterEditorEvent.delete() = _Delete; } diff --git a/frontend/app_flowy/lib/plugins/grid/application/filter/filter_create_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/filter/filter_create_bloc.dart index ff933a1da3..65835c2f81 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/filter/filter_create_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/filter/filter_create_bloc.dart @@ -90,48 +90,48 @@ class GridCreateFilterBloc case FieldType.Checkbox: return _ffiService.insertCheckboxFilter( fieldId: fieldId, - condition: CheckboxFilterCondition.IsChecked, + condition: CheckboxFilterConditionPB.IsChecked, ); case FieldType.DateTime: final timestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000; return _ffiService.insertDateFilter( fieldId: fieldId, - condition: DateFilterCondition.DateIs, + condition: DateFilterConditionPB.DateIs, timestamp: timestamp, ); case FieldType.MultiSelect: return _ffiService.insertSelectOptionFilter( fieldId: fieldId, - condition: SelectOptionCondition.OptionIs, + condition: SelectOptionConditionPB.OptionIs, fieldType: FieldType.MultiSelect, ); case FieldType.Checklist: return _ffiService.insertChecklistFilter( fieldId: fieldId, - condition: ChecklistFilterCondition.IsIncomplete, + condition: ChecklistFilterConditionPB.IsIncomplete, ); case FieldType.Number: return _ffiService.insertNumberFilter( fieldId: fieldId, - condition: NumberFilterCondition.Equal, + condition: NumberFilterConditionPB.Equal, content: "", ); case FieldType.RichText: return _ffiService.insertTextFilter( fieldId: fieldId, - condition: TextFilterCondition.Contains, + condition: TextFilterConditionPB.Contains, content: '', ); case FieldType.SingleSelect: return _ffiService.insertSelectOptionFilter( fieldId: fieldId, - condition: SelectOptionCondition.OptionIs, + condition: SelectOptionConditionPB.OptionIs, fieldType: FieldType.SingleSelect, ); case FieldType.URL: return _ffiService.insertURLFilter( fieldId: fieldId, - condition: TextFilterCondition.Contains, + condition: TextFilterConditionPB.Contains, ); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/filter/filter_service.dart b/frontend/app_flowy/lib/plugins/grid/application/filter/filter_service.dart index f30a9dc263..858afbc338 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/filter/filter_service.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/filter/filter_service.dart @@ -32,7 +32,7 @@ class FilterFFIService { Future> insertTextFilter({ required String fieldId, String? filterId, - required TextFilterCondition condition, + required TextFilterConditionPB condition, required String content, }) { final filter = TextFilterPB() @@ -50,7 +50,7 @@ class FilterFFIService { Future> insertCheckboxFilter({ required String fieldId, String? filterId, - required CheckboxFilterCondition condition, + required CheckboxFilterConditionPB condition, }) { final filter = CheckboxFilterPB()..condition = condition; @@ -65,7 +65,7 @@ class FilterFFIService { Future> insertNumberFilter({ required String fieldId, String? filterId, - required NumberFilterCondition condition, + required NumberFilterConditionPB condition, String content = "", }) { final filter = NumberFilterPB() @@ -83,7 +83,7 @@ class FilterFFIService { Future> insertDateFilter({ required String fieldId, String? filterId, - required DateFilterCondition condition, + required DateFilterConditionPB condition, int? start, int? end, int? timestamp, @@ -112,7 +112,7 @@ class FilterFFIService { Future> insertURLFilter({ required String fieldId, String? filterId, - required TextFilterCondition condition, + required TextFilterConditionPB condition, String content = "", }) { final filter = TextFilterPB() @@ -130,7 +130,7 @@ class FilterFFIService { Future> insertSelectOptionFilter({ required String fieldId, required FieldType fieldType, - required SelectOptionCondition condition, + required SelectOptionConditionPB condition, String? filterId, List optionIds = const [], }) { @@ -148,7 +148,7 @@ class FilterFFIService { Future> insertChecklistFilter({ required String fieldId, - required ChecklistFilterCondition condition, + required ChecklistFilterConditionPB condition, String? filterId, List optionIds = const [], }) { @@ -196,7 +196,7 @@ class FilterFFIService { required String filterId, required FieldType fieldType, }) { - TextFilterCondition.DoesNotContain.value; + TextFilterConditionPB.DoesNotContain.value; final deleteFilterPayload = DeleteFilterPayloadPB.create() ..fieldId = fieldId diff --git a/frontend/app_flowy/lib/plugins/grid/application/filter/select_option_filter_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/filter/select_option_filter_bloc.dart index 4cf76e7cac..54852bb53e 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/filter/select_option_filter_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/filter/select_option_filter_bloc.dart @@ -33,7 +33,7 @@ class SelectOptionFilterEditorBloc _startListening(); _loadOptions(); }, - updateCondition: (SelectOptionCondition condition) { + updateCondition: (SelectOptionConditionPB condition) { _ffiService.insertSelectOptionFilter( filterId: filterInfo.filter.id, fieldId: filterInfo.fieldInfo.id, @@ -114,7 +114,7 @@ class SelectOptionFilterEditorEvent with _$SelectOptionFilterEditorEvent { const factory SelectOptionFilterEditorEvent.didReceiveFilter( FilterPB filter) = _DidReceiveFilter; const factory SelectOptionFilterEditorEvent.updateCondition( - SelectOptionCondition condition) = _UpdateCondition; + SelectOptionConditionPB condition) = _UpdateCondition; const factory SelectOptionFilterEditorEvent.updateContent( List optionIds) = _UpdateContent; const factory SelectOptionFilterEditorEvent.updateFilterDescription( diff --git a/frontend/app_flowy/lib/plugins/grid/application/filter/text_filter_editor_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/filter/text_filter_editor_bloc.dart index e556d04d9e..724d44e093 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/filter/text_filter_editor_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/filter/text_filter_editor_bloc.dart @@ -28,7 +28,7 @@ class TextFilterEditorBloc initial: () async { _startListening(); }, - updateCondition: (TextFilterCondition condition) { + updateCondition: (TextFilterConditionPB condition) { _ffiService.insertTextFilter( filterId: filterInfo.filter.id, fieldId: filterInfo.fieldInfo.id, @@ -88,7 +88,7 @@ class TextFilterEditorEvent with _$TextFilterEditorEvent { const factory TextFilterEditorEvent.didReceiveFilter(FilterPB filter) = _DidReceiveFilter; const factory TextFilterEditorEvent.updateCondition( - TextFilterCondition condition) = _UpdateCondition; + TextFilterConditionPB condition) = _UpdateCondition; const factory TextFilterEditorEvent.updateContent(String content) = _UpdateContent; const factory TextFilterEditorEvent.delete() = _Delete; diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checkbox.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checkbox.dart index 6f8edaa656..717be3d0a2 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checkbox.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checkbox.dart @@ -108,7 +108,7 @@ class _CheckboxFilterEditorState extends State { children: [ FlowyText(state.filterInfo.fieldInfo.name), const HSpace(4), - CheckboxFilterConditionList( + CheckboxFilterConditionPBList( filterInfo: state.filterInfo, popoverMutex: popoverMutex, onCondition: (condition) { @@ -136,11 +136,11 @@ class _CheckboxFilterEditorState extends State { } } -class CheckboxFilterConditionList extends StatelessWidget { +class CheckboxFilterConditionPBList extends StatelessWidget { final FilterInfo filterInfo; final PopoverMutex popoverMutex; - final Function(CheckboxFilterCondition) onCondition; - const CheckboxFilterConditionList({ + final Function(CheckboxFilterConditionPB) onCondition; + const CheckboxFilterConditionPBList({ required this.filterInfo, required this.popoverMutex, required this.onCondition, @@ -154,7 +154,7 @@ class CheckboxFilterConditionList extends StatelessWidget { asBarrier: true, mutex: popoverMutex, direction: PopoverDirection.bottomWithCenterAligned, - actions: CheckboxFilterCondition.values + actions: CheckboxFilterConditionPB.values .map( (action) => ConditionWrapper( action, @@ -177,7 +177,7 @@ class CheckboxFilterConditionList extends StatelessWidget { } class ConditionWrapper extends ActionCell { - final CheckboxFilterCondition inner; + final CheckboxFilterConditionPB inner; final bool isSelected; ConditionWrapper(this.inner, this.isSelected); @@ -195,12 +195,12 @@ class ConditionWrapper extends ActionCell { String get name => inner.filterName; } -extension TextFilterConditionExtension on CheckboxFilterCondition { +extension TextFilterConditionPBExtension on CheckboxFilterConditionPB { String get filterName { switch (this) { - case CheckboxFilterCondition.IsChecked: + case CheckboxFilterConditionPB.IsChecked: return LocaleKeys.grid_checkboxFilter_isChecked.tr(); - case CheckboxFilterCondition.IsUnChecked: + case CheckboxFilterConditionPB.IsUnChecked: return LocaleKeys.grid_checkboxFilter_isUnchecked.tr(); default: return ""; diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checklist/checklist.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checklist/checklist.dart index 114ececac7..aba0c5d2c8 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checklist/checklist.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/checklist/checklist.dart @@ -92,7 +92,7 @@ class ChecklistState extends State { children: [ FlowyText(state.filterInfo.fieldInfo.name), const HSpace(4), - ChecklistFilterConditionList( + ChecklistFilterConditionPBList( filterInfo: state.filterInfo, ), const Spacer(), @@ -117,9 +117,9 @@ class ChecklistState extends State { } } -class ChecklistFilterConditionList extends StatelessWidget { +class ChecklistFilterConditionPBList extends StatelessWidget { final FilterInfo filterInfo; - const ChecklistFilterConditionList({ + const ChecklistFilterConditionPBList({ required this.filterInfo, Key? key, }) : super(key: key); @@ -130,7 +130,7 @@ class ChecklistFilterConditionList extends StatelessWidget { return PopoverActionList( asBarrier: true, direction: PopoverDirection.bottomWithCenterAligned, - actions: ChecklistFilterCondition.values + actions: ChecklistFilterConditionPB.values .map((action) => ConditionWrapper(action)) .toList(), buildChild: (controller) { @@ -150,7 +150,7 @@ class ChecklistFilterConditionList extends StatelessWidget { } class ConditionWrapper extends ActionCell { - final ChecklistFilterCondition inner; + final ChecklistFilterConditionPB inner; ConditionWrapper(this.inner); @@ -158,12 +158,12 @@ class ConditionWrapper extends ActionCell { String get name => inner.filterName; } -extension ChecklistFilterConditionExtension on ChecklistFilterCondition { +extension ChecklistFilterConditionPBExtension on ChecklistFilterConditionPB { String get filterName { switch (this) { - case ChecklistFilterCondition.IsComplete: + case ChecklistFilterConditionPB.IsComplete: return LocaleKeys.grid_checklistFilter_isComplete.tr(); - case ChecklistFilterCondition.IsIncomplete: + case ChecklistFilterConditionPB.IsIncomplete: return LocaleKeys.grid_checklistFilter_isIncomplted.tr(); default: return ""; diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/condition_list.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/condition_list.dart index 2ece1ce0d7..e8cc4a9ae6 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/condition_list.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/condition_list.dart @@ -12,7 +12,7 @@ import 'package:flutter/material.dart'; class SelectOptionFilterConditionList extends StatelessWidget { final FilterInfo filterInfo; final PopoverMutex popoverMutex; - final Function(SelectOptionCondition) onCondition; + final Function(SelectOptionConditionPB) onCondition; const SelectOptionFilterConditionList({ required this.filterInfo, required this.popoverMutex, @@ -27,7 +27,7 @@ class SelectOptionFilterConditionList extends StatelessWidget { asBarrier: true, mutex: popoverMutex, direction: PopoverDirection.bottomWithCenterAligned, - actions: SelectOptionCondition.values + actions: SelectOptionConditionPB.values .map( (action) => ConditionWrapper( action, @@ -59,7 +59,7 @@ class SelectOptionFilterConditionList extends StatelessWidget { } class ConditionWrapper extends ActionCell { - final SelectOptionCondition inner; + final SelectOptionConditionPB inner; final bool isSelected; final FieldType fieldType; @@ -84,16 +84,16 @@ class ConditionWrapper extends ActionCell { } } -extension SelectOptionConditionExtension on SelectOptionCondition { +extension SelectOptionConditionPBExtension on SelectOptionConditionPB { String get singleSelectFilterName { switch (this) { - case SelectOptionCondition.OptionIs: + case SelectOptionConditionPB.OptionIs: return LocaleKeys.grid_singleSelectOptionFilter_is.tr(); - case SelectOptionCondition.OptionIsEmpty: + case SelectOptionConditionPB.OptionIsEmpty: return LocaleKeys.grid_singleSelectOptionFilter_isEmpty.tr(); - case SelectOptionCondition.OptionIsNot: + case SelectOptionConditionPB.OptionIsNot: return LocaleKeys.grid_singleSelectOptionFilter_isNot.tr(); - case SelectOptionCondition.OptionIsNotEmpty: + case SelectOptionConditionPB.OptionIsNotEmpty: return LocaleKeys.grid_singleSelectOptionFilter_isNotEmpty.tr(); default: return ""; @@ -102,13 +102,13 @@ extension SelectOptionConditionExtension on SelectOptionCondition { String get multiSelectFilterName { switch (this) { - case SelectOptionCondition.OptionIs: + case SelectOptionConditionPB.OptionIs: return LocaleKeys.grid_multiSelectOptionFilter_contains.tr(); - case SelectOptionCondition.OptionIsEmpty: + case SelectOptionConditionPB.OptionIsEmpty: return LocaleKeys.grid_multiSelectOptionFilter_isEmpty.tr(); - case SelectOptionCondition.OptionIsNot: + case SelectOptionConditionPB.OptionIsNot: return LocaleKeys.grid_multiSelectOptionFilter_doesNotContain.tr(); - case SelectOptionCondition.OptionIsNotEmpty: + case SelectOptionConditionPB.OptionIsNotEmpty: return LocaleKeys.grid_multiSelectOptionFilter_isNotEmpty.tr(); default: return ""; diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/select_option.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/select_option.dart index 8f835a032d..3f0fe9a0b1 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/select_option.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/select_option/select_option.dart @@ -101,9 +101,9 @@ class _SelectOptionFilterEditorState extends State { SliverToBoxAdapter(child: _buildFilterPannel(context, state)), ]; - if (state.filter.condition != SelectOptionCondition.OptionIsEmpty && + if (state.filter.condition != SelectOptionConditionPB.OptionIsEmpty && state.filter.condition != - SelectOptionCondition.OptionIsNotEmpty) { + SelectOptionConditionPB.OptionIsNotEmpty) { slivers.add(const SliverToBoxAdapter(child: VSpace(4))); slivers.add( SliverToBoxAdapter( diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/text.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/text.dart index 1c51eba0ff..4c7ead3d81 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/text.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/text.dart @@ -64,8 +64,8 @@ class _TextFilterChoicechipState extends State { String _makeFilterDesc(TextFilterEditorState state) { String filterDesc = state.filter.condition.choicechipPrefix; - if (state.filter.condition == TextFilterCondition.TextIsEmpty || - state.filter.condition == TextFilterCondition.TextIsNotEmpty) { + if (state.filter.condition == TextFilterConditionPB.TextIsEmpty || + state.filter.condition == TextFilterConditionPB.TextIsNotEmpty) { return filterDesc; } @@ -98,8 +98,8 @@ class _TextFilterEditorState extends State { _buildFilterPannel(context, state), ]; - if (state.filter.condition != TextFilterCondition.TextIsEmpty && - state.filter.condition != TextFilterCondition.TextIsNotEmpty) { + if (state.filter.condition != TextFilterConditionPB.TextIsEmpty && + state.filter.condition != TextFilterConditionPB.TextIsNotEmpty) { children.add(const VSpace(4)); children.add(_buildFilterTextField(context, state)); } @@ -120,7 +120,7 @@ class _TextFilterEditorState extends State { children: [ FlowyText(state.filterInfo.fieldInfo.name), const HSpace(4), - TextFilterConditionList( + TextFilterConditionPBList( filterInfo: state.filterInfo, popoverMutex: popoverMutex, onCondition: (condition) { @@ -163,11 +163,11 @@ class _TextFilterEditorState extends State { } } -class TextFilterConditionList extends StatelessWidget { +class TextFilterConditionPBList extends StatelessWidget { final FilterInfo filterInfo; final PopoverMutex popoverMutex; - final Function(TextFilterCondition) onCondition; - const TextFilterConditionList({ + final Function(TextFilterConditionPB) onCondition; + const TextFilterConditionPBList({ required this.filterInfo, required this.popoverMutex, required this.onCondition, @@ -181,7 +181,7 @@ class TextFilterConditionList extends StatelessWidget { asBarrier: true, mutex: popoverMutex, direction: PopoverDirection.bottomWithCenterAligned, - actions: TextFilterCondition.values + actions: TextFilterConditionPB.values .map( (action) => ConditionWrapper( action, @@ -204,7 +204,7 @@ class TextFilterConditionList extends StatelessWidget { } class ConditionWrapper extends ActionCell { - final TextFilterCondition inner; + final TextFilterConditionPB inner; final bool isSelected; ConditionWrapper(this.inner, this.isSelected); @@ -222,24 +222,24 @@ class ConditionWrapper extends ActionCell { String get name => inner.filterName; } -extension TextFilterConditionExtension on TextFilterCondition { +extension TextFilterConditionPBExtension on TextFilterConditionPB { String get filterName { switch (this) { - case TextFilterCondition.Contains: + case TextFilterConditionPB.Contains: return LocaleKeys.grid_textFilter_contains.tr(); - case TextFilterCondition.DoesNotContain: + case TextFilterConditionPB.DoesNotContain: return LocaleKeys.grid_textFilter_doesNotContain.tr(); - case TextFilterCondition.EndsWith: + case TextFilterConditionPB.EndsWith: return LocaleKeys.grid_textFilter_endsWith.tr(); - case TextFilterCondition.Is: + case TextFilterConditionPB.Is: return LocaleKeys.grid_textFilter_is.tr(); - case TextFilterCondition.IsNot: + case TextFilterConditionPB.IsNot: return LocaleKeys.grid_textFilter_isNot.tr(); - case TextFilterCondition.StartsWith: + case TextFilterConditionPB.StartsWith: return LocaleKeys.grid_textFilter_startWith.tr(); - case TextFilterCondition.TextIsEmpty: + case TextFilterConditionPB.TextIsEmpty: return LocaleKeys.grid_textFilter_isEmpty.tr(); - case TextFilterCondition.TextIsNotEmpty: + case TextFilterConditionPB.TextIsNotEmpty: return LocaleKeys.grid_textFilter_isNotEmpty.tr(); default: return ""; @@ -248,17 +248,17 @@ extension TextFilterConditionExtension on TextFilterCondition { String get choicechipPrefix { switch (this) { - case TextFilterCondition.DoesNotContain: + case TextFilterConditionPB.DoesNotContain: return LocaleKeys.grid_textFilter_choicechipPrefix_isNot.tr(); - case TextFilterCondition.EndsWith: + case TextFilterConditionPB.EndsWith: return LocaleKeys.grid_textFilter_choicechipPrefix_endWith.tr(); - case TextFilterCondition.IsNot: + case TextFilterConditionPB.IsNot: return LocaleKeys.grid_textFilter_choicechipPrefix_isNot.tr(); - case TextFilterCondition.StartsWith: + case TextFilterConditionPB.StartsWith: return LocaleKeys.grid_textFilter_choicechipPrefix_startWith.tr(); - case TextFilterCondition.TextIsEmpty: + case TextFilterConditionPB.TextIsEmpty: return LocaleKeys.grid_textFilter_choicechipPrefix_isEmpty.tr(); - case TextFilterCondition.TextIsNotEmpty: + case TextFilterConditionPB.TextIsNotEmpty: return LocaleKeys.grid_textFilter_choicechipPrefix_isNotEmpty.tr(); default: return ""; diff --git a/frontend/app_flowy/test/bloc_test/grid_test/filter/create_filter_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/filter/create_filter_test.dart index db9dfdccab..292c17be1b 100644 --- a/frontend/app_flowy/test/bloc_test/grid_test/filter/create_filter_test.dart +++ b/frontend/app_flowy/test/bloc_test/grid_test/filter/create_filter_test.dart @@ -19,7 +19,7 @@ void main() { final textField = context.textFieldContext(); await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); @@ -32,7 +32,7 @@ void main() { final textField = context.textFieldContext(); await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); @@ -60,7 +60,7 @@ void main() { final textField = context.textFieldContext(); service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); @@ -81,7 +81,7 @@ void main() { final textField = context.textFieldContext(); await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); @@ -102,7 +102,7 @@ void main() { await gridResponseFuture(); await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsNotEmpty, + condition: TextFilterConditionPB.TextIsNotEmpty, content: ""); await gridResponseFuture(); assert(context.rowInfos.isEmpty); @@ -121,7 +121,7 @@ void main() { await gridResponseFuture(); await service.insertCheckboxFilter( fieldId: checkboxField.id, - condition: CheckboxFilterCondition.IsUnChecked, + condition: CheckboxFilterConditionPB.IsUnChecked, ); await gridResponseFuture(); assert(gridBloc.state.rowInfos.length == 3); @@ -140,7 +140,7 @@ void main() { await gridResponseFuture(); await service.insertCheckboxFilter( fieldId: checkboxField.id, - condition: CheckboxFilterCondition.IsChecked, + condition: CheckboxFilterConditionPB.IsChecked, ); await gridResponseFuture(); assert(gridBloc.state.rowInfos.isEmpty); diff --git a/frontend/app_flowy/test/bloc_test/grid_test/filter/edit_filter_field_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/filter/edit_filter_field_test.dart index d1e6263b24..2171ab948c 100644 --- a/frontend/app_flowy/test/bloc_test/grid_test/filter/edit_filter_field_test.dart +++ b/frontend/app_flowy/test/bloc_test/grid_test/filter/edit_filter_field_test.dart @@ -28,7 +28,7 @@ void main() { // Insert filter for the text field await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); assert(menuBloc.state.filters.length == 1); diff --git a/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_menu_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_menu_test.dart index 46a52fc834..d345ff4b2a 100644 --- a/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_menu_test.dart +++ b/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_menu_test.dart @@ -23,7 +23,7 @@ void main() { final textField = context.textFieldContext(); await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); assert(menuBloc.state.creatableFields.length == 2); @@ -42,7 +42,7 @@ void main() { // Create filter await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); @@ -51,11 +51,11 @@ void main() { await service.insertTextFilter( fieldId: textField.id, filterId: textFilter.filter.id, - condition: TextFilterCondition.Is, + condition: TextFilterConditionPB.Is, content: "ABC"); await gridResponseFuture(); assert(menuBloc.state.filters.first.textFilter()!.condition == - TextFilterCondition.Is); + TextFilterConditionPB.Is); assert(menuBloc.state.filters.first.textFilter()!.content == "ABC"); }); } diff --git a/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_checkbox_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_checkbox_test.dart index 60ba6580fe..9551c7a16c 100644 --- a/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_checkbox_test.dart +++ b/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_checkbox_test.dart @@ -23,7 +23,7 @@ void main() { final checkboxField = context.checkboxFieldContext(); await service.insertCheckboxFilter( fieldId: checkboxField.id, - condition: CheckboxFilterCondition.IsChecked, + condition: CheckboxFilterConditionPB.IsChecked, ); await gridResponseFuture(); assert(context.rowInfos.length == 1, @@ -42,7 +42,7 @@ void main() { final checkboxField = context.checkboxFieldContext(); await service.insertCheckboxFilter( fieldId: checkboxField.id, - condition: CheckboxFilterCondition.IsUnChecked, + condition: CheckboxFilterConditionPB.IsUnChecked, ); await gridResponseFuture(); assert(context.rowInfos.length == 2, diff --git a/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_text_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_text_test.dart index bea99b55e9..6192633d57 100644 --- a/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_text_test.dart +++ b/frontend/app_flowy/test/bloc_test/grid_test/filter/filter_rows_by_text_test.dart @@ -19,7 +19,7 @@ void main() { // create a new filter await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); assert(context.fieldController.filterInfos.length == 1, @@ -46,7 +46,7 @@ void main() { // create a new filter await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsNotEmpty, + condition: TextFilterConditionPB.TextIsNotEmpty, content: ""); await gridResponseFuture(); assert(context.rowInfos.length == 2, @@ -71,7 +71,7 @@ void main() { // create a new filter await service.insertTextFilter( fieldId: textField.id, - condition: TextFilterCondition.TextIsEmpty, + condition: TextFilterConditionPB.TextIsEmpty, content: ""); await gridResponseFuture(); assert(context.fieldController.filterInfos.length == 1, @@ -84,7 +84,7 @@ void main() { await service.insertTextFilter( fieldId: textField.id, filterId: textFilter.filter.id, - condition: TextFilterCondition.TextIsNotEmpty, + condition: TextFilterConditionPB.TextIsNotEmpty, content: ""); await gridResponseFuture(); assert(context.rowInfos.length == 2); @@ -106,7 +106,9 @@ void main() { final textField = context.textFieldContext(); // create a new filter await service.insertTextFilter( - fieldId: textField.id, condition: TextFilterCondition.Is, content: "A"); + fieldId: textField.id, + condition: TextFilterConditionPB.Is, + content: "A"); await gridResponseFuture(); assert(context.rowInfos.length == 1, "expect 1 but receive ${context.rowInfos.length}"); @@ -116,7 +118,7 @@ void main() { await service.insertTextFilter( fieldId: textField.id, filterId: textFilter.filter.id, - condition: TextFilterCondition.Is, + condition: TextFilterConditionPB.Is, content: "B"); await gridResponseFuture(); assert(context.rowInfos.length == 1); @@ -125,7 +127,7 @@ void main() { await service.insertTextFilter( fieldId: textField.id, filterId: textFilter.filter.id, - condition: TextFilterCondition.Is, + condition: TextFilterConditionPB.Is, content: "b"); await gridResponseFuture(); assert(context.rowInfos.length == 1); @@ -134,7 +136,7 @@ void main() { await service.insertTextFilter( fieldId: textField.id, filterId: textFilter.filter.id, - condition: TextFilterCondition.Is, + condition: TextFilterConditionPB.Is, content: "C"); await gridResponseFuture(); assert(context.rowInfos.isEmpty); diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs index 6476926b39..81d659f4e6 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checkbox_filter.rs @@ -5,35 +5,35 @@ use grid_rev_model::FilterRevision; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct CheckboxFilterPB { #[pb(index = 1)] - pub condition: CheckboxFilterCondition, + pub condition: CheckboxFilterConditionPB, } #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] -pub enum CheckboxFilterCondition { +pub enum CheckboxFilterConditionPB { IsChecked = 0, IsUnChecked = 1, } -impl std::convert::From for u32 { - fn from(value: CheckboxFilterCondition) -> Self { +impl std::convert::From for u32 { + fn from(value: CheckboxFilterConditionPB) -> Self { value as u32 } } -impl std::default::Default for CheckboxFilterCondition { +impl std::default::Default for CheckboxFilterConditionPB { fn default() -> Self { - CheckboxFilterCondition::IsChecked + CheckboxFilterConditionPB::IsChecked } } -impl std::convert::TryFrom for CheckboxFilterCondition { +impl std::convert::TryFrom for CheckboxFilterConditionPB { type Error = ErrorCode; fn try_from(value: u8) -> Result { match value { - 0 => Ok(CheckboxFilterCondition::IsChecked), - 1 => Ok(CheckboxFilterCondition::IsUnChecked), + 0 => Ok(CheckboxFilterConditionPB::IsChecked), + 1 => Ok(CheckboxFilterConditionPB::IsUnChecked), _ => Err(ErrorCode::InvalidData), } } @@ -42,7 +42,8 @@ impl std::convert::TryFrom for CheckboxFilterCondition { impl std::convert::From<&FilterRevision> for CheckboxFilterPB { fn from(rev: &FilterRevision) -> Self { CheckboxFilterPB { - condition: CheckboxFilterCondition::try_from(rev.condition).unwrap_or(CheckboxFilterCondition::IsChecked), + condition: CheckboxFilterConditionPB::try_from(rev.condition) + .unwrap_or(CheckboxFilterConditionPB::IsChecked), } } } diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs index a697ebbe11..bbd2480836 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/checklist_filter.rs @@ -5,35 +5,35 @@ use grid_rev_model::FilterRevision; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct ChecklistFilterPB { #[pb(index = 1)] - pub condition: ChecklistFilterCondition, + pub condition: ChecklistFilterConditionPB, } #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] -pub enum ChecklistFilterCondition { +pub enum ChecklistFilterConditionPB { IsComplete = 0, IsIncomplete = 1, } -impl std::convert::From for u32 { - fn from(value: ChecklistFilterCondition) -> Self { +impl std::convert::From for u32 { + fn from(value: ChecklistFilterConditionPB) -> Self { value as u32 } } -impl std::default::Default for ChecklistFilterCondition { +impl std::default::Default for ChecklistFilterConditionPB { fn default() -> Self { - ChecklistFilterCondition::IsIncomplete + ChecklistFilterConditionPB::IsIncomplete } } -impl std::convert::TryFrom for ChecklistFilterCondition { +impl std::convert::TryFrom for ChecklistFilterConditionPB { type Error = ErrorCode; fn try_from(value: u8) -> Result { match value { - 0 => Ok(ChecklistFilterCondition::IsComplete), - 1 => Ok(ChecklistFilterCondition::IsIncomplete), + 0 => Ok(ChecklistFilterConditionPB::IsComplete), + 1 => Ok(ChecklistFilterConditionPB::IsIncomplete), _ => Err(ErrorCode::InvalidData), } } @@ -42,8 +42,8 @@ impl std::convert::TryFrom for ChecklistFilterCondition { impl std::convert::From<&FilterRevision> for ChecklistFilterPB { fn from(rev: &FilterRevision) -> Self { ChecklistFilterPB { - condition: ChecklistFilterCondition::try_from(rev.condition) - .unwrap_or(ChecklistFilterCondition::IsIncomplete), + condition: ChecklistFilterConditionPB::try_from(rev.condition) + .unwrap_or(ChecklistFilterConditionPB::IsIncomplete), } } } diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs index 84fa43471f..b70b1b0944 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/date_filter.rs @@ -7,7 +7,7 @@ use std::str::FromStr; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct DateFilterPB { #[pb(index = 1)] - pub condition: DateFilterCondition, + pub condition: DateFilterConditionPB, #[pb(index = 2, one_of)] pub start: Option, @@ -20,19 +20,19 @@ pub struct DateFilterPB { } #[derive(Deserialize, Serialize, Default, Clone, Debug)] -pub struct DateFilterContent { +pub struct DateFilterContentPB { pub start: Option, pub end: Option, pub timestamp: Option, } -impl ToString for DateFilterContent { +impl ToString for DateFilterContentPB { fn to_string(&self) -> String { serde_json::to_string(self).unwrap() } } -impl FromStr for DateFilterContent { +impl FromStr for DateFilterContentPB { type Err = serde_json::Error; fn from_str(s: &str) -> Result { @@ -42,7 +42,7 @@ impl FromStr for DateFilterContent { #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] -pub enum DateFilterCondition { +pub enum DateFilterConditionPB { DateIs = 0, DateBefore = 1, DateAfter = 2, @@ -53,42 +53,42 @@ pub enum DateFilterCondition { DateIsNotEmpty = 7, } -impl std::convert::From for u32 { - fn from(value: DateFilterCondition) -> Self { +impl std::convert::From for u32 { + fn from(value: DateFilterConditionPB) -> Self { value as u32 } } -impl std::default::Default for DateFilterCondition { +impl std::default::Default for DateFilterConditionPB { fn default() -> Self { - DateFilterCondition::DateIs + DateFilterConditionPB::DateIs } } -impl std::convert::TryFrom for DateFilterCondition { +impl std::convert::TryFrom for DateFilterConditionPB { type Error = ErrorCode; fn try_from(value: u8) -> Result { match value { - 0 => Ok(DateFilterCondition::DateIs), - 1 => Ok(DateFilterCondition::DateBefore), - 2 => Ok(DateFilterCondition::DateAfter), - 3 => Ok(DateFilterCondition::DateOnOrBefore), - 4 => Ok(DateFilterCondition::DateOnOrAfter), - 5 => Ok(DateFilterCondition::DateWithIn), - 6 => Ok(DateFilterCondition::DateIsEmpty), + 0 => Ok(DateFilterConditionPB::DateIs), + 1 => Ok(DateFilterConditionPB::DateBefore), + 2 => Ok(DateFilterConditionPB::DateAfter), + 3 => Ok(DateFilterConditionPB::DateOnOrBefore), + 4 => Ok(DateFilterConditionPB::DateOnOrAfter), + 5 => Ok(DateFilterConditionPB::DateWithIn), + 6 => Ok(DateFilterConditionPB::DateIsEmpty), _ => Err(ErrorCode::InvalidData), } } } impl std::convert::From<&FilterRevision> for DateFilterPB { fn from(rev: &FilterRevision) -> Self { - let condition = DateFilterCondition::try_from(rev.condition).unwrap_or(DateFilterCondition::DateIs); + let condition = DateFilterConditionPB::try_from(rev.condition).unwrap_or(DateFilterConditionPB::DateIs); let mut filter = DateFilterPB { condition, ..Default::default() }; - if let Ok(content) = DateFilterContent::from_str(&rev.content) { + if let Ok(content) = DateFilterContentPB::from_str(&rev.content) { filter.start = content.start; filter.end = content.end; filter.timestamp = content.timestamp; diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs index 0eed1a9e1c..900059ccab 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/number_filter.rs @@ -5,7 +5,7 @@ use grid_rev_model::FilterRevision; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct NumberFilterPB { #[pb(index = 1)] - pub condition: NumberFilterCondition, + pub condition: NumberFilterConditionPB, #[pb(index = 2)] pub content: String, @@ -13,7 +13,7 @@ pub struct NumberFilterPB { #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] -pub enum NumberFilterCondition { +pub enum NumberFilterConditionPB { Equal = 0, NotEqual = 1, GreaterThan = 2, @@ -24,30 +24,30 @@ pub enum NumberFilterCondition { NumberIsNotEmpty = 7, } -impl std::default::Default for NumberFilterCondition { +impl std::default::Default for NumberFilterConditionPB { fn default() -> Self { - NumberFilterCondition::Equal + NumberFilterConditionPB::Equal } } -impl std::convert::From for u32 { - fn from(value: NumberFilterCondition) -> Self { +impl std::convert::From for u32 { + fn from(value: NumberFilterConditionPB) -> Self { value as u32 } } -impl std::convert::TryFrom for NumberFilterCondition { +impl std::convert::TryFrom for NumberFilterConditionPB { type Error = ErrorCode; fn try_from(n: u8) -> Result { match n { - 0 => Ok(NumberFilterCondition::Equal), - 1 => Ok(NumberFilterCondition::NotEqual), - 2 => Ok(NumberFilterCondition::GreaterThan), - 3 => Ok(NumberFilterCondition::LessThan), - 4 => Ok(NumberFilterCondition::GreaterThanOrEqualTo), - 5 => Ok(NumberFilterCondition::LessThanOrEqualTo), - 6 => Ok(NumberFilterCondition::NumberIsEmpty), - 7 => Ok(NumberFilterCondition::NumberIsNotEmpty), + 0 => Ok(NumberFilterConditionPB::Equal), + 1 => Ok(NumberFilterConditionPB::NotEqual), + 2 => Ok(NumberFilterConditionPB::GreaterThan), + 3 => Ok(NumberFilterConditionPB::LessThan), + 4 => Ok(NumberFilterConditionPB::GreaterThanOrEqualTo), + 5 => Ok(NumberFilterConditionPB::LessThanOrEqualTo), + 6 => Ok(NumberFilterConditionPB::NumberIsEmpty), + 7 => Ok(NumberFilterConditionPB::NumberIsNotEmpty), _ => Err(ErrorCode::InvalidData), } } @@ -56,7 +56,7 @@ impl std::convert::TryFrom for NumberFilterCondition { impl std::convert::From<&FilterRevision> for NumberFilterPB { fn from(rev: &FilterRevision) -> Self { NumberFilterPB { - condition: NumberFilterCondition::try_from(rev.condition).unwrap_or(NumberFilterCondition::Equal), + condition: NumberFilterConditionPB::try_from(rev.condition).unwrap_or(NumberFilterConditionPB::Equal), content: rev.content.clone(), } } diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs index d73ef933a1..9b182f9378 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs @@ -6,7 +6,7 @@ use grid_rev_model::FilterRevision; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct SelectOptionFilterPB { #[pb(index = 1)] - pub condition: SelectOptionCondition, + pub condition: SelectOptionConditionPB, #[pb(index = 2)] pub option_ids: Vec, @@ -14,34 +14,34 @@ pub struct SelectOptionFilterPB { #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] -pub enum SelectOptionCondition { +pub enum SelectOptionConditionPB { OptionIs = 0, OptionIsNot = 1, OptionIsEmpty = 2, OptionIsNotEmpty = 3, } -impl std::convert::From for u32 { - fn from(value: SelectOptionCondition) -> Self { +impl std::convert::From for u32 { + fn from(value: SelectOptionConditionPB) -> Self { value as u32 } } -impl std::default::Default for SelectOptionCondition { +impl std::default::Default for SelectOptionConditionPB { fn default() -> Self { - SelectOptionCondition::OptionIs + SelectOptionConditionPB::OptionIs } } -impl std::convert::TryFrom for SelectOptionCondition { +impl std::convert::TryFrom for SelectOptionConditionPB { type Error = ErrorCode; fn try_from(value: u8) -> Result { match value { - 0 => Ok(SelectOptionCondition::OptionIs), - 1 => Ok(SelectOptionCondition::OptionIsNot), - 2 => Ok(SelectOptionCondition::OptionIsEmpty), - 3 => Ok(SelectOptionCondition::OptionIsNotEmpty), + 0 => Ok(SelectOptionConditionPB::OptionIs), + 1 => Ok(SelectOptionConditionPB::OptionIsNot), + 2 => Ok(SelectOptionConditionPB::OptionIsEmpty), + 3 => Ok(SelectOptionConditionPB::OptionIsNotEmpty), _ => Err(ErrorCode::InvalidData), } } @@ -51,7 +51,7 @@ impl std::convert::From<&FilterRevision> for SelectOptionFilterPB { fn from(rev: &FilterRevision) -> Self { let ids = SelectOptionIds::from(rev.content.clone()); SelectOptionFilterPB { - condition: SelectOptionCondition::try_from(rev.condition).unwrap_or(SelectOptionCondition::OptionIs), + condition: SelectOptionConditionPB::try_from(rev.condition).unwrap_or(SelectOptionConditionPB::OptionIs), option_ids: ids.into_inner(), } } diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs index 57f1fcfdf5..f7a5770f2c 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/text_filter.rs @@ -5,7 +5,7 @@ use grid_rev_model::FilterRevision; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct TextFilterPB { #[pb(index = 1)] - pub condition: TextFilterCondition, + pub condition: TextFilterConditionPB, #[pb(index = 2)] pub content: String, @@ -13,7 +13,7 @@ pub struct TextFilterPB { #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] -pub enum TextFilterCondition { +pub enum TextFilterConditionPB { Is = 0, IsNot = 1, Contains = 2, @@ -24,31 +24,31 @@ pub enum TextFilterCondition { TextIsNotEmpty = 7, } -impl std::convert::From for u32 { - fn from(value: TextFilterCondition) -> Self { +impl std::convert::From for u32 { + fn from(value: TextFilterConditionPB) -> Self { value as u32 } } -impl std::default::Default for TextFilterCondition { +impl std::default::Default for TextFilterConditionPB { fn default() -> Self { - TextFilterCondition::Is + TextFilterConditionPB::Is } } -impl std::convert::TryFrom for TextFilterCondition { +impl std::convert::TryFrom for TextFilterConditionPB { type Error = ErrorCode; fn try_from(value: u8) -> Result { match value { - 0 => Ok(TextFilterCondition::Is), - 1 => Ok(TextFilterCondition::IsNot), - 2 => Ok(TextFilterCondition::Contains), - 3 => Ok(TextFilterCondition::DoesNotContain), - 4 => Ok(TextFilterCondition::StartsWith), - 5 => Ok(TextFilterCondition::EndsWith), - 6 => Ok(TextFilterCondition::TextIsEmpty), - 7 => Ok(TextFilterCondition::TextIsNotEmpty), + 0 => Ok(TextFilterConditionPB::Is), + 1 => Ok(TextFilterConditionPB::IsNot), + 2 => Ok(TextFilterConditionPB::Contains), + 3 => Ok(TextFilterConditionPB::DoesNotContain), + 4 => Ok(TextFilterConditionPB::StartsWith), + 5 => Ok(TextFilterConditionPB::EndsWith), + 6 => Ok(TextFilterConditionPB::TextIsEmpty), + 7 => Ok(TextFilterConditionPB::TextIsNotEmpty), _ => Err(ErrorCode::InvalidData), } } @@ -57,7 +57,7 @@ impl std::convert::TryFrom for TextFilterCondition { impl std::convert::From<&FilterRevision> for TextFilterPB { fn from(rev: &FilterRevision) -> Self { TextFilterPB { - condition: TextFilterCondition::try_from(rev.condition).unwrap_or(TextFilterCondition::Is), + condition: TextFilterConditionPB::try_from(rev.condition).unwrap_or(TextFilterConditionPB::Is), content: rev.content.clone(), } } diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs index 57c8db310e..4ad7cb8c18 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs @@ -1,6 +1,6 @@ use crate::entities::parser::NotEmptyStr; use crate::entities::{ - CheckboxFilterPB, ChecklistFilterPB, DateFilterContent, DateFilterPB, FieldType, NumberFilterPB, + CheckboxFilterPB, ChecklistFilterPB, DateFilterContentPB, DateFilterPB, FieldType, NumberFilterPB, SelectOptionFilterPB, TextFilterPB, }; use crate::services::field::SelectOptionIds; @@ -116,6 +116,7 @@ pub struct AlterFilterPayloadPB { #[pb(index = 2)] pub field_type: FieldType, + /// Create a new filter if the filter_id is None #[pb(index = 3, one_of)] pub filter_id: Option, @@ -169,7 +170,7 @@ impl TryInto for AlterFilterPayloadPB { FieldType::DateTime => { let filter = DateFilterPB::try_from(bytes).map_err(|_| ErrorCode::ProtobufSerde)?; condition = filter.condition as u8; - content = DateFilterContent { + content = DateFilterContentPB { start: filter.start, end: filter.end, timestamp: filter.timestamp, @@ -196,6 +197,7 @@ impl TryInto for AlterFilterPayloadPB { #[derive(Debug)] pub struct AlterFilterParams { pub field_id: String, + /// Create a new filter if the filter_id is None pub filter_id: Option, pub field_type: FieldTypeRevision, pub condition: u8, diff --git a/frontend/rust-lib/flowy-grid/src/entities/mod.rs b/frontend/rust-lib/flowy-grid/src/entities/mod.rs index 61b6b82b49..9f83360346 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/mod.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/mod.rs @@ -6,6 +6,7 @@ mod group_entities; pub mod parser; mod row_entities; pub mod setting_entities; +mod sort_entities; mod view_entities; pub use cell_entities::*; @@ -15,4 +16,5 @@ pub use grid_entities::*; pub use group_entities::*; pub use row_entities::*; pub use setting_entities::*; +pub use sort_entities::*; pub use view_entities::*; diff --git a/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs index 7e33acc0b7..6f7b73b5a8 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs @@ -1,7 +1,8 @@ use crate::entities::parser::NotEmptyStr; use crate::entities::{ - AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, DeleteFilterPayloadPB, DeleteGroupParams, - DeleteGroupPayloadPB, InsertGroupParams, InsertGroupPayloadPB, RepeatedFilterPB, RepeatedGroupConfigurationPB, + AlterFilterParams, AlterFilterPayloadPB, AlterSortParams, AlterSortPayloadPB, DeleteFilterParams, + DeleteFilterPayloadPB, DeleteGroupParams, DeleteGroupPayloadPB, DeleteSortParams, DeleteSortPayloadPB, + InsertGroupParams, InsertGroupPayloadPB, RepeatedFilterPB, RepeatedGroupConfigurationPB, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::ErrorCode; @@ -83,7 +84,7 @@ pub struct GridSettingChangesetPB { pub layout_type: GridLayout, #[pb(index = 3, one_of)] - pub insert_filter: Option, + pub alter_filter: Option, #[pb(index = 4, one_of)] pub delete_filter: Option, @@ -93,6 +94,12 @@ pub struct GridSettingChangesetPB { #[pb(index = 6, one_of)] pub delete_group: Option, + + #[pb(index = 7, one_of)] + pub alter_sort: Option, + + #[pb(index = 8, one_of)] + pub delete_sort: Option, } impl TryInto for GridSettingChangesetPB { @@ -103,7 +110,7 @@ impl TryInto for GridSettingChangesetPB { .map_err(|_| ErrorCode::ViewIdInvalid)? .0; - let insert_filter = match self.insert_filter { + let insert_filter = match self.alter_filter { None => None, Some(payload) => Some(payload.try_into()?), }; @@ -123,6 +130,16 @@ impl TryInto for GridSettingChangesetPB { None => None, }; + let alert_sort = match self.alter_sort { + None => None, + Some(payload) => Some(payload.try_into()?), + }; + + let delete_sort = match self.delete_sort { + None => None, + Some(payload) => Some(payload.try_into()?), + }; + Ok(GridSettingChangesetParams { grid_id: view_id, layout_type: self.layout_type.into(), @@ -130,6 +147,8 @@ impl TryInto for GridSettingChangesetPB { delete_filter, insert_group, delete_group, + alert_sort, + delete_sort, }) } } @@ -141,6 +160,8 @@ pub struct GridSettingChangesetParams { pub delete_filter: Option, pub insert_group: Option, pub delete_group: Option, + pub alert_sort: Option, + pub delete_sort: Option, } impl GridSettingChangesetParams { diff --git a/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs new file mode 100644 index 0000000000..87e8d5689f --- /dev/null +++ b/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs @@ -0,0 +1,118 @@ +use crate::entities::parser::NotEmptyStr; +use crate::entities::FieldType; +use crate::services::sort::SortType; +use bytes::Bytes; +use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_error::ErrorCode; +use grid_rev_model::{FieldRevision, FieldTypeRevision}; + +#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] +pub struct GridSortPB { + #[pb(index = 1)] + pub id: String, + + #[pb(index = 2)] + pub field_id: String, + + #[pb(index = 3)] + pub field_type: FieldType, + + #[pb(index = 4)] + pub condition: GridSortConditionPB, +} + +#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] +#[repr(u8)] +pub enum GridSortConditionPB { + Ascending = 0, + Descending = 1, +} +impl std::default::Default for GridSortConditionPB { + fn default() -> Self { + Self::Ascending + } +} +#[derive(ProtoBuf, Debug, Default, Clone)] +pub struct AlterSortPayloadPB { + #[pb(index = 1)] + pub field_id: String, + + #[pb(index = 2)] + pub field_type: FieldType, + + /// Create a new filter if the filter_id is None + #[pb(index = 3, one_of)] + pub sort_id: Option, + + #[pb(index = 4)] + pub condition: GridSortConditionPB, +} + +impl TryInto for AlterSortPayloadPB { + type Error = ErrorCode; + + fn try_into(self) -> Result { + let field_id = NotEmptyStr::parse(self.field_id) + .map_err(|_| ErrorCode::FieldIdIsEmpty)? + .0; + let sort_id = match self.sort_id { + None => None, + Some(filter_id) => Some(NotEmptyStr::parse(filter_id).map_err(|_| ErrorCode::FilterIdIsEmpty)?.0), + }; + + Ok(AlterSortParams { + field_id, + sort_id, + field_type: self.field_type.into(), + condition: self.condition as u8, + }) + } +} + +#[derive(Debug)] +pub struct AlterSortParams { + pub field_id: String, + /// Create a new sort if the sort is None + pub sort_id: Option, + pub field_type: FieldTypeRevision, + pub condition: u8, +} + +#[derive(ProtoBuf, Debug, Default, Clone)] +pub struct DeleteSortPayloadPB { + #[pb(index = 1)] + pub field_id: String, + + #[pb(index = 2)] + pub field_type: FieldType, + + #[pb(index = 3)] + pub sort_id: String, +} + +impl TryInto for DeleteSortPayloadPB { + type Error = ErrorCode; + + fn try_into(self) -> Result { + let field_id = NotEmptyStr::parse(self.field_id) + .map_err(|_| ErrorCode::FieldIdIsEmpty)? + .0; + + let sort_id = NotEmptyStr::parse(self.sort_id) + .map_err(|_| ErrorCode::UnexpectedEmptyString)? + .0; + + let sort_type = SortType { + field_id, + field_type: self.field_type, + }; + + Ok(DeleteSortParams { sort_type, sort_id }) + } +} + +#[derive(Debug)] +pub struct DeleteSortParams { + pub sort_type: SortType, + pub sort_id: String, +} diff --git a/frontend/rust-lib/flowy-grid/src/event_handler.rs b/frontend/rust-lib/flowy-grid/src/event_handler.rs index 1a54350b48..52259eef6e 100644 --- a/frontend/rust-lib/flowy-grid/src/event_handler.rs +++ b/frontend/rust-lib/flowy-grid/src/event_handler.rs @@ -58,6 +58,13 @@ pub(crate) async fn update_grid_setting_handler( if let Some(delete_filter) = params.delete_filter { let _ = editor.delete_filter(delete_filter).await?; } + + if let Some(alter_sort) = params.alert_sort { + let _ = editor.create_or_update_sort(alter_sort).await?; + } + if let Some(delete_sort) = params.delete_sort { + let _ = editor.delete_sort(delete_sort).await?; + } Ok(()) } diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_filter.rs index c6b6c4c138..0c0171ef67 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_filter.rs @@ -1,4 +1,4 @@ -use crate::entities::{CheckboxFilterCondition, CheckboxFilterPB}; +use crate::entities::{CheckboxFilterConditionPB, CheckboxFilterPB}; use crate::services::cell::{CellData, CellFilterOperation, TypeCellData}; use crate::services::field::{CheckboxCellData, CheckboxTypeOptionPB}; use flowy_error::FlowyResult; @@ -7,8 +7,8 @@ impl CheckboxFilterPB { pub fn is_visible(&self, cell_data: &CheckboxCellData) -> bool { let is_check = cell_data.is_check(); match self.condition { - CheckboxFilterCondition::IsChecked => is_check, - CheckboxFilterCondition::IsUnChecked => !is_check, + CheckboxFilterConditionPB::IsChecked => is_check, + CheckboxFilterConditionPB::IsUnChecked => !is_check, } } } @@ -26,14 +26,14 @@ impl CellFilterOperation for CheckboxTypeOptionPB { #[cfg(test)] mod tests { - use crate::entities::{CheckboxFilterCondition, CheckboxFilterPB}; + use crate::entities::{CheckboxFilterConditionPB, CheckboxFilterPB}; use crate::services::field::CheckboxCellData; use std::str::FromStr; #[test] fn checkbox_filter_is_check_test() { let checkbox_filter = CheckboxFilterPB { - condition: CheckboxFilterCondition::IsChecked, + condition: CheckboxFilterConditionPB::IsChecked, }; for (value, visible) in [("true", true), ("yes", true), ("false", false), ("no", false)] { let data = CheckboxCellData::from_str(value).unwrap(); @@ -44,7 +44,7 @@ mod tests { #[test] fn checkbox_filter_is_uncheck_test() { let checkbox_filter = CheckboxFilterPB { - condition: CheckboxFilterCondition::IsUnChecked, + condition: CheckboxFilterConditionPB::IsUnChecked, }; for (value, visible) in [("false", true), ("no", true), ("true", false), ("yes", false)] { let data = CheckboxCellData::from_str(value).unwrap(); diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_filter.rs index 4785fcc5ae..896aa94d3e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_filter.rs @@ -1,4 +1,4 @@ -use crate::entities::{DateFilterCondition, DateFilterPB}; +use crate::entities::{DateFilterConditionPB, DateFilterPB}; use crate::services::cell::{CellData, CellFilterOperation, TypeCellData}; use crate::services::field::{DateTimestamp, DateTypeOptionPB}; use chrono::NaiveDateTime; @@ -7,13 +7,13 @@ use flowy_error::FlowyResult; impl DateFilterPB { pub fn is_visible>>(&self, cell_timestamp: T) -> bool { match cell_timestamp.into() { - None => DateFilterCondition::DateIsEmpty == self.condition, + None => DateFilterConditionPB::DateIsEmpty == self.condition, Some(timestamp) => { match self.condition { - DateFilterCondition::DateIsNotEmpty => { + DateFilterConditionPB::DateIsNotEmpty => { return true; } - DateFilterCondition::DateIsEmpty => { + DateFilterConditionPB::DateIsEmpty => { return false; } _ => {} @@ -45,11 +45,11 @@ impl DateFilterPB { // We assume that the cell_timestamp doesn't contain hours, just day. match self.condition { - DateFilterCondition::DateIs => cell_date == expected_date, - DateFilterCondition::DateBefore => cell_date < expected_date, - DateFilterCondition::DateAfter => cell_date > expected_date, - DateFilterCondition::DateOnOrBefore => cell_date <= expected_date, - DateFilterCondition::DateOnOrAfter => cell_date >= expected_date, + DateFilterConditionPB::DateIs => cell_date == expected_date, + DateFilterConditionPB::DateBefore => cell_date < expected_date, + DateFilterConditionPB::DateAfter => cell_date > expected_date, + DateFilterConditionPB::DateOnOrBefore => cell_date <= expected_date, + DateFilterConditionPB::DateOnOrAfter => cell_date >= expected_date, _ => true, } } @@ -73,12 +73,12 @@ impl CellFilterOperation for DateTypeOptionPB { #[cfg(test)] mod tests { #![allow(clippy::all)] - use crate::entities::{DateFilterCondition, DateFilterPB}; + use crate::entities::{DateFilterConditionPB, DateFilterPB}; #[test] fn date_filter_is_test() { let filter = DateFilterPB { - condition: DateFilterCondition::DateIs, + condition: DateFilterConditionPB::DateIs, timestamp: Some(1668387885), end: None, start: None, @@ -91,7 +91,7 @@ mod tests { #[test] fn date_filter_before_test() { let filter = DateFilterPB { - condition: DateFilterCondition::DateBefore, + condition: DateFilterConditionPB::DateBefore, timestamp: Some(1668387885), start: None, end: None, @@ -105,7 +105,7 @@ mod tests { #[test] fn date_filter_before_or_on_test() { let filter = DateFilterPB { - condition: DateFilterCondition::DateOnOrBefore, + condition: DateFilterConditionPB::DateOnOrBefore, timestamp: Some(1668387885), start: None, end: None, @@ -118,7 +118,7 @@ mod tests { #[test] fn date_filter_after_test() { let filter = DateFilterPB { - condition: DateFilterCondition::DateAfter, + condition: DateFilterConditionPB::DateAfter, timestamp: Some(1668387885), start: None, end: None, @@ -132,7 +132,7 @@ mod tests { #[test] fn date_filter_within_test() { let filter = DateFilterPB { - condition: DateFilterCondition::DateWithIn, + condition: DateFilterConditionPB::DateWithIn, start: Some(1668272685), // 11/13 end: Some(1668618285), // 11/17 timestamp: None, @@ -150,7 +150,7 @@ mod tests { #[test] fn date_filter_is_empty_test() { let filter = DateFilterPB { - condition: DateFilterCondition::DateIsEmpty, + condition: DateFilterConditionPB::DateIsEmpty, start: None, end: None, timestamp: None, diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_filter.rs index 2fdf4bab97..c3d3d4bc39 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_filter.rs @@ -1,4 +1,4 @@ -use crate::entities::{NumberFilterCondition, NumberFilterPB}; +use crate::entities::{NumberFilterConditionPB, NumberFilterPB}; use crate::services::cell::{CellFilterOperation, TypeCellData}; use crate::services::field::{NumberCellData, NumberTypeOptionPB}; use flowy_error::FlowyResult; @@ -10,10 +10,10 @@ impl NumberFilterPB { pub fn is_visible(&self, num_cell_data: &NumberCellData) -> bool { if self.content.is_empty() { match self.condition { - NumberFilterCondition::NumberIsEmpty => { + NumberFilterConditionPB::NumberIsEmpty => { return num_cell_data.is_empty(); } - NumberFilterCondition::NumberIsNotEmpty => { + NumberFilterConditionPB::NumberIsNotEmpty => { return !num_cell_data.is_empty(); } _ => {} @@ -24,12 +24,12 @@ impl NumberFilterPB { Some(cell_decimal) => { let decimal = Decimal::from_str(&self.content).unwrap_or_else(|_| Decimal::zero()); match self.condition { - NumberFilterCondition::Equal => cell_decimal == &decimal, - NumberFilterCondition::NotEqual => cell_decimal != &decimal, - NumberFilterCondition::GreaterThan => cell_decimal > &decimal, - NumberFilterCondition::LessThan => cell_decimal < &decimal, - NumberFilterCondition::GreaterThanOrEqualTo => cell_decimal >= &decimal, - NumberFilterCondition::LessThanOrEqualTo => cell_decimal <= &decimal, + NumberFilterConditionPB::Equal => cell_decimal == &decimal, + NumberFilterConditionPB::NotEqual => cell_decimal != &decimal, + NumberFilterConditionPB::GreaterThan => cell_decimal > &decimal, + NumberFilterConditionPB::LessThan => cell_decimal < &decimal, + NumberFilterConditionPB::GreaterThanOrEqualTo => cell_decimal >= &decimal, + NumberFilterConditionPB::LessThanOrEqualTo => cell_decimal <= &decimal, _ => true, } } @@ -52,12 +52,12 @@ impl CellFilterOperation for NumberTypeOptionPB { #[cfg(test)] mod tests { - use crate::entities::{NumberFilterCondition, NumberFilterPB}; + use crate::entities::{NumberFilterConditionPB, NumberFilterPB}; use crate::services::field::{NumberCellData, NumberFormat}; #[test] fn number_filter_equal_test() { let number_filter = NumberFilterPB { - condition: NumberFilterCondition::Equal, + condition: NumberFilterConditionPB::Equal, content: "123".to_owned(), }; @@ -75,7 +75,7 @@ mod tests { #[test] fn number_filter_greater_than_test() { let number_filter = NumberFilterPB { - condition: NumberFilterCondition::GreaterThan, + condition: NumberFilterConditionPB::GreaterThan, content: "12".to_owned(), }; for (num_str, visible) in [("123", true), ("10", false), ("30", true), ("", false)] { @@ -87,7 +87,7 @@ mod tests { #[test] fn number_filter_less_than_test() { let number_filter = NumberFilterPB { - condition: NumberFilterCondition::LessThan, + condition: NumberFilterConditionPB::LessThan, content: "100".to_owned(), }; for (num_str, visible) in [("12", true), ("1234", false), ("30", true), ("", false)] { diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_filter.rs index 913d1e353a..2f10547a81 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/checklist_filter.rs @@ -1,4 +1,4 @@ -use crate::entities::{ChecklistFilterCondition, ChecklistFilterPB}; +use crate::entities::{ChecklistFilterConditionPB, ChecklistFilterPB}; use crate::services::field::{SelectOptionPB, SelectedSelectOptions}; impl ChecklistFilterPB { @@ -15,7 +15,7 @@ impl ChecklistFilterPB { .collect::>(); match self.condition { - ChecklistFilterCondition::IsComplete => { + ChecklistFilterConditionPB::IsComplete => { if selected_option_ids.is_empty() { return false; } @@ -23,7 +23,7 @@ impl ChecklistFilterPB { all_option_ids.retain(|option_id| !selected_option_ids.contains(option_id)); all_option_ids.is_empty() } - ChecklistFilterCondition::IsIncomplete => { + ChecklistFilterConditionPB::IsIncomplete => { if selected_option_ids.is_empty() { return true; } diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs index a9c0bdde93..22bc719b62 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs @@ -1,6 +1,6 @@ #![allow(clippy::needless_collect)] -use crate::entities::{ChecklistFilterPB, FieldType, SelectOptionCondition, SelectOptionFilterPB}; +use crate::entities::{ChecklistFilterPB, FieldType, SelectOptionConditionPB, SelectOptionFilterPB}; use crate::services::cell::{CellFilterOperation, TypeCellData}; use crate::services::field::{ChecklistTypeOptionPB, MultiSelectTypeOptionPB, SingleSelectTypeOptionPB}; use crate::services::field::{SelectTypeOptionSharedAction, SelectedSelectOptions}; @@ -10,7 +10,7 @@ impl SelectOptionFilterPB { pub fn is_visible(&self, selected_options: &SelectedSelectOptions, field_type: FieldType) -> bool { let selected_option_ids: Vec<&String> = selected_options.options.iter().map(|option| &option.id).collect(); match self.condition { - SelectOptionCondition::OptionIs => match field_type { + SelectOptionConditionPB::OptionIs => match field_type { FieldType::SingleSelect => { if self.option_ids.is_empty() { return true; @@ -43,7 +43,7 @@ impl SelectOptionFilterPB { } _ => false, }, - SelectOptionCondition::OptionIsNot => match field_type { + SelectOptionConditionPB::OptionIsNot => match field_type { FieldType::SingleSelect => { if self.option_ids.is_empty() { return true; @@ -72,8 +72,8 @@ impl SelectOptionFilterPB { } _ => false, }, - SelectOptionCondition::OptionIsEmpty => selected_option_ids.is_empty(), - SelectOptionCondition::OptionIsNotEmpty => !selected_option_ids.is_empty(), + SelectOptionConditionPB::OptionIsEmpty => selected_option_ids.is_empty(), + SelectOptionConditionPB::OptionIsNotEmpty => !selected_option_ids.is_empty(), } } } @@ -112,14 +112,14 @@ impl CellFilterOperation for ChecklistTypeOptionPB { #[cfg(test)] mod tests { #![allow(clippy::all)] - use crate::entities::{FieldType, SelectOptionCondition, SelectOptionFilterPB}; + use crate::entities::{FieldType, SelectOptionConditionPB, SelectOptionFilterPB}; use crate::services::field::selection_type_option::{SelectOptionPB, SelectedSelectOptions}; #[test] fn select_option_filter_is_empty_test() { let option = SelectOptionPB::new("A"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIsEmpty, + condition: SelectOptionConditionPB::OptionIsEmpty, option_ids: vec![], }; @@ -152,7 +152,7 @@ mod tests { let option_1 = SelectOptionPB::new("A"); let option_2 = SelectOptionPB::new("B"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIsNotEmpty, + condition: SelectOptionConditionPB::OptionIsNotEmpty, option_ids: vec![option_1.id.clone(), option_2.id.clone()], }; @@ -191,7 +191,7 @@ mod tests { let option_2 = SelectOptionPB::new("B"); let option_3 = SelectOptionPB::new("C"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIsNot, + condition: SelectOptionConditionPB::OptionIsNot, option_ids: vec![option_1.id.clone(), option_2.id.clone()], }; @@ -215,7 +215,7 @@ mod tests { let option_3 = SelectOptionPB::new("c"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![option_1.id.clone()], }; for (options, is_visible) in vec![ @@ -237,7 +237,7 @@ mod tests { let option_2 = SelectOptionPB::new("B"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![], }; for (options, is_visible) in vec![ @@ -258,7 +258,7 @@ mod tests { let option_2 = SelectOptionPB::new("B"); let option_3 = SelectOptionPB::new("C"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIsNot, + condition: SelectOptionConditionPB::OptionIsNot, option_ids: vec![option_1.id.clone(), option_2.id.clone()], }; @@ -283,7 +283,7 @@ mod tests { let option_3 = SelectOptionPB::new("C"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![option_1.id.clone(), option_2.id.clone()], }; for (options, is_visible) in vec![ @@ -305,7 +305,7 @@ mod tests { let option_1 = SelectOptionPB::new("A"); let filter = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![], }; for (options, is_visible) in vec![(vec![option_1.clone()], true), (vec![], true)] { diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_filter.rs index 7e6ca21474..226f2a436f 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_filter.rs @@ -1,4 +1,4 @@ -use crate::entities::{TextFilterCondition, TextFilterPB}; +use crate::entities::{TextFilterConditionPB, TextFilterPB}; use crate::services::cell::{CellData, CellFilterOperation, TypeCellData}; use crate::services::field::{RichTextTypeOptionPB, TextCellData}; use flowy_error::FlowyResult; @@ -8,14 +8,14 @@ impl TextFilterPB { let cell_data = cell_data.as_ref().to_lowercase(); let content = &self.content.to_lowercase(); match self.condition { - TextFilterCondition::Is => &cell_data == content, - TextFilterCondition::IsNot => &cell_data != content, - TextFilterCondition::Contains => cell_data.contains(content), - TextFilterCondition::DoesNotContain => !cell_data.contains(content), - TextFilterCondition::StartsWith => cell_data.starts_with(content), - TextFilterCondition::EndsWith => cell_data.ends_with(content), - TextFilterCondition::TextIsEmpty => cell_data.is_empty(), - TextFilterCondition::TextIsNotEmpty => !cell_data.is_empty(), + TextFilterConditionPB::Is => &cell_data == content, + TextFilterConditionPB::IsNot => &cell_data != content, + TextFilterConditionPB::Contains => cell_data.contains(content), + TextFilterConditionPB::DoesNotContain => !cell_data.contains(content), + TextFilterConditionPB::StartsWith => cell_data.starts_with(content), + TextFilterConditionPB::EndsWith => cell_data.ends_with(content), + TextFilterConditionPB::TextIsEmpty => cell_data.is_empty(), + TextFilterConditionPB::TextIsNotEmpty => !cell_data.is_empty(), } } } @@ -34,12 +34,12 @@ impl CellFilterOperation for RichTextTypeOptionPB { #[cfg(test)] mod tests { #![allow(clippy::all)] - use crate::entities::{TextFilterCondition, TextFilterPB}; + use crate::entities::{TextFilterConditionPB, TextFilterPB}; #[test] fn text_filter_equal_test() { let text_filter = TextFilterPB { - condition: TextFilterCondition::Is, + condition: TextFilterConditionPB::Is, content: "appflowy".to_owned(), }; @@ -51,7 +51,7 @@ mod tests { #[test] fn text_filter_start_with_test() { let text_filter = TextFilterPB { - condition: TextFilterCondition::StartsWith, + condition: TextFilterConditionPB::StartsWith, content: "appflowy".to_owned(), }; @@ -63,7 +63,7 @@ mod tests { #[test] fn text_filter_end_with_test() { let text_filter = TextFilterPB { - condition: TextFilterCondition::EndsWith, + condition: TextFilterConditionPB::EndsWith, content: "appflowy".to_owned(), }; @@ -74,7 +74,7 @@ mod tests { #[test] fn text_filter_empty_test() { let text_filter = TextFilterPB { - condition: TextFilterCondition::TextIsEmpty, + condition: TextFilterConditionPB::TextIsEmpty, content: "appflowy".to_owned(), }; @@ -84,7 +84,7 @@ mod tests { #[test] fn text_filter_contain_test() { let text_filter = TextFilterPB { - condition: TextFilterCondition::Contains, + condition: TextFilterConditionPB::Contains, content: "appflowy".to_owned(), }; diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs index c8c67d3852..2e02bb238b 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -588,6 +588,14 @@ impl GridRevisionEditor { Ok(()) } + pub async fn delete_sort(&self, params: DeleteSortParams) -> FlowyResult<()> { + todo!() + } + + pub async fn create_or_update_sort(&self, params: AlterSortParams) -> FlowyResult<()> { + todo!() + } + pub async fn move_row(&self, params: MoveRowParams) -> FlowyResult<()> { let MoveRowParams { view_id: _, diff --git a/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs b/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs index 221069eb5a..8294bf0e7e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/view_editor/editor.rs @@ -133,6 +133,7 @@ impl GridViewRevisionEditor { self.rev_manager.generate_snapshot().await; self.rev_manager.close().await; self.filter_controller.read().await.close().await; + self.sort_controller.read().await.close().await; } pub async fn handle_block_event(&self, event: Cow<'_, GridBlockEvent>) { diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checkbox_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checkbox_filter_test.rs index 0a28bb5d15..5980c39404 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checkbox_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checkbox_filter_test.rs @@ -1,6 +1,6 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::GridFilterTest; -use flowy_grid::entities::CheckboxFilterCondition; +use flowy_grid::entities::CheckboxFilterConditionPB; #[tokio::test] async fn grid_filter_checkbox_is_check_test() { @@ -9,7 +9,7 @@ async fn grid_filter_checkbox_is_check_test() { // The initial number of checked is 2 let scripts = vec![ CreateCheckboxFilter { - condition: CheckboxFilterCondition::IsChecked, + condition: CheckboxFilterConditionPB::IsChecked, }, AssertFilterChanged { visible_row_len: 0, @@ -24,7 +24,7 @@ async fn grid_filter_checkbox_is_uncheck_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateCheckboxFilter { - condition: CheckboxFilterCondition::IsUnChecked, + condition: CheckboxFilterConditionPB::IsUnChecked, }, AssertNumberOfVisibleRows { expected: 3 }, ]; diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checklist_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checklist_filter_test.rs index a89a93cdb4..05b4754ff7 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checklist_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/checklist_filter_test.rs @@ -1,13 +1,13 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::GridFilterTest; -use flowy_grid::entities::ChecklistFilterCondition; +use flowy_grid::entities::ChecklistFilterConditionPB; #[tokio::test] async fn grid_filter_checklist_is_incomplete_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateChecklistFilter { - condition: ChecklistFilterCondition::IsIncomplete, + condition: ChecklistFilterConditionPB::IsIncomplete, }, AssertNumberOfVisibleRows { expected: 4 }, ]; @@ -19,7 +19,7 @@ async fn grid_filter_checklist_is_complete_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateChecklistFilter { - condition: ChecklistFilterCondition::IsComplete, + condition: ChecklistFilterConditionPB::IsComplete, }, AssertNumberOfVisibleRows { expected: 1 }, ]; diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/date_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/date_filter_test.rs index b36aedf19f..8be96ad4f0 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/date_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/date_filter_test.rs @@ -1,13 +1,13 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::GridFilterTest; -use flowy_grid::entities::DateFilterCondition; +use flowy_grid::entities::DateFilterConditionPB; #[tokio::test] async fn grid_filter_date_is_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateDateFilter { - condition: DateFilterCondition::DateIs, + condition: DateFilterConditionPB::DateIs, start: None, end: None, timestamp: Some(1647251762), @@ -22,7 +22,7 @@ async fn grid_filter_date_after_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateDateFilter { - condition: DateFilterCondition::DateAfter, + condition: DateFilterConditionPB::DateAfter, start: None, end: None, timestamp: Some(1647251762), @@ -37,7 +37,7 @@ async fn grid_filter_date_on_or_after_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateDateFilter { - condition: DateFilterCondition::DateOnOrAfter, + condition: DateFilterConditionPB::DateOnOrAfter, start: None, end: None, timestamp: Some(1668359085), @@ -52,7 +52,7 @@ async fn grid_filter_date_on_or_before_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateDateFilter { - condition: DateFilterCondition::DateOnOrBefore, + condition: DateFilterConditionPB::DateOnOrBefore, start: None, end: None, timestamp: Some(1668359085), @@ -67,7 +67,7 @@ async fn grid_filter_date_within_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateDateFilter { - condition: DateFilterCondition::DateWithIn, + condition: DateFilterConditionPB::DateWithIn, start: Some(1647251762), end: Some(1668704685), timestamp: None, diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/number_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/number_filter_test.rs index d39649c1af..a4bb99e4e0 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/number_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/number_filter_test.rs @@ -1,13 +1,13 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::GridFilterTest; -use flowy_grid::entities::NumberFilterCondition; +use flowy_grid::entities::NumberFilterConditionPB; #[tokio::test] async fn grid_filter_number_is_equal_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateNumberFilter { - condition: NumberFilterCondition::Equal, + condition: NumberFilterConditionPB::Equal, content: "1".to_string(), }, AssertNumberOfVisibleRows { expected: 1 }, @@ -20,7 +20,7 @@ async fn grid_filter_number_is_less_than_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateNumberFilter { - condition: NumberFilterCondition::LessThan, + condition: NumberFilterConditionPB::LessThan, content: "3".to_string(), }, AssertNumberOfVisibleRows { expected: 2 }, @@ -34,7 +34,7 @@ async fn grid_filter_number_is_less_than_test2() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateNumberFilter { - condition: NumberFilterCondition::LessThan, + condition: NumberFilterConditionPB::LessThan, content: "$3".to_string(), }, AssertNumberOfVisibleRows { expected: 2 }, @@ -47,7 +47,7 @@ async fn grid_filter_number_is_less_than_or_equal_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateNumberFilter { - condition: NumberFilterCondition::LessThanOrEqualTo, + condition: NumberFilterConditionPB::LessThanOrEqualTo, content: "3".to_string(), }, AssertNumberOfVisibleRows { expected: 3 }, @@ -60,7 +60,7 @@ async fn grid_filter_number_is_empty_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateNumberFilter { - condition: NumberFilterCondition::NumberIsEmpty, + condition: NumberFilterConditionPB::NumberIsEmpty, content: "".to_string(), }, AssertNumberOfVisibleRows { expected: 1 }, @@ -73,7 +73,7 @@ async fn grid_filter_number_is_not_empty_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateNumberFilter { - condition: NumberFilterCondition::NumberIsNotEmpty, + condition: NumberFilterConditionPB::NumberIsNotEmpty, content: "".to_string(), }, AssertNumberOfVisibleRows { expected: 4 }, diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs index 49727674eb..89e0658d54 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs @@ -6,7 +6,7 @@ use std::time::Duration; use bytes::Bytes; use futures::TryFutureExt; -use flowy_grid::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, GridLayout, GridSettingChangesetParams, GridSettingPB, RowPB, TextFilterCondition, FieldType, NumberFilterCondition, CheckboxFilterCondition, DateFilterCondition, DateFilterContent, SelectOptionCondition, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterCondition, ChecklistFilterPB}; +use flowy_grid::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, GridLayout, GridSettingChangesetParams, GridSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB}; use flowy_grid::services::field::{SelectOptionCellChangeset, SelectOptionIds}; use flowy_grid::services::setting::GridSettingChangesetBuilder; use grid_rev_model::{FieldRevision, FieldTypeRevision}; @@ -28,37 +28,37 @@ pub enum FilterScript { payload: AlterFilterPayloadPB, }, CreateTextFilter { - condition: TextFilterCondition, + condition: TextFilterConditionPB, content: String, }, UpdateTextFilter { filter: FilterPB, - condition: TextFilterCondition, + condition: TextFilterConditionPB, content: String, }, CreateNumberFilter { - condition: NumberFilterCondition, + condition: NumberFilterConditionPB, content: String, }, CreateCheckboxFilter { - condition: CheckboxFilterCondition, + condition: CheckboxFilterConditionPB, }, CreateDateFilter{ - condition: DateFilterCondition, + condition: DateFilterConditionPB, start: Option, end: Option, timestamp: Option, }, CreateMultiSelectFilter { - condition: SelectOptionCondition, + condition: SelectOptionConditionPB, option_ids: Vec, }, CreateSingleSelectFilter { - condition: SelectOptionCondition, + condition: SelectOptionConditionPB, option_ids: Vec, }, CreateChecklistFilter { - condition: ChecklistFilterCondition, + condition: ChecklistFilterConditionPB, }, AssertFilterCount { count: i32, diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs index fb654f887b..53c7962ece 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs @@ -1,13 +1,13 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::GridFilterTest; -use flowy_grid::entities::{FieldType, SelectOptionCondition}; +use flowy_grid::entities::{FieldType, SelectOptionConditionPB}; #[tokio::test] async fn grid_filter_multi_select_is_empty_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateMultiSelectFilter { - condition: SelectOptionCondition::OptionIsEmpty, + condition: SelectOptionConditionPB::OptionIsEmpty, option_ids: vec![], }, AssertNumberOfVisibleRows { expected: 2 }, @@ -20,7 +20,7 @@ async fn grid_filter_multi_select_is_not_empty_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateMultiSelectFilter { - condition: SelectOptionCondition::OptionIsNotEmpty, + condition: SelectOptionConditionPB::OptionIsNotEmpty, option_ids: vec![], }, AssertNumberOfVisibleRows { expected: 3 }, @@ -35,7 +35,7 @@ async fn grid_filter_multi_select_is_test() { let mut options = test.get_multi_select_type_option(&field_rev.id); let scripts = vec![ CreateMultiSelectFilter { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![options.remove(0).id, options.remove(0).id], }, AssertNumberOfVisibleRows { expected: 3 }, @@ -50,7 +50,7 @@ async fn grid_filter_multi_select_is_test2() { let mut options = test.get_multi_select_type_option(&field_rev.id); let scripts = vec![ CreateMultiSelectFilter { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![options.remove(1).id], }, AssertNumberOfVisibleRows { expected: 3 }, @@ -63,7 +63,7 @@ async fn grid_filter_single_select_is_empty_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateSingleSelectFilter { - condition: SelectOptionCondition::OptionIsEmpty, + condition: SelectOptionConditionPB::OptionIsEmpty, option_ids: vec![], }, AssertNumberOfVisibleRows { expected: 2 }, @@ -78,7 +78,7 @@ async fn grid_filter_single_select_is_test() { let mut options = test.get_single_select_type_option(&field_rev.id).options; let scripts = vec![ CreateSingleSelectFilter { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![options.remove(0).id], }, AssertNumberOfVisibleRows { expected: 2 }, @@ -94,7 +94,7 @@ async fn grid_filter_single_select_is_test2() { let option = options.remove(0); let scripts = vec![ CreateSingleSelectFilter { - condition: SelectOptionCondition::OptionIs, + condition: SelectOptionConditionPB::OptionIs, option_ids: vec![option.id.clone()], }, AssertNumberOfVisibleRows { expected: 2 }, diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs index acbcf267cb..d02fe4dc82 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs @@ -1,6 +1,6 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::*; -use flowy_grid::entities::{AlterFilterPayloadPB, FieldType, TextFilterCondition, TextFilterPB}; +use flowy_grid::entities::{AlterFilterPayloadPB, FieldType, TextFilterConditionPB, TextFilterPB}; use flowy_grid::services::filter::FilterType; #[tokio::test] @@ -8,7 +8,7 @@ async fn grid_filter_text_is_empty_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::TextIsEmpty, + condition: TextFilterConditionPB::TextIsEmpty, content: "".to_string(), }, AssertFilterCount { count: 1 }, @@ -26,7 +26,7 @@ async fn grid_filter_text_is_not_empty_test() { // Only one row's text of the initial rows is "" let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::TextIsNotEmpty, + condition: TextFilterConditionPB::TextIsNotEmpty, content: "".to_string(), }, AssertFilterCount { count: 1 }, @@ -58,7 +58,7 @@ async fn grid_filter_is_text_test() { // Only one row's text of the initial rows is "A" let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::Is, + condition: TextFilterConditionPB::Is, content: "A".to_string(), }, AssertFilterChanged { @@ -74,7 +74,7 @@ async fn grid_filter_contain_text_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::Contains, + condition: TextFilterConditionPB::Contains, content: "A".to_string(), }, AssertFilterChanged { @@ -90,7 +90,7 @@ async fn grid_filter_contain_text_test2() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::Contains, + condition: TextFilterConditionPB::Contains, content: "A".to_string(), }, AssertFilterChanged { @@ -115,7 +115,7 @@ async fn grid_filter_does_not_contain_text_test() { // None of the initial rows contains the text "AB" let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::DoesNotContain, + condition: TextFilterConditionPB::DoesNotContain, content: "AB".to_string(), }, AssertFilterChanged { @@ -131,7 +131,7 @@ async fn grid_filter_start_with_text_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::StartsWith, + condition: TextFilterConditionPB::StartsWith, content: "A".to_string(), }, AssertFilterChanged { @@ -147,7 +147,7 @@ async fn grid_filter_ends_with_text_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::EndsWith, + condition: TextFilterConditionPB::EndsWith, content: "A".to_string(), }, AssertNumberOfVisibleRows { expected: 2 }, @@ -160,7 +160,7 @@ async fn grid_update_text_filter_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::EndsWith, + condition: TextFilterConditionPB::EndsWith, content: "A".to_string(), }, AssertNumberOfVisibleRows { expected: 2 }, @@ -172,7 +172,7 @@ async fn grid_update_text_filter_test() { let scripts = vec![ UpdateTextFilter { filter, - condition: TextFilterCondition::Is, + condition: TextFilterConditionPB::Is, content: "A".to_string(), }, AssertNumberOfVisibleRows { expected: 1 }, @@ -186,7 +186,7 @@ async fn grid_filter_delete_test() { let mut test = GridFilterTest::new().await; let field_rev = test.get_first_field_rev(FieldType::RichText).clone(); let text_filter = TextFilterPB { - condition: TextFilterCondition::TextIsEmpty, + condition: TextFilterConditionPB::TextIsEmpty, content: "".to_string(), }; let payload = AlterFilterPayloadPB::new(&field_rev, text_filter); @@ -214,7 +214,7 @@ async fn grid_filter_update_empty_text_cell_test() { let mut test = GridFilterTest::new().await; let scripts = vec![ CreateTextFilter { - condition: TextFilterCondition::TextIsEmpty, + condition: TextFilterConditionPB::TextIsEmpty, content: "".to_string(), }, AssertFilterCount { count: 1 },