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", "preview": "vite preview",
"format": "prettier --write .", "format": "prettier --write .",
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .", "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", "test:prettier": "yarn prettier --list-different src",
"tauri:dev": "tauri dev", "tauri:dev": "tauri dev",
"test": "jest" "test": "jest"

View File

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

View File

@ -124,7 +124,7 @@ export const TestCreateSelectOptionInCell = () => {
const cellController = await makeSingleSelectCellController(fieldInfo.field.id, row, databaseController).then( const cellController = await makeSingleSelectCellController(fieldInfo.field.id, row, databaseController).then(
(result) => result.unwrap() (result) => result.unwrap()
); );
await cellController.subscribeChanged({ cellController.subscribeChanged({
onCellChanged: (value) => { onCellChanged: (value) => {
if (value.some) { if (value.some) {
const option: SelectOptionCellDataPB = value.unwrap(); 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 field = fieldInfo.field;
const typeOptionController = new TypeOptionController(viewId, Some(fieldInfo)); 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 // temporary hack to set grouping field
let groupingFieldSelected = false; let groupingFieldSelected = false;
switch (field.field_type) { switch (field.field_type) {
case FieldType.SingleSelect: case FieldType.SingleSelect:
case FieldType.MultiSelect: case FieldType.MultiSelect:
case FieldType.Checklist: case FieldType.Checklist: {
{ let selectOptions: ISelectOption[] = [];
let typeOption: SingleSelectTypeOptionPB | MultiSelectTypeOptionPB | ChecklistTypeOptionPB | undefined; let typeOption: SingleSelectTypeOptionPB | MultiSelectTypeOptionPB | ChecklistTypeOptionPB | undefined;
if (field.field_type === FieldType.SingleSelect) { if (field.field_type === FieldType.SingleSelect) {
typeOption = (await makeSingleSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap(); typeOption = (await makeSingleSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
if (!groupingFieldSelected) { if (!groupingFieldSelected) {
if (dispatch) { if (dispatch) {
dispatch(boardActions.setGroupingFieldId({ fieldId: field.id })); dispatch(boardActions.setGroupingFieldId({ fieldId: field.id }));
}
groupingFieldSelected = true;
} }
groupingFieldSelected = true;
} }
if (field.field_type === FieldType.MultiSelect) { }
typeOption = (await makeMultiSelectTypeOptionContext(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 (field.field_type === FieldType.Checklist) {
} typeOption = (await makeChecklistTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
}
if (typeOption) { if (typeOption) {
selectOptions = typeOption.options.map<ISelectOption>((option) => { selectOptions = typeOption.options.map<ISelectOption>((option) => {
return { return {
selectOptionId: option.id, selectOptionId: option.id,
title: option.name, title: option.name,
color: option.color, color: option.color,
}; };
}); });
}
} }
break;
case FieldType.Number: return {
{ fieldId: field.id,
const typeOption = (await makeNumberTypeOptionContext(typeOptionController).getTypeOption()).unwrap(); title: field.name,
numberFormat = typeOption.format; fieldType: field.field_type,
} fieldOptions: {
break; selectOptions,
case FieldType.DateTime: },
{ };
const typeOption = (await makeDateTypeOptionContext(typeOptionController).getTypeOption()).unwrap(); }
dateFormat = typeOption.date_format;
timeFormat = typeOption.time_format; case FieldType.Number: {
includeTime = typeOption.include_time; const typeOption = (await makeNumberTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
} return {
break; 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 { DatabasePB } from '../../../../services/backend';
import { RowChangedReason, RowInfo } from './row/row_cache'; import { RowChangedReason, RowInfo } from './row/row_cache';
import { Err, Ok, Result } from 'ts-results'; import { Err, Ok, Result } from 'ts-results';
import { FlowyError, RowPB } from '../../../../services/backend';
export type SubscribeCallbacks = { export type SubscribeCallbacks = {
onViewChanged?: (data: DatabasePB) => void; onViewChanged?: (data: DatabasePB) => void;

View File

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

View File

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