mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: dynamic appends not support template schema
This commit is contained in:
parent
aa69973a90
commit
2f1cc6c938
@ -40,8 +40,7 @@ const InternalDetailsBlockProvider = (props) => {
|
|||||||
|
|
||||||
export const DetailsBlockProvider = (props) => {
|
export const DetailsBlockProvider = (props) => {
|
||||||
const params = { ...props.params };
|
const params = { ...props.params };
|
||||||
const { collection } = props;
|
const { appends } = useAssociationNames();
|
||||||
const { appends } = useAssociationNames(collection);
|
|
||||||
if (!Object.keys(params).includes('appends')) {
|
if (!Object.keys(params).includes('appends')) {
|
||||||
params['appends'] = appends;
|
params['appends'] = appends;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ export const FormBlockProvider = (props) => {
|
|||||||
const currentCollection = useCollection();
|
const currentCollection = useCollection();
|
||||||
const { designable } = useDesignable();
|
const { designable } = useDesignable();
|
||||||
const isEmptyRecord = useIsEmptyRecord();
|
const isEmptyRecord = useIsEmptyRecord();
|
||||||
const { appends, updateAssociationValues } = useAssociationNames(collection);
|
const { appends, updateAssociationValues } = useAssociationNames();
|
||||||
if (!Object.keys(params).includes('appends')) {
|
if (!Object.keys(params).includes('appends')) {
|
||||||
params['appends'] = appends;
|
params['appends'] = appends;
|
||||||
}
|
}
|
||||||
|
@ -1073,10 +1073,20 @@ export const useAssociationFilterBlockProps = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useAssociationNames = (collection) => {
|
const getTemplateSchema = ({ uid }) => {
|
||||||
|
const conf = {
|
||||||
|
url: `/uiSchemas:getJsonSchema/${uid}`,
|
||||||
|
};
|
||||||
|
const { data, loading } = useRequest(conf);
|
||||||
|
if (loading) {
|
||||||
|
// return;
|
||||||
|
}
|
||||||
|
return new Schema(data?.data || {});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useAssociationNames = () => {
|
||||||
const { getCollectionJoinField } = useCollectionManager();
|
const { getCollectionJoinField } = useCollectionManager();
|
||||||
const { getTemplateById } = useSchemaTemplateManager();
|
const { getTemplateById } = useSchemaTemplateManager();
|
||||||
|
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const associationValues = [];
|
const associationValues = [];
|
||||||
const formSchema = fieldSchema.reduceProperties((buf, schema) => {
|
const formSchema = fieldSchema.reduceProperties((buf, schema) => {
|
||||||
@ -1086,6 +1096,13 @@ export const useAssociationNames = (collection) => {
|
|||||||
return buf;
|
return buf;
|
||||||
}, new Schema({}));
|
}, new Schema({}));
|
||||||
|
|
||||||
|
const templateSchema = formSchema.reduceProperties((buf, schema) => {
|
||||||
|
if (schema['x-component'] === 'BlockTemplate') {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}, null);
|
||||||
|
|
||||||
const getAssociationAppends = (schema, arr = []) => {
|
const getAssociationAppends = (schema, arr = []) => {
|
||||||
const data = schema.reduceProperties((buf, s) => {
|
const data = schema.reduceProperties((buf, s) => {
|
||||||
const collectionfield = s['x-collection-field'] && getCollectionJoinField(s['x-collection-field']);
|
const collectionfield = s['x-collection-field'] && getCollectionJoinField(s['x-collection-field']);
|
||||||
@ -1106,9 +1123,6 @@ export const useAssociationNames = (collection) => {
|
|||||||
if (s['x-component'] === 'Grid.Row') {
|
if (s['x-component'] === 'Grid.Row') {
|
||||||
const kk = buf?.concat?.();
|
const kk = buf?.concat?.();
|
||||||
return getNesterAppends(s, kk || []);
|
return getNesterAppends(s, kk || []);
|
||||||
} else if (s['x-component'] === 'BlockTemplate') {
|
|
||||||
const templateSchema = getTemplateById(s['x-component-props']?.templateId);
|
|
||||||
return getAssociationAppends(templateSchema, buf);
|
|
||||||
} else {
|
} else {
|
||||||
return !s['x-component']?.includes('Action.') && s['x-component'] !== 'TableField'
|
return !s['x-component']?.includes('Action.') && s['x-component'] !== 'TableField'
|
||||||
? getAssociationAppends(s, buf)
|
? getAssociationAppends(s, buf)
|
||||||
@ -1138,7 +1152,7 @@ export const useAssociationNames = (collection) => {
|
|||||||
for (let i = 0; i < nestedList.length; i++) {
|
for (let i = 0; i < nestedList.length; i++) {
|
||||||
flattenHelper(nestedList[i], nestedList[i][0]);
|
flattenHelper(nestedList[i], nestedList[i][0]);
|
||||||
}
|
}
|
||||||
return uniq(flattenedList.filter((obj) => !obj.startsWith('.')));
|
return uniq(flattenedList.filter((obj) => !obj?.startsWith('.')));
|
||||||
}
|
}
|
||||||
const getNesterAppends = (gridSchema, data) => {
|
const getNesterAppends = (gridSchema, data) => {
|
||||||
gridSchema.reduceProperties((buf, s) => {
|
gridSchema.reduceProperties((buf, s) => {
|
||||||
@ -1147,8 +1161,17 @@ export const useAssociationNames = (collection) => {
|
|||||||
}, data);
|
}, data);
|
||||||
return data.filter((g) => g.length);
|
return data.filter((g) => g.length);
|
||||||
};
|
};
|
||||||
|
if (templateSchema) {
|
||||||
const associations = getAssociationAppends(formSchema);
|
const template = getTemplateById(templateSchema['x-component-props']?.templateId);
|
||||||
const appends = flattenNestedList(associations);
|
const schema = getTemplateSchema(template);
|
||||||
return { appends, updateAssociationValues: appends.filter((v) => associationValues.includes(v)) };
|
if (schema) {
|
||||||
|
const associations = getAssociationAppends(schema);
|
||||||
|
const appends = flattenNestedList(associations);
|
||||||
|
return { appends, updateAssociationValues: appends.filter((v) => associationValues.includes(v)) };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const associations = getAssociationAppends(formSchema);
|
||||||
|
const appends = flattenNestedList(associations);
|
||||||
|
return { appends, updateAssociationValues: appends.filter((v) => associationValues.includes(v)) };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user