Skip to content

Commit 65aaf20

Browse files
committed
fix: unable to add new options to single/multi-select fields when appending rows
1 parent 2e1ac7e commit 65aaf20

File tree

4 files changed

+27
-46
lines changed

4 files changed

+27
-46
lines changed

packages/sdk/src/components/cell-value-editor/CellEditorMain.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import type {
1515
IUserCellValue,
1616
IUserFieldOptions,
1717
} from '@teable/core';
18-
import { FieldKeyType, FieldType } from '@teable/core';
19-
import { updateRecord } from '@teable/openapi';
18+
import { FieldType } from '@teable/core';
19+
import { temporaryPaste } from '@teable/openapi';
2020
import { useCallback, useEffect, useRef } from 'react';
2121
import { useTableId } from '../../hooks';
2222
import { transformSelectOptions } from '../cell-value';
@@ -46,27 +46,19 @@ export const CellEditorMain = (props: Omit<ICellValueEditor, 'wrapClassName' | '
4646
}, [cellValue]);
4747

4848
const onOptionAdd = useCallback(
49-
async (curValue: string | string[] | undefined, name: string) => {
50-
if (!tableId || !recordId) return;
51-
if (type !== FieldType.SingleSelect && type !== FieldType.MultipleSelect) return;
52-
const appendValue =
53-
type === FieldType.SingleSelect
54-
? name
55-
: curValue
56-
? [...(curValue as string[]), name]
57-
: [name];
49+
async (name: string) => {
50+
if (!tableId) return;
5851

59-
await updateRecord(tableId, recordId, {
60-
fieldKeyType: FieldKeyType.Id,
61-
typecast: true,
62-
record: {
63-
fields: {
64-
[fieldId]: appendValue,
65-
},
66-
},
52+
await temporaryPaste(tableId, {
53+
content: name,
54+
projection: [fieldId],
55+
ranges: [
56+
[0, 0],
57+
[0, 0],
58+
],
6759
});
6860
},
69-
[tableId, recordId, type, fieldId]
61+
[tableId, fieldId]
7062
);
7163

7264
switch (type) {

packages/sdk/src/components/editor/select/Editor.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { SelectEditorMain } from './EditorMain';
1010

1111
const SelectEditorBase: ForwardRefRenderFunction<
1212
IEditorRef<string | string[] | undefined>,
13-
ISelectEditorMain<boolean> & {
14-
onOptionAdd?: (curValue: string | string[] | undefined, name: string) => Promise<void>;
15-
}
13+
ISelectEditorMain<boolean>
1614
> = (props, ref) => {
1715
const { value, options = [], isMultiple, onChange, className, style, readonly } = props;
1816
const [open, setOpen] = useState(false);

packages/sdk/src/components/editor/select/EditorMain.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ISelectEditorMain<T extends boolean> extends ICellEditor<ISelec
1515
isMultiple?: T;
1616
style?: React.CSSProperties;
1717
className?: string;
18-
onOptionAdd?: (curValue: string | string[] | undefined, name: string) => Promise<void>;
18+
onOptionAdd?: (optionName: string) => Promise<void>;
1919
}
2020

2121
const getValue = (value?: string | string[]) => {
@@ -82,7 +82,7 @@ const SelectEditorMainBase: ForwardRefRenderFunction<
8282
const onOptionAddInner = async () => {
8383
if (!searchValue || preventAutoNewOptions) return;
8484
setSearchValue('');
85-
await onOptionAdd?.(originValue, searchValue);
85+
await onOptionAdd?.(searchValue);
8686
if (isMultiple) {
8787
const newValue = value.concat(searchValue);
8888
setValue(newValue);

packages/sdk/src/components/grid-enhancements/editor/GridSelectEditor.tsx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type {
33
ISingleSelectCellValue,
44
IMultipleSelectCellValue,
55
} from '@teable/core';
6-
import { FieldType, ColorUtils, FieldKeyType } from '@teable/core';
7-
import { updateRecord } from '@teable/openapi';
6+
import { FieldType, ColorUtils } from '@teable/core';
7+
import { temporaryPaste } from '@teable/openapi';
88
import type { ForwardRefRenderFunction } from 'react';
99
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
1010
import colors from 'tailwindcss/colors';
@@ -70,28 +70,19 @@ const GridSelectEditorBase: ForwardRefRenderFunction<
7070
};
7171

7272
const onOptionAdd = useCallback(
73-
async (curValue: string | string[] | undefined, name: string) => {
74-
const recordId = record.id;
75-
if (!tableId || !recordId) return;
76-
if (fieldType !== FieldType.SingleSelect && fieldType !== FieldType.MultipleSelect) return;
77-
const appendValue =
78-
fieldType === FieldType.SingleSelect
79-
? name
80-
: curValue
81-
? [...(curValue as string[]), name]
82-
: [name];
73+
async (name: string) => {
74+
if (!tableId) return;
8375

84-
await updateRecord(tableId, recordId, {
85-
fieldKeyType: FieldKeyType.Id,
86-
typecast: true,
87-
record: {
88-
fields: {
89-
[fieldId]: appendValue,
90-
},
91-
},
76+
await temporaryPaste(tableId, {
77+
content: name,
78+
projection: [fieldId],
79+
ranges: [
80+
[0, 0],
81+
[0, 0],
82+
],
9283
});
9384
},
94-
[record.id, tableId, fieldType, fieldId]
85+
[tableId, fieldId]
9586
);
9687

9788
return (

0 commit comments

Comments
 (0)