Skip to content

Commit

Permalink
Merge pull request knowledgesystems#2 from leexgh/table-sorting
Browse files Browse the repository at this point in the history
add penetrance sorting function
  • Loading branch information
onursumer authored Sep 25, 2019
2 parents 4e5a849 + e043a7e commit 90c65eb
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions client/src/components/GeneFrequencyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {renderPercentage} from "./ColumnRenderHelper";
import Gene from "./Gene";
import GeneFrequencyTableComponent from "./GeneFrequencyTableComponent";
import GeneTumorTypeFrequencyDecomposition from "./GeneTumorTypeFrequencyDecomposition";
import { comparePenetrance } from './Penetrance';
import PenetranceList from "./PenetranceList";

import "react-table/react-table.css";
Expand Down Expand Up @@ -40,6 +41,19 @@ function renderPenetrance(cellProps: any)
);
}

function sortPenetrance(a: string[], b: string[])
{
const aSorted = a.sort(comparePenetrance);
const bSorted = b.sort(comparePenetrance);
for (let i = 0; i < Math.min(aSorted.length, bSorted.length); i++) {
const comparison = -comparePenetrance(aSorted[i], bSorted[i])
if (comparison !== 0) {
return comparison;
}
}
return Math.sign(a.length - b.length);
}

function renderSubComponent(row: any) {
return (
<div className="p-4">
Expand Down Expand Up @@ -88,7 +102,11 @@ class GeneFrequencyTable extends React.Component<IFrequencyTableProps>
onSearch={this.handleSearch}
info={this.info}
reactTableProps={{
SubComponent: renderSubComponent
SubComponent: renderSubComponent,
defaultSorted: [
{id: ColumnId.PENETRANCE, desc: true},
{id: ColumnId.GERMLINE, desc: true}
]
}}
columns={[
{
Expand All @@ -101,8 +119,8 @@ class GeneFrequencyTable extends React.Component<IFrequencyTableProps>
id: ColumnId.PENETRANCE,
Cell: renderPenetrance,
Header: HEADER_COMPONENT[ColumnId.PENETRANCE],
accessor: ColumnId.PENETRANCE
// TODO sort function!
accessor: ColumnId.PENETRANCE,
sortMethod: sortPenetrance
},
{
id: ColumnId.GERMLINE,
Expand Down

0 comments on commit 90c65eb

Please sign in to comment.