Skip to content

Commit

Permalink
updated type of sampleToMutationGenePanelId
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngoc Nguyen committed Oct 1, 2019
1 parent 2873027 commit fd3d777
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type ICopyNumberTableWrapperProps = {
columnVisibility?: {[columnId: string]: boolean};
columnVisibilityProps?: IColumnVisibilityControlsProps;
status:"loading"|"available"|"unavailable";
sampleToMutationGenePanelId?: any;
sampleToMutationGenePanelId?: {[sampleId:string]:string};
};

@observer
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/mutationTable/MutationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface IMutationTableProps {
showCountHeader?:boolean;
columnVisibility?: {[columnId: string]: boolean};
columnVisibilityProps?: IColumnVisibilityControlsProps;
sampleToMutationGenePanelId?: any;
sampleToMutationGenePanelId?: {[sampleId:string]: string} | undefined;
}

export enum MutationTableColumnType {
Expand Down
87 changes: 57 additions & 30 deletions src/shared/components/mutationTable/column/PanelColumnFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
import * as React from 'react';
import {Mutation, DiscreteCopyNumberData} from "shared/api/generated/CBioPortalAPI";
import {
Mutation,
DiscreteCopyNumberData
} from 'shared/api/generated/CBioPortalAPI';

interface PanelColumnFormatterProps {
data: Mutation[] | DiscreteCopyNumberData[],
sampleToMutationGenePanelId: any,
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 (!Object.keys(sampleToMutationGenePanelId).length) {
return <i className='fa fa-spinner fa-pulse'/>;
}

const genePanelIds:string[] = getGenePanelIds(data, sampleToMutationGenePanelId);
class PanelColumn extends React.Component<PanelColumnFormatterProps, {}> {
constructor(props: PanelColumnFormatterProps) {
super(props);
}

render() {
const { data, sampleToMutationGenePanelId } = this.props;

return (
<div style={{position:'relative'}}>
<ul style={{marginBottom:0}} className="list-inline list-unstyled">{ genePanelIds.join(', ') }</ul>
</div>
)
}
}
if (!sampleToMutationGenePanelId) return;

const getGenePanelIds = (data:any[], sampleToMutationGenePanelId:any) => {
const sampleIds = data.map(datum => datum.sampleId);
return sampleIds.map(id => sampleToMutationGenePanelId[id]);
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:any) => <PanelColumn data={data} sampleToMutationGenePanelId={sampleToMutationGenePanelId}/>,
download: (data:Mutation[] | DiscreteCopyNumberData[], sampleToMutationGenePanelId:any) => getGenePanelIds(data, sampleToMutationGenePanelId),
getGenePanelIds
}
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
};

0 comments on commit fd3d777

Please sign in to comment.