|
@@ -1,5 +1,10 @@
|
|
|
import React from 'react';
|
|
|
-import { SelectOptionCellDataPB, ViewLayoutTypePB } from '../../../services/backend';
|
|
|
+import {
|
|
|
+ FieldType,
|
|
|
+ SelectOptionCellDataPB,
|
|
|
+ SingleSelectTypeOptionPB,
|
|
|
+ ViewLayoutTypePB,
|
|
|
+} from '../../../services/backend';
|
|
|
import { Log } from '../../utils/log';
|
|
|
import {
|
|
|
assertFieldName,
|
|
@@ -11,10 +16,14 @@ import {
|
|
|
makeSingleSelectCellController,
|
|
|
openTestDatabase,
|
|
|
} from './DatabaseTestHelper';
|
|
|
-import { SelectOptionBackendService } from '../../stores/effects/database/cell/select_option_bd_svc';
|
|
|
+import {
|
|
|
+ SelectOptionBackendService,
|
|
|
+ SelectOptionCellBackendService,
|
|
|
+} from '../../stores/effects/database/cell/select_option_bd_svc';
|
|
|
import { TypeOptionController } from '../../stores/effects/database/field/type_option/type_option_controller';
|
|
|
import { None, Some } from 'ts-results';
|
|
|
import { RowBackendService } from '../../stores/effects/database/row/row_bd_svc';
|
|
|
+import { makeSingleSelectTypeOptionContext } from '../../stores/effects/database/field/type_option/type_option_context';
|
|
|
|
|
|
export const TestCreateGrid = () => {
|
|
|
async function createBuildInGrid() {
|
|
@@ -95,8 +104,8 @@ export const TestDeleteRow = () => {
|
|
|
|
|
|
return TestButton('Test delete row', testDeleteRow);
|
|
|
};
|
|
|
-export const TestCreateSelectOption = () => {
|
|
|
- async function testCreateOption() {
|
|
|
+export const TestCreateSelectOptionInCell = () => {
|
|
|
+ async function testCreateOptionInCell() {
|
|
|
const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
|
const databaseController = await openTestDatabase(view.id);
|
|
|
await databaseController.open().then((result) => result.unwrap());
|
|
@@ -111,7 +120,7 @@ export const TestCreateSelectOption = () => {
|
|
|
console.log(option);
|
|
|
},
|
|
|
});
|
|
|
- const backendSvc = new SelectOptionBackendService(cellController.cellIdentifier);
|
|
|
+ const backendSvc = new SelectOptionCellBackendService(cellController.cellIdentifier);
|
|
|
await backendSvc.createOption({ name: 'option' + index });
|
|
|
await cellController.dispose();
|
|
|
}
|
|
@@ -119,7 +128,43 @@ export const TestCreateSelectOption = () => {
|
|
|
await databaseController.dispose();
|
|
|
}
|
|
|
|
|
|
- return TestButton('Test create a select option', testCreateOption);
|
|
|
+ return TestButton('Test create a select option in cell', testCreateOptionInCell);
|
|
|
+};
|
|
|
+
|
|
|
+export const TestGetSingleSelectFieldData = () => {
|
|
|
+ async function testGetSingleSelectFieldData() {
|
|
|
+ const view = await createTestDatabaseView(ViewLayoutTypePB.Grid);
|
|
|
+ const databaseController = await openTestDatabase(view.id);
|
|
|
+ await databaseController.open().then((result) => result.unwrap());
|
|
|
+
|
|
|
+ // Find the single select column
|
|
|
+ const singleSelect = databaseController.fieldController.fieldInfos.find(
|
|
|
+ (fieldInfo) => fieldInfo.field.field_type === FieldType.SingleSelect
|
|
|
+ )!;
|
|
|
+ const typeOptionController = new TypeOptionController(view.id, Some(singleSelect));
|
|
|
+ const singleSelectTypeOptionContext = makeSingleSelectTypeOptionContext(typeOptionController);
|
|
|
+
|
|
|
+ // Create options
|
|
|
+ const singleSelectTypeOptionPB: SingleSelectTypeOptionPB = await singleSelectTypeOptionContext
|
|
|
+ .getTypeOption()
|
|
|
+ .then((result) => result.unwrap());
|
|
|
+ const backendSvc = new SelectOptionBackendService(view.id, singleSelect.field.id);
|
|
|
+ const option1 = await backendSvc.createOption({ name: 'Task 1' }).then((result) => result.unwrap());
|
|
|
+ singleSelectTypeOptionPB.options.splice(0, 0, option1);
|
|
|
+ const option2 = await backendSvc.createOption({ name: 'Task 2' }).then((result) => result.unwrap());
|
|
|
+ singleSelectTypeOptionPB.options.splice(0, 0, option2);
|
|
|
+ const option3 = await backendSvc.createOption({ name: 'Task 3' }).then((result) => result.unwrap());
|
|
|
+ singleSelectTypeOptionPB.options.splice(0, 0, option3);
|
|
|
+ await singleSelectTypeOptionContext.setTypeOption(singleSelectTypeOptionPB);
|
|
|
+
|
|
|
+ // Read options
|
|
|
+ const options = singleSelectTypeOptionPB.options;
|
|
|
+ console.log(options);
|
|
|
+
|
|
|
+ await databaseController.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ return TestButton('Test get single-select column data', testGetSingleSelectFieldData);
|
|
|
};
|
|
|
|
|
|
export const TestEditField = () => {
|