@@ -4,43 +4,11 @@ import classNames from "classnames";
4
4
import moment from "moment" ;
5
5
6
6
import { BucketItem } from "@renderer/modules/qiniu-client" ;
7
- import TooltipText from "@renderer/components/tooltip-text" ;
8
7
import { useI18n } from "@renderer/modules/i18n" ;
8
+ import useIsOverflow from "@renderer/modules/hooks/use-is-overflow" ;
9
+ import TooltipText from "@renderer/components/tooltip-text" ;
9
10
import Duration from "@common/const/duration" ;
10
11
11
- interface BucketNameTooltipProps {
12
- bucket : BucketItem
13
- }
14
-
15
- const BucketNameTooltip : React . FC < BucketNameTooltipProps > = ( {
16
- bucket,
17
- } ) => {
18
- const { translate} = useI18n ( ) ;
19
-
20
- // granted permission text
21
- let grantedPermissionTip : string | null = null
22
- if ( bucket . grantedPermission === "readonly" ) {
23
- grantedPermissionTip = translate ( "browse.bucketTable.bucketGrantedReadOnly" ) ;
24
- } else if ( bucket . grantedPermission === "readwrite" ) {
25
- grantedPermissionTip = translate ( "browse.bucketTable.bucketGrantedReadWrite" ) ;
26
- }
27
-
28
- return (
29
- < >
30
- < div className = "text-start" >
31
- { bucket . name }
32
- {
33
- grantedPermissionTip &&
34
- < span className = "text-info" > ({ grantedPermissionTip } )</ span >
35
- }
36
- </ div >
37
- < div className = "text-start" >
38
- < small className = "text-secondary" > { bucket . remark } </ small >
39
- </ div >
40
- </ >
41
- ) ;
42
- } ;
43
-
44
12
interface BucketTableRowProps {
45
13
data : BucketItem ,
46
14
isSelected : boolean ,
@@ -54,6 +22,8 @@ const BucketTableRow: React.FC<BucketTableRowProps> = ({
54
22
onClickRow,
55
23
onClickBucket,
56
24
} ) => {
25
+ const { translate} = useI18n ( ) ;
26
+
57
27
// icon class name
58
28
let iconClassName = "bi bi-database-fill me-1 text-brown" ;
59
29
if ( bucket . grantedPermission === "readonly" ) {
@@ -62,6 +32,24 @@ const BucketTableRow: React.FC<BucketTableRowProps> = ({
62
32
iconClassName = "bic bic-database-fill-pencil me-1 text-slate" ;
63
33
}
64
34
35
+ // granted permission text
36
+ let grantedPermissionTip : string | null = null
37
+ if ( bucket . grantedPermission === "readonly" ) {
38
+ grantedPermissionTip = translate ( "browse.bucketTable.bucketGrantedReadOnly" ) ;
39
+ } else if ( bucket . grantedPermission === "readwrite" ) {
40
+ grantedPermissionTip = translate ( "browse.bucketTable.bucketGrantedReadWrite" ) ;
41
+ }
42
+
43
+ // is overflow
44
+ const {
45
+ ref : bucketRemarkRef ,
46
+ isOverflow : bucketRemarkIsOverflow ,
47
+ } = useIsOverflow ( ) ;
48
+ const {
49
+ ref : bucketNameRef ,
50
+ isOverflow : bucketNameIsOverflow ,
51
+ } = useIsOverflow ( ) ;
52
+
65
53
// render
66
54
return (
67
55
< tr
@@ -77,24 +65,38 @@ const BucketTableRow: React.FC<BucketTableRowProps> = ({
77
65
} }
78
66
/>
79
67
</ td >
80
- < td >
81
- < TooltipText
82
- tooltipPlacement = "right"
83
- delay = { {
84
- show : Duration . Second ,
85
- hide : 0 ,
86
- } }
87
- tooltipContent = { < BucketNameTooltip bucket = { bucket } /> }
88
- >
89
- < div
90
- className = "d-inline-flex flex-column"
68
+ { /* The `line height: 0` fixes height incorrect of row causing by `overflow-ellipsis-inline` */ }
69
+ < td style = { { lineHeight : 0 } } >
70
+ < div >
71
+ < TooltipText
72
+ disabled = { ! bucket . grantedPermission && ! bucketNameIsOverflow }
73
+ tooltipPlacement = "right"
74
+ delay = { {
75
+ show : Duration . Second ,
76
+ hide : 0 ,
77
+ } }
78
+ tooltipContent = {
79
+ < div className = "text-start" >
80
+ {
81
+ bucketNameIsOverflow &&
82
+ < div className = "text-break-all" >
83
+ { bucket . name }
84
+ </ div >
85
+ }
86
+ < div className = "text-info" >
87
+ { grantedPermissionTip }
88
+ </ div >
89
+ </ div >
90
+ }
91
91
>
92
92
< span
93
93
tabIndex = { 0 }
94
- className = "text-link overflow-ellipsis"
94
+ className = "text-link overflow-ellipsis-inline "
95
95
style = { {
96
96
[ "--line-num" as any ] : bucket . remark ? 1 : 2 ,
97
+ lineHeight : "var(--bs-body-line-height)" ,
97
98
} }
99
+ ref = { bucketNameRef }
98
100
onKeyUp = { e => {
99
101
if ( e . code === "Space" ) {
100
102
e . stopPropagation ( ) ;
@@ -109,16 +111,26 @@ const BucketTableRow: React.FC<BucketTableRowProps> = ({
109
111
< i className = { iconClassName } />
110
112
{ bucket . name }
111
113
</ span >
112
- {
113
- bucket . remark &&
114
+ </ TooltipText >
115
+ </ div >
116
+ {
117
+ bucket . remark &&
118
+ < div >
119
+ < TooltipText
120
+ disabled = { ! bucketRemarkIsOverflow }
121
+ tooltipPlacement = "right"
122
+ tooltipContent = { < div className = "text-start" > { bucket . remark } </ div > }
123
+ >
114
124
< small
115
- className = "text-secondary overflow-ellipsis"
125
+ ref = { bucketRemarkRef }
126
+ className = "text-secondary overflow-ellipsis-inline"
127
+ style = { { lineHeight : "var(--bs-body-line-height)" } }
116
128
>
117
129
{ bucket . remark }
118
130
</ small >
119
- }
131
+ </ TooltipText >
120
132
</ div >
121
- </ TooltipText >
133
+ }
122
134
</ td >
123
135
{ /* may empty string, so use `||` instead of `??` */ }
124
136
< td className = "align-middle" > { bucket . regionName || bucket . regionId } </ td >
0 commit comments