New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
accept query parameters (for tags and categories) #28
accept query parameters (for tags and categories) #28
Conversation
@@ -147,6 +170,10 @@ function createToolListMarkup(parentEl) { | |||
} | |||
}); | |||
|
|||
if(categorieInUrl === keys[i]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: space after if
@@ -134,6 +156,7 @@ function getToolTooltip(id) { | |||
|
|||
function createToolListMarkup(parentEl) { | |||
var keys = Object.keys(COMPONENT_MAPPING); | |||
var categorieInUrl = getParameterByName("category"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: categoryInUrl
@@ -13,6 +13,28 @@ function hasFilter(name, filters) { | |||
return false; | |||
} | |||
|
|||
function getParameterByName(name, url) { | |||
if (!url) url = window.location.href; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer getting the parameters from window.location.search rather than href.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far! Thanks for the PR
} | ||
|
||
function parseTagsInUrl(url) { | ||
if (!url) url = window.location.search; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this line and the url parameter in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, my bad
@@ -13,6 +13,28 @@ function hasFilter(name, filters) { | |||
return false; | |||
} | |||
|
|||
function getParameterByName(name, url) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The url parameter is unused in the file, can you remove it?
@@ -13,6 +13,28 @@ function hasFilter(name, filters) { | |||
return false; | |||
} | |||
|
|||
function getParameterByName(name, url) { | |||
if (!url) url = window.location.search; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var urlParams = window.location.search;
@@ -13,6 +13,28 @@ function hasFilter(name, filters) { | |||
return false; | |||
} | |||
|
|||
function getParameterByName(name, url) { | |||
if (!url) url = window.location.search; | |||
name = name.replace(/[\[\]]/g, "\\$&"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a new line after this line
if (!url) url = window.location.search; | ||
name = name.replace(/[\[\]]/g, "\\$&"); | ||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | ||
results = regex.exec(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use var results
(we don't use the var x, y; notation)
and add a new line after this one.
I'll let @captainbrosset do a last review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Here are a few more comments.
var urlParams = window.location.search; | ||
name = name.replace(/[\[\]]/g, "\\$&"); | ||
|
||
var results = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)").exec(urlParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for parsing url parameters, the URL
constructor can be used instead:
var params = new URL(window.location).searchParams;
This gives you a ready to use object to retrieve the parameters. See https://developer.mozilla.org/en-US/docs/Web/API/URL
It seems to have decent browser support too except for Edge/IE, but I've never tested the site in these browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! It's a lot better than a Regex
@@ -134,6 +156,7 @@ function getToolTooltip(id) { | |||
|
|||
function createToolListMarkup(parentEl) { | |||
var keys = Object.keys(COMPONENT_MAPPING); | |||
var categoryInUrl = getParameterByName("category"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename category
to tool
. We don't use the word category anywhere in the code or the UI, and tool seems to me like a better fit. Also easier to type.
return decodeURIComponent(results[2].replace(/\+/g, " ")); | ||
} | ||
|
||
function parseTagsInUrl() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't parse tags. It retrieves them form the URL using another function and then sets the corresponding inputs.
So I suggest changing its name to setFiltersFromUrlParams
.
function parseTagsInUrl() { | ||
var easy = getParameterByName("easy"); | ||
var mentored = getParameterByName("mentored"); | ||
if (easy === "false" || (mentored === "true" && easy === null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About this logic: why do we need to even have values for easy
and mentored
.
It seems to me that this could work with just ?easy&mentored
, or ?easy
, or ?mentored
.
I don't think we need them to have true/false
as a value. It makes the URL harder to type, and we can derive the same meaning with the values.
So:
- if neither
easy
normentored
are part of the URL params, then we use to the default settings, - if
easy
is in the URL params but notmentored
, then we search for easy/non-mentored bugs - if
easy
is not in the URL params butmentored
is, then we search for non-easy/mentored bugs - if both
easy
andmentored
are in the URL params, then we search for easy/mentored bugs
How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it's easier to write.
} | ||
|
||
if (params.has(name)) { | ||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use double quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the new commits. Just a few final nit comments, I'm not blocking the review just for this, but if you do have time, it'd gladly take another commit with these fixed.
@@ -303,7 +342,7 @@ function matchesSearchString(bug) { | |||
var query = searchString.toLowerCase(); | |||
|
|||
return bug.summary.toLowerCase().indexOf(query) !== -1 || | |||
(bug.id + "").indexOf(query) !== -1; | |||
(bug.id + "").indexOf(query) !== -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this seems like an unrelated formatting change. Can you change it back?
@@ -280,7 +319,7 @@ function createBugMarkup(bug) { | |||
attributes: { | |||
"class": "tag old-bug", | |||
"title": "This bug has been inactive for more than " + | |||
INACTIVE_AFTER + " days" | |||
INACTIVE_AFTER + " days" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this seems like an unrelated formatting change. Can you change it back?
"component", | ||
"keywords", | ||
"mentors", | ||
"attachments"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this seems like an unrelated formatting change. Can you change it back?
Thanks @AmarOk1412 |
Cf. issue #25
Add 3 parameters. Now we can get http://firefox-dev.tools/?easy=true&mentored=true&category=inspector for example.