fix: change IDatabaseField fix eslint errors

This commit is contained in:
ascarbek 2023-03-06 16:13:43 +06:00
parent 557a524648
commit 7ca4da0966
7 changed files with 85 additions and 82 deletions

View File

@ -9,6 +9,7 @@
"preview": "vite preview",
"format": "prettier --write .",
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .",
"test:errors": "eslint --quiet --ext .js,.ts,.tsx .",
"test:prettier": "yarn prettier --list-different src",
"tauri:dev": "tauri dev",
"test": "jest"

View File

@ -37,7 +37,7 @@ export async function assertTextCell(
const cellController = await makeTextCellController(fieldId, rowInfo, databaseController).then((result) =>
result.unwrap()
);
await cellController.subscribeChanged({
cellController.subscribeChanged({
onCellChanged: (value) => {
const cellContent = value.unwrap();
if (cellContent !== expectedContent) {

View File

@ -124,7 +124,7 @@ export const TestCreateSelectOptionInCell = () => {
const cellController = await makeSingleSelectCellController(fieldInfo.field.id, row, databaseController).then(
(result) => result.unwrap()
);
await cellController.subscribeChanged({
cellController.subscribeChanged({
onCellChanged: (value) => {
if (value.some) {
const option: SelectOptionCellDataPB = value.unwrap();

View File

@ -25,75 +25,84 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
const field = fieldInfo.field;
const typeOptionController = new TypeOptionController(viewId, Some(fieldInfo));
let selectOptions: ISelectOption[] | undefined;
let numberFormat: NumberFormat | undefined;
let dateFormat: DateFormat | undefined;
let timeFormat: TimeFormat | undefined;
let includeTime: boolean | undefined;
// temporary hack to set grouping field
let groupingFieldSelected = false;
switch (field.field_type) {
case FieldType.SingleSelect:
case FieldType.MultiSelect:
case FieldType.Checklist:
{
let typeOption: SingleSelectTypeOptionPB | MultiSelectTypeOptionPB | ChecklistTypeOptionPB | undefined;
case FieldType.Checklist: {
let selectOptions: ISelectOption[] = [];
let typeOption: SingleSelectTypeOptionPB | MultiSelectTypeOptionPB | ChecklistTypeOptionPB | undefined;
if (field.field_type === FieldType.SingleSelect) {
typeOption = (await makeSingleSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
if (!groupingFieldSelected) {
if (dispatch) {
dispatch(boardActions.setGroupingFieldId({ fieldId: field.id }));
}
groupingFieldSelected = true;
if (field.field_type === FieldType.SingleSelect) {
typeOption = (await makeSingleSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
if (!groupingFieldSelected) {
if (dispatch) {
dispatch(boardActions.setGroupingFieldId({ fieldId: field.id }));
}
groupingFieldSelected = true;
}
if (field.field_type === FieldType.MultiSelect) {
typeOption = (await makeMultiSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
}
if (field.field_type === FieldType.Checklist) {
typeOption = (await makeChecklistTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
}
}
if (field.field_type === FieldType.MultiSelect) {
typeOption = (await makeMultiSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
}
if (field.field_type === FieldType.Checklist) {
typeOption = (await makeChecklistTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
}
if (typeOption) {
selectOptions = typeOption.options.map<ISelectOption>((option) => {
return {
selectOptionId: option.id,
title: option.name,
color: option.color,
};
});
}
if (typeOption) {
selectOptions = typeOption.options.map<ISelectOption>((option) => {
return {
selectOptionId: option.id,
title: option.name,
color: option.color,
};
});
}
break;
case FieldType.Number:
{
const typeOption = (await makeNumberTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
numberFormat = typeOption.format;
}
break;
case FieldType.DateTime:
{
const typeOption = (await makeDateTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
dateFormat = typeOption.date_format;
timeFormat = typeOption.time_format;
includeTime = typeOption.include_time;
}
break;
return {
fieldId: field.id,
title: field.name,
fieldType: field.field_type,
fieldOptions: {
selectOptions,
},
};
}
case FieldType.Number: {
const typeOption = (await makeNumberTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
return {
fieldId: field.id,
title: field.name,
fieldType: field.field_type,
fieldOptions: {
numberFormat: typeOption.format,
},
};
}
case FieldType.DateTime: {
const typeOption = (await makeDateTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
return {
fieldId: field.id,
title: field.name,
fieldType: field.field_type,
fieldOptions: {
dateFormat: typeOption.date_format,
timeFormat: typeOption.time_format,
includeTime: typeOption.include_time,
},
};
}
default: {
return {
fieldId: field.id,
title: field.name,
fieldType: field.field_type,
};
}
}
return {
fieldId: field.id,
title: field.name,
fieldType: field.field_type,
fieldOptions: {
selectOptions,
numberFormat,
dateFormat,
timeFormat,
includeTime,
},
};
}

View File

@ -4,7 +4,6 @@ import { DatabaseViewCache } from './view/database_view_cache';
import { DatabasePB } from '../../../../services/backend';
import { RowChangedReason, RowInfo } from './row/row_cache';
import { Err, Ok, Result } from 'ts-results';
import { FlowyError, RowPB } from '../../../../services/backend';
export type SubscribeCallbacks = {
onViewChanged?: (data: DatabasePB) => void;

View File

@ -1,5 +1,4 @@
import { OnNotificationError } from '../../../../../services/backend/notifications';
import { AFNotificationObserver } from '../../../../../services/backend/notifications';
import { OnNotificationError, AFNotificationObserver } from '../../../../../services/backend/notifications';
import { FolderNotificationParser } from './parser';
import { FlowyError, FolderNotification } from '../../../../../services/backend';
import { Result } from 'ts-results';

View File

@ -8,19 +8,25 @@ export interface ISelectOption {
color?: SelectOptionColorPB;
}
export interface IFieldOptions {
selectOptions?: ISelectOption[];
dateFormat?: DateFormat;
timeFormat?: TimeFormat;
includeTime?: boolean;
numberFormat?: NumberFormat;
export interface ISelectOptionType {
selectOptions: ISelectOption[];
}
export interface IDateType {
dateFormat: DateFormat;
timeFormat: TimeFormat;
includeTime: boolean;
}
export interface INumberType {
numberFormat: NumberFormat;
}
export interface IDatabaseField {
fieldId: string;
title: string;
fieldType: FieldType;
fieldOptions: IFieldOptions;
fieldOptions?: ISelectOptionType | IDateType | INumberType;
}
export interface IDatabaseColumn {
@ -29,19 +35,8 @@ export interface IDatabaseColumn {
visible: boolean;
}
/*export interface ICellData {
rowId: string;
fieldId: string;
cellId: string;
data: string[];
}*/
// export type DatabaseCellMap = { [keys: string]: ICellData };
export interface IDatabaseRow {
rowId: string;
// key(fieldId) -> value(Cell)
// cells: DatabaseCellMap;
}
export type DatabaseFieldMap = { [keys: string]: IDatabaseField };