fix(Details): block template (#3807)

* fix: add 'Details' in condition

* fix: block template
This commit is contained in:
Zeke Zhang 2024-03-25 16:25:41 +08:00 committed by GitHub
parent 2195a31f5b
commit 0269a1ff7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 52 additions and 22 deletions

View File

@ -330,7 +330,9 @@ export const useParamsFromRecord = () => {
const { fields } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const { getCollectionJoinField } = useCollectionManager_deprecated();
const collectionField = getCollectionJoinField(fieldSchema?.['x-decorator-props']?.resource);
const collectionField = getCollectionJoinField(
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association,
);
const filterFields = fields
.filter((v) => {
return ['boolean', 'date', 'integer', 'radio', 'sort', 'string', 'time', 'uid', 'uuid'].includes(v.type);

View File

@ -177,7 +177,8 @@ export const multiDataDetailsBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'Details',
collectionName: name,

View File

@ -16,7 +16,8 @@ export const singleDataDetailsBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
insertAdjacentPosition: 'beforeEnd',
componentName: 'ReadPrettyFormItem',

View File

@ -51,7 +51,8 @@ export const creationFormBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'FormItem',
collectionName: name,
@ -117,7 +118,8 @@ export const createFormBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'FormItem',
collectionName: name,

View File

@ -50,7 +50,8 @@ export const editFormBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'FormItem',
collectionName: name,

View File

@ -257,7 +257,8 @@ export const gridCardBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'GridCard',

View File

@ -196,7 +196,8 @@ export const listBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'List',

View File

@ -359,7 +359,8 @@ export const tableBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'Table',
collectionName: name,

View File

@ -22,7 +22,8 @@ export const filterCollapseBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'FilterCollapse',

View File

@ -23,7 +23,8 @@ export const filterFormBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'FilterFormItem',
collectionName: name,

View File

@ -18,7 +18,8 @@ export const AssociationFilterBlockDesigner = () => {
const template = useSchemaTemplate();
const fieldSchema = useFieldSchema();
const { t } = useTranslation();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return (
<GeneralSchemaDesigner template={template} title={title || name}>

View File

@ -62,7 +62,8 @@ export const formSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'FormItem',
collectionName: name,
@ -103,7 +104,8 @@ export const readPrettyFormSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
insertAdjacentPosition: 'beforeEnd',
componentName: 'ReadPrettyFormItem',
@ -294,7 +296,8 @@ export const formDetailsSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'Details',
collectionName: name,

View File

@ -39,7 +39,8 @@ export const GridCardDesigner = () => {
const sortFields = useSortFields(name);
const record = useRecord();
const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || [];
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
const columnCount = field.decoratorProps.columnCount || defaultColumnCount;
const columnCountSchema = useMemo(() => {

View File

@ -35,7 +35,8 @@ export const ListDesigner = () => {
const sortFields = useSortFields(name);
const record = useRecord();
const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || [];
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
const sort = defaultSort?.map((item: string) => {
return item.startsWith('-')
? {

View File

@ -78,7 +78,8 @@ export const TableBlockDesigner = () => {
const { dn } = useDesignable();
const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || [];
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
const supportTemplate = !fieldSchema?.['x-decorator-props']?.disableTemplate;
const sort = defaultSort?.map((item: string) => {
return item?.startsWith('-')

View File

@ -1685,6 +1685,15 @@ function useAssociationFields({
const targetCollection = cm.getCollection(field.target);
const title = `${compile(field.uiSchema.title || field.name)} -> ${compile(targetCollection.title)}`;
const templates = getTemplatesByCollection(dataSource, field.target).filter((template) => {
// 针对弹窗中的详情区块
if (componentName === 'ReadPrettyFormItem') {
if (['hasOne', 'belongsTo'].includes(field.type)) {
return template.componentName === 'ReadPrettyFormItem';
} else {
return template.componentName === 'Details';
}
}
return (
componentName &&
template.componentName === componentName &&

View File

@ -291,7 +291,7 @@ export const SchemaSettingsTemplate = function Template(props) {
const findGridSchema = (fieldSchema) => {
return fieldSchema.reduceProperties((buf, s) => {
if (s['x-component'] === 'FormV2') {
if (s['x-component'] === 'FormV2' || s['x-component'] === 'Details') {
const f = s.reduceProperties((buf, s) => {
if (s['x-component'] === 'Grid' || s['x-component'] === 'BlockTemplate') {
return s;
@ -308,7 +308,7 @@ const findGridSchema = (fieldSchema) => {
const findBlockTemplateSchema = (fieldSchema) => {
return fieldSchema.reduceProperties((buf, s) => {
if (s['x-component'] === 'FormV2') {
if (s['x-component'] === 'FormV2' || s['x-component'] === 'Details') {
const f = s.reduceProperties((buf, s) => {
if (s['x-component'] === 'BlockTemplate') {
return s;

View File

@ -205,7 +205,8 @@ export const calendarBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'Calendar',
collectionName: name,

View File

@ -230,7 +230,8 @@ export const mapBlockSettings = new SchemaSettings({
useComponentProps() {
const { name } = useCollection();
const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const defaultResource =
fieldSchema?.['x-decorator-props']?.resource || fieldSchema?.['x-decorator-props']?.association;
return {
componentName: 'Map',
collectionName: name,