• 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/editor/user/Editor.tsx
NEW
1
import type { IUserFieldOptions, IUserCellValue } from '@teable/core';
×
NEW
2
import { Button, Popover, PopoverContent, PopoverTrigger, cn } from '@teable/ui-lib';
×
NEW
3
import { useRef, useState } from 'react';
×
4
import type { IUserEditorMainProps } from './EditorMain';
×
5
import { UserEditorMain } from './EditorMain';
×
NEW
6
import { UserTag } from './UserTag';
×
7

×
NEW
8
interface IUserEditorProps extends Omit<IUserEditorMainProps, 'isMultiple'> {
×
NEW
9
  options: IUserFieldOptions;
×
NEW
10
}
×
NEW
11

×
NEW
12
export const UserEditor = (props: IUserEditorProps) => {
×
NEW
13
  const { value, options, onChange, className, style, readonly, ...reset } = props;
×
14
  const [open, setOpen] = useState(false);
×
15
  const selectRef = useRef<HTMLButtonElement>(null);
×
16

×
17
  const { isMultiple } = options;
×
18
  const arrayValue = (isMultiple ? value : value ? [value] : null) as IUserCellValue[];
×
19

×
NEW
20
  const onDelete = (id: string) => {
×
NEW
21
    const newValue = arrayValue?.filter((v) => v.id !== id);
×
NEW
22
    onChange?.(isMultiple ? newValue : newValue?.[0]);
×
23
  };
×
24

×
25
  const onChangeInner = (val?: IUserCellValue | IUserCellValue[]) => {
×
26
    onChange?.(val);
×
27
    if (!isMultiple) {
×
28
      setOpen(false);
×
29
    }
×
30
  };
×
31

×
32
  const triggerContent = (
×
33
    <Button
×
34
      style={style}
×
35
      variant="outline"
×
36
      role="combobox"
×
37
      aria-expanded={open}
×
38
      className={cn(
×
NEW
39
        'w-full h-auto min-h-[32px] sm:min-h-[32px] py-1 flex flex-wrap justify-start hover:bg-transparent gap-1.5',
×
40
        className
×
41
      )}
×
42
    >
×
43
      {arrayValue?.map(({ id, title, avatarUrl }) => (
×
NEW
44
        <UserTag key={id} name={title} avatar={avatarUrl} onDelete={() => onDelete(id)} />
×
45
      ))}
×
46
    </Button>
×
47
  );
×
48

×
49
  return (
×
50
    <>
×
51
      {readonly ? (
×
52
        triggerContent
×
53
      ) : (
×
54
        <Popover open={open} onOpenChange={setOpen} modal>
×
55
          <PopoverTrigger ref={selectRef} asChild>
×
56
            {triggerContent}
×
57
          </PopoverTrigger>
×
58
          <PopoverContent className="p-0" style={{ width: selectRef.current?.offsetWidth || 0 }}>
×
NEW
59
            <UserEditorMain
×
NEW
60
              {...reset}
×
NEW
61
              value={value}
×
NEW
62
              isMultiple={isMultiple}
×
NEW
63
              onChange={onChangeInner}
×
NEW
64
            />
×
65
          </PopoverContent>
×
66
        </Popover>
×
67
      )}
×
68
    </>
×
69
  );
×
70
};
×
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