-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Gene panel column to tables in Patient View
- Loading branch information
1 parent
5e96142
commit f5ba1e6
Showing
6 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/shared/components/mutationTable/column/PanelColumnFormatter.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import PanelColumnFormatter from "./PanelColumnFormatter"; | ||
import { shallow } from "enzyme"; | ||
import { assert } from 'chai'; | ||
|
||
const mockData = [ | ||
{ | ||
alteration: 1, | ||
entrezGeneId: 1, | ||
gene: { | ||
entrezGeneId: 1, | ||
hugoGeneSymbol: 'test', | ||
geneticEntityId: 1, | ||
type: 'test' | ||
}, | ||
molecularProfileId: 'test', | ||
patientId: 'test', | ||
sampleId: 'sampleId', | ||
studyId: 'test', | ||
uniquePatientKey: 'test', | ||
uniqueSampleKey: 'test', | ||
} | ||
]; | ||
|
||
const mockSampleToMutationGenePanelId = { 'sampleId': 'genePanelId' }; | ||
|
||
describe("PanelColumnFormatter", () => { | ||
it('renders spinner icon if sampleToMutationGenePanelId object is empty', () => { | ||
const PanelColumn = shallow(PanelColumnFormatter.renderFunction(mockData, {})); | ||
assert.isTrue(PanelColumn.find('i.fa-spinner').exists()); | ||
}); | ||
|
||
it('renders gene panel information', () => { | ||
const PanelColumn = shallow(PanelColumnFormatter.renderFunction( | ||
mockData, | ||
mockSampleToMutationGenePanelId | ||
)); | ||
assert.isTrue(PanelColumn.text().includes('genePanelId')); | ||
}); | ||
|
||
it('returns a list of gene panel ids on download', () => { | ||
const genePanelIds = PanelColumnFormatter.download(mockData, mockSampleToMutationGenePanelId); | ||
assert.deepEqual(genePanelIds, ['genePanelId']) | ||
}); | ||
|
||
it('returns a list of gene panel ids on getGenePanelIds', () => { | ||
const genePanelIds = PanelColumnFormatter.getGenePanelIds(mockData, mockSampleToMutationGenePanelId); | ||
assert.deepEqual(genePanelIds, ['genePanelId']) | ||
}) | ||
}) |
67 changes: 67 additions & 0 deletions
67
src/shared/components/mutationTable/column/PanelColumnFormatter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import { | ||
Mutation, | ||
DiscreteCopyNumberData | ||
} from 'shared/api/generated/CBioPortalAPI'; | ||
|
||
interface PanelColumnFormatterProps { | ||
data: Mutation[] | DiscreteCopyNumberData[]; | ||
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined; | ||
} | ||
|
||
class PanelColumn extends React.Component<PanelColumnFormatterProps, {}> { | ||
constructor(props: PanelColumnFormatterProps) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
const { data, sampleToMutationGenePanelId } = this.props; | ||
|
||
if (!sampleToMutationGenePanelId) return; | ||
|
||
if (sampleToMutationGenePanelId && !Object.keys(sampleToMutationGenePanelId).length) { | ||
return <i className='fa fa-spinner fa-pulse' />; | ||
} | ||
|
||
const genePanelIds: string[] = getGenePanelIds( | ||
data, | ||
sampleToMutationGenePanelId | ||
); | ||
|
||
return ( | ||
<div style={{ position: 'relative' }}> | ||
<ul style={{ marginBottom: 0 }} className='list-inline list-unstyled'> | ||
{genePanelIds.join(', ')} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const getGenePanelIds = ( | ||
data: any[], | ||
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined | ||
) => { | ||
if (sampleToMutationGenePanelId) { | ||
const sampleIds = data.map((datum) => datum.sampleId); | ||
return sampleIds.map((id) => sampleToMutationGenePanelId[id]); | ||
} | ||
return []; | ||
}; | ||
|
||
export default { | ||
renderFunction: ( | ||
data: Mutation[] | DiscreteCopyNumberData[], | ||
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined | ||
) => ( | ||
<PanelColumn | ||
data={data} | ||
sampleToMutationGenePanelId={sampleToMutationGenePanelId} | ||
/> | ||
), | ||
download: ( | ||
data: Mutation[] | DiscreteCopyNumberData[], | ||
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined | ||
) => getGenePanelIds(data, sampleToMutationGenePanelId), | ||
getGenePanelIds | ||
}; |