1
- import React from 'react' ;
2
-
3
1
import DataTable from '@gravity-ui/react-data-table' ;
2
+ import type { TextProps } from '@gravity-ui/uikit' ;
4
3
import { Text } from '@gravity-ui/uikit' ;
5
4
import { isNil } from 'lodash' ;
6
5
@@ -63,21 +62,14 @@ export function getAllColumns() {
63
62
) ,
64
63
align : DataTable . LEFT ,
65
64
render : ( { row} ) => < TopicDataTimestamp timestamp = { row . WriteTimestamp } /> ,
66
- width : 220 ,
65
+ width : 100 ,
67
66
} ,
68
67
{
69
68
name : TOPIC_DATA_COLUMNS_IDS . TS_DIFF ,
70
69
header : TOPIC_DATA_COLUMNS_TITLES [ TOPIC_DATA_COLUMNS_IDS . TS_DIFF ] ,
71
70
align : DataTable . RIGHT ,
72
- render : ( { row} ) => {
73
- const numericValue = safeParseNumber ( row . TimestampDiff ) ;
74
- return (
75
- < span className = { b ( 'ts-diff' , { danger : numericValue >= 100_000 } ) } >
76
- { formatToMs ( numericValue ) }
77
- </ span >
78
- ) ;
79
- } ,
80
- width : 90 ,
71
+ render : ( { row : { TimestampDiff} } ) => < TopicDataTsDiff value = { TimestampDiff } /> ,
72
+ width : 110 ,
81
73
note : i18n ( 'context_ts-diff' ) ,
82
74
} ,
83
75
{
@@ -99,43 +91,16 @@ export function getAllColumns() {
99
91
name : TOPIC_DATA_COLUMNS_IDS . MESSAGE ,
100
92
header : TOPIC_DATA_COLUMNS_TITLES [ TOPIC_DATA_COLUMNS_IDS . MESSAGE ] ,
101
93
align : DataTable . LEFT ,
102
- render : ( { row : { Message, OriginalSize} } ) => {
103
- if ( isNil ( Message ) ) {
104
- return EMPTY_DATA_PLACEHOLDER ;
105
- }
106
- let encryptedMessage ;
107
- let invalid = false ;
108
- try {
109
- encryptedMessage = atob ( Message ) ;
110
- } catch {
111
- encryptedMessage = i18n ( 'description_failed-decode' ) ;
112
- invalid = true ;
113
- }
114
-
115
- const truncated = safeParseNumber ( OriginalSize ) > TOPIC_MESSAGE_SIZE_LIMIT ;
116
- return (
117
- < Text
118
- variant = "body-2"
119
- color = { invalid ? 'secondary' : 'primary' }
120
- className = { b ( 'message' , { invalid} ) }
121
- >
122
- { encryptedMessage }
123
- { truncated && (
124
- < Text color = "secondary" className = { b ( 'truncated' ) } >
125
- { ' ' }
126
- { i18n ( 'description_truncated' ) }
127
- </ Text >
128
- ) }
129
- </ Text >
130
- ) ;
131
- } ,
94
+ render : ( { row : { Message, OriginalSize} } ) => (
95
+ < TopicDataMessage message = { Message } size = { OriginalSize } />
96
+ ) ,
132
97
width : 500 ,
133
98
} ,
134
99
{
135
100
name : TOPIC_DATA_COLUMNS_IDS . SIZE ,
136
101
header : TOPIC_DATA_COLUMNS_TITLES [ TOPIC_DATA_COLUMNS_IDS . SIZE ] ,
137
102
align : DataTable . RIGHT ,
138
- render : ( { row} ) => formatBytes ( row . StorageSize ) ,
103
+ render : ( { row : { StorageSize } } ) => < TopicDataSize size = { StorageSize } /> ,
139
104
width : 100 ,
140
105
} ,
141
106
{
@@ -146,7 +111,7 @@ export function getAllColumns() {
146
111
/>
147
112
) ,
148
113
align : DataTable . RIGHT ,
149
- render : ( { row} ) => formatBytes ( row . OriginalSize ) ,
114
+ render : ( { row : { OriginalSize } } ) => < TopicDataSize size = { OriginalSize } /> ,
150
115
width : 100 ,
151
116
} ,
152
117
{
@@ -193,21 +158,86 @@ export const REQUIRED_TOPIC_DATA_COLUMNS: TopicDataColumnId[] = ['offset'];
193
158
interface TopicDataTimestampProps {
194
159
timestamp ?: string ;
195
160
}
196
- function TopicDataTimestamp ( { timestamp} : TopicDataTimestampProps ) {
161
+ export function TopicDataTimestamp ( { timestamp} : TopicDataTimestampProps ) {
197
162
if ( ! timestamp ) {
198
163
return EMPTY_DATA_PLACEHOLDER ;
199
164
}
200
165
const formatted = formatTimestamp ( timestamp ) ;
201
166
const splitted = formatted . split ( '.' ) ;
202
167
const ms = splitted . pop ( ) ;
203
168
return (
204
- < React . Fragment >
169
+ < Text variant = "body-2" >
205
170
{ splitted . join ( '.' ) }
206
- < span className = { b ( 'timestamp-ms' ) } > .{ ms } </ span >
207
- </ React . Fragment >
171
+ < Text variant = "body-2" color = "secondary" >
172
+ .{ ms }
173
+ </ Text >
174
+ </ Text >
208
175
) ;
209
176
}
210
177
178
+ interface TopicDataTsDiffProps {
179
+ value ?: string ;
180
+ baseColor ?: TextProps [ 'color' ] ;
181
+ variant ?: TextProps [ 'variant' ] ;
182
+ }
183
+
184
+ export function TopicDataTsDiff ( {
185
+ value,
186
+ baseColor = 'primary' ,
187
+ variant = 'body-2' ,
188
+ } : TopicDataTsDiffProps ) {
189
+ const numericValue = safeParseNumber ( value ) ;
190
+ return (
191
+ < Text variant = { variant } color = { numericValue >= 100_000 ? 'danger' : baseColor } >
192
+ { formatToMs ( numericValue ) }
193
+ </ Text >
194
+ ) ;
195
+ }
196
+
197
+ interface TopicDataMessageProps {
198
+ message ?: string ;
199
+ size ?: number ;
200
+ }
201
+
202
+ export function TopicDataMessage ( { message, size} : TopicDataMessageProps ) {
203
+ if ( isNil ( message ) ) {
204
+ return EMPTY_DATA_PLACEHOLDER ;
205
+ }
206
+ let encryptedMessage ;
207
+ let invalid = false ;
208
+ try {
209
+ encryptedMessage = atob ( message ) ;
210
+ } catch {
211
+ encryptedMessage = i18n ( 'description_failed-decode' ) ;
212
+ invalid = true ;
213
+ }
214
+
215
+ const truncated = safeParseNumber ( size ) > TOPIC_MESSAGE_SIZE_LIMIT ;
216
+ return (
217
+ < Text
218
+ variant = "body-2"
219
+ color = { invalid ? 'secondary' : 'primary' }
220
+ className = { b ( 'message' , { invalid} ) }
221
+ >
222
+ { encryptedMessage }
223
+ { truncated && (
224
+ < Text color = "secondary" className = { b ( 'truncated' ) } >
225
+ { ' ' }
226
+ { i18n ( 'description_truncated' ) }
227
+ </ Text >
228
+ ) }
229
+ </ Text >
230
+ ) ;
231
+ }
232
+
233
+ interface TopicDataSizeProps {
234
+ size ?: number ;
235
+ }
236
+
237
+ export function TopicDataSize ( { size} : TopicDataSizeProps ) {
238
+ return formatBytes ( size ) ;
239
+ }
240
+
211
241
function valueOrPlaceholder (
212
242
value : string | number | undefined ,
213
243
placeholder = EMPTY_DATA_PLACEHOLDER ,
0 commit comments