mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:55:33 +00:00
fix: relational data should be loaded correctly on first render (#3016)
* fix: subform should lazy load data * fix: relational data should be loaded correctly on first render
This commit is contained in:
parent
3b5b732a1a
commit
d9e7ba6e8d
@ -301,14 +301,18 @@ export const BlockProvider = (props: {
|
||||
}) => {
|
||||
const { collection, association, name } = props;
|
||||
const resource = useResource(props);
|
||||
const params = useMemo(() => ({ ...props.params }), [props.params]);
|
||||
const { appends, updateAssociationValues } = useAssociationNames();
|
||||
const params = useMemo(() => {
|
||||
if (!props.params) {
|
||||
return props.params;
|
||||
}
|
||||
if (!props.params['appends']) {
|
||||
return { ...props.params, appends };
|
||||
}
|
||||
return { ...props.params };
|
||||
}, [appends, props.params]);
|
||||
const blockValue = useMemo(() => ({ name }), [name]);
|
||||
|
||||
if (!Object.keys(params).includes('appends')) {
|
||||
params['appends'] = appends;
|
||||
}
|
||||
|
||||
return (
|
||||
<BlockContext.Provider value={blockValue}>
|
||||
<MaybeCollectionProvider collection={collection}>
|
||||
|
@ -1278,10 +1278,10 @@ export const useAssociationNames = () => {
|
||||
const getAssociationAppends = (schema, str) => {
|
||||
schema.reduceProperties((pre, s) => {
|
||||
const prefix = pre || str;
|
||||
const collectionfield = s['x-collection-field'] && getCollectionJoinField(s['x-collection-field']);
|
||||
const collectionField = s['x-collection-field'] && getCollectionJoinField(s['x-collection-field']);
|
||||
const isAssociationSubfield = s.name.includes('.');
|
||||
const isAssociationField =
|
||||
collectionfield && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany'].includes(collectionfield.type);
|
||||
collectionField && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany'].includes(collectionField.type);
|
||||
|
||||
// 根据联动规则中条件的字段获取一些 appends
|
||||
if (s['x-linkage-rules']) {
|
||||
@ -1301,8 +1301,8 @@ export const useAssociationNames = () => {
|
||||
});
|
||||
}
|
||||
|
||||
const isTreeCollection = isAssociationField && getCollection(collectionfield.target)?.template === 'tree';
|
||||
if (collectionfield && (isAssociationField || isAssociationSubfield) && s['x-component'] !== 'TableField') {
|
||||
const isTreeCollection = isAssociationField && getCollection(collectionField.target)?.template === 'tree';
|
||||
if (collectionField && (isAssociationField || isAssociationSubfield) && s['x-component'] !== 'TableField') {
|
||||
const fieldPath = !isAssociationField && isAssociationSubfield ? getAssociationPath(s.name) : s.name;
|
||||
const path = prefix === '' || !prefix ? fieldPath : prefix + '.' + fieldPath;
|
||||
if (isTreeCollection) {
|
||||
|
@ -287,5 +287,11 @@ export default VariablesProvider;
|
||||
* @returns
|
||||
*/
|
||||
function shouldToRequest(value) {
|
||||
// fix https://nocobase.height.app/T-2502
|
||||
// 兼容对多子表单子表格字段的情况
|
||||
if (JSON.stringify(value) === '[{}]') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return value === undefined;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user