mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:06:25 +00:00
Merge branch 'main' into next
This commit is contained in:
commit
207d571756
@ -297,4 +297,12 @@ export class Collection {
|
||||
isTitleField(field: CollectionFieldOptions) {
|
||||
return this.app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterface(field.interface)?.titleUsable;
|
||||
}
|
||||
|
||||
/**
|
||||
* is inherited from other collection
|
||||
* @returns boolean
|
||||
*/
|
||||
isInherited() {
|
||||
return this.inherits.length > 0;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export const BlockSchemaToolbar = (props) => {
|
||||
const cm = useCollectionManager();
|
||||
let { name: currentCollectionName, title: currentCollectionTitle } = useCollection() || {};
|
||||
const template = useSchemaTemplate();
|
||||
const { association } = useDataBlockProps() || {};
|
||||
const { association, collection } = useDataBlockProps() || {};
|
||||
const compile = useCompile();
|
||||
|
||||
if (association) {
|
||||
@ -31,7 +31,10 @@ export const BlockSchemaToolbar = (props) => {
|
||||
}
|
||||
|
||||
const associationField = cm.getCollectionField(association);
|
||||
const associationCollection = cm.getCollection(associationField?.target);
|
||||
// If both the collection and association parameters exist at the same time,
|
||||
// it means that the collection of the current block is a child collection of inheritance,
|
||||
// and the title of the child collection needs to be displayed at this time
|
||||
const associationCollection = cm.getCollection(collection || associationField?.target);
|
||||
const templateName = ['FormItem', 'ReadPrettyFormItem'].includes(template?.componentName)
|
||||
? `${template?.name} ${t('(Fields only)')}`
|
||||
: template?.name;
|
||||
|
@ -11,10 +11,10 @@ import { FormOutlined } from '@ant-design/icons';
|
||||
import React, { useCallback } from 'react';
|
||||
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application';
|
||||
import { useCollection_deprecated } from '../../../../collection-manager';
|
||||
import { useAssociationName, useCollectionManager } from '../../../../data-source';
|
||||
import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils';
|
||||
import { useSchemaTemplateManager } from '../../../../schema-templates';
|
||||
import { createDetailsUISchema } from './createDetailsUISchema';
|
||||
import { useAssociationName } from '../../../../data-source';
|
||||
|
||||
export const RecordReadPrettyFormBlockInitializer = () => {
|
||||
const itemConfig = useSchemaInitializerItem();
|
||||
@ -37,21 +37,26 @@ export function useCreateSingleDetailsSchema() {
|
||||
const { insert } = useSchemaInitializer();
|
||||
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
|
||||
const association = useAssociationName();
|
||||
const cm = useCollectionManager();
|
||||
|
||||
const templateWrap = useCallback(
|
||||
(templateSchema, options) => {
|
||||
const { item } = options;
|
||||
if (item.template.componentName === 'ReadPrettyFormItem') {
|
||||
const collectionName = item.collectionName || item.name;
|
||||
const collection = cm.getCollection(collectionName);
|
||||
const blockSchema = createDetailsUISchema(
|
||||
association
|
||||
? {
|
||||
association,
|
||||
// see: https://applink.feishu.cn/client/message/link/open?token=AmP9n9dkwcABZrr3nBdAwAI%3D
|
||||
collectionName: collection.isInherited() ? collectionName : undefined,
|
||||
dataSource: item.dataSource,
|
||||
templateSchema: templateSchema,
|
||||
isCurrent: true,
|
||||
}
|
||||
: {
|
||||
collectionName: item.collectionName || item.name,
|
||||
collectionName,
|
||||
dataSource: item.dataSource,
|
||||
templateSchema: templateSchema,
|
||||
},
|
||||
@ -64,7 +69,7 @@ export function useCreateSingleDetailsSchema() {
|
||||
return templateSchema;
|
||||
}
|
||||
},
|
||||
[association],
|
||||
[association, cm],
|
||||
);
|
||||
|
||||
const createSingleDetailsSchema = useCallback(
|
||||
@ -73,23 +78,27 @@ export function useCreateSingleDetailsSchema() {
|
||||
const template = await getTemplateSchemaByMode(item);
|
||||
insert(templateWrap(template, { item }));
|
||||
} else {
|
||||
const collectionName = item.collectionName || item.name;
|
||||
const collection = cm.getCollection(collectionName);
|
||||
insert(
|
||||
createDetailsUISchema(
|
||||
association
|
||||
? {
|
||||
association,
|
||||
// see: https://applink.feishu.cn/client/message/link/open?token=AmP9n9dkwcABZrr3nBdAwAI%3D
|
||||
collectionName: collection.isInherited() ? collectionName : undefined,
|
||||
dataSource: item.dataSource,
|
||||
isCurrent: true,
|
||||
}
|
||||
: {
|
||||
collectionName: item.collectionName || item.name,
|
||||
collectionName,
|
||||
dataSource: item.dataSource,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
[association, getTemplateSchemaByMode, insert, templateWrap],
|
||||
[association, cm, getTemplateSchemaByMode, insert, templateWrap],
|
||||
);
|
||||
|
||||
return { createSingleDetailsSchema, templateWrap };
|
||||
|
@ -10,8 +10,8 @@
|
||||
import { FormOutlined } from '@ant-design/icons';
|
||||
import React, { useCallback } from 'react';
|
||||
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application';
|
||||
import { useAssociationName } from '../../../../data-source';
|
||||
import { useCollection_deprecated } from '../../../../collection-manager';
|
||||
import { useAssociationName, useCollectionManager } from '../../../../data-source';
|
||||
import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils';
|
||||
import { useSchemaTemplateManager } from '../../../../schema-templates';
|
||||
import { createEditFormBlockUISchema } from './createEditFormBlockUISchema';
|
||||
@ -49,40 +49,47 @@ export const RecordFormBlockInitializer = () => {
|
||||
export function useCreateEditFormBlock() {
|
||||
const { insert } = useSchemaInitializer();
|
||||
const association = useAssociationName();
|
||||
const cm = useCollectionManager();
|
||||
|
||||
const createEditFormBlock = useCallback(
|
||||
({ item }) => {
|
||||
const collectionName = item.collectionName || item.name;
|
||||
const collection = cm.getCollection(collectionName);
|
||||
insert(
|
||||
createEditFormBlockUISchema(
|
||||
association
|
||||
? {
|
||||
association,
|
||||
collectionName: collection.isInherited() ? collectionName : undefined,
|
||||
dataSource: item.dataSource,
|
||||
isCurrent: true,
|
||||
}
|
||||
: {
|
||||
collectionName: item.collectionName || item.name,
|
||||
collectionName,
|
||||
dataSource: item.dataSource,
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
[association, insert],
|
||||
[association, cm, insert],
|
||||
);
|
||||
|
||||
const templateWrap = useCallback(
|
||||
(templateSchema, { item }) => {
|
||||
if (item.template.componentName === 'FormItem') {
|
||||
const collectionName = item.collectionName || item.name;
|
||||
const collection = cm.getCollection(collectionName);
|
||||
const blockSchema = createEditFormBlockUISchema(
|
||||
association
|
||||
? {
|
||||
association,
|
||||
collectionName: collection.isInherited() ? collectionName : undefined,
|
||||
dataSource: item.dataSource,
|
||||
templateSchema: templateSchema,
|
||||
isCurrent: true,
|
||||
}
|
||||
: {
|
||||
collectionName: item.collectionName || item.name,
|
||||
collectionName,
|
||||
dataSource: item.dataSource,
|
||||
templateSchema: templateSchema,
|
||||
},
|
||||
@ -95,7 +102,7 @@ export function useCreateEditFormBlock() {
|
||||
return templateSchema;
|
||||
}
|
||||
},
|
||||
[association],
|
||||
[association, cm],
|
||||
);
|
||||
|
||||
return { createEditFormBlock, templateWrap };
|
||||
|
@ -13,7 +13,6 @@ import {
|
||||
useActionAvailable,
|
||||
useCollection,
|
||||
useCollectionManager_deprecated,
|
||||
useCollection_deprecated,
|
||||
useCreateAssociationDetailsBlock,
|
||||
useCreateAssociationDetailsWithoutPagination,
|
||||
useCreateAssociationFormBlock,
|
||||
@ -46,7 +45,7 @@ export const canMakeAssociationBlock = (field) => {
|
||||
};
|
||||
|
||||
function useRecordBlocks() {
|
||||
const collection = useCollection_deprecated();
|
||||
const collection = useCollection();
|
||||
const { getChildrenCollections } = useCollectionManager_deprecated();
|
||||
const collectionsWithView = getChildrenCollections(collection.name, true, collection.dataSource).filter(
|
||||
(v) => v?.filterTargetKey,
|
||||
@ -60,7 +59,7 @@ function useRecordBlocks() {
|
||||
collectionName: collection.name,
|
||||
dataSource: collection.dataSource,
|
||||
useComponentProps() {
|
||||
const currentCollection = useCollection_deprecated();
|
||||
const currentCollection = useCollection();
|
||||
const { createSingleDetailsSchema, templateWrap } = useCreateSingleDetailsSchema();
|
||||
const { createAssociationDetailsBlock } = useCreateAssociationDetailsBlock();
|
||||
const {
|
||||
@ -126,7 +125,7 @@ function useRecordBlocks() {
|
||||
collectionName: collection.name,
|
||||
dataSource: collection.dataSource,
|
||||
useComponentProps() {
|
||||
const currentCollection = useCollection_deprecated();
|
||||
const currentCollection = useCollection();
|
||||
const { createEditFormBlock, templateWrap: templateWrapEdit } = useCreateEditFormBlock();
|
||||
const collectionsNeedToDisplay = [currentCollection, ...collectionsWithView];
|
||||
|
||||
|
@ -12,9 +12,9 @@ import React, { useCallback } from 'react';
|
||||
|
||||
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../application';
|
||||
import { useCollectionManager_deprecated } from '../../collection-manager';
|
||||
import { createDetailsWithPaginationUISchema } from '../../modules/blocks/data-blocks/details-multi/createDetailsWithPaginationUISchema';
|
||||
import { useSchemaTemplateManager } from '../../schema-templates';
|
||||
import { useRecordCollectionDataSourceItems } from '../utils';
|
||||
import { createDetailsWithPaginationUISchema } from '../../modules/blocks/data-blocks/details-multi/createDetailsWithPaginationUISchema';
|
||||
|
||||
export const RecordAssociationDetailsBlockInitializer = () => {
|
||||
const itemConfig = useSchemaInitializerItem();
|
||||
|
Loading…
Reference in New Issue
Block a user