@@ -22,6 +22,7 @@ import {
2222 ClinicalData ,
2323 StudyViewFilter ,
2424} from 'cbioportal-ts-api-client' ;
25+ import { getResourceConfig } from 'shared/lib/ResourceUtils' ;
2526
2627export interface IFilesLinksTable {
2728 resourceDisplayName : string ;
@@ -250,13 +251,33 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
250251 )
251252 )
252253 : [ ] ;
253- const resourcesPerPatientColumnName =
254- uniqueResourceTypes . length === 1 && uniqueResourceTypes [ 0 ]
255- ? `${ pluralize (
256- uniqueResourceTypes [ 0 ] as string ,
257- 2
258- ) } per Patient`
259- : 'Resources per Patient' ;
254+ let resourcesPerPatientColumnName = 'Resources per Patient' ;
255+ let shouldHideResourcesPerPatientColumn = false ;
256+
257+ if ( uniqueResourceTypes . length === 1 && uniqueResourceTypes [ 0 ] ) {
258+ const def = this . props . store . resourceDefinitions . result ?. find (
259+ d => d . displayName === uniqueResourceTypes [ 0 ]
260+ ) ;
261+ if ( def ) {
262+ const config = getResourceConfig ( def ) ;
263+ if ( config . columnHeader ) {
264+ resourcesPerPatientColumnName = config . columnHeader ;
265+ } else {
266+ resourcesPerPatientColumnName = `${ pluralize (
267+ uniqueResourceTypes [ 0 ] as string ,
268+ 2
269+ ) } per Patient`;
270+ }
271+ if ( config . hideResourcesPerPatientColumn ) {
272+ shouldHideResourcesPerPatientColumn = true ;
273+ }
274+ } else {
275+ resourcesPerPatientColumnName = `${ pluralize (
276+ uniqueResourceTypes [ 0 ] as string ,
277+ 2
278+ ) } per Patient`;
279+ }
280+ }
260281
261282 let defaultColumns : Column < { [ id : string ] : any } > [ ] = [
262283 {
@@ -357,8 +378,11 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
357378 return < div > { data . description } </ div > ;
358379 } ,
359380 } ,
381+ ] ;
360382
361- {
383+ // Conditionally add the last column if not hidden
384+ if ( ! shouldHideResourcesPerPatientColumn ) {
385+ defaultColumns . push ( {
362386 ...this . getDefaultColumnConfig (
363387 'resourcesPerPatient' ,
364388 resourcesPerPatientColumnName ,
@@ -367,8 +391,8 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
367391 render : ( data : { [ id : string ] : number } ) => {
368392 return < div > { data . resourcesPerPatient } </ div > ;
369393 } ,
370- } ,
371- ] ;
394+ } ) ;
395+ }
372396
373397 return defaultColumns ;
374398 }
@@ -388,17 +412,67 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
388412 < Else >
389413 < FilesLinksTableComponent
390414 initialItemsPerPage = { 20 }
391- headerComponent = {
392- < div className = { 'positionAbsolute' } >
393- < strong >
394- {
395- this . resourceData . result
396- ?. totalItems
397- } { ' ' }
398- { this . props . resourceDisplayName }
399- </ strong >
400- </ div >
401- }
415+ headerComponent = { ( ( ) => {
416+ // Determine if there's only one unique resource type
417+ const uniqueResourceTypes =
418+ this . resourceData . result &&
419+ this . resourceData . result . data
420+ ? _ . uniq (
421+ this . resourceData . result . data . map (
422+ item =>
423+ item . typeOfResource as string
424+ )
425+ )
426+ : [ ] ;
427+ let def ;
428+ if (
429+ uniqueResourceTypes . length === 1 &&
430+ uniqueResourceTypes [ 0 ]
431+ ) {
432+ def = this . props . store . resourceDefinitions . result ?. find (
433+ d =>
434+ d . displayName ===
435+ uniqueResourceTypes [ 0 ]
436+ ) ;
437+ }
438+ let customName = '' ;
439+ if ( def ) {
440+ const config = getResourceConfig ( def ) ;
441+ if ( config . customizedDisplayName ) {
442+ customName =
443+ config . customizedDisplayName ;
444+ }
445+ }
446+
447+ return (
448+ < div className = { 'positionAbsolute' } >
449+ < strong >
450+ {
451+ this . resourceData . result
452+ ?. totalItems
453+ } { ' ' }
454+ { customName ? (
455+ customName
456+ ) : (
457+ < >
458+ { pluralize (
459+ 'sample' ,
460+ this . resourceData
461+ . result
462+ ?. totalItems ||
463+ 0
464+ ) } { ' ' }
465+ with{ ' ' }
466+ {
467+ this . props
468+ . resourceDisplayName
469+ }
470+ </ >
471+ ) }
472+ </ strong >
473+ </ div >
474+ ) ;
475+ } ) ( ) }
402476 data = { this . resourceData . result ?. data || [ ] }
403477 columns = { this . columns }
404478 showColumnVisibility = { false }
0 commit comments