• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8536869866

03 Apr 2024 10:05AM CUT coverage: 21.234% (-0.3%) from 21.535%
8536869866

Pull #514

github

web-flow
Merge 91a25d710 into 45ee7ebb3
Pull Request #514: refactor: user and link selector

1394 of 2532 branches covered (55.06%)

27 of 1620 new or added lines in 60 files covered. (1.67%)

4 existing lines in 2 files now uncovered.

14588 of 68702 relevant lines covered (21.23%)

2.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/sdk/src/components/record-list/RecordList.tsx
NEW
1
import { useVirtualizer } from '@tanstack/react-virtual';
×
NEW
2
import { Command, CommandItem, CommandList, Separator, cn } from '@teable/ui-lib';
×
NEW
3
import React, { useEffect, useRef } from 'react';
×
NEW
4
import { useTranslation } from '../../context/app/i18n';
×
NEW
5
interface IRecordListProps {
×
NEW
6
  empty?: string | React.ReactNode;
×
NEW
7
  className?: string;
×
NEW
8
  rowCount: number;
×
NEW
9
  isLoading?: boolean;
×
NEW
10
  itemHeight?: number;
×
NEW
11
  children?: React.ReactNode;
×
NEW
12
  itemRender: (index: number) => React.ReactNode;
×
NEW
13
  onSelect?: (index: number) => void;
×
NEW
14
  onVisibleChange?: (range: [number, number]) => void;
×
NEW
15
}
×
NEW
16

×
NEW
17
export const RecordList = (props: IRecordListProps) => {
×
NEW
18
  const {
×
NEW
19
    empty,
×
NEW
20
    rowCount,
×
NEW
21
    children,
×
NEW
22
    className,
×
NEW
23
    isLoading,
×
NEW
24
    itemHeight = 46,
×
NEW
25
    onSelect,
×
NEW
26
    itemRender,
×
NEW
27
    onVisibleChange,
×
NEW
28
  } = props;
×
NEW
29
  const { t } = useTranslation();
×
NEW
30
  const listRef = useRef<HTMLDivElement>(null);
×
NEW
31

×
NEW
32
  const rowVirtualizer = useVirtualizer({
×
NEW
33
    count: rowCount,
×
NEW
34
    getScrollElement: () => listRef.current,
×
NEW
35
    estimateSize: () => itemHeight,
×
NEW
36
  });
×
NEW
37

×
NEW
38
  useEffect(() => {
×
NEW
39
    if (rowVirtualizer.range) {
×
NEW
40
      const { startIndex, endIndex } = rowVirtualizer.range;
×
NEW
41
      onVisibleChange?.([startIndex, endIndex]);
×
NEW
42
    }
×
NEW
43
  }, [onVisibleChange, rowVirtualizer.range]);
×
NEW
44

×
NEW
45
  return (
×
NEW
46
    <Command className={cn('flex flex-col', className)}>
×
NEW
47
      {children && (
×
NEW
48
        <div className="w-full">
×
NEW
49
          {children}
×
NEW
50
          <Separator className="my-2" />
×
NEW
51
        </div>
×
NEW
52
      )}
×
NEW
53
      {isLoading ? (
×
NEW
54
        <div className="flex h-full items-center justify-center">{t('common.loading')}</div>
×
NEW
55
      ) : (
×
NEW
56
        rowCount === 0 && (
×
NEW
57
          <div className="flex h-full items-center justify-center">
×
NEW
58
            {empty || t('common.noRecords')}
×
NEW
59
          </div>
×
NEW
60
        )
×
NEW
61
      )}
×
NEW
62
      <CommandList
×
NEW
63
        ref={listRef}
×
NEW
64
        className={cn('w-full flex-1 overflow-auto', {
×
NEW
65
          'h-0': isLoading || rowCount > 0,
×
NEW
66
        })}
×
NEW
67
      >
×
NEW
68
        <div
×
NEW
69
          style={{
×
NEW
70
            height: `${rowVirtualizer.getTotalSize()}px`,
×
NEW
71
            width: '100%',
×
NEW
72
            position: 'relative',
×
NEW
73
          }}
×
NEW
74
        >
×
NEW
75
          {rowVirtualizer.getVirtualItems().map((virtualItem) => (
×
NEW
76
            <CommandItem
×
NEW
77
              key={virtualItem.key}
×
NEW
78
              style={{
×
NEW
79
                position: 'absolute',
×
NEW
80
                top: 0,
×
NEW
81
                left: 0,
×
NEW
82
                width: '100%',
×
NEW
83
                height: `${virtualItem.size}px`,
×
NEW
84
                transform: `translateY(${virtualItem.start}px)`,
×
NEW
85
              }}
×
NEW
86
              value={virtualItem.key.toString()}
×
NEW
87
              onSelect={() => onSelect?.(virtualItem.index)}
×
NEW
88
            >
×
NEW
89
              {itemRender(virtualItem.index)}
×
NEW
90
            </CommandItem>
×
NEW
91
          ))}
×
NEW
92
        </div>
×
NEW
93
      </CommandList>
×
NEW
94
    </Command>
×
NEW
95
  );
×
NEW
96
};
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc