Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson committed Jul 29, 2022
1 parent 2c7ebae commit 5be489d
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 106 deletions.
5 changes: 4 additions & 1 deletion taxonium_backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ app.get("/nextstrain_json/:root_id", async (req, res) => {
processedData.nodes,
config
);
res.setHeader("Content-Disposition", "attachment; " + "filename="+root_id+".nextstrain.json");
res.setHeader(
"Content-Disposition",
"attachment; " + "filename=" + root_id + ".nextstrain.json"
);
res.send(json);
});

Expand Down
34 changes: 16 additions & 18 deletions taxonium_web_client/src/components/Basic.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import classNames from "classnames";

export const Button = ({ onClick, className, children, title, href }) => {
if(href && onClick){
if (href && onClick) {
throw new Error("Button cannot have both href and onClick");
}
if(href){
if (href) {
return (
<a
className={classNames(
Expand All @@ -14,27 +14,25 @@ export const Button = ({ onClick, className, children, title, href }) => {
)}
href={href}
title={title}

>
{children}
</a>
);
} else {
return (
<button
className={classNames(
"tx-button",
"border border-gray-400 shadow-sm rounded py-1 px-2 bg-gray-100 hover:bg-gray-200 text-sm text-gray-700",
className
)}
onClick={onClick}
title={title}
>
{children}
</button>
);
}
else{
return (
<button
className={classNames(
"tx-button",
"border border-gray-400 shadow-sm rounded py-1 px-2 bg-gray-100 hover:bg-gray-200 text-sm text-gray-700",
className
)}
onClick={onClick}
title={title}
>
{children}
</button>
);
}
};

export const Select = ({ onChange, className, children, value, title }) => {
Expand Down
157 changes: 86 additions & 71 deletions taxonium_web_client/src/components/SearchPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { RiAddCircleLine, RiArrowLeftUpLine } from "react-icons/ri";
import { BiPalette } from "react-icons/bi";
import { Button } from "../components/Basic";
import ReactTooltip from "react-tooltip";
import {BsBoxArrowInUpRight} from "react-icons/bs";
import { BsBoxArrowInUpRight } from "react-icons/bs";

import { FaSearch, FaShare } from "react-icons/fa";



import { Select } from "./Basic";
import ListOutputModal from "./ListOutputModal";

import { useState, useMemo } from "react";
import { useState, useMemo } from "react";

import classNames from "classnames";

Expand Down Expand Up @@ -60,7 +58,7 @@ function SearchPanel({
} else {
return null;
}
}, [selectedDetails.nodeDetails, perNodeFunctions]);
}, [selectedDetails.nodeDetails]);

const [listOutputModalOpen, setListOutputModalOpen] = useState(false);

Expand Down Expand Up @@ -134,73 +132,91 @@ function SearchPanel({
)}
{key === "num_tips" && (
<span className="ml-1">
<a data-for='menu_descendants' data-tip='8' className="cursor-pointer"> <FaShare className="inline-block" /></a>
<ReactTooltip id='menu_descendants'
getContent={(dataTip) =>
<div>
<h2>For this clade:</h2>
<div className="mb-3"><Button
className="mb-2"

onClick={() => {
if (
selectedDetails.nodeDetails.num_tips > 100000 &&
!window.warning_shown
) {
// pop up a warning and ask if we want to continue
alert(
"WARNING: This node has a large number of descendants. Displaying them all may take a while or crash this browser window. Are you sure you want to continue? If so press the button again."
);
window.warning_shown = true;
return;
}
setListOutputModalOpen(true);
}}
>
List all tips
</Button></div>
<a
data-for="menu_descendants"
data-tip="8"
className="cursor-pointer"
>
{" "}
<FaShare className="inline-block" />
</a>
<ReactTooltip
id="menu_descendants"
getContent={(dataTip) => (
<div>
<h2>For this clade:</h2>
<div className="mb-3">
<Button
className="mb-2"
onClick={() => {
if (
selectedDetails.nodeDetails.num_tips > 100000 &&
!window.warning_shown
) {
// pop up a warning and ask if we want to continue
alert(
"WARNING: This node has a large number of descendants. Displaying them all may take a while or crash this browser window. Are you sure you want to continue? If so press the button again."
);
window.warning_shown = true;
return;
}
setListOutputModalOpen(true);
}}
>
List all tips
</Button>
</div>

{config.enable_ns_download && (
<>


<div className="mb-3"><Button className="" onClick={handleDownloadJson}>Download Nextstrain JSON</Button></div>


{backend.type === "server" && selectedDetails.nodeDetails[key]<20000 && (
<>
<div className="mb-3"><Button className=""
href={"https://nextstrain.org/fetch/"+
backend.getNextstrainJsonUrl(selectedDetails.nodeDetails.node_id, config).replace("https://","").replace("http://","")
}

>
View clade in NextStrain
</Button></div>
</>
)}
</>
)}
{config.enable_ns_download && (
<>
<div className="mb-3">
<Button className="" onClick={handleDownloadJson}>
Download Nextstrain JSON
</Button>
</div>

{config.covspectrum_links && (
<div className="mb-3">
<Button href={covSpectrumQuery} className="" >
Find in
CovSpectrum
</Button></div>
)}
{backend.type === "server" &&
selectedDetails.nodeDetails[key] < 20000 && (
<>
<div className="mb-3">
<Button
className=""
href={
"https://nextstrain.org/fetch/" +
backend
.getNextstrainJsonUrl(
selectedDetails.nodeDetails.node_id,
config
)
.replace("https://", "")
.replace("http://", "")
}
>
View clade in NextStrain
</Button>
</div>
</>
)}
</>
)}

</div> }
effect='solid'
delayHide={500}
delayShow={0}
delayUpdate={500}

place={'right'}
border={true}
type={'light'}
/>

{config.covspectrum_links && (
<div className="mb-3">
<Button href={covSpectrumQuery} className="">
Find in CovSpectrum
</Button>
</div>
)}
</div>
)}
effect="solid"
delayHide={500}
delayShow={0}
delayUpdate={500}
place={"right"}
border={true}
type={"light"}
/>
</span>
)}
</div>
Expand Down Expand Up @@ -428,7 +444,7 @@ function SearchPanel({
</div>
</>
)}

<div>
{selectedDetails.nodeDetails.acknowledgements && (
<div className="text-xs mt-3 text-gray-700 mr-3">
Expand All @@ -449,7 +465,6 @@ function SearchPanel({
</div>
)}
</div>

</div>
)}
</div>
Expand Down
32 changes: 16 additions & 16 deletions taxonium_web_client/src/hooks/useServerBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ function useServerBackend(backend_url, sid, url_on_fail) {
[backend_url, sid]
);

const getNextstrainJsonUrl = useCallback((nodeId, config) => {
return backend_url + "/nextstrain_json/" + nodeId ;


}, [backend_url]);


const getNextstrainJson = useCallback((nodeId, config) => {
const url = getNextstrainJsonUrl(nodeId, config);
// load this
window.location.href = url;


}, [getNextstrainJsonUrl]);
const getNextstrainJsonUrl = useCallback(
(nodeId, config) => {
return backend_url + "/nextstrain_json/" + nodeId;
},
[backend_url]
);

const getNextstrainJson = useCallback(
(nodeId, config) => {
const url = getNextstrainJsonUrl(nodeId, config);
// load this
window.location.href = url;
},
[getNextstrainJsonUrl]
);

return useMemo(() => {
return {
Expand All @@ -177,7 +177,7 @@ function useServerBackend(backend_url, sid, url_on_fail) {
type: "server",
backend_url: backend_url,
getNextstrainJson,
getNextstrainJsonUrl
getNextstrainJsonUrl,
};
}, [
queryNodes,
Expand All @@ -189,7 +189,7 @@ function useServerBackend(backend_url, sid, url_on_fail) {
getTipAtts,
backend_url,
getNextstrainJson,
getNextstrainJsonUrl
getNextstrainJsonUrl,
]);
}

Expand Down

1 comment on commit 5be489d

@vercel
Copy link

@vercel vercel bot commented on 5be489d Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.