Skip to content

Commit ef0d59f

Browse files
authored
Merge pull request #500 from AppFlowy-IO/opti_create_option
2 parents 7b71fd7 + e8540b4 commit ef0d59f

File tree

64 files changed

+1441
-1256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1441
-1256
lines changed

frontend/app_flowy/lib/startup/deps_resolver.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
1515
import 'package:app_flowy/workspace/presentation/home/menu/menu.dart';
1616
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
1717
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
18-
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show EditFieldContext;
19-
import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart';
20-
import 'package:flowy_sdk/protobuf/flowy-grid/number_type_option.pb.dart';
2118
import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart';
2219
import 'package:get_it/get_it.dart';
2320

@@ -157,21 +154,14 @@ void _resolveGridDeps(GetIt getIt) {
157154
),
158155
);
159156

160-
getIt.registerFactoryParam<FieldEditorBloc, String, EditFieldContextLoader>(
161-
(gridId, fieldLoader) => FieldEditorBloc(
162-
gridId: gridId,
163-
fieldLoader: fieldLoader,
164-
),
165-
);
166-
167157
getIt.registerFactoryParam<TextCellBloc, GridCellContext, void>(
168158
(context, _) => TextCellBloc(
169159
cellContext: context,
170160
),
171161
);
172162

173-
getIt.registerFactoryParam<SelectionCellBloc, GridSelectOptionCellContext, void>(
174-
(context, _) => SelectionCellBloc(
163+
getIt.registerFactoryParam<SelectOptionCellBloc, GridSelectOptionCellContext, void>(
164+
(context, _) => SelectOptionCellBloc(
175165
cellContext: context,
176166
),
177167
);
@@ -195,18 +185,6 @@ void _resolveGridDeps(GetIt getIt) {
195185
),
196186
);
197187

198-
getIt.registerFactoryParam<FieldEditorPannelBloc, EditFieldContext, void>(
199-
(context, _) => FieldEditorPannelBloc(context),
200-
);
201-
202-
getIt.registerFactoryParam<DateTypeOptionBloc, DateTypeOption, void>(
203-
(typeOption, _) => DateTypeOptionBloc(typeOption: typeOption),
204-
);
205-
206-
getIt.registerFactoryParam<NumberTypeOptionBloc, NumberTypeOption, void>(
207-
(typeOption, _) => NumberTypeOptionBloc(typeOption: typeOption),
208-
);
209-
210188
getIt.registerFactoryParam<GridPropertyBloc, String, GridFieldCache>(
211189
(gridId, cache) => GridPropertyBloc(gridId: gridId, fieldCache: cache),
212190
);

frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GridCellContextBuilder {
1919
return GridCellContext(
2020
gridCell: _gridCell,
2121
cellCache: _cellCache,
22-
cellDataLoader: CellDataLoader(gridCell: _gridCell),
22+
cellDataLoader: GridCellDataLoader(gridCell: _gridCell),
2323
cellDataPersistence: CellDataPersistence(gridCell: _gridCell),
2424
);
2525
case FieldType.DateTime:
@@ -30,17 +30,24 @@ class GridCellContextBuilder {
3030
cellDataPersistence: DateCellDataPersistence(gridCell: _gridCell),
3131
);
3232
case FieldType.Number:
33+
final cellDataLoader = GridCellDataLoader(
34+
gridCell: _gridCell,
35+
config: const GridCellDataConfig(
36+
reloadOnCellChanged: true,
37+
reloadOnFieldChanged: true,
38+
),
39+
);
3340
return GridCellContext(
3441
gridCell: _gridCell,
3542
cellCache: _cellCache,
36-
cellDataLoader: CellDataLoader(gridCell: _gridCell, reloadOnCellChanged: true),
43+
cellDataLoader: cellDataLoader,
3744
cellDataPersistence: CellDataPersistence(gridCell: _gridCell),
3845
);
3946
case FieldType.RichText:
4047
return GridCellContext(
4148
gridCell: _gridCell,
4249
cellCache: _cellCache,
43-
cellDataLoader: CellDataLoader(gridCell: _gridCell),
50+
cellDataLoader: GridCellDataLoader(gridCell: _gridCell),
4451
cellDataPersistence: CellDataPersistence(gridCell: _gridCell),
4552
);
4653
case FieldType.MultiSelect:
@@ -62,7 +69,7 @@ class _GridCellContext<T, D> extends Equatable {
6269
final GridCell gridCell;
6370
final GridCellCache cellCache;
6471
final GridCellCacheKey _cacheKey;
65-
final _GridCellDataLoader<T> cellDataLoader;
72+
final IGridCellDataLoader<T> cellDataLoader;
6673
final _GridCellDataPersistence<D> cellDataPersistence;
6774
final FieldService _fieldService;
6875

@@ -150,8 +157,8 @@ class _GridCellContext<T, D> extends Equatable {
150157
return data;
151158
}
152159

153-
Future<Either<List<int>, FlowyError>> getTypeOptionData() {
154-
return _fieldService.getTypeOptionData(fieldType: fieldType);
160+
Future<Either<FieldTypeOptionData, FlowyError>> getTypeOptionData() {
161+
return _fieldService.getFieldTypeOptionData(fieldType: fieldType);
155162
}
156163

157164
Future<Option<FlowyError>> saveCellData(D data) {

frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/data_cache.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class GridCellCache {
104104
}
105105

106106
Future<void> dispose() async {
107+
_fieldListenerByFieldId.clear();
108+
_cellDataByFieldId.clear();
107109
fieldDelegate.dispose();
108110
}
109111
}

frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/data_loader.dart

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
part of 'cell_service.dart';
22

3-
abstract class GridCellDataConfig {
3+
abstract class IGridCellDataConfig {
44
// The cell data will reload if it receives the field's change notification.
55
bool get reloadOnFieldChanged;
66

@@ -11,34 +11,36 @@ abstract class GridCellDataConfig {
1111
bool get reloadOnCellChanged;
1212
}
1313

14-
class DefaultCellDataConfig implements GridCellDataConfig {
14+
class GridCellDataConfig implements IGridCellDataConfig {
1515
@override
1616
final bool reloadOnCellChanged;
1717

1818
@override
1919
final bool reloadOnFieldChanged;
2020

21-
DefaultCellDataConfig({
21+
const GridCellDataConfig({
2222
this.reloadOnCellChanged = false,
2323
this.reloadOnFieldChanged = false,
2424
});
2525
}
2626

27-
abstract class _GridCellDataLoader<T> {
27+
abstract class IGridCellDataLoader<T> {
2828
Future<T?> loadData();
2929

30-
GridCellDataConfig get config;
30+
IGridCellDataConfig get config;
3131
}
3232

33-
class CellDataLoader extends _GridCellDataLoader<Cell> {
33+
class GridCellDataLoader extends IGridCellDataLoader<Cell> {
3434
final CellService service = CellService();
3535
final GridCell gridCell;
36-
final GridCellDataConfig _config;
3736

38-
CellDataLoader({
37+
@override
38+
final IGridCellDataConfig config;
39+
40+
GridCellDataLoader({
3941
required this.gridCell,
40-
bool reloadOnCellChanged = false,
41-
}) : _config = DefaultCellDataConfig(reloadOnCellChanged: reloadOnCellChanged);
42+
this.config = const GridCellDataConfig(),
43+
});
4244

4345
@override
4446
Future<Cell?> loadData() {
@@ -54,20 +56,17 @@ class CellDataLoader extends _GridCellDataLoader<Cell> {
5456
});
5557
});
5658
}
57-
58-
@override
59-
GridCellDataConfig get config => _config;
6059
}
6160

62-
class DateCellDataLoader extends _GridCellDataLoader<DateCellData> {
61+
class DateCellDataLoader extends IGridCellDataLoader<DateCellData> {
6362
final GridCell gridCell;
64-
final GridCellDataConfig _config;
63+
final IGridCellDataConfig _config;
6564
DateCellDataLoader({
6665
required this.gridCell,
67-
}) : _config = DefaultCellDataConfig(reloadOnFieldChanged: true);
66+
}) : _config = const GridCellDataConfig(reloadOnFieldChanged: true);
6867

6968
@override
70-
GridCellDataConfig get config => _config;
69+
IGridCellDataConfig get config => _config;
7170

7271
@override
7372
Future<DateCellData?> loadData() {
@@ -88,7 +87,7 @@ class DateCellDataLoader extends _GridCellDataLoader<DateCellData> {
8887
}
8988
}
9089

91-
class SelectOptionCellDataLoader extends _GridCellDataLoader<SelectOptionCellData> {
90+
class SelectOptionCellDataLoader extends IGridCellDataLoader<SelectOptionCellData> {
9291
final SelectOptionService service;
9392
final GridCell gridCell;
9493
SelectOptionCellDataLoader({
@@ -108,5 +107,5 @@ class SelectOptionCellDataLoader extends _GridCellDataLoader<SelectOptionCellDat
108107
}
109108

110109
@override
111-
GridCellDataConfig get config => DefaultCellDataConfig();
110+
IGridCellDataConfig get config => const GridCellDataConfig(reloadOnFieldChanged: true);
112111
}

frontend/app_flowy/lib/workspace/application/grid/cell/selection_cell_bloc.dart renamed to frontend/app_flowy/lib/workspace/application/grid/cell/select_option_cell_bloc.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:freezed_annotation/freezed_annotation.dart';
55
import 'package:app_flowy/workspace/application/grid/cell/cell_service/cell_service.dart';
66

7-
part 'selection_cell_bloc.freezed.dart';
7+
part 'select_option_cell_bloc.freezed.dart';
88

9-
class SelectionCellBloc extends Bloc<SelectionCellEvent, SelectionCellState> {
9+
class SelectOptionCellBloc extends Bloc<SelectOptionCellEvent, SelectOptionCellState> {
1010
final GridSelectOptionCellContext cellContext;
1111
void Function()? _onCellChangedFn;
1212

13-
SelectionCellBloc({
13+
SelectOptionCellBloc({
1414
required this.cellContext,
15-
}) : super(SelectionCellState.initial(cellContext)) {
16-
on<SelectionCellEvent>(
15+
}) : super(SelectOptionCellState.initial(cellContext)) {
16+
on<SelectOptionCellEvent>(
1717
(event, emit) async {
1818
await event.map(
1919
initial: (_InitialCell value) async {
@@ -44,7 +44,7 @@ class SelectionCellBloc extends Bloc<SelectionCellEvent, SelectionCellState> {
4444
_onCellChangedFn = cellContext.startListening(
4545
onCellChanged: ((selectOptionContext) {
4646
if (!isClosed) {
47-
add(SelectionCellEvent.didReceiveOptions(
47+
add(SelectOptionCellEvent.didReceiveOptions(
4848
selectOptionContext.options,
4949
selectOptionContext.selectOptions,
5050
));
@@ -55,25 +55,25 @@ class SelectionCellBloc extends Bloc<SelectionCellEvent, SelectionCellState> {
5555
}
5656

5757
@freezed
58-
class SelectionCellEvent with _$SelectionCellEvent {
59-
const factory SelectionCellEvent.initial() = _InitialCell;
60-
const factory SelectionCellEvent.didReceiveOptions(
58+
class SelectOptionCellEvent with _$SelectOptionCellEvent {
59+
const factory SelectOptionCellEvent.initial() = _InitialCell;
60+
const factory SelectOptionCellEvent.didReceiveOptions(
6161
List<SelectOption> options,
6262
List<SelectOption> selectedOptions,
6363
) = _DidReceiveOptions;
6464
}
6565

6666
@freezed
67-
class SelectionCellState with _$SelectionCellState {
68-
const factory SelectionCellState({
67+
class SelectOptionCellState with _$SelectOptionCellState {
68+
const factory SelectOptionCellState({
6969
required List<SelectOption> options,
7070
required List<SelectOption> selectedOptions,
71-
}) = _SelectionCellState;
71+
}) = _SelectOptionCellState;
7272

73-
factory SelectionCellState.initial(GridSelectOptionCellContext context) {
73+
factory SelectOptionCellState.initial(GridSelectOptionCellContext context) {
7474
final data = context.getCellData();
7575

76-
return SelectionCellState(
76+
return SelectOptionCellState(
7777
options: data?.options ?? [],
7878
selectedOptions: data?.selectOptions ?? [],
7979
);

frontend/app_flowy/lib/workspace/application/grid/cell/selection_editor_bloc.dart renamed to frontend/app_flowy/lib/workspace/application/grid/cell/select_option_editor_bloc.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import 'package:freezed_annotation/freezed_annotation.dart';
77
import 'package:app_flowy/workspace/application/grid/cell/cell_service/cell_service.dart';
88
import 'select_option_service.dart';
99

10-
part 'selection_editor_bloc.freezed.dart';
10+
part 'select_option_editor_bloc.freezed.dart';
1111

12-
class SelectOptionEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionEditorState> {
12+
class SelectOptionCellEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionEditorState> {
1313
final SelectOptionService _selectOptionService;
1414
final GridSelectOptionCellContext cellContext;
1515
void Function()? _onCellChangedFn;
1616

17-
SelectOptionEditorBloc({
17+
SelectOptionCellEditorBloc({
1818
required this.cellContext,
1919
}) : _selectOptionService = SelectOptionService(gridCell: cellContext.gridCell),
2020
super(SelectOptionEditorState.initial(cellContext)) {

frontend/app_flowy/lib/workspace/application/grid/field/field_action_sheet_bloc.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FieldActionSheetBloc extends Bloc<FieldActionSheetEvent, FieldActionSheetS
1111
final FieldService fieldService;
1212

1313
FieldActionSheetBloc({required Field field, required this.fieldService})
14-
: super(FieldActionSheetState.initial(EditFieldContext.create()..gridField = field)) {
14+
: super(FieldActionSheetState.initial(FieldTypeOptionData.create()..field_2 = field)) {
1515
on<FieldActionSheetEvent>(
1616
(event, emit) async {
1717
await event.map(
@@ -67,14 +67,14 @@ class FieldActionSheetEvent with _$FieldActionSheetEvent {
6767
@freezed
6868
class FieldActionSheetState with _$FieldActionSheetState {
6969
const factory FieldActionSheetState({
70-
required EditFieldContext editContext,
70+
required FieldTypeOptionData fieldTypeOptionData,
7171
required String errorText,
7272
required String fieldName,
7373
}) = _FieldActionSheetState;
7474

75-
factory FieldActionSheetState.initial(EditFieldContext editContext) => FieldActionSheetState(
76-
editContext: editContext,
75+
factory FieldActionSheetState.initial(FieldTypeOptionData data) => FieldActionSheetState(
76+
fieldTypeOptionData: data,
7777
errorText: '',
78-
fieldName: editContext.gridField.name,
78+
fieldName: data.field_2.name,
7979
);
8080
}

frontend/app_flowy/lib/workspace/application/grid/field/field_cell_bloc.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
1919
super(FieldCellState.initial(cellContext)) {
2020
on<FieldCellEvent>(
2121
(event, emit) async {
22-
await event.map(
23-
initial: (_InitialCell value) async {
22+
event.when(
23+
initial: () {
2424
_startListening();
2525
},
26-
didReceiveFieldUpdate: (_DidReceiveFieldUpdate value) {
27-
emit(state.copyWith(field: value.field));
26+
didReceiveFieldUpdate: (field) {
27+
emit(state.copyWith(field: field));
2828
},
29-
updateWidth: (_UpdateWidth value) {
29+
updateWidth: (offset) {
3030
final defaultWidth = state.field.width.toDouble();
31-
final width = defaultWidth + value.offset;
31+
final width = defaultWidth + offset;
3232
if (width > defaultWidth && width < 300) {
3333
_fieldService.updateField(width: width);
3434
}

0 commit comments

Comments
 (0)