@@ -130,6 +130,53 @@ const rowsLongTextTruncatedMiddle: TableRowType[] = [
130130 } ,
131131] ;
132132
133+ const rowsLongTextWrap : TableRowType [ ] = [
134+ {
135+ id : 'row-1' ,
136+ items : [
137+ {
138+ label :
139+ 'console.clickhouse.cloud_Archive.01-01-1975.lorem-ipsum-a-very-long-filename-01.csv' ,
140+ overflowMode : 'truncated' ,
141+ } ,
142+ { label : 'system.query_log' } ,
143+ { label : '2024-01-15 14:32:01' } ,
144+ ] ,
145+ } ,
146+ {
147+ id : 'row-2' ,
148+ items : [
149+ {
150+ label :
151+ 'console.clickhouse.cloud_Export.15-03-2024.analytics-events-production-02.parquet' ,
152+ overflowMode : 'wrap' ,
153+ } ,
154+ { label : 'default.events_local_v2_replica' } ,
155+ { label : '2024-01-15 14:28:45' } ,
156+ ] ,
157+ } ,
158+ {
159+ id : 'row-3' ,
160+ items : [
161+ {
162+ label :
163+ 'console.clickhouse.cloud_Backup.28-02-2024.user-sessions-aggregated-daily-03.csv.gz' ,
164+ overflowMode : 'wrap' ,
165+ } ,
166+ { label : 'analytics.page_views_aggregated_daily_mv' } ,
167+ { label : '2024-01-15 14:25:12' } ,
168+ ] ,
169+ } ,
170+ {
171+ id : 'row-4' ,
172+ items : [
173+ { label : 'data.csv' , overflowMode : 'wrap' } ,
174+ { label : 'users' } ,
175+ { label : '2024-01-15 14:20:00' } ,
176+ ] ,
177+ } ,
178+ ] ;
179+
133180const meta : Meta < typeof Table > = {
134181 component : Table ,
135182 title : 'Display/Table' ,
@@ -297,6 +344,51 @@ export const LongText: StoryObj<typeof Table> = {
297344 } ,
298345} ;
299346
347+ export const LongTextWrap : StoryObj < typeof Table > = {
348+ args : {
349+ headers : [ { label : 'File' } , { label : 'Table' } , { label : 'Timestamp' } ] ,
350+ rows : rowsLongTextWrap ,
351+ mobileLayout : 'list' ,
352+ } ,
353+ render : ( { rows, headers, mobileLayout, ...props } ) => {
354+ const [ sort , setSort ] = useState < [ number , 'asc' | 'desc' ] > ( [ 0 , 'asc' ] ) ;
355+
356+ const sortedHeaders = useMemo (
357+ ( ) =>
358+ headers . map ( ( header , headerIndex ) => ( {
359+ ...header ,
360+ isSortable : true ,
361+ sortDir : sort [ 0 ] === headerIndex ? sort [ 1 ] : undefined ,
362+ } ) ) ,
363+ [ headers , sort ]
364+ ) ;
365+
366+ const sortedRows = useMemo (
367+ ( ) =>
368+ [ ...rows ] . sort ( ( a , b ) => {
369+ const [ cellIdx , sortDir ] = sort ;
370+ const cellA = a . items [ cellIdx ] ?. label ?. toString ( ) || '' ;
371+ const cellB = b . items [ cellIdx ] ?. label ?. toString ( ) || '' ;
372+ const result = cellA . localeCompare ( cellB , 'en' , { numeric : true } ) ;
373+ return sortDir === 'asc' ? result : - result ;
374+ } ) ,
375+ [ rows , sort ]
376+ ) ;
377+
378+ return (
379+ < div style = { { maxWidth : mobileLayout === 'scroll' ? '400px' : 'none' } } >
380+ < Table
381+ { ...props }
382+ headers = { sortedHeaders }
383+ rows = { sortedRows }
384+ mobileLayout = { mobileLayout }
385+ onSort = { ( dir , _ , idx ) => void setSort ( [ idx , dir ] ) }
386+ />
387+ </ div >
388+ ) ;
389+ } ,
390+ } ;
391+
300392export const LongTextTruncated : StoryObj < typeof Table > = {
301393 args : {
302394 headers : [ { label : 'File' } , { label : 'Table' } , { label : 'Timestamp' } ] ,
0 commit comments