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 { import {
action, action,
ArrayField, ArrayField,
@ -7,11 +7,13 @@ import {
observer, observer,
RecursionField, RecursionField,
useFieldSchema, useFieldSchema,
useForm,
} from '@tachybase/schema'; } from '@tachybase/schema';
import { Button } from 'antd'; import { useAsyncEffect } from 'ahooks';
import { Button, Tabs } from 'antd';
import { createStyles } from 'antd-style'; import { createStyles } from 'antd-style';
import { unionBy, uniqBy } from 'lodash'; import { set, unionBy, uniqBy } from 'lodash';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { import {
@ -21,11 +23,12 @@ import {
SchemaComponentOptions, SchemaComponentOptions,
useActionContext, useActionContext,
} from '../..'; } from '../..';
import { useAPIClient, useRequest } from '../../../api-client';
import { useCreateActionProps } from '../../../block-provider/hooks'; import { useCreateActionProps } from '../../../block-provider/hooks';
import { FormActiveFieldsProvider } from '../../../block-provider/hooks/useFormActiveFields'; import { FormActiveFieldsProvider } from '../../../block-provider/hooks/useFormActiveFields';
import { TableSelectorParamsProvider } from '../../../block-provider/TableSelectorProvider'; import { TableSelectorParamsProvider } from '../../../block-provider/TableSelectorProvider';
import { CollectionProvider_deprecated } from '../../../collection-manager'; 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 { markRecordAsNew } from '../../../data-source/collection-record/isNewRecord';
import { FlagProvider } from '../../../flag-provider'; import { FlagProvider } from '../../../flag-provider';
import { useCompile } from '../../hooks'; import { useCompile } from '../../hooks';

View File

@ -78,6 +78,12 @@ export const InternalTabs = observer((props) => {
itemParams['childrenOptions'] = childrenItem?.data?.data; itemParams['childrenOptions'] = childrenItem?.data?.data;
if (itemParams['parentOptions']?.length && itemParams['childrenOptions']?.length) { if (itemParams['parentOptions']?.length && itemParams['childrenOptions']?.length) {
optionsItem.unshift({
value: 'all',
label: t('All'),
key: 'all',
childrenItems: [],
});
itemParams['parentOptions'].forEach((parentItem) => { itemParams['parentOptions'].forEach((parentItem) => {
const items = itemParams['childrenOptions'] const items = itemParams['childrenOptions']
.map((item) => { .map((item) => {
@ -93,6 +99,7 @@ export const InternalTabs = observer((props) => {
}) })
.filter(Boolean); .filter(Boolean);
if (!items.length) return; if (!items.length) return;
optionsItem[0].childrenItems.push(...items);
optionsItem.push({ optionsItem.push({
...parentItem, ...parentItem,
value: parentItem?.id, value: parentItem?.id,
@ -138,7 +145,7 @@ export const InternalTabs = observer((props) => {
setDefOptions(filterParantOptions); setDefOptions(filterParantOptions);
setOptions(filterOptions); setOptions(filterOptions);
} else { } else {
const filterDefOptions = tabsFilterOptions(options, fieldTabs, quickAddField); const filterDefOptions = tabsFilterOptions(defOptions, fieldTabs, quickAddField);
setDefOptions(filterDefOptions); setDefOptions(filterDefOptions);
const filterOptions = tabsFilterOptions(options, fieldTabs, quickAddField); const filterOptions = tabsFilterOptions(options, fieldTabs, quickAddField);
setOptions(filterOptions); setOptions(filterOptions);
@ -151,11 +158,14 @@ export const InternalTabs = observer((props) => {
}); });
}); });
const onSelect = (value) => { const onSelect = (value) => {
if (!value) {
setOptions(defOptions);
}
if (quickAddParentField && quickAddParentField.value !== 'none') { if (quickAddParentField && quickAddParentField.value !== 'none') {
const filterOption = defOptions const filterOption = defOptions
.map((item) => { ?.map((item) => {
const filterItem = item?.childrenItems?.filter((childrenItem) => fuzzysearch(value, childrenItem?.label)); 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 { return {
...item, ...item,
childrenItems: filterItem.length ? filterItem : item.childrenItems, childrenItems: filterItem.length ? filterItem : item.childrenItems,
@ -184,7 +194,7 @@ export const InternalTabs = observer((props) => {
placeholder={t('Please enter search content')} placeholder={t('Please enter search content')}
prefix={<SearchOutlined />} prefix={<SearchOutlined />}
onChange={(e) => { onChange={(e) => {
onSelect(e.target.value); onSelect(e?.target?.value);
}} }}
/> />
@ -196,7 +206,7 @@ export const InternalTabs = observer((props) => {
items={options.map((item) => ({ items={options.map((item) => ({
...item, ...item,
children: ( children: (
<Space> <Space style={{ maxHeight: '30vh', overflow: 'auto', padding: '10px 0px 20px 0px' }}>
{item?.childrenItems?.map((childrenitem, index) => ( {item?.childrenItems?.map((childrenitem, index) => (
<Button <Button
key={index} key={index}
@ -211,12 +221,12 @@ export const InternalTabs = observer((props) => {
</Space> </Space>
), ),
}))} }))}
style={{ height: '30vh', overflow: 'auto', padding: '10px' }} style={{ maxHeight: '30vh', padding: '10px' }}
></Tabs> ></Tabs>
) : null} ) : null}
</> </>
) : ( ) : (
<Space style={{ height: '30vh', overflow: 'auto', padding: '10px' }}> <Space style={{ maxHeight: '30vh', overflow: 'auto', padding: '10px' }}>
{options.map((item, index) => ( {options.map((item, index) => (
<Button <Button
key={index} key={index}