diff --git a/.github/workflows/rust_ci.yaml b/.github/workflows/rust_ci.yaml index 500f92fcf7..e74bc776ec 100644 --- a/.github/workflows/rust_ci.yaml +++ b/.github/workflows/rust_ci.yaml @@ -25,21 +25,21 @@ jobs: test-on-ubuntu: runs-on: ubuntu-latest steps: - - name: Maximize build space - uses: easimon/maximize-build-space@master - with: - root-reserve-mb: 2048 - swap-size-mb: 1024 - remove-dotnet: 'true' + # - name: Maximize build space + # uses: easimon/maximize-build-space@master + # with: + # root-reserve-mb: 2048 + # swap-size-mb: 1024 + # remove-dotnet: 'true' - # the following step is required to avoid running out of space - - name: Maximize build space - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf /opt/ghc - sudo rm -rf "/usr/local/share/boost" - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - sudo docker image prune --all --force + # # the following step is required to avoid running out of space + # - name: Maximize build space + # run: | + # sudo rm -rf /usr/share/dotnet + # sudo rm -rf /opt/ghc + # sudo rm -rf "/usr/local/share/boost" + # sudo rm -rf "$AGENT_TOOLSDIRECTORY" + # sudo docker image prune --all --force - name: Checkout source code uses: actions/checkout@v4 diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_editor_bloc.dart index 99d5f45e90..aa360ff36e 100644 --- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_editor_bloc.dart +++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_editor_bloc.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:appflowy/plugins/database/application/cell/cell_controller_builder.dart'; import 'package:appflowy/plugins/database/application/field/type_option/select_type_option_actions.dart'; +import 'package:appflowy/plugins/database/application/field/type_option/type_option_data_parser.dart'; import 'package:appflowy/plugins/database/domain/field_service.dart'; import 'package:appflowy/plugins/database/domain/select_option_cell_service.dart'; import 'package:appflowy_backend/log.dart'; @@ -18,8 +19,9 @@ const String createSelectOptionSuggestionId = class SelectOptionCellEditorBloc extends Bloc<SelectOptionCellEditorEvent, SelectOptionCellEditorState> { - SelectOptionCellEditorBloc({required this.cellController}) - : _selectOptionService = SelectOptionCellBackendService( + SelectOptionCellEditorBloc({ + required this.cellController, + }) : _selectOptionService = SelectOptionCellBackendService( viewId: cellController.viewId, fieldId: cellController.fieldId, rowId: cellController.rowId, @@ -48,7 +50,8 @@ class SelectOptionCellEditorBloc super(SelectOptionCellEditorState.initial(cellController)) { _dispatch(); _startListening(); - _loadOptions(); + final loadedOptions = _loadAllOptions(cellController); + add(SelectOptionCellEditorEvent.didUpdateOptions(loadedOptions)); } final SelectOptionCellBackendService _selectOptionService; @@ -64,17 +67,19 @@ class SelectOptionCellEditorBloc on<SelectOptionCellEditorEvent>( (event, emit) async { await event.when( - didReceiveOptions: (options, selectedOptions) { - final result = _getVisibleOptions(options); + didUpdateCell: (selectedOptions) { + emit(state.copyWith(selectedOptions: selectedOptions)); + }, + didUpdateOptions: (options) { allOptions ..clear() ..addAll(options); + final result = _getVisibleOptions(options); emit( state.copyWith( options: result.options, createSelectOptionSuggestion: result.createSelectOptionSuggestion, - selectedOptions: selectedOptions, ), ); }, @@ -166,37 +171,28 @@ class SelectOptionCellEditorBloc void _startListening() { _onCellChangedFn = cellController.addListener( - onCellChanged: (_) { - _loadOptions(); + onCellChanged: (cellData) { + if (isClosed) { + Log.warn("Unexpecteded closing the bloc"); + return; + } + add( + SelectOptionCellEditorEvent.didUpdateCell( + cellData == null ? [] : cellData.selectOptions, + ), + ); }, onCellFieldChanged: (field) { - _loadOptions(); + if (isClosed) { + Log.warn("Unexpecteded closing the bloc"); + return; + } + final loadedOptions = _loadAllOptions(cellController); + add(SelectOptionCellEditorEvent.didUpdateOptions(loadedOptions)); }, ); } - void _loadOptions() { - if (isClosed) { - Log.warn("Unexpecteded closing the bloc"); - return; - } - - final cellData = cellController.getCellData(); - - if (cellData != null) { - add( - SelectOptionCellEditorEvent.didReceiveOptions( - cellData.options, - cellData.selectOptions, - ), - ); - } else { - add( - const SelectOptionCellEditorEvent.didReceiveOptions([], []), - ); - } - } - Future<void> _createOption({ required String name, required SelectOptionColorPB color, @@ -347,10 +343,12 @@ class SelectOptionCellEditorBloc @freezed class SelectOptionCellEditorEvent with _$SelectOptionCellEditorEvent { - const factory SelectOptionCellEditorEvent.didReceiveOptions( - List<SelectOptionPB> options, + const factory SelectOptionCellEditorEvent.didUpdateCell( List<SelectOptionPB> selectedOptions, - ) = _DidReceiveOptions; + ) = _DidUpdateCell; + const factory SelectOptionCellEditorEvent.didUpdateOptions( + List<SelectOptionPB> options, + ) = _DidUpdateOptions; const factory SelectOptionCellEditorEvent.createOption() = _CreateOption; const factory SelectOptionCellEditorEvent.selectOption(String optionId) = _SelectOption; @@ -400,11 +398,12 @@ class SelectOptionCellEditorState with _$SelectOptionCellEditorState { }) = _SelectOptionEditorState; factory SelectOptionCellEditorState.initial( - SelectOptionCellController context, + SelectOptionCellController cellController, ) { - final data = context.getCellData(loadIfNotExist: false); + final allOptions = _loadAllOptions(cellController); + final data = cellController.getCellData(); return SelectOptionCellEditorState( - options: data?.options ?? [], + options: allOptions, selectedOptions: data?.selectOptions ?? [], createSelectOptionSuggestion: null, focusedOptionId: null, @@ -432,3 +431,21 @@ class CreateSelectOptionSuggestion { final String name; final SelectOptionColorPB color; } + +List<SelectOptionPB> _loadAllOptions( + SelectOptionCellController cellController, +) { + if (cellController.fieldType == FieldType.SingleSelect) { + return cellController + .getTypeOption<SingleSelectTypeOptionPB>( + SingleSelectTypeOptionDataParser(), + ) + .options; + } else { + return cellController + .getTypeOption<MultiSelectTypeOptionPB>( + MultiSelectTypeOptionDataParser(), + ) + .options; + } +} diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/cell_controller.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/cell_controller.dart index 98361cd97a..c810fc1a82 100644 --- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/cell_controller.dart +++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/cell_controller.dart @@ -161,7 +161,7 @@ class CellController<T, D> { /// Return the TypeOptionPB that can be parsed into corresponding class using the [parser]. /// [PD] is the type that the parser return. - PD getTypeOption<PD, P extends TypeOptionParser>(P parser) { + PD getTypeOption<PD>(TypeOptionParser parser) { return parser.fromBuffer(fieldInfo.field.typeOptionData); } diff --git a/frontend/rust-lib/event-integration/src/folder_event.rs b/frontend/rust-lib/event-integration/src/folder_event.rs index 7b07bd996e..c687069333 100644 --- a/frontend/rust-lib/event-integration/src/folder_event.rs +++ b/frontend/rust-lib/event-integration/src/folder_event.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use collab_folder::{FolderData, View}; use flowy_folder::entities::icon::UpdateViewIconPayloadPB; use flowy_folder::event_map::FolderEvent; @@ -11,7 +13,6 @@ use flowy_user::entities::{ }; use flowy_user::errors::FlowyError; use flowy_user::event_map::UserEvent; -use std::sync::Arc; use flowy_user_pub::entities::Role; use crate::event_builder::EventBuilder; diff --git a/frontend/rust-lib/event-integration/src/lib.rs b/frontend/rust-lib/event-integration/src/lib.rs index 74df0edce0..6b9a037588 100644 --- a/frontend/rust-lib/event-integration/src/lib.rs +++ b/frontend/rust-lib/event-integration/src/lib.rs @@ -14,7 +14,6 @@ use tokio::select; use tokio::time::sleep; use flowy_core::config::AppFlowyCoreConfig; -use flowy_core::integrate::log::create_log_filter; use flowy_core::AppFlowyCore; use flowy_notification::register_notification_sender; use flowy_server::AppFlowyServer; diff --git a/frontend/rust-lib/event-integration/tests/database/local_test/test.rs b/frontend/rust-lib/event-integration/tests/database/local_test/test.rs index 3d293d2283..7f113d1535 100644 --- a/frontend/rust-lib/event-integration/tests/database/local_test/test.rs +++ b/frontend/rust-lib/event-integration/tests/database/local_test/test.rs @@ -504,7 +504,6 @@ async fn update_single_select_cell_event_test() { let cell = test.get_cell(&grid_view.id, &row_id, &field_id).await; let select_option_cell = SelectOptionCellDataPB::try_from(Bytes::from(cell.data)).unwrap(); - assert_eq!(select_option_cell.options.len(), 1); assert_eq!(select_option_cell.select_options.len(), 1); } diff --git a/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/select_option_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/select_option_entities.rs index 9252c1ea31..c5e931b017 100644 --- a/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/select_option_entities.rs +++ b/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/select_option_entities.rs @@ -103,16 +103,10 @@ impl From<SelectOptionColorPB> for SelectOptionColor { } } -/// [SelectOptionCellDataPB] contains a list of user's selected options and a list of all the options -/// that the cell can use. +/// [SelectOptionCellDataPB] contains a list of user's selected options #[derive(Clone, Debug, Default, ProtoBuf)] pub struct SelectOptionCellDataPB { - /// The available options that the cell can use. #[pb(index = 1)] - pub options: Vec<SelectOptionPB>, - - /// The selected options for the cell. - #[pb(index = 2)] pub select_options: Vec<SelectOptionPB>, } diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_option.rs index fd44264a0e..f7755f55b5 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_option.rs @@ -47,18 +47,12 @@ pub enum SelectOptionColor { #[derive(Debug)] pub struct SelectOptionCellData { - pub options: Vec<SelectOption>, pub select_options: Vec<SelectOption>, } impl From<SelectOptionCellData> for SelectOptionCellDataPB { fn from(data: SelectOptionCellData) -> Self { SelectOptionCellDataPB { - options: data - .options - .into_iter() - .map(|option| option.into()) - .collect(), select_options: data .select_options .into_iter() diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs index 51c6e5e261..4e558b5c83 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs @@ -58,10 +58,7 @@ pub trait SelectTypeOptionSharedAction: Send + Sync { select_options.truncate(number_of_max_options); }, } - SelectOptionCellData { - options: self.options().clone(), - select_options, - } + SelectOptionCellData { select_options } } fn to_type_option_data(&self) -> TypeOptionData; diff --git a/frontend/rust-lib/flowy-search/src/folder/indexer.rs b/frontend/rust-lib/flowy-search/src/folder/indexer.rs index 8506056cfc..c70b8af99b 100644 --- a/frontend/rust-lib/flowy-search/src/folder/indexer.rs +++ b/frontend/rust-lib/flowy-search/src/folder/indexer.rs @@ -170,7 +170,7 @@ impl FolderIndexManagerImpl { Ok(writer) => Ok(writer), Err(e) => { tracing::error!("FolderIndexManager failed to lock index writer: {:?}", e); - return Err(FlowyError::folder_index_manager_unavailable()); + Err(FlowyError::folder_index_manager_unavailable()) }, }, None => Err(FlowyError::folder_index_manager_unavailable()),