Skip to content

Commit e24fbf3

Browse files
authored
Merge pull request ManageIQ#8825 from jeffibm/fix-datatable-truncation
Fix text truncation in data tables
2 parents bacd478 + d758a7d commit e24fbf3

File tree

2 files changed

+80
-30
lines changed

2 files changed

+80
-30
lines changed

app/javascript/components/miq-data-table/miq-table-cell.jsx

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ import {
1212
const MiqTableCell = ({
1313
cell, onCellClick, row, truncate,
1414
}) => {
15-
const truncateText = <span title={cell.value} className="bx--front-line">{cell.value}</span>;
16-
const truncateClass = ((cell.value).length > 40) && truncate ? 'truncate_cell' : '';
15+
const longText = truncate && ((cell.value).length > 40);
16+
const veryLongText = truncate && ((cell.value).length > 300);
17+
18+
const truncateClass = longText ? 'truncate_cell' : '';
19+
const wrapClass = longText ? 'white_space_normal' : '';
20+
const longerTextClass = veryLongText ? 'truncate_longer_text' : '';
21+
22+
const truncateText = (
23+
<span title={cell.value} className={classNames('bx--front-line', wrapClass, longerTextClass)}>
24+
{cell.value}
25+
</span>
26+
);
1727
const cellClass = classNames('cell', truncateClass, cell.data.style_class);
1828
const cellText = () => (
1929
<div className={cellClass}>
@@ -60,16 +70,21 @@ const MiqTableCell = ({
6070
};
6171

6272
/** Fuction to render icon(s) in cell. */
63-
const renderIcon = (icon, style, showText) => (
64-
<div className={cellClass}>
65-
{
66-
typeof (icon) === 'string'
67-
? <i className={classNames('fa-lg', 'icon', icon)} style={style} />
68-
: icon.map((i, index) => <i className={classNames('fa-lg', 'icon', i)} key={index.toString()} />)
69-
}
70-
{showText && truncateText}
71-
</div>
72-
);
73+
const renderIcon = (icon, style, showText) => {
74+
const hasBackground = Object.keys(style).includes('background');
75+
const styledIconClass = hasBackground ? 'styled_icon' : '';
76+
const longerTextClass = hasBackground && veryLongText ? 'styled_icon_margin' : '';
77+
return (
78+
<div className={cellClass}>
79+
{
80+
typeof (icon) === 'string'
81+
? <i className={classNames('fa-lg', 'icon', icon, styledIconClass, longerTextClass)} style={style} />
82+
: icon.map((i, index) => <i className={classNames('fa-lg', 'icon', i)} key={index.toString()} />)
83+
}
84+
{showText && truncateText}
85+
</div>
86+
);
87+
};
7388

7489
/** Fuction to render an icon in cell based on the 'type' in 'item'. */
7590
const cellIcon = (item, showText) => {
@@ -101,9 +116,9 @@ const MiqTableCell = ({
101116
const cellButton = (item) => (
102117
<div className={cellClass}>
103118
<Button
104-
onClick={(e) => cellButtonEvent(item,e)}
119+
onClick={(e) => cellButtonEvent(item, e)}
105120
disabled={item.disabled}
106-
onKeyPress={(e) => cellButtonEvent(item,e)}
121+
onKeyPress={(e) => cellButtonEvent(item, e)}
107122
tabIndex={0}
108123
title={item.title ? item.title : truncateText}
109124
kind={item.kind ? item.kind : 'primary'}
@@ -115,7 +130,6 @@ const MiqTableCell = ({
115130
);
116131

117132
/** Function to render a Text Box inside cell. */
118-
/* eslint-disable no-eval */
119133
const cellTextInput = (item, id) => (
120134
<div className={cellClass}>
121135
<TextInput
@@ -136,7 +150,6 @@ const MiqTableCell = ({
136150
);
137151

138152
/** Function to render a Toggle inside cell. */
139-
/* eslint-disable no-eval */
140153
const cellToggle = (item, id) => (
141154
<div className={cellClass}>
142155
<Toggle
@@ -153,12 +166,9 @@ const MiqTableCell = ({
153166
);
154167

155168
/** Function to render a Link inside cell. */
156-
/* eslint-disable no-eval */
157-
const cellLink = (item, id) => (
169+
const cellLink = (item, _id) => (
158170
<div className={cellClass}>
159-
<Link
160-
href={item.href}
161-
>
171+
<Link href={item.href}>
162172
{item.label}
163173
</Link>
164174
</div>

app/stylesheet/miq-data-table.scss

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@
5757

5858
.cell {
5959
display: flex;
60-
align-items: center;
60+
align-items: flex-start;
6161
justify-content: flex-start;
6262

6363
&.truncate_cell {
64-
max-width: 250px;
64+
max-width: 700px;
65+
min-width: 150px;
6566
}
6667

6768
.array_list {
@@ -75,18 +76,32 @@
7576
}
7677

7778
.image {
78-
width: 30px;
79-
height: 30px;
80-
margin-right: 5px;
79+
width: 20px;
80+
height: 20px;
81+
margin-right: 8px;
82+
margin-top: 4px;
8183
}
8284

8385
.icon {
8486
min-width: 30px;
8587
height: 30px;
8688
display: flex;
8789
align-items: center;
88-
justify-content: center;
89-
margin-right: 5px;
90+
justify-content: flex-start;
91+
margin-top: 0;
92+
93+
&.styled_icon {
94+
min-width: 20px;
95+
height: 20px;
96+
justify-content: center;
97+
margin-right: 5px;
98+
margin-top: 5px;
99+
font-size: 14px;
100+
}
101+
102+
&.styled_icon_margin {
103+
margin-top: 9px;
104+
}
90105
}
91106

92107
.icon.fa-ruby {
@@ -113,16 +128,39 @@
113128
}
114129
}
115130

131+
td {
132+
vertical-align: top;
133+
}
134+
116135
td.no_text {
117136
width: 50px;
118137
}
119138

139+
td .bx--checkbox--inline {
140+
margin-top: 4px;
141+
}
142+
120143
td .bx--front-line {
121144
width: 100%;
122145
display: inline-block;
123-
text-overflow: ellipsis;
124-
white-space: nowrap;
125146
overflow: hidden;
147+
white-space: nowrap;
148+
margin-top: 5px;
149+
150+
&.white_space_normal {
151+
white-space: normal !important;
152+
text-align: justify;
153+
}
154+
155+
&.truncate_longer_text {
156+
max-height: 300px;
157+
display: -webkit-box;
158+
max-width: 200px;
159+
-webkit-line-clamp: 15;
160+
-webkit-box-orient: vertical;
161+
overflow: hidden;
162+
margin-bottom: 8px;
163+
}
126164
}
127165
}
128166
}
@@ -186,6 +224,8 @@
186224
}
187225

188226
thead tr th {
227+
vertical-align: middle;
228+
189229
.bx--table-header-label {
190230
min-width: fit-content;
191231
}

0 commit comments

Comments
 (0)