fix: scopeKeyOptions should be obtained in real-time (#4029)

* fix: formula field caluation error

* fix: scopeKeyOptions

* fix: bug

* fix: bug
This commit is contained in:
katherinehhh 2024-04-13 09:28:24 +08:00 committed by GitHub
parent f36bc41a11
commit 3fd5b05940
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 5 deletions

View File

@ -175,12 +175,13 @@ export const EditFieldAction = (props) => {
const compile = useCompile(); const compile = useCompile();
const [data, setData] = useState<any>({}); const [data, setData] = useState<any>({});
const { isDialect } = useDialect(); const { isDialect } = useDialect();
const scopeKeyOptions = useMemo(() => { const scopeKeyOptions = useMemo(() => {
return ( return (
record?.fields || record?.fields ||
getCollection(record.collectionName) getCollection(record.collectionName)
.options.fields.filter((v) => { .options.fields.filter((v) => {
return v.interface === 'select'; return ['string', 'bigInt', 'integer'].includes(v.type);
}) })
.map((k) => { .map((k) => {
return { return {

View File

@ -22,7 +22,7 @@ export class SortFieldInterface extends CollectionFieldInterface {
'x-validator': 'integer', 'x-validator': 'integer',
}, },
}; };
availableTypes = ['bigInt', 'integer', 'sort']; availableTypes = ['sort'];
hasDefaultValue = false; hasDefaultValue = false;
properties = { properties = {
...defaultProps, ...defaultProps,

View File

@ -191,6 +191,7 @@ const EditFieldAction = (props) => {
const compile = useCompile(); const compile = useCompile();
const { name } = useParams(); const { name } = useParams();
const isDialect = (dialect: string) => currentDatabase?.dialect === dialect; const isDialect = (dialect: string) => currentDatabase?.dialect === dialect;
const fields = record?.fields || getCollection(record.collectionName, name)?.options?.fields;
const currentCollections = useMemo(() => { const currentCollections = useMemo(() => {
return collections.map((v) => { return collections.map((v) => {
return { return {
@ -204,7 +205,7 @@ const EditFieldAction = (props) => {
record?.fields || record?.fields ||
getCollection(record.collectionName, name) getCollection(record.collectionName, name)
?.options?.fields.filter((v) => { ?.options?.fields.filter((v) => {
return v.interface === 'select'; return ['string', 'bigInt', 'integer'].includes(v.type);
}) })
.map((k) => { .map((k) => {
return { return {
@ -213,7 +214,7 @@ const EditFieldAction = (props) => {
}; };
}) })
); );
}, [record.name]); }, [record.name, fields]);
return ( return (
<RecordProvider record={record} parent={parentRecord}> <RecordProvider record={record} parent={parentRecord}>
<ActionContextProvider value={{ visible, setVisible }}> <ActionContextProvider value={{ visible, setVisible }}>

View File

@ -20,7 +20,9 @@ const getInterfaceOptions = (data, type) => {
return v.children.length > 0; return v.children.length > 0;
}); });
}; };
const isValueInOptions = (value, options) => {
return options?.some((option) => option.children?.some?.((child) => child.name === value));
};
export const CollectionFieldInterfaceSelect = observer( export const CollectionFieldInterfaceSelect = observer(
(props: any) => { (props: any) => {
const { value, handleFieldChange } = props; const { value, handleFieldChange } = props;
@ -51,6 +53,19 @@ export const CollectionFieldInterfaceSelect = observer(
); );
setSelectValue(targetValue); setSelectValue(targetValue);
} }
//选中的值不在选项中切换为第一个
} else if (selectValue && !isValueInOptions(selectValue, options)) {
const targetValue = options[0]?.children?.[0]?.name;
const interfaceConfig = getInterface(targetValue);
handleFieldChange(
{
interface: targetValue,
uiSchema: { title: record?.uiSchema?.title, ...interfaceConfig?.default?.uiSchema },
},
record.name,
false,
);
setSelectValue(targetValue);
} }
}, [options]); }, [options]);