Skip to content

Commit 637c5be

Browse files
authored
Add branch URL parameter support with Copy Link button (#7465)
- Add ?branch= URL parameter support for shareable links - Add "Copy Link" button next to branch input field - URL parameter takes precedence over localStorage - Button shows "Copied!" feedback after copying This enables sharing visualization links with specific branch configurations.
1 parent 38e27aa commit 637c5be

File tree

10 files changed

+109
-12
lines changed

10 files changed

+109
-12
lines changed

doc/cost-models/lookupcoin/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ <h3 id="data-source-toggle">Data Source Configuration</h3>
3030
<div class="controls-content">
3131
<div class="control-group-vertical">
3232
<label for="branch-name">Branch name:</label>
33-
<input type="text" id="branch-name" placeholder="master" style="width: 100%; font-family: monospace;">
33+
<div class="branch-input-row">
34+
<input type="text" id="branch-name" placeholder="master">
35+
<button id="copy-link" title="Copy shareable link">Copy Link</button>
36+
</div>
3437
</div>
3538
<div class="control-group-vertical">
3639
<label for="csv-url">CSV file URL:</label>

doc/cost-models/lookupcoin/plot.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ function getFileUrls(baseUrl) {
3939
};
4040
}
4141

42-
// Load settings from localStorage
42+
// Load settings from localStorage (URL param takes precedence)
4343
function loadSettings() {
44+
const urlBranch = getBranchFromUrl();
4445
return {
45-
branch: localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
46+
branch: urlBranch || localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
4647
csvUrl: localStorage.getItem(STORAGE_KEYS.CSV_URL) || '',
4748
jsonUrl: localStorage.getItem(STORAGE_KEYS.JSON_URL) || '',
4849
collapsed: localStorage.getItem(STORAGE_KEYS.DATA_SOURCE_COLLAPSED) === 'true'
@@ -136,6 +137,20 @@ async function init() {
136137
// Set up plot control event listeners (only once)
137138
setupControls();
138139

140+
// Set up copy link button
141+
document.getElementById('copy-link').addEventListener('click', () => {
142+
const branch = document.getElementById('branch-name').value.trim() || DEFAULT_BRANCH;
143+
const url = new URL(window.location.href);
144+
url.search = '';
145+
url.searchParams.set('branch', branch);
146+
navigator.clipboard.writeText(url.toString());
147+
// Brief visual feedback
148+
const btn = document.getElementById('copy-link');
149+
const original = btn.textContent;
150+
btn.textContent = 'Copied!';
151+
setTimeout(() => btn.textContent = original, 1500);
152+
});
153+
139154
// Initial load
140155
await loadAndRenderData();
141156
}

doc/cost-models/shared/styles.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ nav a.active {
273273
color: var(--academic-gray);
274274
}
275275

276+
.branch-input-row {
277+
display: flex;
278+
gap: 8px;
279+
align-items: center;
280+
}
281+
282+
.branch-input-row input {
283+
flex: 1;
284+
font-family: 'Monaco', 'Courier New', monospace;
285+
}
286+
287+
.branch-input-row button {
288+
padding: 6px 12px;
289+
font-size: 0.85em;
290+
}
291+
276292
button {
277293
background-color: var(--cardano-blue);
278294
color: white;

doc/cost-models/shared/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,12 @@ async function loadData(csvUrl, jsonUrl) {
381381
throw error;
382382
}
383383
}
384+
385+
/**
386+
* Get branch name from URL query parameter
387+
* @returns {string|null} Branch name or null if not specified
388+
*/
389+
function getBranchFromUrl() {
390+
const params = new URLSearchParams(window.location.search);
391+
return params.get('branch');
392+
}

doc/cost-models/unvaluedata/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ <h3 id="data-source-toggle">Data Source Configuration</h3>
3030
<div class="controls-content">
3131
<div class="control-group-vertical">
3232
<label for="branch-name">Branch name:</label>
33-
<input type="text" id="branch-name" placeholder="master" style="width: 100%; font-family: monospace;">
33+
<div class="branch-input-row">
34+
<input type="text" id="branch-name" placeholder="master">
35+
<button id="copy-link" title="Copy shareable link">Copy Link</button>
36+
</div>
3437
</div>
3538
<div class="control-group-vertical">
3639
<label for="csv-url">CSV file URL:</label>

doc/cost-models/unvaluedata/plot.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ function getFileUrls(baseUrl) {
3939
};
4040
}
4141

42-
// Load settings from localStorage
42+
// Load settings from localStorage (URL param takes precedence)
4343
function loadSettings() {
44+
const urlBranch = getBranchFromUrl();
4445
return {
45-
branch: localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
46+
branch: urlBranch || localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
4647
csvUrl: localStorage.getItem(STORAGE_KEYS.CSV_URL) || '',
4748
jsonUrl: localStorage.getItem(STORAGE_KEYS.JSON_URL) || '',
4849
collapsed: localStorage.getItem(STORAGE_KEYS.DATA_SOURCE_COLLAPSED) === 'true'
@@ -136,6 +137,20 @@ async function init() {
136137
// Set up plot control event listeners (only once)
137138
setupControls();
138139

140+
// Set up copy link button
141+
document.getElementById('copy-link').addEventListener('click', () => {
142+
const branch = document.getElementById('branch-name').value.trim() || DEFAULT_BRANCH;
143+
const url = new URL(window.location.href);
144+
url.search = '';
145+
url.searchParams.set('branch', branch);
146+
navigator.clipboard.writeText(url.toString());
147+
// Brief visual feedback
148+
const btn = document.getElementById('copy-link');
149+
const original = btn.textContent;
150+
btn.textContent = 'Copied!';
151+
setTimeout(() => btn.textContent = original, 1500);
152+
});
153+
139154
// Initial load
140155
await loadAndRenderData();
141156
}

doc/cost-models/valuecontains/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ <h3 id="data-source-toggle">Data Source Configuration</h3>
3030
<div class="controls-content">
3131
<div class="control-group-vertical">
3232
<label for="branch-name">Branch name:</label>
33-
<input type="text" id="branch-name" placeholder="master" style="width: 100%; font-family: monospace;">
33+
<div class="branch-input-row">
34+
<input type="text" id="branch-name" placeholder="master">
35+
<button id="copy-link" title="Copy shareable link">Copy Link</button>
36+
</div>
3437
</div>
3538
<div class="control-group-vertical">
3639
<label for="csv-url">CSV file URL:</label>

doc/cost-models/valuecontains/plot.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ function getFileUrls(baseUrl) {
3939
};
4040
}
4141

42-
// Load settings from localStorage
42+
// Load settings from localStorage (URL param takes precedence)
4343
function loadSettings() {
44+
const urlBranch = getBranchFromUrl();
4445
return {
45-
branch: localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
46+
branch: urlBranch || localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
4647
csvUrl: localStorage.getItem(STORAGE_KEYS.CSV_URL) || '',
4748
jsonUrl: localStorage.getItem(STORAGE_KEYS.JSON_URL) || '',
4849
collapsed: localStorage.getItem(STORAGE_KEYS.DATA_SOURCE_COLLAPSED) === 'true'
@@ -136,6 +137,20 @@ async function init() {
136137
// Set up plot control event listeners (only once)
137138
setupControls();
138139

140+
// Set up copy link button
141+
document.getElementById('copy-link').addEventListener('click', () => {
142+
const branch = document.getElementById('branch-name').value.trim() || DEFAULT_BRANCH;
143+
const url = new URL(window.location.href);
144+
url.search = '';
145+
url.searchParams.set('branch', branch);
146+
navigator.clipboard.writeText(url.toString());
147+
// Brief visual feedback
148+
const btn = document.getElementById('copy-link');
149+
const original = btn.textContent;
150+
btn.textContent = 'Copied!';
151+
setTimeout(() => btn.textContent = original, 1500);
152+
});
153+
139154
// Initial load
140155
await loadAndRenderData();
141156
}

doc/cost-models/valuedata/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ <h3 id="data-source-toggle">Data Source Configuration</h3>
3030
<div class="controls-content">
3131
<div class="control-group-vertical">
3232
<label for="branch-name">Branch name:</label>
33-
<input type="text" id="branch-name" placeholder="master" style="width: 100%; font-family: monospace;">
33+
<div class="branch-input-row">
34+
<input type="text" id="branch-name" placeholder="master">
35+
<button id="copy-link" title="Copy shareable link">Copy Link</button>
36+
</div>
3437
</div>
3538
<div class="control-group-vertical">
3639
<label for="csv-url">CSV file URL:</label>

doc/cost-models/valuedata/plot.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ function getFileUrls(baseUrl) {
3939
};
4040
}
4141

42-
// Load settings from localStorage
42+
// Load settings from localStorage (URL param takes precedence)
4343
function loadSettings() {
44+
const urlBranch = getBranchFromUrl();
4445
return {
45-
branch: localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
46+
branch: urlBranch || localStorage.getItem(STORAGE_KEYS.BRANCH) || DEFAULT_BRANCH,
4647
csvUrl: localStorage.getItem(STORAGE_KEYS.CSV_URL) || '',
4748
jsonUrl: localStorage.getItem(STORAGE_KEYS.JSON_URL) || '',
4849
collapsed: localStorage.getItem(STORAGE_KEYS.DATA_SOURCE_COLLAPSED) === 'true'
@@ -136,6 +137,20 @@ async function init() {
136137
// Set up plot control event listeners (only once)
137138
setupControls();
138139

140+
// Set up copy link button
141+
document.getElementById('copy-link').addEventListener('click', () => {
142+
const branch = document.getElementById('branch-name').value.trim() || DEFAULT_BRANCH;
143+
const url = new URL(window.location.href);
144+
url.search = '';
145+
url.searchParams.set('branch', branch);
146+
navigator.clipboard.writeText(url.toString());
147+
// Brief visual feedback
148+
const btn = document.getElementById('copy-link');
149+
const original = btn.textContent;
150+
btn.textContent = 'Copied!';
151+
setTimeout(() => btn.textContent = original, 1500);
152+
});
153+
139154
// Initial load
140155
await loadAndRenderData();
141156
}

0 commit comments

Comments
 (0)