This commit is contained in:
dream2023 2024-01-18 18:41:15 +08:00
parent 4560619ef3
commit b4d950566c
10 changed files with 29 additions and 7 deletions

View File

@ -26,6 +26,7 @@ export const CreateFormBlockInitializer = () => {
const blockSchema = createFormBlockSchema({
actionInitializers: 'CreateFormActionInitializers',
association,
namespace: collection.namespace,
collection: collection.name,
template: s,
});
@ -41,6 +42,7 @@ export const CreateFormBlockInitializer = () => {
createFormBlockSchema({
actionInitializers: 'CreateFormActionInitializers',
association,
namespace: collection.namespace,
collection: collection.name,
}),
);

View File

@ -28,6 +28,7 @@ export const RecordAssociationBlockInitializer = () => {
createTableBlockSchema({
rowKey: collection.filterTargetKey,
collection: field.target,
namespace: collection.namespace,
resource,
association: resource,
}),

View File

@ -28,6 +28,7 @@ export const RecordAssociationDetailsBlockInitializer = () => {
createDetailsBlockSchema({
collection: field.target,
resource,
namespace: collection.namespace,
association: resource,
rowKey: collection.filterTargetKey || 'id',
}),

View File

@ -1,17 +1,20 @@
import React from 'react';
import React, { useMemo } from 'react';
import { FormOutlined } from '@ant-design/icons';
import { useSchemaTemplateManager } from '../../schema-templates';
import { createFormBlockSchema, useRecordCollectionDataSourceItems } from '../utils';
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../application';
import { useCollectionManager } from '../../collection-manager';
export const RecordAssociationFormBlockInitializer = () => {
const itemConfig = useSchemaInitializerItem();
const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
const { insert } = useSchemaInitializer();
const { getCollection } = useCollectionManager();
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
const field = itemConfig.field;
const collection = field.target;
const collectionName = field.target;
const collection = useMemo(() => getCollection(collectionName), [collectionName]);
const resource = `${field.collectionName}.${field.name}`;
return (
<SchemaInitializerItem
@ -27,7 +30,8 @@ export const RecordAssociationFormBlockInitializer = () => {
const s = await getTemplateSchemaByMode(item);
if (item.template.componentName === 'FormItem') {
const blockSchema = createFormBlockSchema({
collection,
collection: collectionName,
namespace: collection.namespace,
resource,
association: resource,
action,
@ -46,8 +50,9 @@ export const RecordAssociationFormBlockInitializer = () => {
} else {
insert(
createFormBlockSchema({
collection,
collection: collectionName,
resource,
namespace: collection.namespace,
association: resource,
action,
useSourceId: '{{ useSourceIdFromParentRecord }}',

View File

@ -30,6 +30,7 @@ export const RecordAssociationGridCardBlockInitializer = () => {
rowKey: collection.filterTargetKey,
collection: field.target,
resource,
namespace: collection.namespace,
association: resource,
}),
);

View File

@ -30,6 +30,7 @@ export const RecordAssociationListBlockInitializer = () => {
rowKey: collection.filterTargetKey,
collection: field.target,
resource,
namespace: collection.namespace,
association: resource,
}),
);

View File

@ -25,6 +25,7 @@ export const RecordFormBlockInitializer = () => {
const blockSchema = createFormBlockSchema({
association,
collection: collection.name,
namespace: collection.namespace,
action: 'get',
useSourceId: '{{ useSourceIdFromParentRecord }}',
useParams: '{{ useParamsFromRecord }}',
@ -43,6 +44,7 @@ export const RecordFormBlockInitializer = () => {
createFormBlockSchema({
association,
collection: collection.name,
namespace: collection.namespace,
action: 'get',
useSourceId: '{{ useSourceIdFromParentRecord }}',
useParams: '{{ useParamsFromRecord }}',

View File

@ -5,15 +5,19 @@ import { useBlockRequestContext } from '../../block-provider';
import { useSchemaTemplateManager } from '../../schema-templates';
import { createReadPrettyFormBlockSchema, useRecordCollectionDataSourceItems } from '../utils';
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../application';
import { useCollectionManager } from '../../collection-manager';
export const RecordReadPrettyAssociationFormBlockInitializer = () => {
const itemConfig = useSchemaInitializerItem();
const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
const { insert } = useSchemaInitializer();
const { getCollection } = useCollectionManager();
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
const field = itemConfig.field;
const collection = field.target;
const collectionName = field.target;
const collection = getCollection(collectionName);
const resource = `${field.collectionName}.${field.name}`;
const { block } = useBlockRequestContext();
const actionInitializers = block !== 'TableField' ? 'ReadPrettyFormActionInitializers' : null;
@ -28,7 +32,8 @@ export const RecordReadPrettyAssociationFormBlockInitializer = () => {
if (item.template.componentName === 'ReadPrettyFormItem') {
const blockSchema = createReadPrettyFormBlockSchema({
actionInitializers,
collection,
collection: collectionName,
namespace: collection.namespace,
resource,
association: resource,
action: 'get',
@ -47,9 +52,10 @@ export const RecordReadPrettyAssociationFormBlockInitializer = () => {
insert(
createReadPrettyFormBlockSchema({
actionInitializers,
collection,
collection: collectionName,
resource,
association: resource,
namespace: collection.namespace,
action: 'get',
useSourceId: '{{ useSourceIdFromParentRecord }}',
useParams: '{{ useParamsFromRecord }}',

View File

@ -37,6 +37,7 @@ export const RecordReadPrettyFormBlockInitializer = () => {
actionInitializers,
association,
collection: collection.name,
namespace: collection.namespace,
action: 'get',
useSourceId: '{{ useSourceIdFromParentRecord }}',
useParams: '{{ useParamsFromRecord }}',
@ -55,6 +56,7 @@ export const RecordReadPrettyFormBlockInitializer = () => {
actionInitializers,
association,
collection: collection.name,
namespace: collection.namespace,
action: 'get',
useSourceId: '{{ useSourceIdFromParentRecord }}',
useParams: '{{ useParamsFromRecord }}',

View File

@ -19,6 +19,7 @@ export const TableSelectorInitializer = () => {
createTableSelectorSchema({
rowKey: collection.filterTargetKey,
collection: collection.name,
namespace: collection.namespace,
resource: collection.name,
}),
);