From 5ae062ce8af42a4b5621212adbdb2fb3195295b9 Mon Sep 17 00:00:00 2001 From: wjh Date: Wed, 5 Jun 2024 16:47:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E5=BF=AB=E9=80=9F=E6=B7=BB=E5=8A=A0=E6=90=9C=E7=B4=A2?= =?UTF-8?q?bug,=E6=B7=BB=E5=8A=A0=E5=88=86=E7=B1=BB=E7=9A=84=E6=89=80?= =?UTF-8?q?=E6=9C=89=E9=80=89=E9=A1=B9=20(#1129)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1129 Reviewed-by: sealday Co-authored-by: wjh Co-committed-by: wjh --- .../antd/association-field/SubTable.tsx | 11 +++++---- .../SubTabs/InternalTabs.tsx | 24 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx index 0c2c447b0..7ec98de78 100644 --- a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useMemo, useState } from 'react'; +import React, { useContext, useEffect, useMemo, useState } from 'react'; import { action, ArrayField, @@ -7,11 +7,13 @@ import { observer, RecursionField, useFieldSchema, + useForm, } from '@tachybase/schema'; -import { Button } from 'antd'; +import { useAsyncEffect } from 'ahooks'; +import { Button, Tabs } from 'antd'; import { createStyles } from 'antd-style'; -import { unionBy, uniqBy } from 'lodash'; +import { set, unionBy, uniqBy } from 'lodash'; import { useTranslation } from 'react-i18next'; import { @@ -21,11 +23,12 @@ import { SchemaComponentOptions, useActionContext, } from '../..'; +import { useAPIClient, useRequest } from '../../../api-client'; import { useCreateActionProps } from '../../../block-provider/hooks'; import { FormActiveFieldsProvider } from '../../../block-provider/hooks/useFormActiveFields'; import { TableSelectorParamsProvider } from '../../../block-provider/TableSelectorProvider'; import { CollectionProvider_deprecated } from '../../../collection-manager'; -import { CollectionRecordProvider, useCollectionRecord } from '../../../data-source'; +import { CollectionRecordProvider, useCollectionManager, useCollectionRecord } from '../../../data-source'; import { markRecordAsNew } from '../../../data-source/collection-record/isNewRecord'; import { FlagProvider } from '../../../flag-provider'; import { useCompile } from '../../hooks'; diff --git a/packages/core/client/src/schema-component/antd/association-field/SubTabs/InternalTabs.tsx b/packages/core/client/src/schema-component/antd/association-field/SubTabs/InternalTabs.tsx index 432ef5f3f..7a9694e2f 100644 --- a/packages/core/client/src/schema-component/antd/association-field/SubTabs/InternalTabs.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/SubTabs/InternalTabs.tsx @@ -78,6 +78,12 @@ export const InternalTabs = observer((props) => { itemParams['childrenOptions'] = childrenItem?.data?.data; if (itemParams['parentOptions']?.length && itemParams['childrenOptions']?.length) { + optionsItem.unshift({ + value: 'all', + label: t('All'), + key: 'all', + childrenItems: [], + }); itemParams['parentOptions'].forEach((parentItem) => { const items = itemParams['childrenOptions'] .map((item) => { @@ -93,6 +99,7 @@ export const InternalTabs = observer((props) => { }) .filter(Boolean); if (!items.length) return; + optionsItem[0].childrenItems.push(...items); optionsItem.push({ ...parentItem, value: parentItem?.id, @@ -138,7 +145,7 @@ export const InternalTabs = observer((props) => { setDefOptions(filterParantOptions); setOptions(filterOptions); } else { - const filterDefOptions = tabsFilterOptions(options, fieldTabs, quickAddField); + const filterDefOptions = tabsFilterOptions(defOptions, fieldTabs, quickAddField); setDefOptions(filterDefOptions); const filterOptions = tabsFilterOptions(options, fieldTabs, quickAddField); setOptions(filterOptions); @@ -151,11 +158,14 @@ export const InternalTabs = observer((props) => { }); }); const onSelect = (value) => { + if (!value) { + setOptions(defOptions); + } if (quickAddParentField && quickAddParentField.value !== 'none') { const filterOption = defOptions - .map((item) => { + ?.map((item) => { const filterItem = item?.childrenItems?.filter((childrenItem) => fuzzysearch(value, childrenItem?.label)); - if (fuzzysearch(value, item?.label) || filterItem.length) { + if (fuzzysearch(value, item?.label) || filterItem?.length) { return { ...item, childrenItems: filterItem.length ? filterItem : item.childrenItems, @@ -184,7 +194,7 @@ export const InternalTabs = observer((props) => { placeholder={t('Please enter search content')} prefix={} onChange={(e) => { - onSelect(e.target.value); + onSelect(e?.target?.value); }} /> @@ -196,7 +206,7 @@ export const InternalTabs = observer((props) => { items={options.map((item) => ({ ...item, children: ( - + {item?.childrenItems?.map((childrenitem, index) => (