Skip to content

Commit 1031722

Browse files
committed
code refactor
1 parent 674b830 commit 1031722

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

components/vc-table/src/TableCell.jsx

+31-33
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ export default {
6161
handleVisibilityChange(visible) {
6262
this.tooltipVisible = this.notShowTooltip ? false : visible;
6363
},
64+
getRawText(record, dataIndex) {
65+
let text;
66+
if (typeof dataIndex === 'number') {
67+
text = get(record, dataIndex);
68+
} else if (!dataIndex || dataIndex.length === 0) {
69+
text = record;
70+
} else {
71+
text = get(record, dataIndex);
72+
}
73+
return text;
74+
},
6475
},
6576

6677
render() {
@@ -78,14 +89,7 @@ export default {
7889
const cls = className || column.class;
7990
// We should return undefined if no dataIndex is specified, but in order to
8091
// be compatible with object-path's behavior, we return the record object instead.
81-
let text;
82-
if (typeof dataIndex === 'number') {
83-
text = get(record, dataIndex);
84-
} else if (!dataIndex || dataIndex.length === 0) {
85-
text = record;
86-
} else {
87-
text = get(record, dataIndex);
88-
}
92+
let text = this.getRawText(record, dataIndex);
8993
this.tooltipContent = text;
9094

9195
let tdProps = {
@@ -133,31 +137,25 @@ export default {
133137
tdProps.style = { ...tdProps.style, textAlign: column.align };
134138
}
135139

136-
if (column.showOverflowTooltip) {
137-
return (
138-
<BodyCell {...tdProps} class="has-tooltip" style={{maxWidth: 0}}>
139-
<Tooltip
140-
onVisibleChange={this.handleVisibilityChange}
141-
visible={this.tooltipVisible}
142-
placement="top"
143-
title={this.tooltipContent}>
144-
<div>
145-
{indentText}
146-
{expandIcon}
147-
{text}
148-
</div>
149-
</Tooltip>
150-
</BodyCell>
151-
);
152-
} else {
153-
return (
154-
<BodyCell {...tdProps}>
155-
{indentText}
156-
{expandIcon}
157-
{text}
158-
</BodyCell>
159-
);
160-
}
140+
const cellContent = [
141+
indentText,
142+
expandIcon,
143+
text,
144+
];
161145

146+
return column.showOverflowTooltip ? (
147+
<BodyCell {...tdProps} class="has-tooltip" style={{maxWidth: 0}}>
148+
<Tooltip
149+
onVisibleChange={this.handleVisibilityChange}
150+
visible={this.tooltipVisible}
151+
title={this.tooltipContent}>
152+
<div>{cellContent}</div>
153+
</Tooltip>
154+
</BodyCell>
155+
) : (
156+
<BodyCell {...tdProps}>
157+
{cellContent}
158+
</BodyCell>
159+
);
162160
},
163161
};

0 commit comments

Comments
 (0)