Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Table): 处理 Column.formatter 返回循环依赖对象的情况 #809

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/_util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,14 @@ export function concat(arr: any[], arr2: any[]) {
}
return arr;
}

// JSON.stringify
export function stringify(value: any, onError?: (err: unknown) => void, fallbackValue: string = ''): string {
try {
const str = JSON.stringify(value);
return str;
} catch (err) {
onError?.(err);
return fallbackValue;
}
}
14 changes: 9 additions & 5 deletions components/table/components/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { provideKey } from '../const';

import type { ActionType } from '../interface';
import type { ColumnInst } from '../column';
import { stringify } from '../../_util/utils';

const cellProps = {
row: {
Expand All @@ -40,8 +41,10 @@ const cellProps = {

export type InnerCellProps = ExtractPropTypes<typeof cellProps>;

const COMPONENT_NAME = 'FTableCell';

export default defineComponent({
name: 'FTableCell',
name: COMPONENT_NAME,
props: cellProps,
setup(props) {
const { prefixCls } = inject(provideKey);
Expand Down Expand Up @@ -102,13 +105,14 @@ export default defineComponent({
const result = formatterResult ?? cellValue;
Object.assign(ellipsisProps, { content: result });
return hasEllipsis
? (
<Ellipsis {...ellipsisProps}></Ellipsis>
)
? <Ellipsis {...ellipsisProps} />
: (
<Fragment>
{typeof result === 'object'
? JSON.stringify(result)
? stringify(
result,
(err) => console.warn(`[${COMPONENT_NAME}]: render error occurred due to \n`, err),
)
: result}
</Fragment>
);
Expand Down