Skip to content

Commit 14d294c

Browse files
liujupingJackLian
authored andcommitted
feat: when field rendering error, output error log
1 parent b4c20b1 commit 14d294c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

packages/editor-skeleton/src/components/field/fields.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/no-unused-prop-types */
2-
import { Component, MouseEvent } from 'react';
2+
import { Component, ErrorInfo, MouseEvent } from 'react';
33
import { isObject } from 'lodash';
44
import classNames from 'classnames';
55
import { Icon } from '@alifd/next';
@@ -9,6 +9,9 @@ import { PopupPipe, PopupContext } from '../popup';
99
import './index.less';
1010
import InlineTip from './inlinetip';
1111
import { intl } from '../../locale';
12+
import { Logger } from '@alilc/lowcode-utils';
13+
14+
const logger = new Logger({ level: 'warn', bizName: 'skeleton:field' });
1215

1316
export interface FieldProps {
1417
className?: string;
@@ -31,6 +34,10 @@ export class Field extends Component<FieldProps> {
3134
hasError: false,
3235
};
3336

37+
private body: HTMLDivElement | null = null;
38+
39+
private dispose?: () => void;
40+
3441
constructor(props: any) {
3542
super(props);
3643
this.handleClear = this.handleClear.bind(this);
@@ -47,10 +54,6 @@ export class Field extends Component<FieldProps> {
4754
onExpandChange && onExpandChange(!collapsed);
4855
};
4956

50-
private body: HTMLDivElement | null = null;
51-
52-
private dispose?: () => void;
53-
5457
private deployBlockTesting() {
5558
if (this.dispose) {
5659
this.dispose();
@@ -101,7 +104,13 @@ export class Field extends Component<FieldProps> {
101104
}
102105

103106
static getDerivedStateFromError() {
104-
return { hasError: true };
107+
return {
108+
hasError: true,
109+
};
110+
}
111+
112+
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
113+
logger.error(`${this.props.title} has error`, error, errorInfo);
105114
}
106115

107116
getTipContent(propName: string, tip?: any): any {
@@ -194,6 +203,7 @@ export class Field extends Component<FieldProps> {
194203
*/
195204
function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) {
196205
return null;
206+
197207
/*
198208
let tip: any = null;
199209
let className = 'lc-valuestate';

packages/types/src/shell/model/resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface IBaseModelResource<
2424
get description(): string | undefined;
2525

2626
get config(): {
27-
disableBehaviors?: ('copy' | 'remove')[];
27+
[key: string]: any;
2828
} | undefined;
2929
}
3030

packages/types/src/shell/type/resource-list.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export interface IPublicResourceData {
55
/** 资源名字 */
66
resourceName: string;
77

8+
/** 资源扩展配置 */
9+
config?: {
10+
[key: string]: any;
11+
};
12+
813
/** 资源标题 */
914
title?: string;
1015

@@ -20,7 +25,7 @@ export interface IPublicResourceData {
2025
/** 资源 icon */
2126
icon?: ReactElement;
2227

23-
/** 资源其他配置 */
28+
/** 资源其他配置,资源初始化时的第二个参数 */
2429
options: {
2530
[key: string]: any;
2631
};

0 commit comments

Comments
 (0)