feat(client): search and select collection

This commit is contained in:
chenos 2022-11-08 22:39:01 +08:00
parent 72838b7f49
commit 406813e932
8 changed files with 63 additions and 5 deletions

View File

@ -581,4 +581,5 @@ export default {
"Please select the records to be updated": "Please select the records to be updated",
"Selector": "Selector",
"Inner": "Inner",
"Search and select collection": "Search and select collection",
}

View File

@ -588,4 +588,5 @@ export default {
"Error message": "エラーメッセージ",
"Record picker": "レコードピッカー",
"Sortable": "ソート可能",
"Search and select collection": "Search and select collection",
}

View File

@ -557,4 +557,5 @@ export default {
"Print": "Печать",
'Single select and radio fields can be used as the grouping field': 'Одиночное поле выбора и радиополя могут использоваться в качестве поля группировки',
'Sign up successfully, and automatically jump to the sign in page': 'Зарегистрируйтесь успешно и автоматически перейдете на страницу входа',
"Search and select collection": "Search and select collection",
}

View File

@ -556,4 +556,5 @@ export default {
"Print": "Yazdır",
'Single select and radio fields can be used as the grouping field': 'Gruplama alanı olarak tek seçim ve radyo alanları kullanılabilir',
'Sign up successfully, and automatically jump to the sign in page': 'Başarılı bir şekilde kaydolun ve otomatik olarak oturum açma sayfasına geçin',
"Search and select collection": "Search and select collection",
}

View File

@ -734,4 +734,5 @@ export default {
"Please select the records to be updated": "请选择要更新的记录",
"Selector": "选择器",
"Inner": "里面",
"Search and select collection": "搜索并选择数据表",
}

View File

@ -188,6 +188,7 @@ SchemaInitializer.Item = (props: SchemaInitializerItemProps) => {
eventKey={item.key}
key={item.key}
onClick={(info) => {
item?.clearKeywords();
onClick({ ...info, item });
}}
>
@ -215,6 +216,7 @@ SchemaInitializer.Item = (props: SchemaInitializerItemProps) => {
eventKey={eventKey ? `${eventKey}-${index}` : info.key}
icon={typeof icon === 'string' ? <Icon type={icon as string} /> : icon}
onClick={(opts) => {
info?.clearKeywords();
onClick({ ...opts, item: info });
}}
>

View File

@ -0,0 +1,34 @@
import { Divider, Input } from 'antd';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useCollectionManager } from '../collection-manager';
export const SelectCollection = ({ value, onChange, setSelected }) => {
const { t } = useTranslation();
const { collections } = useCollectionManager();
return (
<div style={{ width: 210 }}>
<Input
allowClear
style={{ padding: '0 4px 6px' }}
bordered={false}
placeholder={t('Search and select collection')}
value={value}
onChange={(e) => {
const names = collections
.filter((collection) => {
if (!collection.title) {
return;
}
return collection.title.toUpperCase().includes(e.target.value.toUpperCase());
})
.map((item) => item.name);
setSelected(names);
onChange(e.target.value);
}}
/>
<Divider style={{ margin: 0 }}/>
</div>
);
};

View File

@ -1,10 +1,12 @@
import { ISchema, Schema, useFieldSchema, useForm } from '@formily/react';
import { uid } from '@formily/shared';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { SchemaInitializerItemOptions } from '../';
import { useCollection, useCollectionManager } from '../collection-manager';
import { useDesignable } from '../schema-component';
import { useSchemaTemplateManager } from '../schema-templates';
import { SelectCollection } from './SelectCollection';
export const itemsMerge = (items1, items2) => {
return items1;
@ -427,17 +429,28 @@ export const useCollectionDataSourceItems = (componentName) => {
const { t } = useTranslation();
const { collections } = useCollectionManager();
const { getTemplatesByCollection } = useSchemaTemplateManager();
const [selected, setSelected] = useState([]);
const [value, onChange] = useState(null);
const clearKeywords = () => {
setSelected([]);
onChange(null);
};
return [
{
key: 'tableBlock',
type: 'itemGroup',
title: t('Select collection'),
title: React.createElement(SelectCollection, {
value,
onChange,
setSelected,
}),
children: collections
?.filter((item) => {
if(item.inherit){
return false
}else{
return !(item?.isThrough && item?.autoCreate);
const b = !value || selected.includes(item.name);
if (item.inherit) {
return false;
} else {
return b && !(item?.isThrough && item?.autoCreate);
}
})
?.map((item, index) => {
@ -453,6 +466,7 @@ export const useCollectionDataSourceItems = (componentName) => {
type: 'item',
name: item.name,
title: item.title,
clearKeywords,
};
}
return {
@ -465,6 +479,7 @@ export const useCollectionDataSourceItems = (componentName) => {
type: 'item',
name: item.name,
title: t('Blank block'),
clearKeywords,
},
{
type: 'divider',
@ -482,6 +497,7 @@ export const useCollectionDataSourceItems = (componentName) => {
mode: 'copy',
name: item.name,
template,
clearKeywords,
title: templateName || t('Untitled'),
};
}),
@ -497,6 +513,7 @@ export const useCollectionDataSourceItems = (componentName) => {
return {
type: 'item',
mode: 'reference',
clearKeywords,
name: item.name,
template,
title: templateName || t('Untitled'),