1- import React from 'react' ;
2-
31import DataTable from '@gravity-ui/react-data-table' ;
2+ import type { TextProps } from '@gravity-ui/uikit' ;
43import { Text } from '@gravity-ui/uikit' ;
54import { isNil } from 'lodash' ;
65
@@ -63,21 +62,14 @@ export function getAllColumns() {
6362 ) ,
6463 align : DataTable . LEFT ,
6564 render : ( { row} ) => < TopicDataTimestamp timestamp = { row . WriteTimestamp } /> ,
66- width : 220 ,
65+ width : 100 ,
6766 } ,
6867 {
6968 name : TOPIC_DATA_COLUMNS_IDS . TS_DIFF ,
7069 header : TOPIC_DATA_COLUMNS_TITLES [ TOPIC_DATA_COLUMNS_IDS . TS_DIFF ] ,
7170 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 ,
8173 note : i18n ( 'context_ts-diff' ) ,
8274 } ,
8375 {
@@ -99,43 +91,16 @@ export function getAllColumns() {
9991 name : TOPIC_DATA_COLUMNS_IDS . MESSAGE ,
10092 header : TOPIC_DATA_COLUMNS_TITLES [ TOPIC_DATA_COLUMNS_IDS . MESSAGE ] ,
10193 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+ ) ,
13297 width : 500 ,
13398 } ,
13499 {
135100 name : TOPIC_DATA_COLUMNS_IDS . SIZE ,
136101 header : TOPIC_DATA_COLUMNS_TITLES [ TOPIC_DATA_COLUMNS_IDS . SIZE ] ,
137102 align : DataTable . RIGHT ,
138- render : ( { row} ) => formatBytes ( row . StorageSize ) ,
103+ render : ( { row : { StorageSize } } ) => < TopicDataSize size = { StorageSize } /> ,
139104 width : 100 ,
140105 } ,
141106 {
@@ -146,7 +111,7 @@ export function getAllColumns() {
146111 />
147112 ) ,
148113 align : DataTable . RIGHT ,
149- render : ( { row} ) => formatBytes ( row . OriginalSize ) ,
114+ render : ( { row : { OriginalSize } } ) => < TopicDataSize size = { OriginalSize } /> ,
150115 width : 100 ,
151116 } ,
152117 {
@@ -193,21 +158,86 @@ export const REQUIRED_TOPIC_DATA_COLUMNS: TopicDataColumnId[] = ['offset'];
193158interface TopicDataTimestampProps {
194159 timestamp ?: string ;
195160}
196- function TopicDataTimestamp ( { timestamp} : TopicDataTimestampProps ) {
161+ export function TopicDataTimestamp ( { timestamp} : TopicDataTimestampProps ) {
197162 if ( ! timestamp ) {
198163 return EMPTY_DATA_PLACEHOLDER ;
199164 }
200165 const formatted = formatTimestamp ( timestamp ) ;
201166 const splitted = formatted . split ( '.' ) ;
202167 const ms = splitted . pop ( ) ;
203168 return (
204- < React . Fragment >
169+ < Text variant = "body-2" >
205170 { 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 >
208175 ) ;
209176}
210177
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+
211241function valueOrPlaceholder (
212242 value : string | number | undefined ,
213243 placeholder = EMPTY_DATA_PLACEHOLDER ,
0 commit comments