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

Modernise javascript #402

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Modernise javascript #402

wants to merge 11 commits into from

Conversation

MunyaradziMagura
Copy link
Collaborator

Pull Request Checklist

  • Pull request is based on the main branch
  • Pull request includes a sign off

… != operator is used for non-strict inequality comparison. Here are a few reasons why you might prefer to use !== instead of !=:

The !== operator checks both the value and the type of the operands, whereas the != operator performs type coercion, which can lead to unexpected results. By using !==, you ensure that the values being compared are of the same type, making your code more robust and less prone to errors.
we did not need to separate the URL variable into a separate "separated" variable so i changed it to one variable to get and split the variable.

also replaced some of the vars with const
Copy link
Contributor

@bahriddin bahriddin 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 bringing up this PR 👏🏽
I didn't get what exactly this chunk is doing but I am providing general feedback.

@@ -42,18 +42,22 @@ $( document ).on('turbolinks:load', function() {
});

// Check if filter needs to be applied
if ((window._search != undefined) && (window._search.length > 0 )) {
if ((window._search !== undefined) && (window._search.length > 0 )) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tested edge cases? AFAIK there is a difference between != and !==. For example,

null != undefined       // false
null !== undefined      // true

function openRequestedPopup() {
windowObjectReference = window.open(_scorecard_path, 'Scorecard', strWindowFeatures);
}
const openRequestedPopup = () => windowObjectReference = window.open(_scorecard_path, 'Scorecard', strWindowFeatures);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is windowObjectReference used somewhere?

function refreshParent() {
window.opener.location.reload();
}
const refreshParent = () => window.opener.location.reload();
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find its call. Could you please check if there is?

function openRequestedPopup(team_scorecards_path) {
windowObjectReference = window.open(team_scorecards_path, 'Team Scorecards', strWindowFeatures);
}
const openRequestedPopup = (team_scorecards_path) => windowObjectReference = window.open(team_scorecards_path, 'Team Scorecards', strWindowFeatures);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is windowObjectReference used somewhere?

window.opener.location.reload();
}

const refreshParent = () => window.opener.location.reload();
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find its call. Could you please check if there is?

Comment on lines +53 to +57
const url = window.location.href;
const tail = url.substring(url.lastIndexOf('/') + 1);

// Remove any query parameters from the segment
const clean_tail = tail.substring(0, tail.lastIndexOf('?'));
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the whole purpose of these lines are to clean up the url. In this case we should wrap it into one function. Please, take this code as an example only:

Suggested change
const url = window.location.href;
const tail = url.substring(url.lastIndexOf('/') + 1);
// Remove any query parameters from the segment
const clean_tail = tail.substring(0, tail.lastIndexOf('?'));
...
const url_tail_without_parameters = url => {
const tail = url.substring(url.lastIndexOf('/') + 1);
// Remove any query parameters from the segment
return tail.substring(0, tail.lastIndexOf('?'));
}
...
const clean_tail = url_tail_without_parameters(window.location.href);

$("#hiddendescription").html(content);
$("#team_data_set_description").css("height", $("#hiddendescription").outerHeight());
} catch (e) {

console.error('An error occured.', e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Dp we use some error monitoring service like BugSnag?

@astley92 astley92 removed their request for review June 27, 2023 03:20
@bmpickford bmpickford removed their assignment Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean code a refactor would be good
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants