mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add get type option data handler
This commit is contained in:
parent
cb0a86893b
commit
13cb7eeb24
@ -59,15 +59,15 @@ class GridCellContextBuilder {
|
||||
}
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class GridCellContext<T> extends Equatable {
|
||||
class GridCellContext<C> extends Equatable {
|
||||
final GridCell gridCell;
|
||||
final GridCellCache cellCache;
|
||||
final GridCellCacheKey _cacheKey;
|
||||
final GridCellDataLoader<T> cellDataLoader;
|
||||
final GridCellDataLoader<C> cellDataLoader;
|
||||
final CellService _cellService = CellService();
|
||||
|
||||
late final CellListener _cellListener;
|
||||
late final ValueNotifier<T?> _cellDataNotifier;
|
||||
late final ValueNotifier<C?> _cellDataNotifier;
|
||||
bool isListening = false;
|
||||
VoidCallback? _onFieldChangedFn;
|
||||
Timer? _delayOperation;
|
||||
@ -78,7 +78,7 @@ class GridCellContext<T> extends Equatable {
|
||||
required this.cellDataLoader,
|
||||
}) : _cacheKey = GridCellCacheKey(objectId: gridCell.rowId, fieldId: gridCell.field.id);
|
||||
|
||||
GridCellContext<T> clone() {
|
||||
GridCellContext<C> clone() {
|
||||
return GridCellContext(
|
||||
gridCell: gridCell,
|
||||
cellDataLoader: cellDataLoader,
|
||||
@ -100,7 +100,7 @@ class GridCellContext<T> extends Equatable {
|
||||
|
||||
GridCellCacheKey get cacheKey => _cacheKey;
|
||||
|
||||
VoidCallback? startListening({required void Function(T) onCellChanged}) {
|
||||
VoidCallback? startListening({required void Function(C) onCellChanged}) {
|
||||
if (isListening) {
|
||||
Log.error("Already started. It seems like you should call clone first");
|
||||
return null;
|
||||
@ -125,7 +125,7 @@ class GridCellContext<T> extends Equatable {
|
||||
|
||||
onCellChangedFn() {
|
||||
final value = _cellDataNotifier.value;
|
||||
if (value is T) {
|
||||
if (value is C) {
|
||||
onCellChanged(value);
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ class GridCellContext<T> extends Equatable {
|
||||
_cellDataNotifier.removeListener(fn);
|
||||
}
|
||||
|
||||
T? getCellData() {
|
||||
C? getCellData() {
|
||||
final data = cellCache.get(cacheKey);
|
||||
if (data == null) {
|
||||
_loadData();
|
||||
|
@ -1,13 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'package:app_flowy/workspace/application/grid/cell/cell_service.dart';
|
||||
|
||||
import 'select_option_service.dart';
|
||||
|
||||
part 'selection_editor_bloc.freezed.dart';
|
||||
|
@ -119,14 +119,12 @@ class _FieldEditorPannelState extends State<FieldEditorPannel> {
|
||||
context.read<FieldEditorPannelBloc>().add(FieldEditorPannelEvent.didUpdateTypeOptionData(data));
|
||||
});
|
||||
|
||||
final typeOptionContext = TypeOptionContext(
|
||||
gridId: state.gridId,
|
||||
field: state.field,
|
||||
data: state.typeOptionData,
|
||||
);
|
||||
|
||||
final builder = _makeTypeOptionBuild(
|
||||
typeOptionContext: typeOptionContext,
|
||||
typeOptionContext: TypeOptionContext(
|
||||
gridId: state.gridId,
|
||||
field: state.field,
|
||||
data: state.typeOptionData,
|
||||
),
|
||||
overlayDelegate: overlayDelegate,
|
||||
dataDelegate: dataDelegate,
|
||||
);
|
||||
|
@ -171,6 +171,23 @@ class GridEventMoveItem {
|
||||
}
|
||||
}
|
||||
|
||||
class GridEventGetFieldTypeOption {
|
||||
GetEditFieldContextPayload request;
|
||||
GridEventGetFieldTypeOption(this.request);
|
||||
|
||||
Future<Either<FieldTypeOptionData, FlowyError>> send() {
|
||||
final request = FFIRequest.create()
|
||||
..event = GridEvent.GetFieldTypeOption.toString()
|
||||
..payload = requestToBytes(this.request);
|
||||
|
||||
return Dispatch.asyncRequest(request)
|
||||
.then((bytesResult) => bytesResult.fold(
|
||||
(okBytes) => left(FieldTypeOptionData.fromBuffer(okBytes)),
|
||||
(errBytes) => right(FlowyError.fromBuffer(errBytes)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class GridEventNewSelectOption {
|
||||
CreateSelectOptionPayload request;
|
||||
GridEventNewSelectOption(this.request);
|
||||
|
@ -642,6 +642,67 @@ class EditFieldContext extends $pb.GeneratedMessage {
|
||||
void clearTypeOptionData() => clearField(3);
|
||||
}
|
||||
|
||||
class FieldTypeOptionData extends $pb.GeneratedMessage {
|
||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'FieldTypeOptionData', createEmptyInstance: create)
|
||||
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'fieldId')
|
||||
..a<$core.List<$core.int>>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'typeOptionData', $pb.PbFieldType.OY)
|
||||
..hasRequiredFields = false
|
||||
;
|
||||
|
||||
FieldTypeOptionData._() : super();
|
||||
factory FieldTypeOptionData({
|
||||
$core.String? fieldId,
|
||||
$core.List<$core.int>? typeOptionData,
|
||||
}) {
|
||||
final _result = create();
|
||||
if (fieldId != null) {
|
||||
_result.fieldId = fieldId;
|
||||
}
|
||||
if (typeOptionData != null) {
|
||||
_result.typeOptionData = typeOptionData;
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
factory FieldTypeOptionData.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
||||
factory FieldTypeOptionData.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
|
||||
@$core.Deprecated(
|
||||
'Using this can add significant overhead to your binary. '
|
||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
||||
'Will be removed in next major version')
|
||||
FieldTypeOptionData clone() => FieldTypeOptionData()..mergeFromMessage(this);
|
||||
@$core.Deprecated(
|
||||
'Using this can add significant overhead to your binary. '
|
||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||
'Will be removed in next major version')
|
||||
FieldTypeOptionData copyWith(void Function(FieldTypeOptionData) updates) => super.copyWith((message) => updates(message as FieldTypeOptionData)) as FieldTypeOptionData; // ignore: deprecated_member_use
|
||||
$pb.BuilderInfo get info_ => _i;
|
||||
@$core.pragma('dart2js:noInline')
|
||||
static FieldTypeOptionData create() => FieldTypeOptionData._();
|
||||
FieldTypeOptionData createEmptyInstance() => create();
|
||||
static $pb.PbList<FieldTypeOptionData> createRepeated() => $pb.PbList<FieldTypeOptionData>();
|
||||
@$core.pragma('dart2js:noInline')
|
||||
static FieldTypeOptionData getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<FieldTypeOptionData>(create);
|
||||
static FieldTypeOptionData? _defaultInstance;
|
||||
|
||||
@$pb.TagNumber(1)
|
||||
$core.String get fieldId => $_getSZ(0);
|
||||
@$pb.TagNumber(1)
|
||||
set fieldId($core.String v) { $_setString(0, v); }
|
||||
@$pb.TagNumber(1)
|
||||
$core.bool hasFieldId() => $_has(0);
|
||||
@$pb.TagNumber(1)
|
||||
void clearFieldId() => clearField(1);
|
||||
|
||||
@$pb.TagNumber(2)
|
||||
$core.List<$core.int> get typeOptionData => $_getN(1);
|
||||
@$pb.TagNumber(2)
|
||||
set typeOptionData($core.List<$core.int> v) { $_setBytes(1, v); }
|
||||
@$pb.TagNumber(2)
|
||||
$core.bool hasTypeOptionData() => $_has(1);
|
||||
@$pb.TagNumber(2)
|
||||
void clearTypeOptionData() => clearField(2);
|
||||
}
|
||||
|
||||
class RepeatedField extends $pb.GeneratedMessage {
|
||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'RepeatedField', createEmptyInstance: create)
|
||||
..pc<Field>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'items', $pb.PbFieldType.PM, subBuilder: Field.create)
|
||||
|
@ -136,6 +136,17 @@ const EditFieldContext$json = const {
|
||||
|
||||
/// Descriptor for `EditFieldContext`. Decode as a `google.protobuf.DescriptorProto`.
|
||||
final $typed_data.Uint8List editFieldContextDescriptor = $convert.base64Decode('ChBFZGl0RmllbGRDb250ZXh0EhcKB2dyaWRfaWQYASABKAlSBmdyaWRJZBIlCgpncmlkX2ZpZWxkGAIgASgLMgYuRmllbGRSCWdyaWRGaWVsZBIoChB0eXBlX29wdGlvbl9kYXRhGAMgASgMUg50eXBlT3B0aW9uRGF0YQ==');
|
||||
@$core.Deprecated('Use fieldTypeOptionDataDescriptor instead')
|
||||
const FieldTypeOptionData$json = const {
|
||||
'1': 'FieldTypeOptionData',
|
||||
'2': const [
|
||||
const {'1': 'field_id', '3': 1, '4': 1, '5': 9, '10': 'fieldId'},
|
||||
const {'1': 'type_option_data', '3': 2, '4': 1, '5': 12, '10': 'typeOptionData'},
|
||||
],
|
||||
};
|
||||
|
||||
/// Descriptor for `FieldTypeOptionData`. Decode as a `google.protobuf.DescriptorProto`.
|
||||
final $typed_data.Uint8List fieldTypeOptionDataDescriptor = $convert.base64Decode('ChNGaWVsZFR5cGVPcHRpb25EYXRhEhkKCGZpZWxkX2lkGAEgASgJUgdmaWVsZElkEigKEHR5cGVfb3B0aW9uX2RhdGEYAiABKAxSDnR5cGVPcHRpb25EYXRh');
|
||||
@$core.Deprecated('Use repeatedFieldDescriptor instead')
|
||||
const RepeatedField$json = const {
|
||||
'1': 'RepeatedField',
|
||||
|
@ -20,6 +20,7 @@ class GridEvent extends $pb.ProtobufEnum {
|
||||
static const GridEvent DuplicateField = GridEvent._(15, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DuplicateField');
|
||||
static const GridEvent GetEditFieldContext = GridEvent._(16, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetEditFieldContext');
|
||||
static const GridEvent MoveItem = GridEvent._(17, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'MoveItem');
|
||||
static const GridEvent GetFieldTypeOption = GridEvent._(18, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetFieldTypeOption');
|
||||
static const GridEvent NewSelectOption = GridEvent._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NewSelectOption');
|
||||
static const GridEvent GetSelectOptionContext = GridEvent._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'GetSelectOptionContext');
|
||||
static const GridEvent UpdateSelectOption = GridEvent._(32, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateSelectOption');
|
||||
@ -42,6 +43,7 @@ class GridEvent extends $pb.ProtobufEnum {
|
||||
DuplicateField,
|
||||
GetEditFieldContext,
|
||||
MoveItem,
|
||||
GetFieldTypeOption,
|
||||
NewSelectOption,
|
||||
GetSelectOptionContext,
|
||||
UpdateSelectOption,
|
||||
|
@ -22,6 +22,7 @@ const GridEvent$json = const {
|
||||
const {'1': 'DuplicateField', '2': 15},
|
||||
const {'1': 'GetEditFieldContext', '2': 16},
|
||||
const {'1': 'MoveItem', '2': 17},
|
||||
const {'1': 'GetFieldTypeOption', '2': 18},
|
||||
const {'1': 'NewSelectOption', '2': 30},
|
||||
const {'1': 'GetSelectOptionContext', '2': 31},
|
||||
const {'1': 'UpdateSelectOption', '2': 32},
|
||||
@ -36,4 +37,4 @@ const GridEvent$json = const {
|
||||
};
|
||||
|
||||
/// Descriptor for `GridEvent`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
||||
final $typed_data.Uint8List gridEventDescriptor = $convert.base64Decode('CglHcmlkRXZlbnQSDwoLR2V0R3JpZERhdGEQABIRCg1HZXRHcmlkQmxvY2tzEAESDQoJR2V0RmllbGRzEAoSDwoLVXBkYXRlRmllbGQQCxIPCgtJbnNlcnRGaWVsZBAMEg8KC0RlbGV0ZUZpZWxkEA0SEQoNU3dpdGNoVG9GaWVsZBAOEhIKDkR1cGxpY2F0ZUZpZWxkEA8SFwoTR2V0RWRpdEZpZWxkQ29udGV4dBAQEgwKCE1vdmVJdGVtEBESEwoPTmV3U2VsZWN0T3B0aW9uEB4SGgoWR2V0U2VsZWN0T3B0aW9uQ29udGV4dBAfEhYKElVwZGF0ZVNlbGVjdE9wdGlvbhAgEg0KCUNyZWF0ZVJvdxAyEgoKBkdldFJvdxAzEg0KCURlbGV0ZVJvdxA0EhAKDER1cGxpY2F0ZVJvdxA1EgsKB0dldENlbGwQRhIOCgpVcGRhdGVDZWxsEEcSGgoWVXBkYXRlQ2VsbFNlbGVjdE9wdGlvbhBI');
|
||||
final $typed_data.Uint8List gridEventDescriptor = $convert.base64Decode('CglHcmlkRXZlbnQSDwoLR2V0R3JpZERhdGEQABIRCg1HZXRHcmlkQmxvY2tzEAESDQoJR2V0RmllbGRzEAoSDwoLVXBkYXRlRmllbGQQCxIPCgtJbnNlcnRGaWVsZBAMEg8KC0RlbGV0ZUZpZWxkEA0SEQoNU3dpdGNoVG9GaWVsZBAOEhIKDkR1cGxpY2F0ZUZpZWxkEA8SFwoTR2V0RWRpdEZpZWxkQ29udGV4dBAQEgwKCE1vdmVJdGVtEBESFgoSR2V0RmllbGRUeXBlT3B0aW9uEBISEwoPTmV3U2VsZWN0T3B0aW9uEB4SGgoWR2V0U2VsZWN0T3B0aW9uQ29udGV4dBAfEhYKElVwZGF0ZVNlbGVjdE9wdGlvbhAgEg0KCUNyZWF0ZVJvdxAyEgoKBkdldFJvdxAzEg0KCURlbGV0ZVJvdxA0EhAKDER1cGxpY2F0ZVJvdxA1EgsKB0dldENlbGwQRhIOCgpVcGRhdGVDZWxsEEcSGgoWVXBkYXRlQ2VsbFNlbGVjdE9wdGlvbhBI');
|
||||
|
@ -128,6 +128,22 @@ pub(crate) async fn get_field_context_handler(
|
||||
data_result(edit_context)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn get_field_type_option_data_handler(
|
||||
data: Data<GetEditFieldContextPayload>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<FieldTypeOptionData, FlowyError> {
|
||||
let params = data.into_inner();
|
||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||
let field_meta = get_or_create_field_meta(params.field_id, ¶ms.field_type, editor).await?;
|
||||
let type_option_data = get_type_option_data(&field_meta, &field_meta.field_type).await?;
|
||||
|
||||
data_result(FieldTypeOptionData {
|
||||
field_id: field_meta.id.clone(),
|
||||
type_option_data,
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn move_item_handler(
|
||||
data: Data<MoveItemPayload>,
|
||||
@ -147,12 +163,7 @@ async fn make_field_edit_context(
|
||||
field_meta: Option<FieldMeta>,
|
||||
) -> FlowyResult<EditFieldContext> {
|
||||
let field_meta = field_meta.unwrap_or(get_or_create_field_meta(field_id, &field_type, editor).await?);
|
||||
let s = field_meta
|
||||
.get_type_option_str(None)
|
||||
.unwrap_or_else(|| default_type_option_builder_from_type(&field_type).entry().json_str());
|
||||
|
||||
let builder = type_option_builder_from_json_str(&s, &field_meta.field_type);
|
||||
let type_option_data = builder.entry().protobuf_bytes().to_vec();
|
||||
let type_option_data = get_type_option_data(&field_meta, &field_type).await?;
|
||||
let field: Field = field_meta.into();
|
||||
Ok(EditFieldContext {
|
||||
grid_id: grid_id.to_string(),
|
||||
@ -161,6 +172,16 @@ async fn make_field_edit_context(
|
||||
})
|
||||
}
|
||||
|
||||
async fn get_type_option_data(field_meta: &FieldMeta, field_type: &FieldType) -> FlowyResult<Vec<u8>> {
|
||||
let s = field_meta
|
||||
.get_type_option_str(&field_type)
|
||||
.unwrap_or_else(|| default_type_option_builder_from_type(&field_type).entry().json_str());
|
||||
let builder = type_option_builder_from_json_str(&s, &field_meta.field_type);
|
||||
let type_option_data = builder.entry().protobuf_bytes().to_vec();
|
||||
|
||||
Ok(type_option_data)
|
||||
}
|
||||
|
||||
async fn get_or_create_field_meta(
|
||||
field_id: Option<String>,
|
||||
field_type: &FieldType,
|
||||
@ -221,7 +242,7 @@ pub(crate) async fn create_row_handler(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
// #[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub(crate) async fn get_cell_handler(
|
||||
data: Data<CellIdentifierPayload>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
|
@ -19,6 +19,7 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
|
||||
.event(GridEvent::DuplicateField, duplicate_field_handler)
|
||||
.event(GridEvent::GetEditFieldContext, get_field_context_handler)
|
||||
.event(GridEvent::MoveItem, move_item_handler)
|
||||
.event(GridEvent::GetFieldTypeOption, get_field_type_option_data_handler)
|
||||
// Row
|
||||
.event(GridEvent::CreateRow, create_row_handler)
|
||||
.event(GridEvent::GetRow, get_row_handler)
|
||||
@ -69,6 +70,9 @@ pub enum GridEvent {
|
||||
#[event(input = "MoveItemPayload")]
|
||||
MoveItem = 17,
|
||||
|
||||
#[event(input = "GetEditFieldContextPayload", output = "FieldTypeOptionData")]
|
||||
GetFieldTypeOption = 18,
|
||||
|
||||
#[event(input = "CreateSelectOptionPayload", output = "SelectOption")]
|
||||
NewSelectOption = 30,
|
||||
|
||||
|
@ -35,6 +35,7 @@ pub enum GridEvent {
|
||||
DuplicateField = 15,
|
||||
GetEditFieldContext = 16,
|
||||
MoveItem = 17,
|
||||
GetFieldTypeOption = 18,
|
||||
NewSelectOption = 30,
|
||||
GetSelectOptionContext = 31,
|
||||
UpdateSelectOption = 32,
|
||||
@ -64,6 +65,7 @@ impl ::protobuf::ProtobufEnum for GridEvent {
|
||||
15 => ::std::option::Option::Some(GridEvent::DuplicateField),
|
||||
16 => ::std::option::Option::Some(GridEvent::GetEditFieldContext),
|
||||
17 => ::std::option::Option::Some(GridEvent::MoveItem),
|
||||
18 => ::std::option::Option::Some(GridEvent::GetFieldTypeOption),
|
||||
30 => ::std::option::Option::Some(GridEvent::NewSelectOption),
|
||||
31 => ::std::option::Option::Some(GridEvent::GetSelectOptionContext),
|
||||
32 => ::std::option::Option::Some(GridEvent::UpdateSelectOption),
|
||||
@ -90,6 +92,7 @@ impl ::protobuf::ProtobufEnum for GridEvent {
|
||||
GridEvent::DuplicateField,
|
||||
GridEvent::GetEditFieldContext,
|
||||
GridEvent::MoveItem,
|
||||
GridEvent::GetFieldTypeOption,
|
||||
GridEvent::NewSelectOption,
|
||||
GridEvent::GetSelectOptionContext,
|
||||
GridEvent::UpdateSelectOption,
|
||||
@ -128,16 +131,17 @@ impl ::protobuf::reflect::ProtobufValue for GridEvent {
|
||||
}
|
||||
|
||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\n\x0fevent_map.proto*\xfd\x02\n\tGridEvent\x12\x0f\n\x0bGetGridData\x10\
|
||||
\n\x0fevent_map.proto*\x95\x03\n\tGridEvent\x12\x0f\n\x0bGetGridData\x10\
|
||||
\0\x12\x11\n\rGetGridBlocks\x10\x01\x12\r\n\tGetFields\x10\n\x12\x0f\n\
|
||||
\x0bUpdateField\x10\x0b\x12\x0f\n\x0bInsertField\x10\x0c\x12\x0f\n\x0bDe\
|
||||
leteField\x10\r\x12\x11\n\rSwitchToField\x10\x0e\x12\x12\n\x0eDuplicateF\
|
||||
ield\x10\x0f\x12\x17\n\x13GetEditFieldContext\x10\x10\x12\x0c\n\x08MoveI\
|
||||
tem\x10\x11\x12\x13\n\x0fNewSelectOption\x10\x1e\x12\x1a\n\x16GetSelectO\
|
||||
ptionContext\x10\x1f\x12\x16\n\x12UpdateSelectOption\x10\x20\x12\r\n\tCr\
|
||||
eateRow\x102\x12\n\n\x06GetRow\x103\x12\r\n\tDeleteRow\x104\x12\x10\n\
|
||||
\x0cDuplicateRow\x105\x12\x0b\n\x07GetCell\x10F\x12\x0e\n\nUpdateCell\
|
||||
\x10G\x12\x1a\n\x16UpdateCellSelectOption\x10Hb\x06proto3\
|
||||
tem\x10\x11\x12\x16\n\x12GetFieldTypeOption\x10\x12\x12\x13\n\x0fNewSele\
|
||||
ctOption\x10\x1e\x12\x1a\n\x16GetSelectOptionContext\x10\x1f\x12\x16\n\
|
||||
\x12UpdateSelectOption\x10\x20\x12\r\n\tCreateRow\x102\x12\n\n\x06GetRow\
|
||||
\x103\x12\r\n\tDeleteRow\x104\x12\x10\n\x0cDuplicateRow\x105\x12\x0b\n\
|
||||
\x07GetCell\x10F\x12\x0e\n\nUpdateCell\x10G\x12\x1a\n\x16UpdateCellSelec\
|
||||
tOption\x10Hb\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
@ -11,6 +11,7 @@ enum GridEvent {
|
||||
DuplicateField = 15;
|
||||
GetEditFieldContext = 16;
|
||||
MoveItem = 17;
|
||||
GetFieldTypeOption = 18;
|
||||
NewSelectOption = 30;
|
||||
GetSelectOptionContext = 31;
|
||||
UpdateSelectOption = 32;
|
||||
|
@ -121,7 +121,6 @@ pub fn apply_cell_data_changeset<T: Into<CellDataChangeset>>(
|
||||
// Ok(s)
|
||||
// }
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(field_meta, data), fields(content))]
|
||||
pub fn decode_cell_data(data: String, field_meta: &FieldMeta, field_type: &FieldType) -> Option<String> {
|
||||
let s = match field_type {
|
||||
FieldType::RichText => field_meta
|
||||
|
@ -36,7 +36,6 @@ pub fn make_cell_by_field_id(
|
||||
Some((field_id, cell))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn make_cell(field_id: &str, field_meta: &FieldMeta, row_meta: &RowMeta) -> Option<Cell> {
|
||||
let cell_meta = row_meta.cells.get(field_id)?.clone();
|
||||
let content = decode_cell_data(cell_meta.data, field_meta, &field_meta.field_type)?;
|
||||
|
@ -206,6 +206,15 @@ pub struct EditFieldContext {
|
||||
pub type_option_data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct FieldTypeOptionData {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub type_option_data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct RepeatedField {
|
||||
#[pb(index = 1)]
|
||||
|
@ -95,7 +95,6 @@ pub struct FieldMeta {
|
||||
|
||||
pub width: i32,
|
||||
|
||||
// #[pb(index = 8)]
|
||||
/// type_options contains key/value pairs
|
||||
/// key: id of the FieldType
|
||||
/// value: type option data that can be parsed into specified TypeOptionStruct.
|
||||
@ -144,8 +143,7 @@ impl FieldMeta {
|
||||
self.type_options.insert(field_type.type_id(), json_str);
|
||||
}
|
||||
|
||||
pub fn get_type_option_str(&self, field_type: Option<FieldType>) -> Option<String> {
|
||||
let field_type = field_type.as_ref().unwrap_or(&self.field_type);
|
||||
pub fn get_type_option_str(&self, field_type: &FieldType) -> Option<String> {
|
||||
self.type_options.get(&field_type.type_id()).map(|s| s.to_owned())
|
||||
}
|
||||
}
|
||||
|
@ -2130,6 +2130,207 @@ impl ::protobuf::reflect::ProtobufValue for EditFieldContext {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct FieldTypeOptionData {
|
||||
// message fields
|
||||
pub field_id: ::std::string::String,
|
||||
pub type_option_data: ::std::vec::Vec<u8>,
|
||||
// special fields
|
||||
pub unknown_fields: ::protobuf::UnknownFields,
|
||||
pub cached_size: ::protobuf::CachedSize,
|
||||
}
|
||||
|
||||
impl<'a> ::std::default::Default for &'a FieldTypeOptionData {
|
||||
fn default() -> &'a FieldTypeOptionData {
|
||||
<FieldTypeOptionData as ::protobuf::Message>::default_instance()
|
||||
}
|
||||
}
|
||||
|
||||
impl FieldTypeOptionData {
|
||||
pub fn new() -> FieldTypeOptionData {
|
||||
::std::default::Default::default()
|
||||
}
|
||||
|
||||
// string field_id = 1;
|
||||
|
||||
|
||||
pub fn get_field_id(&self) -> &str {
|
||||
&self.field_id
|
||||
}
|
||||
pub fn clear_field_id(&mut self) {
|
||||
self.field_id.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_field_id(&mut self, v: ::std::string::String) {
|
||||
self.field_id = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_field_id(&mut self) -> &mut ::std::string::String {
|
||||
&mut self.field_id
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_field_id(&mut self) -> ::std::string::String {
|
||||
::std::mem::replace(&mut self.field_id, ::std::string::String::new())
|
||||
}
|
||||
|
||||
// bytes type_option_data = 2;
|
||||
|
||||
|
||||
pub fn get_type_option_data(&self) -> &[u8] {
|
||||
&self.type_option_data
|
||||
}
|
||||
pub fn clear_type_option_data(&mut self) {
|
||||
self.type_option_data.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_type_option_data(&mut self, v: ::std::vec::Vec<u8>) {
|
||||
self.type_option_data = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_type_option_data(&mut self) -> &mut ::std::vec::Vec<u8> {
|
||||
&mut self.type_option_data
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_type_option_data(&mut self) -> ::std::vec::Vec<u8> {
|
||||
::std::mem::replace(&mut self.type_option_data, ::std::vec::Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Message for FieldTypeOptionData {
|
||||
fn is_initialized(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
while !is.eof()? {
|
||||
let (field_number, wire_type) = is.read_tag_unpack()?;
|
||||
match field_number {
|
||||
1 => {
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.field_id)?;
|
||||
},
|
||||
2 => {
|
||||
::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.type_option_data)?;
|
||||
},
|
||||
_ => {
|
||||
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
|
||||
},
|
||||
};
|
||||
}
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
||||
// Compute sizes of nested messages
|
||||
#[allow(unused_variables)]
|
||||
fn compute_size(&self) -> u32 {
|
||||
let mut my_size = 0;
|
||||
if !self.field_id.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(1, &self.field_id);
|
||||
}
|
||||
if !self.type_option_data.is_empty() {
|
||||
my_size += ::protobuf::rt::bytes_size(2, &self.type_option_data);
|
||||
}
|
||||
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
|
||||
self.cached_size.set(my_size);
|
||||
my_size
|
||||
}
|
||||
|
||||
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
if !self.field_id.is_empty() {
|
||||
os.write_string(1, &self.field_id)?;
|
||||
}
|
||||
if !self.type_option_data.is_empty() {
|
||||
os.write_bytes(2, &self.type_option_data)?;
|
||||
}
|
||||
os.write_unknown_fields(self.get_unknown_fields())?;
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
||||
fn get_cached_size(&self) -> u32 {
|
||||
self.cached_size.get()
|
||||
}
|
||||
|
||||
fn get_unknown_fields(&self) -> &::protobuf::UnknownFields {
|
||||
&self.unknown_fields
|
||||
}
|
||||
|
||||
fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields {
|
||||
&mut self.unknown_fields
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn (::std::any::Any) {
|
||||
self as &dyn (::std::any::Any)
|
||||
}
|
||||
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
|
||||
self as &mut dyn (::std::any::Any)
|
||||
}
|
||||
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||
self
|
||||
}
|
||||
|
||||
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
Self::descriptor_static()
|
||||
}
|
||||
|
||||
fn new() -> FieldTypeOptionData {
|
||||
FieldTypeOptionData::new()
|
||||
}
|
||||
|
||||
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT;
|
||||
descriptor.get(|| {
|
||||
let mut fields = ::std::vec::Vec::new();
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
|
||||
"field_id",
|
||||
|m: &FieldTypeOptionData| { &m.field_id },
|
||||
|m: &mut FieldTypeOptionData| { &mut m.field_id },
|
||||
));
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>(
|
||||
"type_option_data",
|
||||
|m: &FieldTypeOptionData| { &m.type_option_data },
|
||||
|m: &mut FieldTypeOptionData| { &mut m.type_option_data },
|
||||
));
|
||||
::protobuf::reflect::MessageDescriptor::new_pb_name::<FieldTypeOptionData>(
|
||||
"FieldTypeOptionData",
|
||||
fields,
|
||||
file_descriptor_proto()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn default_instance() -> &'static FieldTypeOptionData {
|
||||
static instance: ::protobuf::rt::LazyV2<FieldTypeOptionData> = ::protobuf::rt::LazyV2::INIT;
|
||||
instance.get(FieldTypeOptionData::new)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Clear for FieldTypeOptionData {
|
||||
fn clear(&mut self) {
|
||||
self.field_id.clear();
|
||||
self.type_option_data.clear();
|
||||
self.unknown_fields.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for FieldTypeOptionData {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
::protobuf::text_format::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::reflect::ProtobufValue for FieldTypeOptionData {
|
||||
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
|
||||
::protobuf::reflect::ReflectValueRef::Message(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct RepeatedField {
|
||||
// message fields
|
||||
@ -7733,39 +7934,41 @@ static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
e\x18\x03\x20\x01(\x0e2\n.FieldTypeR\tfieldType\"|\n\x10EditFieldContext\
|
||||
\x12\x17\n\x07grid_id\x18\x01\x20\x01(\tR\x06gridId\x12%\n\ngrid_field\
|
||||
\x18\x02\x20\x01(\x0b2\x06.FieldR\tgridField\x12(\n\x10type_option_data\
|
||||
\x18\x03\x20\x01(\x0cR\x0etypeOptionData\"-\n\rRepeatedField\x12\x1c\n\
|
||||
\x05items\x18\x01\x20\x03(\x0b2\x06.FieldR\x05items\"7\n\x12RepeatedFiel\
|
||||
dOrder\x12!\n\x05items\x18\x01\x20\x03(\x0b2\x0b.FieldOrderR\x05items\"T\
|
||||
\n\x08RowOrder\x12\x15\n\x06row_id\x18\x01\x20\x01(\tR\x05rowId\x12\x19\
|
||||
\n\x08block_id\x18\x02\x20\x01(\tR\x07blockId\x12\x16\n\x06height\x18\
|
||||
\x03\x20\x01(\x05R\x06height\"\xb8\x01\n\x03Row\x12\x0e\n\x02id\x18\x01\
|
||||
\x20\x01(\tR\x02id\x12@\n\x10cell_by_field_id\x18\x02\x20\x03(\x0b2\x17.\
|
||||
Row.CellByFieldIdEntryR\rcellByFieldId\x12\x16\n\x06height\x18\x03\x20\
|
||||
\x01(\x05R\x06height\x1aG\n\x12CellByFieldIdEntry\x12\x10\n\x03key\x18\
|
||||
\x01\x20\x01(\tR\x03key\x12\x1b\n\x05value\x18\x02\x20\x01(\x0b2\x05.Cel\
|
||||
lR\x05value:\x028\x01\")\n\x0bRepeatedRow\x12\x1a\n\x05items\x18\x01\x20\
|
||||
\x03(\x0b2\x04.RowR\x05items\"5\n\x11RepeatedGridBlock\x12\x20\n\x05item\
|
||||
s\x18\x01\x20\x03(\x0b2\n.GridBlockR\x05items\"U\n\x0eGridBlockOrder\x12\
|
||||
\x19\n\x08block_id\x18\x01\x20\x01(\tR\x07blockId\x12(\n\nrow_orders\x18\
|
||||
\x02\x20\x03(\x0b2\t.RowOrderR\trowOrders\"_\n\rIndexRowOrder\x12&\n\tro\
|
||||
w_order\x18\x01\x20\x01(\x0b2\t.RowOrderR\x08rowOrder\x12\x16\n\x05index\
|
||||
\x18\x02\x20\x01(\x05H\0R\x05indexB\x0e\n\x0cone_of_index\"Q\n\x0fUpdate\
|
||||
dRowOrder\x12&\n\trow_order\x18\x01\x20\x01(\x0b2\t.RowOrderR\x08rowOrde\
|
||||
r\x12\x16\n\x03row\x18\x02\x20\x01(\x0b2\x04.RowR\x03row\"\xc6\x01\n\x11\
|
||||
GridRowsChangeset\x12\x19\n\x08block_id\x18\x01\x20\x01(\tR\x07blockId\
|
||||
\x123\n\rinserted_rows\x18\x02\x20\x03(\x0b2\x0e.IndexRowOrderR\x0cinser\
|
||||
tedRows\x12,\n\x0cdeleted_rows\x18\x03\x20\x03(\x0b2\t.RowOrderR\x0bdele\
|
||||
tedRows\x123\n\x0cupdated_rows\x18\x04\x20\x03(\x0b2\x10.UpdatedRowOrder\
|
||||
R\x0bupdatedRows\"E\n\tGridBlock\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02\
|
||||
id\x12(\n\nrow_orders\x18\x02\x20\x03(\x0b2\t.RowOrderR\trowOrders\";\n\
|
||||
\x04Cell\x12\x19\n\x08field_id\x18\x01\x20\x01(\tR\x07fieldId\x12\x18\n\
|
||||
\x07content\x18\x02\x20\x01(\tR\x07content\"+\n\x0cRepeatedCell\x12\x1b\
|
||||
\n\x05items\x18\x01\x20\x03(\x0b2\x05.CellR\x05items\"'\n\x11CreateGridP\
|
||||
ayload\x12\x12\n\x04name\x18\x01\x20\x01(\tR\x04name\"\x1e\n\x06GridId\
|
||||
\x12\x14\n\x05value\x18\x01\x20\x01(\tR\x05value\"#\n\x0bGridBlockId\x12\
|
||||
\x14\n\x05value\x18\x01\x20\x01(\tR\x05value\"f\n\x10CreateRowPayload\
|
||||
\x12\x17\n\x07grid_id\x18\x01\x20\x01(\tR\x06gridId\x12\"\n\x0cstart_row\
|
||||
_id\x18\x02\x20\x01(\tH\0R\nstartRowIdB\x15\n\x13one_of_start_row_id\"\
|
||||
\x18\x03\x20\x01(\x0cR\x0etypeOptionData\"Z\n\x13FieldTypeOptionData\x12\
|
||||
\x19\n\x08field_id\x18\x01\x20\x01(\tR\x07fieldId\x12(\n\x10type_option_\
|
||||
data\x18\x02\x20\x01(\x0cR\x0etypeOptionData\"-\n\rRepeatedField\x12\x1c\
|
||||
\n\x05items\x18\x01\x20\x03(\x0b2\x06.FieldR\x05items\"7\n\x12RepeatedFi\
|
||||
eldOrder\x12!\n\x05items\x18\x01\x20\x03(\x0b2\x0b.FieldOrderR\x05items\
|
||||
\"T\n\x08RowOrder\x12\x15\n\x06row_id\x18\x01\x20\x01(\tR\x05rowId\x12\
|
||||
\x19\n\x08block_id\x18\x02\x20\x01(\tR\x07blockId\x12\x16\n\x06height\
|
||||
\x18\x03\x20\x01(\x05R\x06height\"\xb8\x01\n\x03Row\x12\x0e\n\x02id\x18\
|
||||
\x01\x20\x01(\tR\x02id\x12@\n\x10cell_by_field_id\x18\x02\x20\x03(\x0b2\
|
||||
\x17.Row.CellByFieldIdEntryR\rcellByFieldId\x12\x16\n\x06height\x18\x03\
|
||||
\x20\x01(\x05R\x06height\x1aG\n\x12CellByFieldIdEntry\x12\x10\n\x03key\
|
||||
\x18\x01\x20\x01(\tR\x03key\x12\x1b\n\x05value\x18\x02\x20\x01(\x0b2\x05\
|
||||
.CellR\x05value:\x028\x01\")\n\x0bRepeatedRow\x12\x1a\n\x05items\x18\x01\
|
||||
\x20\x03(\x0b2\x04.RowR\x05items\"5\n\x11RepeatedGridBlock\x12\x20\n\x05\
|
||||
items\x18\x01\x20\x03(\x0b2\n.GridBlockR\x05items\"U\n\x0eGridBlockOrder\
|
||||
\x12\x19\n\x08block_id\x18\x01\x20\x01(\tR\x07blockId\x12(\n\nrow_orders\
|
||||
\x18\x02\x20\x03(\x0b2\t.RowOrderR\trowOrders\"_\n\rIndexRowOrder\x12&\n\
|
||||
\trow_order\x18\x01\x20\x01(\x0b2\t.RowOrderR\x08rowOrder\x12\x16\n\x05i\
|
||||
ndex\x18\x02\x20\x01(\x05H\0R\x05indexB\x0e\n\x0cone_of_index\"Q\n\x0fUp\
|
||||
datedRowOrder\x12&\n\trow_order\x18\x01\x20\x01(\x0b2\t.RowOrderR\x08row\
|
||||
Order\x12\x16\n\x03row\x18\x02\x20\x01(\x0b2\x04.RowR\x03row\"\xc6\x01\n\
|
||||
\x11GridRowsChangeset\x12\x19\n\x08block_id\x18\x01\x20\x01(\tR\x07block\
|
||||
Id\x123\n\rinserted_rows\x18\x02\x20\x03(\x0b2\x0e.IndexRowOrderR\x0cins\
|
||||
ertedRows\x12,\n\x0cdeleted_rows\x18\x03\x20\x03(\x0b2\t.RowOrderR\x0bde\
|
||||
letedRows\x123\n\x0cupdated_rows\x18\x04\x20\x03(\x0b2\x10.UpdatedRowOrd\
|
||||
erR\x0bupdatedRows\"E\n\tGridBlock\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\
|
||||
\x02id\x12(\n\nrow_orders\x18\x02\x20\x03(\x0b2\t.RowOrderR\trowOrders\"\
|
||||
;\n\x04Cell\x12\x19\n\x08field_id\x18\x01\x20\x01(\tR\x07fieldId\x12\x18\
|
||||
\n\x07content\x18\x02\x20\x01(\tR\x07content\"+\n\x0cRepeatedCell\x12\
|
||||
\x1b\n\x05items\x18\x01\x20\x03(\x0b2\x05.CellR\x05items\"'\n\x11CreateG\
|
||||
ridPayload\x12\x12\n\x04name\x18\x01\x20\x01(\tR\x04name\"\x1e\n\x06Grid\
|
||||
Id\x12\x14\n\x05value\x18\x01\x20\x01(\tR\x05value\"#\n\x0bGridBlockId\
|
||||
\x12\x14\n\x05value\x18\x01\x20\x01(\tR\x05value\"f\n\x10CreateRowPayloa\
|
||||
d\x12\x17\n\x07grid_id\x18\x01\x20\x01(\tR\x06gridId\x12\"\n\x0cstart_ro\
|
||||
w_id\x18\x02\x20\x01(\tH\0R\nstartRowIdB\x15\n\x13one_of_start_row_id\"\
|
||||
\xb6\x01\n\x12InsertFieldPayload\x12\x17\n\x07grid_id\x18\x01\x20\x01(\t\
|
||||
R\x06gridId\x12\x1c\n\x05field\x18\x02\x20\x01(\x0b2\x06.FieldR\x05field\
|
||||
\x12(\n\x10type_option_data\x18\x03\x20\x01(\x0cR\x0etypeOptionData\x12&\
|
||||
|
@ -43,6 +43,10 @@ message EditFieldContext {
|
||||
Field grid_field = 2;
|
||||
bytes type_option_data = 3;
|
||||
}
|
||||
message FieldTypeOptionData {
|
||||
string field_id = 1;
|
||||
bytes type_option_data = 2;
|
||||
}
|
||||
message RepeatedField {
|
||||
repeated Field items = 1;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl GridMetaPad {
|
||||
Ok(None)
|
||||
}
|
||||
Some(field_meta) => {
|
||||
if field_meta.get_type_option_str(Some(field_type.clone())).is_none() {
|
||||
if field_meta.get_type_option_str(&field_type).is_none() {
|
||||
let type_option_json = type_option_json_builder(&field_type);
|
||||
field_meta.insert_type_option_str(&field_type, type_option_json);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user