feat: support edit associated form (#920)

Reviewed-on: daoyoucloud/tachybase#920
This commit is contained in:
sealday 2024-05-07 20:30:14 +08:00
parent 330b8b13da
commit dcd89df482
3 changed files with 32 additions and 17 deletions

View File

@ -93,7 +93,7 @@ export const useIsDetailBlock = () => {
export const FormBlockProvider = withDynamicSchemaProps((props) => {
const record = useRecord();
const parentRecordData = useCollectionParentRecordData();
const { collection, isCusomeizeCreate } = props;
const { collection, isCusomeizeCreate, parentRecord } = props;
const { __collection } = record;
const currentCollection = useCollection_deprecated();
const { designable } = useDesignable();
@ -114,7 +114,12 @@ export const FormBlockProvider = withDynamicSchemaProps((props) => {
return (
<TemplateBlockProvider>
<BlockProvider name={props.name || 'form'} {...props} block={'form'} parentRecord={parentRecordData}>
<BlockProvider
name={props.name || 'form'}
{...props}
block={'form'}
parentRecord={parentRecord || parentRecordData}
>
<FormActiveFieldsProvider name="form">
<InternalFormBlockProvider {...props} />
</FormActiveFieldsProvider>

View File

@ -43,6 +43,15 @@ export function useCreateEditFormBlock() {
const createEditFormBlock = useCallback(
({ item }) => {
if (!association && item.associationField) {
const field = item.associationField;
insert(
createEditFormBlockUISchema({
dataSource: item.dataSource,
association: `${field.collectionName}.${field.name}`,
}),
);
} else {
insert(
createEditFormBlockUISchema(
association
@ -57,6 +66,7 @@ export function useCreateEditFormBlock() {
},
),
);
}
},
[association, insert],
);

View File

@ -126,7 +126,7 @@ function useRecordBlocks() {
if (collection) {
return collectionsNeedToDisplay.some((c) => c.name === collection.name);
}
return false;
return true;
},
onlyCurrentDataSource: true,
hideSearch: true,