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

View File

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

View File

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