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

Refactor java script so that project meetings page sources meeting data from vrms data.json #6059 #7873

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from

Conversation

innith
Copy link
Member

@innith innith commented Feb 2, 2025

Fixes #6059

What changes did you make?

  • Refactored the code in assets/js/project-meetings.js to source data from data/external/vrms_data.json, using functions in assets/js/utility/vrms-events.js
  • Added assets/js/project-meetings-check.js to evaluate the changes made to assets/js/project-meetings.js

Why did you make the changes (we will use this info to test)?

CodeQL Alerts

After the PR has been submitted and the resulting GitHub actions/checks have been completed, developers should check the PR for CodeQL alert annotations.

Check the PR's comments. If present on your PR, the CodeQL alert looks similar as shown

Screenshot 2024-10-28 154514

Please let us know that you have checked for CodeQL alerts. Please do not dismiss alerts.

  • I have checked this PR for CodeQL alerts and none were found.
  • I found CodeQL alert(s), and (select one):
    • I have resolved the CodeQL alert(s) as noted
    • I believe the CodeQL alert(s) is a false positive (Merge Team will evaluate)
    • I have followed the Instructions below, but I am still stuck (Merge Team will evaluate)
Instructions for resolving CodeQL alerts

If CodeQL alert/annotations appear, refer to How to Resolve CodeQL alerts.

In general, CodeQL alerts should be resolved prior to PR reviews and merging

Screenshots of Proposed Changes To The Website (if any, please do not include screenshots of code changes)

Visuals before changes are applied

No visual changes applied

Visuals after changes are applied

No visual changes applied

Copy link

github-actions bot commented Feb 2, 2025

Want to review this pull request? Take a look at this documentation for a step by step guide!


From your project repository, check out a new branch and test the changes.

git checkout -b innith-Refactor-JavaScript-so-that-Project-Meetings-page-sources-meeting-data-from-vrms_data.json-#6059 gh-pages
git pull https://github.com/innith/website.git Refactor-JavaScript-so-that-Project-Meetings-page-sources-meeting-data-from-vrms_data.json-#6059

@github-actions github-actions bot added role: front end Tasks for front end developers Complexity: Medium P-Feature: Project Meetings https://www.hackforla.org/project-meetings size: 1pt Can be done in 4-6 hours labels Feb 2, 2025
@Cloid
Copy link
Member

Cloid commented Feb 3, 2025

Review ETA: EOD 2/08/25
Availability: 5-8 PM Weekdays

@Cloid Cloid self-requested a review February 3, 2025 02:08
Copy link
Member

@Cloid Cloid left a comment

Choose a reason for hiding this comment

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

The code refactor is really good and meets the condition of the case. Looking at both live and this branch changes, there is a reduce in latency. Good job. The only changes I request are just simplifying the logic so it's easier to read and debug. Will approve after.


const formatedEvents = formatEventData(eventData)

