-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bryan Lai
committed
Jan 8, 2024
1 parent
c7ff3b5
commit f964259
Showing
7 changed files
with
185 additions
and
216 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
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
107 changes: 107 additions & 0 deletions
107
src/shared/components/oncoprint/OncoprintColorModal.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,107 @@ | ||
import { action, makeObservable, observable } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import { ClinicalTrackSpec } from './Oncoprint'; | ||
import { | ||
getClinicalTrackColor, | ||
getClinicalTrackValues, | ||
} from './ResultsViewOncoprint'; | ||
import { Modal } from 'react-bootstrap'; | ||
import ClinicalTrackColorPicker from './ClinicalTrackColorPicker'; | ||
import { RGBAColor } from 'oncoprintjs'; | ||
import classnames from 'classnames'; | ||
import _ from 'lodash'; | ||
import { rgbaToHex } from 'shared/lib/Colors'; | ||
|
||
interface IOncoprintColorModalProps { | ||
setTrackKeySelectedForEdit: (key: string | null) => void; | ||
selectedClinicalTrack: ClinicalTrackSpec; | ||
handleSelectedClinicalTrackColorChange: ( | ||
value: string, | ||
color: RGBAColor | undefined | ||
) => void; | ||
getSelectedClinicalTrackDefaultColorForValue: (value: string) => number[]; | ||
} | ||
|
||
export const OncoprintColorModal: React.FC<IOncoprintColorModalProps> = observer( | ||
({ | ||
setTrackKeySelectedForEdit, | ||
selectedClinicalTrack, | ||
handleSelectedClinicalTrackColorChange, | ||
getSelectedClinicalTrackDefaultColorForValue, | ||
}: IOncoprintColorModalProps) => { | ||
const clinicalTrackValues = getClinicalTrackValues( | ||
selectedClinicalTrack | ||
); | ||
|
||
return ( | ||
<Modal show={true} onHide={() => setTrackKeySelectedForEdit(null)}> | ||
<Modal.Header closeButton> | ||
<Modal.Title> | ||
Color Configuration: {selectedClinicalTrack.label} | ||
</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<table className="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Value</th> | ||
<th>Color</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{clinicalTrackValues.map(value => ( | ||
<tr> | ||
<td>{value}</td> | ||
<td> | ||
<ClinicalTrackColorPicker | ||
handleClinicalTrackColorChange={ | ||
handleSelectedClinicalTrackColorChange | ||
} | ||
clinicalTrackValue={value} | ||
color={getClinicalTrackColor( | ||
selectedClinicalTrack, | ||
value as string | ||
)} | ||
/> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
<button | ||
className={classnames('btn', 'btn-default', 'btn-sm', { | ||
hidden: _.every( | ||
clinicalTrackValues, | ||
v => | ||
rgbaToHex( | ||
getClinicalTrackColor( | ||
selectedClinicalTrack, | ||
v as string | ||
) | ||
) === | ||
rgbaToHex( | ||
getSelectedClinicalTrackDefaultColorForValue( | ||
v | ||
) as RGBAColor | ||
) | ||
), | ||
})} | ||
data-test="resetColors" | ||
style={{ marginTop: 5 }} | ||
onClick={() => { | ||
clinicalTrackValues.forEach(v => { | ||
handleSelectedClinicalTrackColorChange( | ||
v, | ||
undefined | ||
); | ||
}); | ||
}} | ||
> | ||
Reset Colors | ||
</button> | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
} | ||
); |
Oops, something went wrong.