fix: currentObject can not loadData (#2385)
This commit is contained in:
parent
05cba94982
commit
316b12a4ba
@ -120,8 +120,9 @@ const ConstantTypes = {
|
|||||||
|
|
||||||
function getTypedConstantOption(type: string, types: true | string[], fieldNames) {
|
function getTypedConstantOption(type: string, types: true | string[], fieldNames) {
|
||||||
const allTypes = Object.values(ConstantTypes);
|
const allTypes = Object.values(ConstantTypes);
|
||||||
const children = (
|
const children = (types
|
||||||
types ? allTypes.filter((item) => (Array.isArray(types) && types.includes(item.value)) || types === true) : allTypes
|
? allTypes.filter((item) => (Array.isArray(types) && types.includes(item.value)) || types === true)
|
||||||
|
: allTypes
|
||||||
).map((item) =>
|
).map((item) =>
|
||||||
Object.keys(item).reduce(
|
Object.keys(item).reduce(
|
||||||
(result, key) =>
|
(result, key) =>
|
||||||
@ -181,27 +182,29 @@ export function Input(props) {
|
|||||||
fieldNames ?? {},
|
fieldNames ?? {},
|
||||||
);
|
);
|
||||||
|
|
||||||
const { component: ConstantComponent, ...constantOption }: DefaultOptionType & { component?: React.FC<any> } =
|
const {
|
||||||
useMemo(() => {
|
component: ConstantComponent,
|
||||||
if (children) {
|
...constantOption
|
||||||
return {
|
}: DefaultOptionType & { component?: React.FC<any> } = useMemo(() => {
|
||||||
value: '',
|
if (children) {
|
||||||
label: t('Constant'),
|
|
||||||
[names.value]: '',
|
|
||||||
[names.label]: t('Constant'),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (useTypedConstant) {
|
|
||||||
return getTypedConstantOption(type, useTypedConstant, names);
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
value: '',
|
value: '',
|
||||||
label: t('Null'),
|
label: t('Constant'),
|
||||||
[names.value]: '',
|
[names.value]: '',
|
||||||
[names.label]: t('Null'),
|
[names.label]: t('Constant'),
|
||||||
component: ConstantTypes.null.component,
|
|
||||||
};
|
};
|
||||||
}, [type, useTypedConstant]);
|
}
|
||||||
|
if (useTypedConstant) {
|
||||||
|
return getTypedConstantOption(type, useTypedConstant, names);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
value: '',
|
||||||
|
label: t('Null'),
|
||||||
|
[names.value]: '',
|
||||||
|
[names.label]: t('Null'),
|
||||||
|
component: ConstantTypes.null.component,
|
||||||
|
};
|
||||||
|
}, [type, useTypedConstant]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOptions([compile(constantOption), ...(scope ? cloneDeep(scope) : [])]);
|
setOptions([compile(constantOption), ...(scope ? cloneDeep(scope) : [])]);
|
||||||
@ -209,7 +212,7 @@ export function Input(props) {
|
|||||||
|
|
||||||
const loadData = async (selectedOptions: DefaultOptionType[]) => {
|
const loadData = async (selectedOptions: DefaultOptionType[]) => {
|
||||||
const option = selectedOptions[selectedOptions.length - 1];
|
const option = selectedOptions[selectedOptions.length - 1];
|
||||||
if (!option.children && !option.isLeaf && option.loadChildren) {
|
if (!option.children?.length && !option.isLeaf && option.loadChildren) {
|
||||||
await option.loadChildren(option);
|
await option.loadChildren(option);
|
||||||
setOptions((prev) => [...prev]);
|
setOptions((prev) => [...prev]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user