Skip to content
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

Merged
merged 6 commits into from Oct 14, 2016

Conversation

AmarOk1412
Copy link

Cf. issue #25

Add 3 parameters. Now we can get http://firefox-dev.tools/?easy=true&mentored=true&category=inspector for example.

@@ -147,6 +170,10 @@ function createToolListMarkup(parentEl) {
}
});

if(categorieInUrl === keys[i]) {
Copy link

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");
Copy link

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;
Copy link

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.

Copy link

@nt1m nt1m left a 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;
Copy link

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?

Copy link
Author

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) {
Copy link

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;
Copy link

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, "\\$&");
Copy link

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);
Copy link

@nt1m nt1m Oct 10, 2016

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.

@nt1m
Copy link

nt1m commented Oct 11, 2016

I'll let @captainbrosset do a last review.

Copy link

@captainbrosset captainbrosset left a 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);
Copy link

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.

Copy link
Author

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");

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() {

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)) {

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 nor mentored are part of the URL params, then we use to the default settings,
  • if easy is in the URL params but not mentored, then we search for easy/non-mentored bugs
  • if easy is not in the URL params but mentored is, then we search for non-easy/mentored bugs
  • if both easy and mentored are in the URL params, then we search for easy/mentored bugs

How does that sound?

Copy link
Author

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 '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use double quotes

Copy link

@captainbrosset captainbrosset left a 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;

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"

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"],

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?

@captainbrosset captainbrosset merged commit e2dab05 into firefox-devtools:gh-pages Oct 14, 2016
@captainbrosset
Copy link

Thanks @AmarOk1412

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants