Skip to content

Commit

Permalink
Add snakeCasing to handle GLAM metric naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
robhudson committed Jan 13, 2021
1 parent 7c5eae5 commit 9c49d3f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/pages/MetricDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,33 @@
};
if (Object.keys(map).includes(app)) {
const p = map[app];
return `https://glam.telemetry.mozilla.org/${p.product}/probe/${metric}/export?app_id=${p.app_id}`;
return `https://glam.telemetry.mozilla.org/${p.product}/probe/${snakeCase(metric)}/explore?app_id=${p.app_id}`;
}
// The app isn't one GLAM supports so return nothing.
return null;
}
/*
* Regular expression description (since JS doesn't have an ignore whitespace flag):
* \b+ // Standard word boundary
* |(?<=[a-z][A-Z])(?=\d*[A-Z]) // A7Aa -> A7|Aa boundary
* |(?<=[a-z][A-Z])(?=\d*[a-z]) // a7Aa -> a7|Aa boundary
* |(?<=[A-Z])(?=\d*[a-z]) // a7A -> a7|A boundary
*/
function snakeCase(str) {
// Convert a string into a snake_cased string.
// Replace non-alphanumeric characters with spaces in the reversed string.
const subbed = str.split('').reverse().join('').replace(/[^\w]|_/g, ' ');
// Apply the regexp on the reversed string.
const words = subbed.split(/\b|(?<=[a-z][A-Z])(?=\d*[A-Z])|(?<=[a-z][A-Z])(?=\d*[a-z])|(?<=[A-Z])(?=\d*[a-z])/);
// Filter spaces between words and snake_case.
const filtered = words.filter((w) => w.trim() !== '').map((w) => w.toLowerCase()).join('_');
// Return string reversed again.
return filtered.split('').reverse().join('')
}
const glamUrl = getGlamUrl(params.app, metricName);
function getMetricDocumentationURI(type) {
Expand Down

0 comments on commit 9c49d3f

Please sign in to comment.