Skip to content

Commit d94354e

Browse files
authored
Merge pull request #413 from zhx828/shorten-alt
Shorten the alteration list when there are more than 5 in the same cell
2 parents 853c2fd + 698198f commit d94354e

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

src/main/webapp/app/pages/ActionableGenesPage.tsx

+54-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from 'react';
1+
import React, { ReactNode } from 'react';
22
import { inject, observer } from 'mobx-react';
33
import { LevelButton } from 'app/components/levelButton/LevelButton';
44
import { Button, Col, Row } from 'react-bootstrap';
55
import classnames from 'classnames';
66
import privateClient from 'app/shared/api/oncokbPrivateClientInstance';
7-
import { remoteData } from 'cbioportal-frontend-commons';
7+
import { remoteData, DefaultTooltip } from 'cbioportal-frontend-commons';
88
import {
99
action,
1010
computed,
@@ -43,6 +43,7 @@ import * as QueryString from 'query-string';
4343
import OncoKBTable from 'app/components/oncokbTable/OncoKBTable';
4444
import { AuthDownloadButton } from 'app/components/authDownloadButton/AuthDownloadButton';
4545
import DocumentTitle from 'react-document-title';
46+
import { COLOR_BLUE } from 'app/config/theme';
4647

4748
type Treatment = {
4849
level: string;
@@ -435,6 +436,52 @@ export default class ActionableGenesPage extends React.Component<
435436
return Promise.resolve(content.join('\n'));
436437
}
437438

439+
concatElementsByComma(list: ReactNode[]) {
440+
return list.reduce((prev, curr) => [prev, ', ', curr]);
441+
}
442+
443+
getAlterationCell(hugoSymbol: string, alterations: string[]) {
444+
const linkedAlts = alterations.map<React.ReactNode>(
445+
(alteration, index: number) => (
446+
<AlterationPageLink
447+
key={index}
448+
hugoSymbol={hugoSymbol}
449+
alteration={alteration}
450+
/>
451+
)
452+
);
453+
if (linkedAlts.length > 5) {
454+
return (
455+
<span>
456+
{linkedAlts[0]} and{' '}
457+
<DefaultTooltip
458+
overlay={
459+
<div style={{ maxWidth: '400px' }}>
460+
{this.concatElementsByComma(linkedAlts)}
461+
</div>
462+
}
463+
overlayStyle={{
464+
opacity: 1
465+
}}
466+
placement="right"
467+
destroyTooltipOnHide={true}
468+
>
469+
<span
470+
style={{
471+
textDecoration: 'underscore',
472+
color: COLOR_BLUE
473+
}}
474+
>
475+
{linkedAlts.length - 1} other alterations
476+
</span>
477+
</DefaultTooltip>
478+
</span>
479+
);
480+
} else {
481+
return this.concatElementsByComma(linkedAlts);
482+
}
483+
}
484+
438485
private columns = [
439486
{
440487
...getDefaultColumnDefinition(TABLE_COLUMN_KEY.LEVEL)
@@ -454,19 +501,14 @@ export default class ActionableGenesPage extends React.Component<
454501
style: { whiteSpace: 'normal' },
455502
defaultSortDesc: false,
456503
sortMethod: defaultSortMethod,
457-
Cell(props: { original: Treatment }) {
504+
Cell: (props: { original: Treatment }) => {
458505
return (
459506
<div style={{ display: 'block' }}>
460507
{' '}
461-
{props.original.alterations
462-
.map<React.ReactNode>((alteration, index: number) => (
463-
<AlterationPageLink
464-
key={index}
465-
hugoSymbol={props.original.hugoSymbol}
466-
alteration={alteration}
467-
/>
468-
))
469-
.reduce((prev, curr) => [prev, ', ', curr])}
508+
{this.getAlterationCell(
509+
props.original.hugoSymbol,
510+
props.original.alterations
511+
)}
470512
</div>
471513
);
472514
}

0 commit comments

Comments
 (0)