fix(Data-templates): avoid errors and add log

This commit is contained in:
Rairn 2023-05-23 16:18:01 +08:00
parent 58fda41513
commit a0dd58e7e3
3 changed files with 19 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import { useFieldSchema } from '@formily/react';
import { forEach, showToast } from '@nocobase/utils/client';
import { error, forEach, showToast } from '@nocobase/utils/client';
import { Select } from 'antd';
import _ from 'lodash';
import React, { useCallback, useEffect } from 'react';
@ -29,15 +29,20 @@ const useDataTemplates = () => {
// 过滤掉已经被删除的字段
items.forEach((item) => {
item.fields = item.fields
.map((field) => {
const joinField = getCollectionJoinField(`${item.collection}.${field}`);
if (joinField) {
return field;
}
return '';
})
.filter(Boolean);
try {
item.fields = item.fields
.map((field) => {
const joinField = getCollectionJoinField(`${item.collection}.${field}`);
if (joinField) {
return field;
}
return '';
})
.filter(Boolean);
} catch (err) {
error(err);
item.fields = [];
}
});
const templates: any = [

View File

@ -4,6 +4,7 @@ export * from './date';
export * from './forEach';
export * from './getValuesByPath';
export * from './json-templates';
export * from './log';
export * from './merge';
export * from './notification';
export * from './number';

View File

@ -0,0 +1,3 @@
export const error = (message: Error | string, ...args: any[]) => {
console.error(message, ...args);
};