@@ -31,17 +31,20 @@ const normalize = (cell: KeyableTableCell | NonKeyableTableCell): string => {
31
31
* table.
32
32
* @template TRow The type of a row of data provided to the
33
33
* table.
34
+ * @template TContext The type of the context in which the table is
35
+ * being rendered.
34
36
* @param style The style to apply to the table.
35
37
* @param schema The schema of the table to show.
36
38
* @returns The created React component.
37
39
*/
38
40
export const createOfflineTableComponent = <
39
41
TKeyableColumnKey extends string ,
40
42
TNonKeyableColumnKey extends string ,
41
- TRow extends TableRow < TKeyableColumnKey , TNonKeyableColumnKey >
43
+ TRow extends TableRow < TKeyableColumnKey , TNonKeyableColumnKey > ,
44
+ TContext
42
45
> (
43
46
style : TableStyle ,
44
- schema : TableSchema < TKeyableColumnKey , TNonKeyableColumnKey , TRow >
47
+ schema : TableSchema < TKeyableColumnKey , TNonKeyableColumnKey , TRow , TContext >
45
48
) : React . FunctionComponent < {
46
49
/**
47
50
* The data to show in the table.
@@ -81,6 +84,11 @@ export const createOfflineTableComponent = <
81
84
* Shown when there are no rows to display.
82
85
*/
83
86
readonly whenEmpty : string ;
87
+
88
+ /**
89
+ * The context in which the table is being rendered.
90
+ */
91
+ readonly context : TContext ;
84
92
} > => {
85
93
const rowViewBase : ViewStyle = {
86
94
width : `100%` ,
@@ -302,7 +310,15 @@ export const createOfflineTableComponent = <
302
310
const oddRowCellStyles = StyleSheet . create ( oddRowCellInput ) ;
303
311
const evenRowCellStyles = StyleSheet . create ( evenRowCellInput ) ;
304
312
305
- return ( { data, whenEmpty, filter, sortBy, sortDirection, onSortChange } ) => {
313
+ return ( {
314
+ data,
315
+ whenEmpty,
316
+ filter,
317
+ sortBy,
318
+ sortDirection,
319
+ onSortChange,
320
+ context,
321
+ } ) => {
306
322
let rows = [ ...data . rows ] ;
307
323
308
324
filter = normalize ( filter ) ;
@@ -323,7 +339,7 @@ export const createOfflineTableComponent = <
323
339
324
340
case `customText` :
325
341
{
326
- const value = column . render ( row [ column . key ] as never ) ;
342
+ const value = column . render ( row [ column . key ] as never , context ) ;
327
343
328
344
if ( normalize ( value ) . includes ( filter ) ) {
329
345
return true ;
@@ -332,7 +348,7 @@ export const createOfflineTableComponent = <
332
348
break ;
333
349
334
350
case `customElement` :
335
- if ( column . containsSearchTerm ( row , filter ) ) {
351
+ if ( column . containsSearchTerm ( row , filter , context ) ) {
336
352
return true ;
337
353
}
338
354
@@ -484,7 +500,10 @@ export const createOfflineTableComponent = <
484
500
}
485
501
486
502
case `customText` : {
487
- const value = column . render ( row [ column . key ] as never ) ;
503
+ const value = column . render (
504
+ row [ column . key ] as never ,
505
+ context
506
+ ) ;
488
507
489
508
// TODO: why does TypeScript think this cannot be null, false or true?
490
509
switch ( value as unknown ) {
@@ -540,7 +559,7 @@ export const createOfflineTableComponent = <
540
559
key = { String ( columnIndex ) }
541
560
style = { customCellStyles [ columnIndex ] }
542
561
>
543
- { column . render ( row ) }
562
+ { column . render ( row , context ) }
544
563
</ View >
545
564
) ;
546
565
}
0 commit comments