fix(association-field): sub-table cannot move (#2727)

This commit is contained in:
katherinehhh 2023-09-27 11:08:38 +08:00 committed by GitHub
parent 01271598fc
commit 4092451bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 2 deletions

View File

@ -7,14 +7,12 @@ import { action } from '@formily/reactive';
import { isArr } from '@formily/shared'; import { isArr } from '@formily/shared';
import { Button } from 'antd'; import { Button } from 'antd';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next';
import { Table } from '../table-v2/Table'; import { Table } from '../table-v2/Table';
import { useAssociationFieldContext } from './hooks'; import { useAssociationFieldContext } from './hooks';
export const SubTable: any = observer( export const SubTable: any = observer(
(props: any) => { (props: any) => {
const { field } = useAssociationFieldContext<ArrayField>(); const { field } = useAssociationFieldContext<ArrayField>();
const { t } = useTranslation();
const move = (fromIndex: number, toIndex: number) => { const move = (fromIndex: number, toIndex: number) => {
if (toIndex === undefined) return; if (toIndex === undefined) return;
if (!isArr(field.value)) return; if (!isArr(field.value)) return;

View File

@ -306,6 +306,7 @@ export const Table: any = observer(
const toIndex = e.over?.data.current?.sortable?.index; const toIndex = e.over?.data.current?.sortable?.index;
const from = field.value[fromIndex] || e.active; const from = field.value[fromIndex] || e.active;
const to = field.value[toIndex] || e.over; const to = field.value[toIndex] || e.over;
field.move(fromIndex, toIndex);
onRowDragEnd({ from, to }); onRowDragEnd({ from, to });
}} }}
> >