Skip to content

Commit 85879c5

Browse files
yaojp123yaojiping
and
yaojiping
authored
chore: optimize text display if text is too long in table (#25)
Co-authored-by: yaojiping <[email protected]>
1 parent 8457778 commit 85879c5

File tree

8 files changed

+66
-7
lines changed

8 files changed

+66
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Tooltip } from "antd";
2+
import { useEffect, useRef, useState } from "react";
3+
4+
export default (props) => {
5+
const { height = 21, width = '100%', children, showTooltip = true } = props;
6+
const [textHeight, setTextHeight] = useState(height);
7+
const textRef = useRef(null);
8+
9+
const handleResize = () => {
10+
if (textRef.current) {
11+
setTextHeight(textRef.current.offsetHeight);
12+
}
13+
};
14+
15+
useEffect(() => {
16+
const resizeObserver = new ResizeObserver(entries => {
17+
entries.forEach(entry => {
18+
const { width, height } = entry.contentRect;
19+
setTextHeight(height);
20+
});
21+
});
22+
23+
if (textRef.current && showTooltip) {
24+
resizeObserver.observe(textRef.current);
25+
}
26+
27+
return () => {
28+
if (textRef.current && showTooltip) {
29+
resizeObserver.unobserve(textRef.current);
30+
}
31+
};
32+
}, [showTooltip]);
33+
34+
return (
35+
<div style={{ position: 'relative', width, height }} onClick={(e) => e.stopPropagation()}>
36+
<div ref={textRef} style={{ visibility: 'hidden'}}>
37+
{children}
38+
</div>
39+
{
40+
showTooltip && textHeight > height ? (
41+
<Tooltip title={children} overlayStyle={{ maxWidth: 'unset !important'}}>
42+
<div style={{ position: 'absolute', left: 0, top: 0, overflow: 'hidden', height, width: '100%', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
43+
{children}
44+
</div>
45+
</Tooltip>
46+
) : (
47+
<div style={{ position: 'absolute', left: 0, top: 0 }}>
48+
{children}
49+
</div>
50+
)
51+
}
52+
</div>
53+
)
54+
}

web/src/components/infini/IconText.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default ({ icon, text }) => {
88
}}
99
>
1010
<span>{icon}</span>
11-
<span>{text}</span>
11+
<span style={{ width: "calc(100% - 20px)"}}>{text}</span>
1212
</span>
1313
);
1414
};

web/src/models/global.js

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ export default {
256256

257257
*fetchConsoleInfo(_, { call, put }) {
258258
const data = yield call(queryConsoleInfo);
259-
console.log(data?.application);
260259
if (data && data.hasOwnProperty("application")&& data?.application.hasOwnProperty("version")) {
261260
const localVersionInfoVal = localStorage.getItem(COUSOLE_VERSION_KEY);
262261
localStorage.setItem(COUSOLE_VERSION_KEY, JSON.stringify(data?.application?.version));

web/src/pages/DataManagement/Index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { isMatch, sorter } from "@/utils/utils";
3434
import { hasAuthority } from "@/utils/authority";
3535
import DeleteIndexModal from "./components/DeleteIndexModal";
3636
import IconText from "@/components/infini/IconText";
37+
import AutoTextEllipsis from "@/components/AutoTextEllipsis";
3738

3839
const { Search } = Input;
3940

@@ -185,7 +186,9 @@ class Index extends PureComponent {
185186
render: (text, record) => (
186187
<IconText
187188
icon={<Icon type="table" />}
188-
text={<Link to={`/insight/discover?index=${text}`}>{text}</Link>}
189+
text={<Link to={`/insight/discover?index=${text}`}>
190+
<AutoTextEllipsis >{text}</AutoTextEllipsis>
191+
</Link>}
189192
/>
190193
),
191194
sorter: (a, b) => sorter.string(a, b, "index"),
@@ -227,6 +230,7 @@ class Index extends PureComponent {
227230
},
228231
{
229232
title: formatMessage({ id: "table.field.actions" }),
233+
width: 116,
230234
render: (text, record) => (
231235
<Fragment>
232236
<a

web/src/pages/Platform/Overview/Cluster/Monitor/indices.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { formatter } from "@/utils/format";
1010
import { filterSearchValue, sorter, formatUtcTimeToLocal } from "@/utils/utils";
1111
import { formatTimeRange } from "@/lib/elasticsearch/util";
1212
import IconText from "@/components/infini/IconText";
13+
import AutoTextEllipsis from "@/components/AutoTextEllipsis";
1314

1415
const { Search } = Input;
1516

@@ -107,7 +108,7 @@ const Indices = ({
107108
timeRange
108109
))},"timeInterval":"${bucketSize}","cluster_name":"${clusterName}"}`}
109110
>
110-
{text}
111+
<AutoTextEllipsis >{text}</AutoTextEllipsis>
111112
</Link>
112113
}
113114
/>

web/src/pages/Platform/Overview/Cluster/Monitor/nodes.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { formatter } from "@/utils/format";
1212
import { formatTimeRange } from "@/lib/elasticsearch/util";
1313
import moment from "moment";
1414
import IconText from "@/components/infini/IconText";
15+
import AutoTextEllipsis from "@/components/AutoTextEllipsis";
1516

1617
const { Search } = Input;
1718
const InputGroup = Input.Group;
@@ -117,7 +118,7 @@ export default ({
117118
record?.name
118119
}"}`}
119120
>
120-
{text}
121+
<AutoTextEllipsis >{text}</AutoTextEllipsis>
121122
</Link>
122123
}
123124
/>

web/src/pages/Platform/Overview/Indices/Monitor/shards.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default ({
147147
record?.node
148148
}"}`}
149149
>
150-
{text}
150+
<AutoTextEllipsis >{text}</AutoTextEllipsis>
151151
</Link>
152152
}
153153
/>

web/src/pages/Platform/Overview/Node/Monitor/shards.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default ({ clusterID, clusterName, nodeID, timeRange, bucketSize }) => {
9797
timeRange
9898
))},"timeInterval":"${bucketSize}","cluster_name":"${clusterName}"}`}
9999
>
100-
{text}
100+
<AutoTextEllipsis >{text}</AutoTextEllipsis>
101101
</Link>
102102
}
103103
/>

0 commit comments

Comments
 (0)