Skip to content

Commit d687281

Browse files
committed
fix: External EM links now use id instead of library.
The EM libraries all use a fully qualified id string that contains the dataset and the body id. This can be split and used to generate the relevant links.
1 parent 5bb53be commit d687281

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/components/ExternalLink.jsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,29 @@ export default function ExternalLink({ id, isLM, library, publishedName }) {
7878
);
7979
}
8080

81-
// is an EM library
82-
let dataset = library
83-
.replace(/flyem_/i, "")
84-
.toLowerCase()
85-
.replace("_v", ":v")
86-
.replace(/\s+/g, "_");
87-
88-
// TODO: fix the pre-release site dataset since it shouldn't be missing the
81+
// This is an EM library, so process with alternative logic
82+
83+
// The ids are in the format of library:vX:idnumber, eg: male-cns:v0.9:17253
84+
// We need to extract the dataset from the bodyId to construct the neuprint link
85+
// eg: id = male-cns:v0.9:17253 -> dataset = male-cns:v0.9 ; bodyId = 17253
86+
// This can be accomplished by splitting on the second colon and using the first part as
87+
// the dataset and the last part as the bodyId
88+
let dataset;
89+
let bodyId;
90+
91+
const match = id.match(/^([^:]*:[^:]*):(.*)$/);
92+
if (!match) { // Fallback if the id doesn't match the expected fully qualified id format
93+
dataset = library
94+
.replace(/flyem_/i, "")
95+
.toLowerCase()
96+
.replace("_v", ":v")
97+
.replace(/\s+/g, "_");
98+
bodyId = id.split(":").pop();
99+
} else {
100+
[, dataset, bodyId] = match;
101+
}
102+
103+
// TODO: fix the pre-release site dataset since it shouldn't be missing the
89104
// version number, but the pre-release site doesn't have a version number.
90105
// Also, the pre-release data on neuprint was called vnc and not manc, so the
91106
// dataset name needs to be converted as well.
@@ -105,7 +120,7 @@ export default function ExternalLink({ id, isLM, library, publishedName }) {
105120
: "https://neuprint.janelia.org/view?dataset=<DATASET>&bodyid=<NAME>";
106121

107122
const finalEMUrl = emUrl
108-
.replace(/<NAME>/, id.split(":").slice(-1))
123+
.replace(/<NAME>/, bodyId)
109124
.replace(/<DATASET>/, dataset);
110125

111126
const secondaryLink = library.match(/flywire_fafb/i) ? (

src/components/__tests__/ExternalLink.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe("ExternalLink: unit tests", () => {
101101
);
102102
expect(getByText("NeuPrint")).toHaveAttribute(
103103
"href",
104-
"https://neuprint.janelia.org/view?dataset=flylight_splitgal4_drivers&bodyid=foo"
104+
"https://neuprint.janelia.org/view?dataset=bar_set:v1.0&bodyid=foo"
105105
);
106106

107107
rerender(<ExternalLink id="foo" isLM={false} library="FlyLight Split-GAL4 Drivers" />);

0 commit comments

Comments
 (0)