fix: 修改子表格快速添加搜索bug,添加分类的所有选项 (#1129)

Reviewed-on: daoyoucloud/tachybase#1129
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-06-05 16:47:33 +08:00 committed by sealday
parent 80e65fe5f6
commit 5ae062ce8a
2 changed files with 24 additions and 11 deletions

View File

@ -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';

View File

@ -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={<SearchOutlined />}
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: (
<Space>
<Space style={{ maxHeight: '30vh', overflow: 'auto', padding: '10px 0px 20px 0px' }}>
{item?.childrenItems?.map((childrenitem, index) => (
<Button
key={index}
@ -211,12 +221,12 @@ export const InternalTabs = observer((props) => {
</Space>
),
}))}
style={{ height: '30vh', overflow: 'auto', padding: '10px' }}
style={{ maxHeight: '30vh', padding: '10px' }}
></Tabs>
) : null}
</>
) : (
<Space style={{ height: '30vh', overflow: 'auto', padding: '10px' }}>
<Space style={{ maxHeight: '30vh', overflow: 'auto', padding: '10px' }}>
{options.map((item, index) => (
<Button
key={index}