Skip to content

Commit 83c3386

Browse files
authored
Merge pull request #468 from vgteam/fix-link
Fix link generation to include path
2 parents 0862fda + 177da35 commit 83c3386

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/components/CopyLink.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ export function CopyLink(props) {
3131
// https://github.com/ljharb/qs#stringifying
3232
const params = qs.stringify(viewTarget, { encodeValuesOnly: true });
3333
console.log("params ", params);
34-
// complete url
35-
const full = window.location.origin + "?" + params;
36-
console.log(full);
34+
35+
// Make a new URL based off the current one
36+
let url = new URL(window.location.toString());
37+
url.search = "?" + params;
38+
url.hash = "";
39+
console.log(url);
3740

3841
try {
3942
// copy full to clipboard
40-
copyCallback(full);
43+
copyCallback(url.toString());
4144
// change text
4245
setText(CLICKED_TEXT);
4346
} catch (err) {
4447
setText(UNCLICKED_TEXT);
45-
setDialogLink(full);
48+
setDialogLink(url.toString());
4649
console.log("copy error");
4750
}
4851
};
@@ -79,11 +82,11 @@ export const urlParamsToViewTarget = (url) => {
7982
// and turn to object to populate in HeaderForm state and viewTarget
8083
// Returns: Object (viewTarget) - see App.js
8184

82-
var result = null;
83-
const s = url.href.split("?");
85+
let parsed = new URL(url);
86+
let result = null;
8487
// If url contains information on viewObject
85-
if (s[1]) {
86-
result = qs.parse(s[1]);
88+
if (parsed.search) {
89+
result = qs.parse(parsed.search.substr(1));
8790
}
8891

8992

src/end-to-end.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ describe("When we wait for it to load", () => {
339339
it("produces correct link for view before & after go is pressed", async () => {
340340
// First test that after pressing go, the link reflects the dat form
341341
const expectedLinkBRCA1 =
342-
"http://localhost?name=snp1kg-BRCA1&tracks[0][trackFile]=exampleData%2Finternal%2Fsnp1kg-BRCA1.vg.xg&tracks[0][trackType]=graph&tracks[0][trackColorSettings][mainPalette]=greys&tracks[0][trackColorSettings][auxPalette]=ygreys&tracks[1][trackFile]=exampleData%2Finternal%2FNA12878-BRCA1.sorted.gam&tracks[1][trackType]=read&region=17%3A1-100&bedFile=exampleData%2Finternal%2Fsnp1kg-BRCA1.bed&dataType=built-in&simplify=false&removeSequences=false";
342+
"http://localhost/?name=snp1kg-BRCA1&tracks[0][trackFile]=exampleData%2Finternal%2Fsnp1kg-BRCA1.vg.xg&tracks[0][trackType]=graph&tracks[0][trackColorSettings][mainPalette]=greys&tracks[0][trackColorSettings][auxPalette]=ygreys&tracks[1][trackFile]=exampleData%2Finternal%2FNA12878-BRCA1.sorted.gam&tracks[1][trackType]=read&region=17%3A1-100&bedFile=exampleData%2Finternal%2Fsnp1kg-BRCA1.bed&dataType=built-in&simplify=false&removeSequences=false";
343343
// Set up dropdown
344344
await act(async () => {
345345
let dropdown = document.getElementById("dataSourceSelect");
@@ -373,7 +373,7 @@ it("produces correct link for view before & after go is pressed", async () => {
373373
await clickCopyLink();
374374

375375
const expectedLinkCactus =
376-
"http://localhost?tracks[0][trackFile]=exampleData%2Fcactus.vg.xg&tracks[0][trackType]=graph&tracks[1][trackFile]=exampleData%2Fcactus-NA12879.sorted.gam&tracks[1][trackType]=read&bedFile=exampleData%2Fcactus.bed&name=cactus&region=ref%3A1-100&dataType=built-in&simplify=false&removeSequences=false";
376+
"http://localhost/?tracks[0][trackFile]=exampleData%2Fcactus.vg.xg&tracks[0][trackType]=graph&tracks[1][trackFile]=exampleData%2Fcactus-NA12879.sorted.gam&tracks[1][trackType]=read&bedFile=exampleData%2Fcactus.bed&name=cactus&region=ref%3A1-100&dataType=built-in&simplify=false&removeSequences=false";
377377
// Make sure link has changed after pressing go
378378
expect(fakeClipboard).toEqual(expectedLinkCactus);
379379
}, 20000);

0 commit comments

Comments
 (0)