chore: create filter bloc

This commit is contained in:
nathan 2022-11-15 10:47:51 +08:00
parent 5d20e16dc5
commit 3dddd907b0
2 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,118 @@
import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/checkbox_filter.pbenum.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/date_filter.pbenum.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/number_filter.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/select_option_filter.pbserver.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/setting_entities.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/util.pb.dart';
class FilterFFIService {
final String viewId;
const FilterFFIService({required this.viewId});
Future<Either<Unit, FlowyError>> createTextFilter({
required String fieldId,
required TextFilterCondition condition,
String content = "",
}) {
return createFilter(
fieldId: fieldId,
fieldType: FieldType.RichText,
condition: condition.value,
content: content,
);
}
Future<Either<Unit, FlowyError>> createCheckboxFilter({
required String fieldId,
required CheckboxFilterCondition condition,
}) {
return createFilter(
fieldId: fieldId,
fieldType: FieldType.Checkbox,
condition: condition.value,
);
}
Future<Either<Unit, FlowyError>> createNumberFilter({
required String fieldId,
required NumberFilterCondition condition,
String content = "",
}) {
return createFilter(
fieldId: fieldId,
fieldType: FieldType.Checkbox,
condition: condition.value,
content: content,
);
}
Future<Either<Unit, FlowyError>> createDateFilter({
required String fieldId,
required DateFilterCondition condition,
String content = "",
}) {
throw UnimplementedError();
}
Future<Either<Unit, FlowyError>> createURLFilter({
required String fieldId,
required TextFilterCondition condition,
String content = "",
}) {
return createFilter(
fieldId: fieldId,
fieldType: FieldType.URL,
condition: condition.value,
content: content,
);
}
Future<Either<Unit, FlowyError>> createSingleSelectFilter({
required String fieldId,
required SelectOptionCondition condition,
List<String> optionIds = const [],
}) {
return createFilter(
fieldId: fieldId,
fieldType: FieldType.SingleSelect,
condition: condition.value,
);
}
Future<Either<Unit, FlowyError>> createMultiSelectFilter({
required String fieldId,
required SelectOptionCondition condition,
List<String> optionIds = const [],
}) {
return createFilter(
fieldId: fieldId,
fieldType: FieldType.MultiSelect,
condition: condition.value,
);
}
Future<Either<Unit, FlowyError>> createFilter({
required String fieldId,
required FieldType fieldType,
required int condition,
String content = "",
}) {
TextFilterCondition.DoesNotContain.value;
final insertFilterPayload = CreateFilterPayloadPB.create()
..fieldId = fieldId
..fieldType = fieldType
..condition = condition
..content = content;
final payload = GridSettingChangesetPB.create()
..gridId = viewId
..insertFilter = insertFilterPayload;
return GridEventUpdateGridSetting(payload).send();
}
}