Merge pull request #629 from AppFlowy-IO/refactor/rename_grid_cell

Refactor/rename grid cell
This commit is contained in:
Nathan.fooo 2022-07-18 19:42:53 +08:00 committed by GitHub
commit ff1b6f8f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 37 deletions

View File

@ -5,14 +5,14 @@ abstract class IGridCellDataConfig {
bool get reloadOnFieldChanged; bool get reloadOnFieldChanged;
} }
abstract class ICellDataParser<T> { abstract class IGridCellDataParser<T> {
T? parserData(List<int> data); T? parserData(List<int> data);
} }
class GridCellDataLoader<T> { class GridCellDataLoader<T> {
final CellService service = CellService(); final CellService service = CellService();
final GridCellIdentifier cellId; final GridCellIdentifier cellId;
final ICellDataParser<T> parser; final IGridCellDataParser<T> parser;
final bool reloadOnFieldChanged; final bool reloadOnFieldChanged;
GridCellDataLoader({ GridCellDataLoader({
@ -40,7 +40,7 @@ class GridCellDataLoader<T> {
} }
} }
class StringCellDataParser implements ICellDataParser<String> { class StringCellDataParser implements IGridCellDataParser<String> {
@override @override
String? parserData(List<int> data) { String? parserData(List<int> data) {
final s = utf8.decode(data); final s = utf8.decode(data);
@ -48,7 +48,7 @@ class StringCellDataParser implements ICellDataParser<String> {
} }
} }
class DateCellDataParser implements ICellDataParser<DateCellDataPB> { class DateCellDataParser implements IGridCellDataParser<DateCellDataPB> {
@override @override
DateCellDataPB? parserData(List<int> data) { DateCellDataPB? parserData(List<int> data) {
if (data.isEmpty) { if (data.isEmpty) {
@ -58,7 +58,7 @@ class DateCellDataParser implements ICellDataParser<DateCellDataPB> {
} }
} }
class SelectOptionCellDataParser implements ICellDataParser<SelectOptionCellDataPB> { class SelectOptionCellDataParser implements IGridCellDataParser<SelectOptionCellDataPB> {
@override @override
SelectOptionCellDataPB? parserData(List<int> data) { SelectOptionCellDataPB? parserData(List<int> data) {
if (data.isEmpty) { if (data.isEmpty) {
@ -68,7 +68,7 @@ class SelectOptionCellDataParser implements ICellDataParser<SelectOptionCellData
} }
} }
class URLCellDataParser implements ICellDataParser<URLCellDataPB> { class URLCellDataParser implements IGridCellDataParser<URLCellDataPB> {
@override @override
URLCellDataPB? parserData(List<int> data) { URLCellDataPB? parserData(List<int> data) {
if (data.isEmpty) { if (data.isEmpty) {

View File

@ -52,6 +52,7 @@ class GridCellControllerBuilder {
final cellDataLoader = GridCellDataLoader( final cellDataLoader = GridCellDataLoader(
cellId: _cellId, cellId: _cellId,
parser: StringCellDataParser(), parser: StringCellDataParser(),
reloadOnFieldChanged: true,
); );
return GridCellController( return GridCellController(
cellId: _cellId, cellId: _cellId,
@ -170,16 +171,13 @@ class IGridCellController<T, D> extends Equatable {
} }
isListening = true; isListening = true;
/// The cell data will be changed by two reasons:
/// 1. User edit the cell
/// 2. User edit the field
/// For example: The number cell reload the cell data that carries the format
/// user input: 12
/// cell display: $12
_cellDataNotifier = ValueNotifier(_cellsCache.get(_cacheKey)); _cellDataNotifier = ValueNotifier(_cellsCache.get(_cacheKey));
_cellListener = CellListener(rowId: cellId.rowId, fieldId: cellId.field.id); _cellListener = CellListener(rowId: cellId.rowId, fieldId: cellId.field.id);
/// 1.Listen on user edit event and load the new cell data if needed. /// 1.Listen on user edit event and load the new cell data if needed.
/// For example:
/// user input: 12
/// cell display: $12
_cellListener.start(onCellChanged: (result) { _cellListener.start(onCellChanged: (result) {
result.fold( result.fold(
(_) => _loadData(), (_) => _loadData(),
@ -193,6 +191,9 @@ class IGridCellController<T, D> extends Equatable {
onCellFieldChanged(); onCellFieldChanged();
} }
/// reloadOnFieldChanged should be true if you need to load the data when the corresponding field is changed
/// For example:
/// 12 -> $12
if (_cellDataLoader.reloadOnFieldChanged) { if (_cellDataLoader.reloadOnFieldChanged) {
_loadData(); _loadData();
} }

View File

@ -30,15 +30,15 @@ class GridCellBuilder {
final key = cell.key(); final key = cell.key();
switch (cell.fieldType) { switch (cell.fieldType) {
case FieldType.Checkbox: case FieldType.Checkbox:
return CheckboxCell(cellControllerBuilder: cellControllerBuilder, key: key); return GridCheckboxCell(cellControllerBuilder: cellControllerBuilder, key: key);
case FieldType.DateTime: case FieldType.DateTime:
return DateCell(cellControllerBuilder: cellControllerBuilder, key: key, style: style); return GridDateCell(cellControllerBuilder: cellControllerBuilder, key: key, style: style);
case FieldType.SingleSelect: case FieldType.SingleSelect:
return SingleSelectCell(cellContorllerBuilder: cellControllerBuilder, style: style, key: key); return GridSingleSelectCell(cellContorllerBuilder: cellControllerBuilder, style: style, key: key);
case FieldType.MultiSelect: case FieldType.MultiSelect:
return MultiSelectCell(cellContorllerBuilder: cellControllerBuilder, style: style, key: key); return GridMultiSelectCell(cellContorllerBuilder: cellControllerBuilder, style: style, key: key);
case FieldType.Number: case FieldType.Number:
return NumberCell(cellContorllerBuilder: cellControllerBuilder, key: key); return GridNumberCell(cellContorllerBuilder: cellControllerBuilder, key: key);
case FieldType.RichText: case FieldType.RichText:
return GridTextCell(cellContorllerBuilder: cellControllerBuilder, style: style, key: key); return GridTextCell(cellContorllerBuilder: cellControllerBuilder, style: style, key: key);
case FieldType.URL: case FieldType.URL:

View File

@ -6,18 +6,18 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'cell_builder.dart'; import 'cell_builder.dart';
class CheckboxCell extends GridCellWidget { class GridCheckboxCell extends GridCellWidget {
final GridCellControllerBuilder cellControllerBuilder; final GridCellControllerBuilder cellControllerBuilder;
CheckboxCell({ GridCheckboxCell({
required this.cellControllerBuilder, required this.cellControllerBuilder,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@override @override
GridCellState<CheckboxCell> createState() => _CheckboxCellState(); GridCellState<GridCheckboxCell> createState() => _CheckboxCellState();
} }
class _CheckboxCellState extends GridCellState<CheckboxCell> { class _CheckboxCellState extends GridCellState<GridCheckboxCell> {
late CheckboxCellBloc _cellBloc; late CheckboxCellBloc _cellBloc;
@override @override

View File

@ -18,11 +18,11 @@ abstract class GridCellDelegate {
GridCellDelegate get delegate; GridCellDelegate get delegate;
} }
class DateCell extends GridCellWidget { class GridDateCell extends GridCellWidget {
final GridCellControllerBuilder cellControllerBuilder; final GridCellControllerBuilder cellControllerBuilder;
late final DateCellStyle? cellStyle; late final DateCellStyle? cellStyle;
DateCell({ GridDateCell({
GridCellStyle? style, GridCellStyle? style,
required this.cellControllerBuilder, required this.cellControllerBuilder,
Key? key, Key? key,
@ -35,10 +35,10 @@ class DateCell extends GridCellWidget {
} }
@override @override
GridCellState<DateCell> createState() => _DateCellState(); GridCellState<GridDateCell> createState() => _DateCellState();
} }
class _DateCellState extends GridCellState<DateCell> { class _DateCellState extends GridCellState<GridDateCell> {
late DateCellBloc _cellBloc; late DateCellBloc _cellBloc;
@override @override

View File

@ -6,19 +6,19 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'cell_builder.dart'; import 'cell_builder.dart';
class NumberCell extends GridCellWidget { class GridNumberCell extends GridCellWidget {
final GridCellControllerBuilder cellContorllerBuilder; final GridCellControllerBuilder cellContorllerBuilder;
NumberCell({ GridNumberCell({
required this.cellContorllerBuilder, required this.cellContorllerBuilder,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@override @override
GridFocusNodeCellState<NumberCell> createState() => _NumberCellState(); GridFocusNodeCellState<GridNumberCell> createState() => _NumberCellState();
} }
class _NumberCellState extends GridFocusNodeCellState<NumberCell> { class _NumberCellState extends GridFocusNodeCellState<GridNumberCell> {
late NumberCellBloc _cellBloc; late NumberCellBloc _cellBloc;
late TextEditingController _controller; late TextEditingController _controller;
Timer? _delayOperation; Timer? _delayOperation;

View File

@ -20,11 +20,11 @@ class SelectOptionCellStyle extends GridCellStyle {
}); });
} }
class SingleSelectCell extends GridCellWidget { class GridSingleSelectCell extends GridCellWidget {
final GridCellControllerBuilder cellContorllerBuilder; final GridCellControllerBuilder cellContorllerBuilder;
late final SelectOptionCellStyle? cellStyle; late final SelectOptionCellStyle? cellStyle;
SingleSelectCell({ GridSingleSelectCell({
required this.cellContorllerBuilder, required this.cellContorllerBuilder,
GridCellStyle? style, GridCellStyle? style,
Key? key, Key? key,
@ -37,10 +37,10 @@ class SingleSelectCell extends GridCellWidget {
} }
@override @override
State<SingleSelectCell> createState() => _SingleSelectCellState(); State<GridSingleSelectCell> createState() => _SingleSelectCellState();
} }
class _SingleSelectCellState extends State<SingleSelectCell> { class _SingleSelectCellState extends State<GridSingleSelectCell> {
late SelectOptionCellBloc _cellBloc; late SelectOptionCellBloc _cellBloc;
@override @override
@ -74,11 +74,11 @@ class _SingleSelectCellState extends State<SingleSelectCell> {
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
class MultiSelectCell extends GridCellWidget { class GridMultiSelectCell extends GridCellWidget {
final GridCellControllerBuilder cellContorllerBuilder; final GridCellControllerBuilder cellContorllerBuilder;
late final SelectOptionCellStyle? cellStyle; late final SelectOptionCellStyle? cellStyle;
MultiSelectCell({ GridMultiSelectCell({
required this.cellContorllerBuilder, required this.cellContorllerBuilder,
GridCellStyle? style, GridCellStyle? style,
Key? key, Key? key,
@ -91,10 +91,10 @@ class MultiSelectCell extends GridCellWidget {
} }
@override @override
State<MultiSelectCell> createState() => _MultiSelectCellState(); State<GridMultiSelectCell> createState() => _MultiSelectCellState();
} }
class _MultiSelectCellState extends State<MultiSelectCell> { class _MultiSelectCellState extends State<GridMultiSelectCell> {
late SelectOptionCellBloc _cellBloc; late SelectOptionCellBloc _cellBloc;
@override @override