Merge pull request #1337 from AppFlowy-IO/fix_create_field

fix: create a new property from grid
This commit is contained in:
Nathan.fooo 2022-10-23 12:06:03 +08:00 committed by GitHub
commit 7a92c5b538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 73 additions and 45 deletions

View File

@ -73,7 +73,7 @@ jobs:
run: |
cargo make --profile development-linux-x86_64 flowy-sdk-dev
- name: Code Generation
- name: Flutter Code Generation
working-directory: frontend/app_flowy
run: |
flutter packages pub run easy_localization:generate -f keys -o locale_keys.g.dart -S assets/translations -s en.json

View File

@ -1,4 +1,4 @@
name: Unit test(Flutter)
name: Frontend test
on:
push:
@ -21,7 +21,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: "stable-2022-04-07"
@ -53,10 +52,6 @@ jobs:
working-directory: frontend
run: |
cargo install cargo-make
- name: Cargo make flowy dev
working-directory: frontend
run: |
cargo make flowy_dev
- name: Flutter Deps
@ -64,12 +59,12 @@ jobs:
run: |
flutter config --enable-linux-desktop
- name: Build FlowySDK
- name: Build Test lib
working-directory: frontend
run: |
cargo make --profile test-linux build-test-lib
- name: Code Generation
- name: Flutter Code Generation
working-directory: frontend/app_flowy
run: |
flutter packages pub get

View File

@ -1,4 +1,4 @@
name: Unit test(Rust)
name: Backend test
on:
push:

View File

@ -156,23 +156,46 @@ abstract class IFieldTypeOptionLoader {
}
}
/// Uses when creating a new field
class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
FieldTypeOptionDataPB? fieldTypeOption;
@override
final String gridId;
NewFieldTypeOptionLoader({
required this.gridId,
});
/// Creates the field type option if the fieldTypeOption is null.
/// Otherwise, it loads the type option data from the backend.
@override
Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
final payload = CreateFieldPayloadPB.create()
..gridId = gridId
..fieldType = FieldType.RichText;
if (fieldTypeOption != null) {
final payload = FieldTypeOptionIdPB.create()
..gridId = gridId
..fieldId = fieldTypeOption!.field_2.id
..fieldType = fieldTypeOption!.field_2.fieldType;
return GridEventCreateFieldTypeOption(payload).send();
return GridEventGetFieldTypeOption(payload).send();
} else {
final payload = CreateFieldPayloadPB.create()
..gridId = gridId
..fieldType = FieldType.RichText;
return GridEventCreateFieldTypeOption(payload).send().then((result) {
return result.fold(
(newFieldTypeOption) {
fieldTypeOption = newFieldTypeOption;
return left(newFieldTypeOption);
},
(err) => right(err),
);
});
}
}
}
/// Uses when editing a existing field
class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
@override
final String gridId;

View File

