@@ -41,10 +41,6 @@ impl<'a> Columns<'a> {
41
41
}
42
42
43
43
impl Columns < ' _ > {
44
- fn descriptors ( & self ) -> impl Iterator < Item = & ColumnDescriptorRef < ' _ > > {
45
- self . inner . values ( ) . map ( |( _, desc) | desc)
46
- }
47
-
48
44
fn index_from_id ( & self , id : Option < egui:: Id > ) -> Option < usize > {
49
45
id. and_then ( |id| self . inner . get ( & id) . map ( |( index, _) | * index) )
50
46
}
@@ -57,7 +53,9 @@ impl Columns<'_> {
57
53
}
58
54
}
59
55
60
- type ColumnRenamerFn < ' a > = Option < Box < dyn Fn ( & ColumnDescriptorRef < ' _ > ) -> String + ' a > > ;
56
+ pub type ColumnNameFn < ' a > = Option < Box < dyn Fn ( & ColumnDescriptorRef < ' _ > ) -> String + ' a > > ;
57
+
58
+ pub type ColumnVisibilityFn < ' a > = Option < Box < dyn Fn ( & ColumnDescriptorRef < ' _ > ) -> bool + ' a > > ;
61
59
62
60
pub struct DataFusionTableWidget < ' a > {
63
61
session_ctx : Arc < SessionContext > ,
@@ -73,7 +71,10 @@ pub struct DataFusionTableWidget<'a> {
73
71
/// Closure used to determine the display name of the column.
74
72
///
75
73
/// Defaults to using [`ColumnDescriptorRef::name`].
76
- column_renamer : ColumnRenamerFn < ' a > ,
74
+ column_name_fn : ColumnNameFn < ' a > ,
75
+
76
+ /// Closure used to determine the visibility of the column
77
+ column_visibility_fn : ColumnVisibilityFn < ' a > ,
77
78
78
79
/// The blueprint used the first time the table is queried.
79
80
initial_blueprint : TableBlueprint ,
@@ -99,7 +100,8 @@ impl<'a> DataFusionTableWidget<'a> {
99
100
100
101
title : None ,
101
102
title_button : None ,
102
- column_renamer : None ,
103
+ column_name_fn : None ,
104
+ column_visibility_fn : None ,
103
105
initial_blueprint : Default :: default ( ) ,
104
106
}
105
107
}
@@ -116,11 +118,22 @@ impl<'a> DataFusionTableWidget<'a> {
116
118
self
117
119
}
118
120
119
- pub fn column_renamer (
121
+ pub fn column_name (
120
122
mut self ,
121
- renamer : impl Fn ( & ColumnDescriptorRef < ' _ > ) -> String + ' a ,
123
+ column_name_fn : impl Fn ( & ColumnDescriptorRef < ' _ > ) -> String + ' a ,
122
124
) -> Self {
123
- self . column_renamer = Some ( Box :: new ( renamer) ) ;
125
+ self . column_name_fn = Some ( Box :: new ( column_name_fn) ) ;
126
+
127
+ self
128
+ }
129
+
130
+ // TODO(ab): this should best be expressed as part of the `TableBlueprint`, but we need better
131
+ // column selector first.
132
+ pub fn column_visibility (
133
+ mut self ,
134
+ column_visibility_fn : impl Fn ( & ColumnDescriptorRef < ' _ > ) -> bool + ' a ,
135
+ ) -> Self {
136
+ self . column_visibility_fn = Some ( Box :: new ( column_visibility_fn) ) ;
124
137
125
138
self
126
139
}
@@ -153,7 +166,8 @@ impl<'a> DataFusionTableWidget<'a> {
153
166
table_ref,
154
167
title,
155
168
title_button,
156
- column_renamer,
169
+ column_name_fn,
170
+ column_visibility_fn,
157
171
initial_blueprint,
158
172
} = self ;
159
173
@@ -256,14 +270,20 @@ impl<'a> DataFusionTableWidget<'a> {
256
270
let mut table_config = TableConfig :: get_with_columns (
257
271
ui. ctx ( ) ,
258
272
id,
259
- columns. descriptors ( ) . map ( |c| {
260
- let name = if let Some ( renamer ) = & column_renamer {
261
- renamer ( c)
273
+ sorbet_schema . columns . descriptors ( ) . map ( |c| {
274
+ let name = if let Some ( column_name_fn ) = & column_name_fn {
275
+ column_name_fn ( & c)
262
276
} else {
263
277
c. name ( BatchType :: Dataframe )
264
278
} ;
265
279
266
- ColumnConfig :: new ( Id :: new ( c) , name)
280
+ let visible = if let Some ( column_visibility_fn) = & column_visibility_fn {
281
+ column_visibility_fn ( & c)
282
+ } else {
283
+ true
284
+ } ;
285
+
286
+ ColumnConfig :: new_with_visible ( Id :: new ( c) , name, visible)
267
287
} ) ,
268
288
) ;
269
289
@@ -280,7 +300,7 @@ impl<'a> DataFusionTableWidget<'a> {
280
300
fields,
281
301
display_record_batches : & display_record_batches,
282
302
columns : & columns,
283
- column_renamer : & column_renamer ,
303
+ column_name_fn : & column_name_fn ,
284
304
blueprint : table_state. blueprint ( ) ,
285
305
new_blueprint : & mut new_blueprint,
286
306
table_config,
@@ -348,7 +368,7 @@ struct DataFusionTableDelegate<'a> {
348
368
fields : & ' a Fields ,
349
369
display_record_batches : & ' a Vec < DisplayRecordBatch > ,
350
370
columns : & ' a Columns < ' a > ,
351
- column_renamer : & ' a ColumnRenamerFn < ' a > ,
371
+ column_name_fn : & ' a ColumnNameFn < ' a > ,
352
372
blueprint : & ' a TableBlueprint ,
353
373
new_blueprint : & ' a mut TableBlueprint ,
354
374
table_config : TableConfig ,
@@ -362,7 +382,7 @@ impl egui_table::TableDelegate for DataFusionTableDelegate<'_> {
362
382
363
383
if let Some ( ( index, desc) ) = self . columns . index_and_descriptor_from_id ( id) {
364
384
let column_name = self . fields [ index] . name ( ) ;
365
- let name = if let Some ( renamer) = self . column_renamer {
385
+ let name = if let Some ( renamer) = self . column_name_fn {
366
386
renamer ( desc)
367
387
} else {
368
388
desc. name ( BatchType :: Dataframe )
0 commit comments