Skip to content

Commit

Permalink
feat: render primers as a colour-coded tag
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Oct 21, 2023
1 parent e648e5d commit 2105232
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/bits/Primer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { memo, useMemo } from "react";
import { Tag } from "antd";

const colors = [
"magenta",
"red",
"volcano",
"orange",
"gold",
"lime",
"green",
"cyan",
"blue",
"geekblue",
"purple",
];

const Primer = memo(({ name }) => {
const colorIndex = Array.from(new TextEncoder().encode(name)).reduce((acc, x) => acc + x, 0) % colors.length;
return <Tag color={colors[colorIndex]} style={{ margin: "0.2em 0.5em 0.2em 0" }}>{name}</Tag>;
});

export default Primer;
9 changes: 4 additions & 5 deletions src/lib/datasets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import groupBy from "lodash/groupBy";
import { Popover } from "antd";
import Primer from "../bits/Primer";

export const PRIMER_GROUPINGS = ["Taxa_group", "Phylum", "Order", "Family", "Genus", "Final_ID"];

Expand All @@ -23,11 +24,9 @@ const taxaRecGroup = (arr, groupings, pathStr) => {
const baseRecord = {
title: isSpeciesLevel ? <span>
<em>{k.split("_").join(" ")}</em>{" "}
<Popover title="Primers" content={<ul style={{ margin: 0, paddingLeft: "1em" }}>
{v.map(p => <li key={`${k}-${p["Primer_name"]}`} style={{ fontFamily: "monospace" }}>
{p["Primer_name"]}
</li>)}
</ul>}>
<Popover title="Primers" content={
v.map(p => <Primer key={`${k}-${p["Primer_name"]}`} name={p["Primer_name"]} />)
}>
(<a href="#" onClick={preventDefault}>
{v.length} available {v.length === 1 ? "primer" : "primers"}
</a>)
Expand Down
2 changes: 1 addition & 1 deletion src/steps/DatasetStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DatasetStep = ({ visible, dataset, setDataset, onFinish }) => {
if (onParseFinish) onParseFinish();

const dataset = createDataset(data);
console.log(dataset);
console.debug("dataset:", dataset);
setDataset(dataset);
});
} finally {
Expand Down
4 changes: 3 additions & 1 deletion src/steps/DiscoverStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
Typography
} from "antd";
import { ArrowLeftOutlined, ArrowRightOutlined, SearchOutlined } from "@ant-design/icons";

import Primer from "../bits/Primer";
import { pluralize } from "../lib/utils";

const DiscoverStep = ({ visible, dataset, onBack, onFinish }) => {
Expand Down Expand Up @@ -244,7 +246,7 @@ const DiscoverStep = ({ visible, dataset, onBack, onFinish }) => {
<div>
<strong>Primers:</strong><br />
{Array.from(r.primers).map((p) => (
<Tag style={{ marginRight: "0.5em" }}>{p}</Tag>
<Primer key={p} name={p} />
))}
</div>
<div>
Expand Down

0 comments on commit 2105232

Please sign in to comment.