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,20 +25,14 @@ 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) {
@ -66,23 +60,6 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
}; };
}); });
} }
}
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 { return {
fieldId: field.id, fieldId: field.id,
@ -90,10 +67,42 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
fieldType: field.field_type, fieldType: field.field_type,
fieldOptions: { fieldOptions: {
selectOptions, selectOptions,
numberFormat,
dateFormat,
timeFormat,
includeTime,
}, },
}; };
} }
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,
};
}
}
}

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 };