packages/sdk/src/components/grid-enhancements/hooks/use-grid-columns.tsx
File use-grid-columns.tsx
has 512 lines of code (exceeds 300 allowed). Consider refactoring. Open
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
Open
const getColumnThemeByField = ({
field,
theme,
sortFieldIds,
groupFieldIds,
- Read upRead up
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
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();
- Read upRead up
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
Open
return {
...baseCellProps,
type: CellType.Boolean,
data: (cellValue as boolean) || false,
isMultiple,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Select,
data: cv,
displayData,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Text,
data: (cellValue as string) || '',
displayData,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Text,
data: (cellValue as string) || '',
displayData: field.cellValue2String(cellValue),
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Chart,
data: cellValue as number[],
displayData: cellValue.map((v) => field.item2String(v)),
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Text,
data: (cellValue as string) || '',
displayData,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.User,
data: data,
customEditor: (props, editorRef) => (
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Number,
data: cellValue as number,
displayData: field.cellValue2String(cellValue),
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Select,
data,
displayData: data,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Text,
data: (cellValue as string) || '',
displayData: field.cellValue2String(cellValue),
Avoid too many return
statements within this function. Open
Open
return { type: CellType.Loading };
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Number,
data: cellValue as number,
displayData: field.cellValue2String(cellValue),
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Rating,
data: (cellValue as number) || 0,
icon,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Link,
data: cellValue ? (Array.isArray(cellValue) ? cellValue : [cellValue]) : [],
displayData: field.cellValue2String(cellValue),
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Number,
data: cellValue as number,
displayData:
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Boolean,
data: (cellValue as boolean) || false,
isMultiple,
Avoid too many return
statements within this function. Open
Open
return {
...baseCellProps,
type: CellType.Image,
data,
displayData,