teableio/teable

View on GitHub
packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx

Summary

Maintainability
D
2 days
Test Coverage

File use-grid-columns.tsx has 512 lines of code (exceeds 300 allowed). Consider refactoring.
Open

import type { IAttachmentCellValue, INumberShowAs, ISingleLineTextShowAs } from '@teable/core';
import { RowHeightLevel, CellValueType, ColorUtils, FieldType } from '@teable/core';
import { useTheme } from '@teable/next-themes';
import { keyBy } from 'lodash';
import { LRUCache } from 'lru-cache';

    Function getColumnThemeByField has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    const getColumnThemeByField = ({
      field,
      theme,
      sortFieldIds,
      groupFieldIds,

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function useGridColumns has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    export function useGridColumns(hasMenu?: boolean, hiddenFieldIds?: string[]) {
      const view = useView() as GridView | undefined;
      const originFields = useFields();
      const totalFields = useFields({ withHidden: true, withDenied: true });
      const fieldEditable = useFieldCellEditable();
    Severity: Minor
    Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid too many return statements within this function.
    Open

                  return {
                    ...baseCellProps,
                    type: CellType.Boolean,
                    data: (cellValue as boolean) || false,
                    isMultiple,
    Severity: Major
    Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return {
                    ...baseCellProps,
                    type: CellType.Select,
                    data: cv,
                    displayData,
      Severity: Major
      Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                      return {
                        ...baseCellProps,
                        type: CellType.Text,
                        data: (cellValue as string) || '',
                        displayData,
        Severity: Major
        Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                        return {
                          ...baseCellProps,
                          type: CellType.Text,
                          data: (cellValue as string) || '',
                          displayData: field.cellValue2String(cellValue),
          Severity: Major
          Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                          return {
                            ...baseCellProps,
                            type: CellType.Chart,
                            data: cellValue as number[],
                            displayData: cellValue.map((v) => field.item2String(v)),
            Severity: Major
            Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return {
                            ...baseCellProps,
                            type: CellType.Text,
                            data: (cellValue as string) || '',
                            displayData,
              Severity: Major
              Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return {
                              ...baseCellProps,
                              type: CellType.User,
                              data: data,
                              customEditor: (props, editorRef) => (
                Severity: Major
                Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return {
                                ...baseCellProps,
                                type: CellType.Number,
                                data: cellValue as number,
                                displayData: field.cellValue2String(cellValue),
                  Severity: Major
                  Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return {
                                  ...baseCellProps,
                                  type: CellType.Select,
                                  data,
                                  displayData: data,
                    Severity: Major
                    Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                    return {
                                      ...baseCellProps,
                                      type: CellType.Text,
                                      data: (cellValue as string) || '',
                                      displayData: field.cellValue2String(cellValue),
                      Severity: Major
                      Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return { type: CellType.Loading };
                        Severity: Major
                        Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                        return {
                                          ...baseCellProps,
                                          type: CellType.Number,
                                          data: cellValue as number,
                                          displayData: field.cellValue2String(cellValue),
                          Severity: Major
                          Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return {
                                          ...baseCellProps,
                                          type: CellType.Rating,
                                          data: (cellValue as number) || 0,
                                          icon,
                            Severity: Major
                            Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return {
                                                ...baseCellProps,
                                                type: CellType.Link,
                                                data: cellValue ? (Array.isArray(cellValue) ? cellValue : [cellValue]) : [],
                                                displayData: field.cellValue2String(cellValue),
                              Severity: Major
                              Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return {
                                              ...baseCellProps,
                                              type: CellType.Number,
                                              data: cellValue as number,
                                              displayData:
                                Severity: Major
                                Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                              return {
                                                ...baseCellProps,
                                                type: CellType.Boolean,
                                                data: (cellValue as boolean) || false,
                                                isMultiple,
                                  Severity: Major
                                  Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return {
                                                  ...baseCellProps,
                                                  type: CellType.Image,
                                                  data,
                                                  displayData,
                                    Severity: Major
                                    Found in packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx - About 30 mins to fix

                                      There are no issues that match your filters.

                                      Category
                                      Status