Skip to content

Commit

Permalink
feat: when field rendering error, output error log
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Aug 23, 2023
1 parent b4c20b1 commit 14d294c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
22 changes: 16 additions & 6 deletions packages/editor-skeleton/src/components/field/fields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/no-unused-prop-types */
import { Component, MouseEvent } from 'react';
import { Component, ErrorInfo, MouseEvent } from 'react';
import { isObject } from 'lodash';
import classNames from 'classnames';
import { Icon } from '@alifd/next';
Expand All @@ -9,6 +9,9 @@ import { PopupPipe, PopupContext } from '../popup';
import './index.less';
import InlineTip from './inlinetip';
import { intl } from '../../locale';
import { Logger } from '@alilc/lowcode-utils';

const logger = new Logger({ level: 'warn', bizName: 'skeleton:field' });

export interface FieldProps {
className?: string;
Expand All @@ -31,6 +34,10 @@ export class Field extends Component<FieldProps> {
hasError: false,
};

private body: HTMLDivElement | null = null;

private dispose?: () => void;

constructor(props: any) {
super(props);
this.handleClear = this.handleClear.bind(this);
Expand All @@ -47,10 +54,6 @@ export class Field extends Component<FieldProps> {
onExpandChange && onExpandChange(!collapsed);
};

private body: HTMLDivElement | null = null;

private dispose?: () => void;

private deployBlockTesting() {
if (this.dispose) {
this.dispose();
Expand Down Expand Up @@ -101,7 +104,13 @@ export class Field extends Component<FieldProps> {
}

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 {
Expand Down Expand Up @@ -194,6 +203,7 @@ export class Field extends Component<FieldProps> {
*/
function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) {
return null;

/*
let tip: any = null;
let className = 'lc-valuestate';
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/shell/model/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IBaseModelResource<
get description(): string | undefined;

get config(): {
disableBehaviors?: ('copy' | 'remove')[];
[key: string]: any;
} | undefined;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/types/src/shell/type/resource-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export interface IPublicResourceData {
/** 资源名字 */
resourceName: string;

/** 资源扩展配置 */
config?: {
[key: string]: any;
};

/** 资源标题 */
title?: string;

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

/** 资源其他配置 */
/** 资源其他配置,资源初始化时的第二个参数 */
options: {
[key: string]: any;
};
Expand Down

0 comments on commit 14d294c

Please sign in to comment.