for (const [key, value] of Object.entries(formatedEvents)) {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend changing [key, value] to [day, event] for readability

Comment on lines +39 to +60
if (!value.length) {
placeToInsert.insertAdjacentHTML(
"beforeend",
`<li>There are no meetings scheduled.</li>`
);
} else {
value.forEach((event) => {
if (event) {
// If a project doesn't have an hflaWebsiteUrl, redirect to the project's Github page
if (event.hflaWebsiteUrl == "") {
event.hflaWebsiteUrl = event.githubUrl
}
let eventHtml;
// insert the correct html for the current page
if (page === "events") {
eventHtml = `<li>${event.start} - ${event.end} </li><li><a href="${event.hflaWebsiteUrl}">${event.name}</a> ${event.meetingName}${event.dsc.length > 0 ? "*" : ""}</li>`;
} else {
if (event.dsc != "") event.meetingName += ", ";
eventHtml = `<li>${event.start} - ${event.end} <a href="${event.hflaWebsiteUrl}">${event.name}</a> ${event.meetingName} ${event.dsc}</li>`;
}
placeToInsert.insertAdjacentHTML("beforeend", eventHtml);
}
Copy link
Member

Choose a reason for hiding this comment

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

An if/else inside an if/else can usually be simplified. It just makes it easier for readability and not having to keep track of different types of branch logic. I'll attach the code with fewer if/else:

// check if the day has any events
    if (!events.length) {
      placeToInsert.insertAdjacentHTML(
        "beforeend",
        `<li>There are no meetings scheduled.</li>`
      );
      continue;
    }

    events.forEach((event) => {
        if(!event) return;
        // If a project doesn't have an hflaWebsiteUrl, redirect to the project's Github page
        if (!event.hflaWebsiteUrl) event.hflaWebsiteUrl = event.githubUrl
        
        let eventHtml;
        // insert the correct html for the current page
        if (page === "events") {
          eventHtml = `<li>${event.start} - ${event.end} </li><li><a href="${event.hflaWebsiteUrl}">${event.name}</a> ${event.meetingName}${event.dsc.length > 0 ? "*" : ""}</li>`;
        } else {
          if (event.dsc != "") event.meetingName += ", ";
          eventHtml = `<li>${event.start} - ${event.end} <a href="${event.hflaWebsiteUrl}">${event.name}</a> ${event.meetingName} ${event.dsc}</li>`;
        }
        placeToInsert.insertAdjacentHTML("beforeend", eventHtml);
      
    });

};
responseData.forEach((item) => {
let day_of_week = getDayString(item.date);
return_obj[day_of_week].push(display_object(item));
Copy link
Member

Choose a reason for hiding this comment

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

From what I understand with js, even if a function has no return value, it'll return an undefined. We can avoid the unnecessary push by declaring it and adding conditional here and readjusting the display_object if conditional to be null if met.

const event = display_object(item);
if (event) return_obj[day_of_week].push(event);

for display_object:

if (!item?.project?.name || item.project.name === "Hack4LA" || /^Test\b/i.test(item.project.name)) {
    return null;
  }
  

@innith
Copy link
Member Author

innith commented Feb 9, 2025

The code refactor is really good and meets the condition of the case. Looking at both live and this branch changes, there is a reduce in latency. Good job. The only changes I request are just simplifying the logic so it's easier to read and debug. Will approve after.

Hi @Cloid , The recommended changes do make the code a lot easier and simpler. However, I see scope for further refactoring the almost similar assets/js/project-meetings.js and assets/js/right-col-content.js files to move their common functions into a utility file (the recommended changes and further optimizations could be better done there). for now, I believe keeping the code similar to assets/js/right-col-content.js could reinforce the necessity of creating the utility file, which would lead to further optimization of the code.

@Cloid
Copy link
Member

Cloid commented Feb 9, 2025

I agree that consolidating it into a single utility file would be more efficient. I was working under the assumption that this wasn’t an option. If that is the end goal, it would be helpful to mention it in both the PR and the Issue itself to ensure clear communication with the team. I'll approve it right after. Definitely, good catch on the similarities.

@mugdhchauhan mugdhchauhan self-requested a review February 12, 2025 03:51
@mugdhchauhan
Copy link
Member

Review ETA: 12 Feb 2025 @ 6 PM (GMT)
Availability: Daily @ 6 PM - 8 PM (GMT)

Copy link
Member

@mugdhchauhan mugdhchauhan left a comment

Choose a reason for hiding this comment

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

Hey @innith, thank you for working on this. Nice work!

Kudos

  • The pull request is made with the correct branch.
  • The pull request post contains a linked issue, and what changes you made and why are clear.
  • The changes to the files are accurate. (Even though the changes that are made to the assets/js/project-meetings.js are copied from lines 26 - 123 of assets/js/right-col-content.js it is ok to do so in this particular case.)
  • You have claimed the orginiating issue well (Refactor JavaScript so that Project Meetings page sources meeting data from vrms_data.json #6059).
  • I can see the changes in my local environment.

Suggested changes

  • For the "CodeQL Alerts" section of the PR post, please check off the relevant box(es).
  • For the Screenshots section of the PR post, you can remove the dropdowns and put "No visual changes to website".
  • You could also update the PR post title like this: Refactor JavaScript so that Project Meetings page sources meeting data from vrms_data.json

After making these changes, please re-request a review from me. Feel free to reach out if you need help with anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complexity: Medium P-Feature: Project Meetings https://www.hackforla.org/project-meetings role: front end Tasks for front end developers size: 1pt Can be done in 4-6 hours
Projects
Status: PRs being reviewed
Development

Successfully merging this pull request may close these issues.

Refactor JavaScript so that Project Meetings page sources meeting data from vrms_data.json
3 participants