浏览代码

fix: change IDatabaseField fix eslint errors

ascarbek 2 年之前
父节点
当前提交
7ca4da0966

+ 1 - 0
frontend/appflowy_tauri/package.json

@@ -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"

+ 1 - 1
frontend/appflowy_tauri/src/appflowy_app/components/TestApiButton/DatabaseTestHelper.ts

@@ -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) {

+ 1 - 1
frontend/appflowy_tauri/src/appflowy_app/components/TestApiButton/TestGrid.tsx

@@ -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();

+ 67 - 58
frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts

@@ -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 }));
           }
-        }
-        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,
-            };
-          });
+          groupingFieldSelected = true;
         }
       }
-      break;
-    case FieldType.Number:
-      {
-        const typeOption = (await makeNumberTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
-        numberFormat = typeOption.format;
+      if (field.field_type === FieldType.MultiSelect) {
+        typeOption = (await makeMultiSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
       }
-      break;
-    case FieldType.DateTime:
-      {
-        const typeOption = (await makeDateTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
-        dateFormat = typeOption.date_format;
-        timeFormat = typeOption.time_format;
-        includeTime = typeOption.include_time;
+      if (field.field_type === FieldType.Checklist) {
+        typeOption = (await makeChecklistTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
       }
-      break;
-  }
 
-  return {
-    fieldId: field.id,
-    title: field.name,
-    fieldType: field.field_type,
-    fieldOptions: {
-      selectOptions,
-      numberFormat,
-      dateFormat,
-      timeFormat,
-      includeTime,
-    },
-  };
+      if (typeOption) {
+        selectOptions = typeOption.options.map<ISelectOption>((option) => {
+          return {
+            selectOptionId: option.id,
+            title: option.name,
+            color: option.color,
+          };
+        });
+      }
+
+      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,
+      };
+    }
+  }
 }

+ 0 - 1
frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts

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

+ 1 - 2
frontend/appflowy_tauri/src/appflowy_app/stores/effects/folder/notifications/observer.ts

@@ -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';

+ 13 - 18
frontend/appflowy_tauri/src/appflowy_app/stores/reducers/database/slice.ts

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