@ -79,8 +79,8 @@ class GridDataController {
);
}
void createRow() {
_gridFFIService.createRow();
Future<void> createRow() async {
await _gridFFIService.createRow();
}
Future<void> dispose() async {

View File

@ -195,7 +195,6 @@ class CreateFieldButton extends StatelessWidget {
popupBuilder: (BuildContext popover) {
return FieldEditor(
gridId: gridId,
fieldName: "",
typeOptionLoader: NewFieldTypeOptionLoader(gridId: gridId),
);
},

View File

@ -7,6 +7,7 @@ void main() {
late AppFlowyGridTest gridTest;
setUpAll(() async {
gridTest = await AppFlowyGridTest.ensureInitialized();
await gridTest.createTestGrid();
});
group('GridBloc', () {

View File

@ -17,8 +17,11 @@ void main() {
group('SingleSelectOptionBloc', () {
late GridSelectOptionCellController cellController;
setUp(() async {
cellController =
await cellTest.makeCellController(FieldType.SingleSelect);
await cellTest.createTestGrid();
await cellTest.createTestRow();
cellController = await cellTest.makeCellController(
FieldType.SingleSelect,
);
});
blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(

View File

@ -19,12 +19,10 @@ class AppFlowyGridTest {
static Future<AppFlowyGridTest> ensureInitialized() async {
final inner = await AppFlowyUnitTest.ensureInitialized();
final test = AppFlowyGridTest(inner);
await test._createTestGrid();
return test;
return AppFlowyGridTest(inner);
}
Future<void> _createTestGrid() async {
Future<void> createTestGrid() async {
final app = await _inner.createTestApp();
final builder = GridPluginBuilder();
final result = await AppService().createView(
@ -42,56 +40,65 @@ class AppFlowyGridTest {
}
class AppFlowyGridSelectOptionCellTest {
final AppFlowyGridCellTest _cellTest;
final AppFlowyGridCellTest _gridCellTest;
AppFlowyGridSelectOptionCellTest(AppFlowyGridCellTest cellTest)
: _cellTest = cellTest;
: _gridCellTest = cellTest;
static Future<AppFlowyGridSelectOptionCellTest> ensureInitialized() async {
final cellTest = await AppFlowyGridCellTest.ensureInitialized();
final test = AppFlowyGridSelectOptionCellTest(cellTest);
return test;
final gridTest = await AppFlowyGridCellTest.ensureInitialized();
return AppFlowyGridSelectOptionCellTest(gridTest);
}
Future<void> createTestGrid() async {
await _gridCellTest.createTestGrid();
}
Future<void> createTestRow() async {
await _gridCellTest.createTestRow();
}
/// For the moment, just edit the first row of the grid.
Future<GridSelectOptionCellController> makeCellController(
FieldType fieldType) async {
assert(fieldType == FieldType.SingleSelect ||
fieldType == FieldType.MultiSelect);
final fieldContexts =
_cellTest._dataController.fieldController.fieldContexts;
_gridCellTest._dataController.fieldController.fieldContexts;
final field =
fieldContexts.firstWhere((element) => element.fieldType == fieldType);
final builder = await _cellTest.cellControllerBuilder(0, field.id);
final builder = await _gridCellTest.cellControllerBuilder(field.id);
final cellController = builder.build() as GridSelectOptionCellController;
return cellController;
}
}
/// Create a new Grid for cell test
class AppFlowyGridCellTest {
// ignore: unused_field
final AppFlowyGridTest _gridTest;
final GridDataController _dataController;
AppFlowyGridCellTest(AppFlowyGridTest gridTest)
: _gridTest = gridTest,
_dataController = GridDataController(view: gridTest.gridView);
late GridDataController _dataController;
AppFlowyGridCellTest(AppFlowyGridTest gridTest) : _gridTest = gridTest;
static Future<AppFlowyGridCellTest> ensureInitialized() async {
final gridTest = await AppFlowyGridTest.ensureInitialized();
final test = AppFlowyGridCellTest(gridTest);
await test._loadGridData();
return test;
return AppFlowyGridCellTest(gridTest);
}
Future<void> _loadGridData() async {
Future<void> createTestRow() async {
await _dataController.createRow();
}
Future<void> createTestGrid() async {
await _gridTest.createTestGrid();
_dataController = GridDataController(view: _gridTest.gridView);
final result = await _dataController.loadData();
result.fold((l) => null, (r) => throw Exception(r));
}
Future<GridCellControllerBuilder> cellControllerBuilder(
int rowIndex, String fieldId) async {
final RowInfo rowInfo = _dataController.rowInfos[rowIndex];
String fieldId,
) async {
final RowInfo rowInfo = _dataController.rowInfos.last;
final blockCache = _dataController.blocks[rowInfo.rowPB.blockId];
final rowCache = blockCache?.rowCache;
@ -105,7 +112,7 @@ class AppFlowyGridCellTest {
rowInfo: rowInfo,
dataController: rowDataController,
)..add(const RowEvent.initial());
await gridResponseFuture(milliseconds: 300);
await gridResponseFuture();
return GridCellControllerBuilder(
cellId: rowBloc.state.gridCellMap[fieldId]!,
@ -115,8 +122,8 @@ class AppFlowyGridCellTest {
}
}
Future<void> gridResponseFuture({int milliseconds = 200}) {
return Future.delayed(gridResponseDuration(milliseconds: milliseconds));
Future<void> gridResponseFuture() {
return Future.delayed(gridResponseDuration(milliseconds: 200));
}
Duration gridResponseDuration({int milliseconds = 200}) {