mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: fetch all select options from field type option instead of cell (#5122)
* refactor: fetch all options from type option * chore: rustfmt * ci: fix rust ci * chore: fix clippy
This commit is contained in:
parent
0ebcca63bb
commit
891fd16a0c
28
.github/workflows/rust_ci.yaml
vendored
28
.github/workflows/rust_ci.yaml
vendored
@ -25,21 +25,21 @@ jobs:
|
|||||||
test-on-ubuntu:
|
test-on-ubuntu:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Maximize build space
|
# - name: Maximize build space
|
||||||
uses: easimon/maximize-build-space@master
|
# uses: easimon/maximize-build-space@master
|
||||||
with:
|
# with:
|
||||||
root-reserve-mb: 2048
|
# root-reserve-mb: 2048
|
||||||
swap-size-mb: 1024
|
# swap-size-mb: 1024
|
||||||
remove-dotnet: 'true'
|
# remove-dotnet: 'true'
|
||||||
|
|
||||||
# the following step is required to avoid running out of space
|
# # the following step is required to avoid running out of space
|
||||||
- name: Maximize build space
|
# - name: Maximize build space
|
||||||
run: |
|
# run: |
|
||||||
sudo rm -rf /usr/share/dotnet
|
# sudo rm -rf /usr/share/dotnet
|
||||||
sudo rm -rf /opt/ghc
|
# sudo rm -rf /opt/ghc
|
||||||
sudo rm -rf "/usr/local/share/boost"
|
# sudo rm -rf "/usr/local/share/boost"
|
||||||
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
# sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
||||||
sudo docker image prune --all --force
|
# sudo docker image prune --all --force
|
||||||
|
|
||||||
- name: Checkout source code
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:appflowy/plugins/database/application/cell/cell_controller_builder.dart';
|
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/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/field_service.dart';
|
||||||
import 'package:appflowy/plugins/database/domain/select_option_cell_service.dart';
|
import 'package:appflowy/plugins/database/domain/select_option_cell_service.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
@ -18,8 +19,9 @@ const String createSelectOptionSuggestionId =
|
|||||||
|
|
||||||
class SelectOptionCellEditorBloc
|
class SelectOptionCellEditorBloc
|
||||||
extends Bloc<SelectOptionCellEditorEvent, SelectOptionCellEditorState> {
|
extends Bloc<SelectOptionCellEditorEvent, SelectOptionCellEditorState> {
|
||||||
SelectOptionCellEditorBloc({required this.cellController})
|
SelectOptionCellEditorBloc({
|
||||||
: _selectOptionService = SelectOptionCellBackendService(
|
required this.cellController,
|
||||||
|
}) : _selectOptionService = SelectOptionCellBackendService(
|
||||||
viewId: cellController.viewId,
|
viewId: cellController.viewId,
|
||||||
fieldId: cellController.fieldId,
|
fieldId: cellController.fieldId,
|
||||||
rowId: cellController.rowId,
|
rowId: cellController.rowId,
|
||||||
@ -48,7 +50,8 @@ class SelectOptionCellEditorBloc
|
|||||||
super(SelectOptionCellEditorState.initial(cellController)) {
|
super(SelectOptionCellEditorState.initial(cellController)) {
|
||||||
_dispatch();
|
_dispatch();
|
||||||
_startListening();
|
_startListening();
|
||||||
_loadOptions();
|
final loadedOptions = _loadAllOptions(cellController);
|
||||||
|
add(SelectOptionCellEditorEvent.didUpdateOptions(loadedOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
final SelectOptionCellBackendService _selectOptionService;
|
final SelectOptionCellBackendService _selectOptionService;
|
||||||
@ -64,17 +67,19 @@ class SelectOptionCellEditorBloc
|
|||||||
on<SelectOptionCellEditorEvent>(
|
on<SelectOptionCellEditorEvent>(
|
||||||
(event, emit) async {
|
(event, emit) async {
|
||||||
await event.when(
|
await event.when(
|
||||||
didReceiveOptions: (options, selectedOptions) {
|
didUpdateCell: (selectedOptions) {
|
||||||
final result = _getVisibleOptions(options);
|
emit(state.copyWith(selectedOptions: selectedOptions));
|
||||||
|
},
|
||||||
|
didUpdateOptions: (options) {
|
||||||
allOptions
|
allOptions
|
||||||
..clear()
|
..clear()
|
||||||
..addAll(options);
|
..addAll(options);
|
||||||
|
final result = _getVisibleOptions(options);
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
options: result.options,
|
options: result.options,
|
||||||
createSelectOptionSuggestion:
|
createSelectOptionSuggestion:
|
||||||
result.createSelectOptionSuggestion,
|
result.createSelectOptionSuggestion,
|
||||||
selectedOptions: selectedOptions,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -166,37 +171,28 @@ class SelectOptionCellEditorBloc
|
|||||||
|
|
||||||
void _startListening() {
|
void _startListening() {
|
||||||
_onCellChangedFn = cellController.addListener(
|
_onCellChangedFn = cellController.addListener(
|
||||||
onCellChanged: (_) {
|
onCellChanged: (cellData) {
|
||||||
_loadOptions();
|
if (isClosed) {
|
||||||
|
Log.warn("Unexpecteded closing the bloc");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
add(
|
||||||
|
SelectOptionCellEditorEvent.didUpdateCell(
|
||||||
|
cellData == null ? [] : cellData.selectOptions,
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
onCellFieldChanged: (field) {
|
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({
|
Future<void> _createOption({
|
||||||
required String name,
|
required String name,
|
||||||
required SelectOptionColorPB color,
|
required SelectOptionColorPB color,
|
||||||
@ -347,10 +343,12 @@ class SelectOptionCellEditorBloc
|
|||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class SelectOptionCellEditorEvent with _$SelectOptionCellEditorEvent {
|
class SelectOptionCellEditorEvent with _$SelectOptionCellEditorEvent {
|
||||||
const factory SelectOptionCellEditorEvent.didReceiveOptions(
|
const factory SelectOptionCellEditorEvent.didUpdateCell(
|
||||||
List<SelectOptionPB> options,
|
|
||||||
List<SelectOptionPB> selectedOptions,
|
List<SelectOptionPB> selectedOptions,
|
||||||
) = _DidReceiveOptions;
|
) = _DidUpdateCell;
|
||||||
|
const factory SelectOptionCellEditorEvent.didUpdateOptions(
|
||||||
|
List<SelectOptionPB> options,
|
||||||
|
) = _DidUpdateOptions;
|
||||||
const factory SelectOptionCellEditorEvent.createOption() = _CreateOption;
|
const factory SelectOptionCellEditorEvent.createOption() = _CreateOption;
|
||||||
const factory SelectOptionCellEditorEvent.selectOption(String optionId) =
|
const factory SelectOptionCellEditorEvent.selectOption(String optionId) =
|
||||||
_SelectOption;
|
_SelectOption;
|
||||||
@ -400,11 +398,12 @@ class SelectOptionCellEditorState with _$SelectOptionCellEditorState {
|
|||||||
}) = _SelectOptionEditorState;
|
}) = _SelectOptionEditorState;
|
||||||
|
|
||||||
factory SelectOptionCellEditorState.initial(
|
factory SelectOptionCellEditorState.initial(
|
||||||
SelectOptionCellController context,
|
SelectOptionCellController cellController,
|
||||||
) {
|
) {
|
||||||
final data = context.getCellData(loadIfNotExist: false);
|
final allOptions = _loadAllOptions(cellController);
|
||||||
|
final data = cellController.getCellData();
|
||||||
return SelectOptionCellEditorState(
|
return SelectOptionCellEditorState(
|
||||||
options: data?.options ?? [],
|
options: allOptions,
|
||||||
selectedOptions: data?.selectOptions ?? [],
|
selectedOptions: data?.selectOptions ?? [],
|
||||||
createSelectOptionSuggestion: null,
|
createSelectOptionSuggestion: null,
|
||||||
focusedOptionId: null,
|
focusedOptionId: null,
|
||||||
@ -432,3 +431,21 @@ class CreateSelectOptionSuggestion {
|
|||||||
final String name;
|
final String name;
|
||||||
final SelectOptionColorPB color;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -161,7 +161,7 @@ class CellController<T, D> {
|
|||||||
|
|
||||||
/// Return the TypeOptionPB that can be parsed into corresponding class using the [parser].
|
/// Return the TypeOptionPB that can be parsed into corresponding class using the [parser].
|
||||||
/// [PD] is the type that the parser return.
|
/// [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);
|
return parser.fromBuffer(fieldInfo.field.typeOptionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use collab_folder::{FolderData, View};
|
use collab_folder::{FolderData, View};
|
||||||
use flowy_folder::entities::icon::UpdateViewIconPayloadPB;
|
use flowy_folder::entities::icon::UpdateViewIconPayloadPB;
|
||||||
use flowy_folder::event_map::FolderEvent;
|
use flowy_folder::event_map::FolderEvent;
|
||||||
@ -11,7 +13,6 @@ use flowy_user::entities::{
|
|||||||
};
|
};
|
||||||
use flowy_user::errors::FlowyError;
|
use flowy_user::errors::FlowyError;
|
||||||
use flowy_user::event_map::UserEvent;
|
use flowy_user::event_map::UserEvent;
|
||||||
use std::sync::Arc;
|
|
||||||
use flowy_user_pub::entities::Role;
|
use flowy_user_pub::entities::Role;
|
||||||
|
|
||||||
use crate::event_builder::EventBuilder;
|
use crate::event_builder::EventBuilder;
|
||||||
|
@ -14,7 +14,6 @@ use tokio::select;
|
|||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
use flowy_core::config::AppFlowyCoreConfig;
|
use flowy_core::config::AppFlowyCoreConfig;
|
||||||
use flowy_core::integrate::log::create_log_filter;
|
|
||||||
use flowy_core::AppFlowyCore;
|
use flowy_core::AppFlowyCore;
|
||||||
use flowy_notification::register_notification_sender;
|
use flowy_notification::register_notification_sender;
|
||||||
use flowy_server::AppFlowyServer;
|
use flowy_server::AppFlowyServer;
|
||||||
|
@ -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 cell = test.get_cell(&grid_view.id, &row_id, &field_id).await;
|
||||||
let select_option_cell = SelectOptionCellDataPB::try_from(Bytes::from(cell.data)).unwrap();
|
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);
|
assert_eq!(select_option_cell.select_options.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
/// [SelectOptionCellDataPB] contains a list of user's selected options
|
||||||
/// that the cell can use.
|
|
||||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||||
pub struct SelectOptionCellDataPB {
|
pub struct SelectOptionCellDataPB {
|
||||||
/// The available options that the cell can use.
|
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub options: Vec<SelectOptionPB>,
|
|
||||||
|
|
||||||
/// The selected options for the cell.
|
|
||||||
#[pb(index = 2)]
|
|
||||||
pub select_options: Vec<SelectOptionPB>,
|
pub select_options: Vec<SelectOptionPB>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,18 +47,12 @@ pub enum SelectOptionColor {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SelectOptionCellData {
|
pub struct SelectOptionCellData {
|
||||||
pub options: Vec<SelectOption>,
|
|
||||||
pub select_options: Vec<SelectOption>,
|
pub select_options: Vec<SelectOption>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SelectOptionCellData> for SelectOptionCellDataPB {
|
impl From<SelectOptionCellData> for SelectOptionCellDataPB {
|
||||||
fn from(data: SelectOptionCellData) -> Self {
|
fn from(data: SelectOptionCellData) -> Self {
|
||||||
SelectOptionCellDataPB {
|
SelectOptionCellDataPB {
|
||||||
options: data
|
|
||||||
.options
|
|
||||||
.into_iter()
|
|
||||||
.map(|option| option.into())
|
|
||||||
.collect(),
|
|
||||||
select_options: data
|
select_options: data
|
||||||
.select_options
|
.select_options
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -58,10 +58,7 @@ pub trait SelectTypeOptionSharedAction: Send + Sync {
|
|||||||
select_options.truncate(number_of_max_options);
|
select_options.truncate(number_of_max_options);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
SelectOptionCellData {
|
SelectOptionCellData { select_options }
|
||||||
options: self.options().clone(),
|
|
||||||
select_options,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_type_option_data(&self) -> TypeOptionData;
|
fn to_type_option_data(&self) -> TypeOptionData;
|
||||||
|
@ -170,7 +170,7 @@ impl FolderIndexManagerImpl {
|
|||||||
Ok(writer) => Ok(writer),
|
Ok(writer) => Ok(writer),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("FolderIndexManager failed to lock index writer: {:?}", 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()),
|
None => Err(FlowyError::folder_index_manager_unavailable()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user