mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix: collectionFieldInterfaceSelect (#3945)
* fix: formula field caluation error * fix: collection manager primarykey * fix: nanoid & uuid suport index * fix: collectionFieldInterfaceSelect
This commit is contained in:
parent
aae936aa01
commit
de5bd5aae7
@ -84,14 +84,14 @@ export const CollectionFields = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dm = useDataSourceManager();
|
const dm = useDataSourceManager();
|
||||||
const handleFieldChange = async (value, filterByTk) => {
|
const handleFieldChange = async (value, filterByTk, flag = true) => {
|
||||||
await api.request({
|
await api.request({
|
||||||
url: `dataSourcesCollections/${dataSourceKey}.${name}/fields:update?filterByTk=${filterByTk}`,
|
url: `dataSourcesCollections/${dataSourceKey}.${name}/fields:update?filterByTk=${filterByTk}`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: value,
|
data: value,
|
||||||
});
|
});
|
||||||
dm.getDataSource(dataSourceKey).reload();
|
dm.getDataSource(dataSourceKey).reload();
|
||||||
message.success(t('Saved successfully'));
|
flag && message.success(t('Saved successfully'));
|
||||||
};
|
};
|
||||||
const useTitleFieldProps = () => {
|
const useTitleFieldProps = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { observer, useForm, useField } from '@formily/react';
|
import { observer, useForm, useField } from '@formily/react';
|
||||||
import { Select, Tag } from 'antd';
|
import { Select, Tag } from 'antd';
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useCompile, useCollectionManager_deprecated, useRecord, useFieldInterfaceOptions } from '@nocobase/client';
|
import { useCompile, useCollectionManager_deprecated, useRecord, useFieldInterfaceOptions } from '@nocobase/client';
|
||||||
|
|
||||||
const getInterfaceOptions = (data, type) => {
|
const getInterfaceOptions = (data, type) => {
|
||||||
@ -31,7 +31,37 @@ export const CollectionFieldInterfaceSelect = observer(
|
|||||||
const data = getInterfaceOptions(initOptions, record.type);
|
const data = getInterfaceOptions(initOptions, record.type);
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const field = useField();
|
const field = useField();
|
||||||
|
const [selectValue, setSelectValue] = useState(value);
|
||||||
const [options, setOptions] = useState(data);
|
const [options, setOptions] = useState(data);
|
||||||
|
const targetRecord = Object.values(form.values)?.[0]?.[field.index];
|
||||||
|
const targetType = targetRecord?.type || record.type;
|
||||||
|
useEffect(() => {
|
||||||
|
//只有一个选项的时候选中该选项
|
||||||
|
if (options.length === 1 && options[0]?.children?.length === 1) {
|
||||||
|
const targetValue = options[0]?.children?.[0]?.name;
|
||||||
|
if (targetValue !== selectValue) {
|
||||||
|
const interfaceConfig = getInterface(targetValue);
|
||||||
|
handleFieldChange(
|
||||||
|
{
|
||||||
|
interface: targetValue,
|
||||||
|
uiSchema: { title: record?.uiSchema?.title, ...interfaceConfig?.default?.uiSchema },
|
||||||
|
},
|
||||||
|
record.name,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
setSelectValue(targetValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [options]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (record?.possibleTypes) {
|
||||||
|
const targetRecord = Object.values(form.values)?.[0]?.[field.index];
|
||||||
|
const targetType = targetRecord?.type || record.type;
|
||||||
|
const newOptions = getInterfaceOptions(initOptions, targetType);
|
||||||
|
setOptions(newOptions);
|
||||||
|
}
|
||||||
|
}, [targetType]);
|
||||||
return ['oho', 'obo', 'o2m', 'm2o', 'm2m'].includes(record.interface) ? (
|
return ['oho', 'obo', 'o2m', 'm2o', 'm2m'].includes(record.interface) ? (
|
||||||
<Tag key={value}>
|
<Tag key={value}>
|
||||||
{compile(initOptions.find((h) => h.key === 'relation')['children'].find((v) => v.name === value)?.['label'])}
|
{compile(initOptions.find((h) => h.key === 'relation')['children'].find((v) => v.name === value)?.['label'])}
|
||||||
@ -41,7 +71,7 @@ export const CollectionFieldInterfaceSelect = observer(
|
|||||||
aria-label={`field-interface-${record?.type}`}
|
aria-label={`field-interface-${record?.type}`}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
role="button"
|
role="button"
|
||||||
defaultValue={value}
|
value={selectValue}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
popupMatchSelectWidth={false}
|
popupMatchSelectWidth={false}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
@ -53,14 +83,7 @@ export const CollectionFieldInterfaceSelect = observer(
|
|||||||
},
|
},
|
||||||
record.name,
|
record.name,
|
||||||
);
|
);
|
||||||
}}
|
setSelectValue(value);
|
||||||
onDropdownVisibleChange={(open) => {
|
|
||||||
if (open && record?.possibleTypes) {
|
|
||||||
const targetRecord = Object.values(form.values)?.[0]?.[field.index];
|
|
||||||
const targetType = targetRecord?.type || record.type;
|
|
||||||
const newOptions = getInterfaceOptions(initOptions, targetType);
|
|
||||||
setOptions(newOptions);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{options.map((group) => (
|
{options.map((group) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user