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

teableio / teable / 8536869866

03 Apr 2024 10:05AM UTC 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
/apps/nextjs-app/src/features/app/blocks/view/form/components/share-link-editor/FormLinkEditor.tsx
1
import type { ILinkCellValue } from '@teable/core';
×
2
import { Plus } from '@teable/icons';
×
3
import { LinkCard } from '@teable/sdk/components';
×
4
import type { LinkField } from '@teable/sdk/model';
×
5
import { Button, Popover, PopoverContent, PopoverTrigger } from '@teable/ui-lib/shadcn';
×
6
import { useTranslation } from 'next-i18next';
×
7
import { useMemo, useState } from 'react';
×
8
import { tableConfig } from '@/features/i18n/table.config';
×
9
import { LinkRecordList } from './LinkRecordList';
×
10

×
11
interface IShareFormLinkEditorProps {
×
12
  shareId: string;
×
13
  field: LinkField;
×
14
  cellValue?: ILinkCellValue | ILinkCellValue[];
×
15
  className?: string;
×
16
  onChange?: (value?: ILinkCellValue | ILinkCellValue[]) => void;
×
17
}
×
18

×
19
export const ShareFormLinkEditor = (props: IShareFormLinkEditorProps) => {
×
20
  const { cellValue, shareId, className, field, onChange } = props;
×
21
  const [open, setOpen] = useState(false);
×
22
  const { t } = useTranslation(tableConfig.i18nNamespaces);
×
23

×
24
  const isMultiple = field.isMultipleCellValue;
×
25

×
26
  const cvArray = useMemo(() => {
×
27
    return isMultiple || !cellValue
×
28
      ? (cellValue as ILinkCellValue[] | undefined)
×
29
      : [cellValue as ILinkCellValue];
×
30
  }, [cellValue, isMultiple]);
×
31

×
32
  const onDeleteRecord = (recordId: string) => {
×
33
    onChange?.(
×
34
      isMultiple ? (cellValue as ILinkCellValue[])?.filter((cv) => cv.id !== recordId) : undefined
×
35
    );
×
36
  };
×
37

×
38
  const selectedRecordIds = useMemo(() => {
×
39
    return cvArray?.map((cv) => cv.id);
×
40
  }, [cvArray]);
×
41

×
42
  const onSelected = (selectedCellValue: ILinkCellValue) => {
×
43
    if (isMultiple) {
×
44
      const arr = (cellValue as ILinkCellValue[]) || [];
×
45
      onChange?.([...arr, selectedCellValue]);
×
46
      return;
×
47
    }
×
48
    setOpen(false);
×
49
    onChange?.(selectedCellValue);
×
50
  };
×
51

×
52
  return (
×
53
    <div className="space-y-3">
×
54
      <Popover open={open} onOpenChange={setOpen}>
×
55
        <PopoverTrigger asChild>
×
56
          <Button variant="outline" size={'sm'} className={className}>
×
57
            <Plus />
×
58
            {t('table:view.addRecord')}
×
59
          </Button>
×
60
        </PopoverTrigger>
×
61
        <PopoverContent className="h-[350px] w-screen md:w-[480px]">
×
62
          <LinkRecordList
×
63
            shareId={shareId}
×
NEW
64
            fieldId={field.id}
×
65
            selectedRecordIds={selectedRecordIds}
×
66
            onSelected={onSelected}
×
67
          />
×
68
        </PopoverContent>
×
69
      </Popover>
×
70
      {cvArray?.map(({ id, title }) => (
×
71
        <LinkCard key={id} title={title} className="truncate" onDelete={() => onDeleteRecord(id)} />
×
72
      ))}
×
73
    </div>
×
74
  );
×
75
};
×
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