mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
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:
parent
f36bc41a11
commit
3fd5b05940
@ -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 {
|
||||||
|
@ -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,
|
||||||
|
@ -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 }}>
|
||||||
|
@ -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]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user