feat: when field rendering error, output error log

This commit is contained in:
liujuping 2023-08-22 17:59:35 +08:00 committed by JackLian
parent 32a24d6289
commit ba9ae3587d
3 changed files with 23 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/* eslint-disable react/no-unused-prop-types */ /* eslint-disable react/no-unused-prop-types */
import { Component, MouseEvent } from 'react'; import { Component, ErrorInfo, MouseEvent } from 'react';
import { isObject } from 'lodash'; import { isObject } from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import { Icon } from '@alifd/next'; import { Icon } from '@alifd/next';
@ -9,6 +9,9 @@ import { PopupPipe, PopupContext } from '../popup';
import './index.less'; import './index.less';
import InlineTip from './inlinetip'; import InlineTip from './inlinetip';
import { intl } from '../../locale'; import { intl } from '../../locale';
import { Logger } from '@alilc/lowcode-utils';
const logger = new Logger({ level: 'warn', bizName: 'skeleton:field' });
export interface FieldProps { export interface FieldProps {
className?: string; className?: string;
@ -31,6 +34,10 @@ export class Field extends Component<FieldProps> {
hasError: false, hasError: false,
}; };
private body: HTMLDivElement | null = null;
private dispose?: () => void;
constructor(props: any) { constructor(props: any) {
super(props); super(props);
this.handleClear = this.handleClear.bind(this); this.handleClear = this.handleClear.bind(this);
@ -47,10 +54,6 @@ export class Field extends Component<FieldProps> {
onExpandChange && onExpandChange(!collapsed); onExpandChange && onExpandChange(!collapsed);
}; };
private body: HTMLDivElement | null = null;
private dispose?: () => void;
private deployBlockTesting() { private deployBlockTesting() {
if (this.dispose) { if (this.dispose) {
this.dispose(); this.dispose();
@ -101,7 +104,13 @@ export class Field extends Component<FieldProps> {
} }
static getDerivedStateFromError() { static getDerivedStateFromError() {
return { hasError: true }; return {
hasError: true,
};
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
logger.error(`${this.props.title} has error`, error, errorInfo);
} }
getTipContent(propName: string, tip?: any): any { getTipContent(propName: string, tip?: any): any {
@ -194,6 +203,7 @@ export class Field extends Component<FieldProps> {
*/ */
function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) { function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) {
return null; return null;
/* /*
let tip: any = null; let tip: any = null;
let className = 'lc-valuestate'; let className = 'lc-valuestate';

View File

@ -24,7 +24,7 @@ export interface IBaseModelResource<
get description(): string | undefined; get description(): string | undefined;
get config(): { get config(): {
disableBehaviors?: ('copy' | 'remove')[]; [key: string]: any;
} | undefined; } | undefined;
} }

View File

@ -5,6 +5,11 @@ export interface IPublicResourceData {
/** 资源名字 */ /** 资源名字 */
resourceName: string; resourceName: string;
/** 资源扩展配置 */
config?: {
[key: string]: any;
};
/** 资源标题 */ /** 资源标题 */
title?: string; title?: string;
@ -20,7 +25,7 @@ export interface IPublicResourceData {
/** 资源 icon */ /** 资源 icon */
icon?: ReactElement; icon?: ReactElement;
/** 资源其他配置 */ /** 资源其他配置,资源初始化时的第二个参数 */
options: { options: {
[key: string]: any; [key: string]: any;
}; };