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,13 +301,17 @@ export const BlockProvider = (props: {
|
|||||||
}) => {
|
}) => {
|
||||||
const { collection, association, name } = props;
|
const { collection, association, name } = props;
|
||||||
const resource = useResource(props);
|
const resource = useResource(props);
|
||||||
const params = useMemo(() => ({ ...props.params }), [props.params]);
|
|
||||||
const { appends, updateAssociationValues } = useAssociationNames();
|
const { appends, updateAssociationValues } = useAssociationNames();
|
||||||
const blockValue = useMemo(() => ({ name }), [name]);
|
const params = useMemo(() => {
|
||||||
|
if (!props.params) {
|
||||||
if (!Object.keys(params).includes('appends')) {
|
return props.params;
|
||||||
params['appends'] = appends;
|
|
||||||
}
|
}
|
||||||
|
if (!props.params['appends']) {
|
||||||
|
return { ...props.params, appends };
|
||||||
|
}
|
||||||
|
return { ...props.params };
|
||||||
|
}, [appends, props.params]);
|
||||||
|
const blockValue = useMemo(() => ({ name }), [name]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BlockContext.Provider value={blockValue}>
|
<BlockContext.Provider value={blockValue}>
|
||||||
|
@ -1278,10 +1278,10 @@ export const useAssociationNames = () => {
|
|||||||
const getAssociationAppends = (schema, str) => {
|
const getAssociationAppends = (schema, str) => {
|
||||||
schema.reduceProperties((pre, s) => {
|
schema.reduceProperties((pre, s) => {
|
||||||
const prefix = pre || str;
|
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 isAssociationSubfield = s.name.includes('.');
|
||||||
const isAssociationField =
|
const isAssociationField =
|
||||||
collectionfield && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany'].includes(collectionfield.type);
|
collectionField && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany'].includes(collectionField.type);
|
||||||
|
|
||||||
// 根据联动规则中条件的字段获取一些 appends
|
// 根据联动规则中条件的字段获取一些 appends
|
||||||
if (s['x-linkage-rules']) {
|
if (s['x-linkage-rules']) {
|
||||||
@ -1301,8 +1301,8 @@ export const useAssociationNames = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTreeCollection = isAssociationField && getCollection(collectionfield.target)?.template === 'tree';
|
const isTreeCollection = isAssociationField && getCollection(collectionField.target)?.template === 'tree';
|
||||||
if (collectionfield && (isAssociationField || isAssociationSubfield) && s['x-component'] !== 'TableField') {
|
if (collectionField && (isAssociationField || isAssociationSubfield) && s['x-component'] !== 'TableField') {
|
||||||
const fieldPath = !isAssociationField && isAssociationSubfield ? getAssociationPath(s.name) : s.name;
|
const fieldPath = !isAssociationField && isAssociationSubfield ? getAssociationPath(s.name) : s.name;
|
||||||
const path = prefix === '' || !prefix ? fieldPath : prefix + '.' + fieldPath;
|
const path = prefix === '' || !prefix ? fieldPath : prefix + '.' + fieldPath;
|
||||||
if (isTreeCollection) {
|
if (isTreeCollection) {
|
||||||
|
@ -287,5 +287,11 @@ export default VariablesProvider;
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function shouldToRequest(value) {
|
function shouldToRequest(value) {
|
||||||
|
// fix https://nocobase.height.app/T-2502
|
||||||
|
// 兼容对多子表单子表格字段的情况
|
||||||
|
if (JSON.stringify(value) === '[{}]') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return value === undefined;
|
return value === undefined;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user