Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: experimental support for linking tips to datasets #1314

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/components/tree/infoPanels/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { infoPanelStyles } from "../../../globalStyles";
import { numericToCalendar } from "../../../util/dateHelpers";
import { getTraitFromNode, getFullAuthorInfoFromNode, getVaccineFromNode,
getAccessionFromNode, getUrlFromNode, collectMutations } from "../../../util/treeMiscHelpers";
import { changePage } from "../../../actions/navigation";

export const styles = {
container: {
Expand Down Expand Up @@ -31,11 +32,13 @@ export const stopProp = (e) => {
};

/* min width to get "collection date" on 1 line: 120 */
const item = (key, value, href) => (
const item = (key, value, href, onClick) => (
<tr key={key}>
<th style={infoPanelStyles.item}>{key}</th>
<td style={infoPanelStyles.item}>{href ? (
<a href={href} target="_blank" rel="noopener noreferrer">{value}</a>
) : onClick ? (
<span style={infoPanelStyles.link} onClick={onClick}>{value}</span>
) :
value
}</td>
Expand Down Expand Up @@ -212,7 +215,7 @@ const getTraitsToDisplay = (node) => {
return Object.keys(node.node_attrs).filter((k) => !ignore.includes(k));
};

const Trait = ({node, trait, colorings}) => {
const Trait = ({node, trait, colorings, dispatch}) => {
const value_tmp = getTraitFromNode(node, trait);
let value = value_tmp;
if (typeof value_tmp === "number") {
Expand All @@ -225,6 +228,12 @@ const Trait = ({node, trait, colorings}) => {
const name = (colorings && colorings[trait] && colorings[trait].title) ?
colorings[trait].title :
trait;

const changeDatasetAction = experimentalMakeChangeDatasetAction(node, trait, dispatch);
if (changeDatasetAction) {
return item(name, value, undefined, changeDatasetAction);
}

const url = getUrlFromNode(node, trait);
if (url) {
return <Link title={name} url={url} value={value}/>;
Expand All @@ -239,7 +248,7 @@ const Trait = ({node, trait, colorings}) => {
* @param {function} props.goAwayCallback
* @param {object} props.colorings
*/
const TipClickedPanel = ({tip, goAwayCallback, colorings, t}) => {
const TipClickedPanel = ({tip, goAwayCallback, colorings, t, dispatch}) => {
if (!tip) {return null;}
const panelStyle = { ...infoPanelStyles.panel};
panelStyle.maxHeight = "70%";
Expand All @@ -255,7 +264,7 @@ const TipClickedPanel = ({tip, goAwayCallback, colorings, t}) => {
<SampleDate node={node} t={t}/>
<PublicationInfo node={node} t={t}/>
{getTraitsToDisplay(node).map((trait) => (
<Trait node={node} trait={trait} colorings={colorings} key={trait}/>
<Trait node={node} trait={trait} colorings={colorings} key={trait} dispatch={dispatch}/>
))}
<AccessionAndUrl node={node}/>
{item("", "")}
Expand All @@ -271,3 +280,10 @@ const TipClickedPanel = ({tip, goAwayCallback, colorings, t}) => {
};

export default TipClickedPanel;

function experimentalMakeChangeDatasetAction(node, trait, dispatch) {
if (!node.node_attrs || !node.node_attrs[trait] || !node.node_attrs[trait].dataset) return undefined;
const dataset = node.node_attrs[trait].dataset;
// todo: best-effort validation of `dataset`
return () => dispatch(changePage({path: dataset}));
}
1 change: 1 addition & 0 deletions src/components/tree/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class Tree extends React.Component {
tip={this.state.selectedTip}
colorings={this.props.metadata.colorings}
t={t}
dispatch={this.props.dispatch}
/>
{this.props.showTangle && this.state.tree && this.state.treeToo ? (
<Tangle
Expand Down
5 changes: 5 additions & 0 deletions src/globalStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ export const infoPanelStyles = {
minWidth: 130,
verticalAlign: "top"
},
link: {
color: "#5097BA",
cursor: "pointer",
fontWeight: 400
},
break: {
marginBottom: "10px"
}
Expand Down