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 project styling #295

Closed
wants to merge 17 commits into from
Closed

Refactor project styling #295

wants to merge 17 commits into from

Conversation

DinneK
Copy link
Contributor

@DinneK DinneK commented Dec 6, 2024

module-name: Add Styling to project page

Problem

The project page needs to match the wireframes created for 3.0

Solution

Project page general styling finished. Pagination refactored to match USWDS design system and Metrics specs.

Result

Search bars still need some tweaks.

Test Plan

tested locally and in prod.

Next steps:

  • Fix nav menu
  • Finish org charts
  • Finish project charts
  • Mobile view
  • Bug fixes

Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
Signed-off-by: Dinne Kopelevich <[email protected]>
@DinneK DinneK added enhancement New feature or request front-end javascript Pull requests that update Javascript code metrics labels Dec 6, 2024
@DinneK DinneK self-assigned this Dec 6, 2024
paginationList.appendChild(prevItem);

const pageRange = getPageRange(currentPage, totalPages, 3);
pageRange.forEach((page, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <no-unused-vars> reported by reviewdog 🐶
'index' is defined but never used.

const searchForm = document.getElementById('search-form');
const searchBox = document.getElementById("search-input");
const projectList = document.getElementById("content-container")
const projectCards = projectList.getElementsByClassName("project-card")
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <no-unused-vars> reported by reviewdog 🐶
'projectCards' is assigned a value but never used.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

prettier

[prettier] reported by reviewdog 🐶

list-style-type:none;


[prettier] reported by reviewdog 🐶

background-color: #E0EAF8;


[prettier] reported by reviewdog 🐶

font-weight: 600;


[prettier] reported by reviewdog 🐶

background-color: #E0EAF8;


[prettier] reported by reviewdog 🐶

box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;


[prettier] reported by reviewdog 🐶

box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;


[prettier] reported by reviewdog 🐶


[prettier] reported by reviewdog 🐶

const toggleButton = document.querySelector(".usa-accordion__button");
const closeButton = document.querySelector(".usa-nav__close");
const menu = document.querySelector(".usa-nav");
const menuIcon = document.querySelector(".usa-accordion__button svg use");


[prettier] reported by reviewdog 🐶

if (toggleButton && closeButton && menu) {


[prettier] reported by reviewdog 🐶

toggleButton.addEventListener("click", () => {
const isOpen = menu.classList.toggle("is-hidden");


[prettier] reported by reviewdog 🐶

menuIcon.setAttribute(
"href",
isOpen ? "/assets/img/sprite.svg#close" : "/assets/img/sprite.svg#menu"
);
});


[prettier] reported by reviewdog 🐶

closeButton.addEventListener("click", () => {
menu.classList.remove("is-hidden");
menuIcon.setAttribute("href", "/assets/img/sprite.svg#menu");
});
} else {
console.error("One or more elements is not found")
}


[prettier] reported by reviewdog 🐶

document.addEventListener("DOMContentLoaded", createNavigation)


[prettier] reported by reviewdog 🐶

import { reportHeadingTemplate, projectCardTemplate } from "./templates";
import DOMPurify from 'dompurify';
const projectsData = document.getElementById('metrics').textContent;
const orgsData = document.getElementById('org-data').textContent;
const parsedOrgsData = JSON.parse(orgsData);
const siteData = JSON.parse(document.getElementById('site-data').textContent);
const parsedProjectsData = JSON.parse(projectsData);
const filtersContainer = document.querySelector('.filters-container');
const templateDiv = document.getElementById('content-container');


[prettier] reported by reviewdog 🐶

const sortDirection = document.getElementById('sort-direction');
const sortSelection = document.getElementById('sort-selection');
let currentPage = 1;
const itemsPerPage = 10;
let filteredProjects = [...parsedProjectsData];


[prettier] reported by reviewdog 🐶

sortSelection.addEventListener('change', () => {


[prettier] reported by reviewdog 🐶

document.getElementById("sort-direction-form").hidden = false;
sortCards();


[prettier] reported by reviewdog 🐶

sortDirection.addEventListener('change', () => {
const isDescending = sortDirection.value === 'descending' ? true : false;
sortCards(isDescending);


[prettier] reported by reviewdog 🐶

if(["maturity_model_tier", "stargazers_count", "forks_count"].includes(selection)) {
sortByNumberAttribute(targetProjects, selection, isDescending);
} else {
sortByStringAttribute(targetProjects, selection, isDescending);


[prettier] reported by reviewdog 🐶

const allProjects = (filteredProjects || parsedProjectsData).map((project) => ({
...project,
org: project.owner
}));
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const paginatedProjects = allProjects.slice(startIndex, endIndex);


[prettier] reported by reviewdog 🐶

if(!acc[curr.org]) {


[prettier] reported by reviewdog 🐶

acc[curr.org].push(curr);


[prettier] reported by reviewdog 🐶


[prettier] reported by reviewdog 🐶

const paginationDiv = document.getElementById('pagination-controls') || document.createElement('div');
paginationDiv.id = 'pagination-controls';
paginationDiv.className = 'usa-pagination';
paginationDiv.innerHTML = '';
const totalPages = Math.ceil(totalProjectsCount / itemsPerPage);
const paginationList = document.createElement('ul');
paginationList.className = 'usa-pagination__list';
const prevItem = document.createElement('li');
prevItem.className = 'usa-pagination__item usa-pagination__arrow';
const prevButton = document.createElement('a');
prevButton.href = 'javascript:void(0);';
prevButton.className = 'usa-pagination__link usa-pagination__previous-page';
prevButton.setAttribute('aria-label', 'Previous page');
if (currentPage === 1) prevButton.classList.add('usa-pagination__disabled');


[prettier] reported by reviewdog 🐶

`;
prevButton.addEventListener('click', () => {


[prettier] reported by reviewdog 🐶

currentPage--;
createProjectCards();


[prettier] reported by reviewdog 🐶

});
prevItem.appendChild(prevButton);
paginationList.appendChild(prevItem);


[prettier] reported by reviewdog 🐶

const pageRange = getPageRange(currentPage, totalPages, 3);


[prettier] reported by reviewdog 🐶

const pageItem = document.createElement('li');
pageItem.className = 'usa-pagination__item';


[prettier] reported by reviewdog 🐶

if (page === '...') {
pageItem.className += ' usa-pagination__overflow';
pageItem.innerHTML = `<span aria-label="ellipsis indicating non-visible pages">…</span>`;


[prettier] reported by reviewdog 🐶

pageItem.className += ' usa-pagination__page-no';
const pageButton = document.createElement('a');
pageButton.href = 'javascript:void(0);';
pageButton.className = `usa-pagination__button${page === currentPage ? ' usa-current' : ''}`;
pageButton.textContent = page;
pageButton.setAttribute('aria-label', `Page ${page}`);
if (page === currentPage) pageButton.setAttribute('aria-current', 'page');
pageButton.addEventListener('click', () => {
currentPage = page;
createProjectCards();
});
pageItem.appendChild(pageButton);


[prettier] reported by reviewdog 🐶

paginationList.appendChild(pageItem);
});
const nextItem = document.createElement('li');
nextItem.className = 'usa-pagination__item usa-pagination__arrow';
const nextButton = document.createElement('a');
nextButton.href = 'javascript:void(0);';
nextButton.className = 'usa-pagination__link usa-pagination__next-page';
nextButton.setAttribute('aria-label', 'Next page');
if (currentPage === totalPages) nextButton.classList.add('usa-pagination__disabled');


[prettier] reported by reviewdog 🐶

`;
nextButton.addEventListener('click', () => {


[prettier] reported by reviewdog 🐶

currentPage++;
createProjectCards();


[prettier] reported by reviewdog 🐶

});
nextItem.appendChild(nextButton);
paginationList.appendChild(nextItem);


[prettier] reported by reviewdog 🐶

paginationDiv.appendChild(paginationList);


[prettier] reported by reviewdog 🐶

templateDiv.parentElement.appendChild(paginationDiv);


[prettier] reported by reviewdog 🐶

const range = [];
const start = Math.max(2, currentPage - visibleRange);
const end = Math.min(totalPages - 1, currentPage + visibleRange);


[prettier] reported by reviewdog 🐶

range.push(1);


[prettier] reported by reviewdog 🐶

if (start > 2) range.push('...');


[prettier] reported by reviewdog 🐶

range.push(i);


[prettier] reported by reviewdog 🐶

if (end < totalPages - 1) range.push('...');


[prettier] reported by reviewdog 🐶

if (totalPages > 1) range.push(totalPages);


[prettier] reported by reviewdog 🐶

return range;


[prettier] reported by reviewdog 🐶

addGlobalEventListener('change', '.usa-checkbox__input', e => {
// Can use this e.target.name to update selected filters object
updateFilters();
updateFilteredProjects()
}, filtersContainer)


[prettier] reported by reviewdog 🐶


[prettier] reported by reviewdog 🐶

projectType: []


[prettier] reported by reviewdog 🐶

document.querySelectorAll('input[name="org-filter"]:checked').forEach(checkbox => {
selectedFiltersObject.organization.push(checkbox.value);
});
document.querySelectorAll('input[name="tier-filter"]:checked').forEach(checkbox => {
selectedFiltersObject.maturityModelTier.push(checkbox.value);
});
document.querySelectorAll('input[name="fisma-level-filter"]:checked').forEach(checkbox => {
selectedFiltersObject.fismaLevel.push(checkbox.value);
});
document.querySelectorAll('input[name="project-type-filter"]:checked').forEach(checkbox => {
selectedFiltersObject.projectType.push(checkbox.value);
});
const allProjects = Object.keys(projects).flatMap((org) => projects[org].map((project) => ({...project, org})))


[prettier] reported by reviewdog 🐶

const matchesOrg = selectedFiltersObject.organization.length === 0 || selectedFiltersObject.organization.includes(project.org);
const matchesTier = selectedFiltersObject.maturityModelTier.length === 0 || selectedFiltersObject.maturityModelTier.includes("Tier" + project.maturityModelTier);
const matchesFisma = selectedFiltersObject.fismaLevel.length === 0 || selectedFiltersObject.fismaLevel.includes(project.fismaLevel);
const matchesType = selectedFiltersObject.projectType.length === 0 || selectedFiltersObject.projectType.includes(project.projectType);
return matchesOrg && matchesTier && matchesFisma && matchesType;
});
updatePagination(filteredProjects);


[prettier] reported by reviewdog 🐶

sortCards();


[prettier] reported by reviewdog 🐶

const totalProjects = (filteredProjects || parsedProjectsData).length;
const totalPages = Math.ceil(totalProjects / itemsPerPage);


[prettier] reported by reviewdog 🐶

currentPage = Math.min(currentPage, totalPages || 1);
renderPaginationControls(totalPages);


[prettier] reported by reviewdog 🐶

const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const paginatedProjects = projects.slice(startIndex, endIndex);


[prettier] reported by reviewdog 🐶

templateDiv.innerHTML = '';


[prettier] reported by reviewdog 🐶

if(!acc[curr.owner]) {


[prettier] reported by reviewdog 🐶

acc[curr.owner].push(curr);


[prettier] reported by reviewdog 🐶


[prettier] reported by reviewdog 🐶

const orgProject = findObject(parsedOrgsData, org);
const orgHeading = reportHeadingTemplate(orgProject);
const projectSectionsTemplate = document.createElement('div');
projectSectionsTemplate.className = 'project_section';
const reportHeading = document.createElement('div');
reportHeading.className = "report_heading";
reportHeading.innerHTML = DOMPurify.sanitize(orgHeading);
projectSectionsTemplate.appendChild(reportHeading);
const projectCards = document.createElement('ul');
projectCards.className = "usa-card-group flex-align-stretch";
groupedByOrg[org].forEach(repoData => {
const projectCard = document.createElement('li');
projectCard.className = 'usa-card project-card tablet:grid-col-12';
projectCard.id = repoData.name;
projectCard.setAttribute('org-name', repoData.owner);
projectCard.innerHTML = DOMPurify.sanitize(projectCardTemplate(repoData));
projectCards.appendChild(projectCard);
});
projectSectionsTemplate.appendChild(projectCards);
templateDiv.append(projectSectionsTemplate);


[prettier] reported by reviewdog 🐶

updateHeadingVisibility();


[prettier] reported by reviewdog 🐶

const searchForm = document.getElementById('search-form');
const searchBox = document.getElementById("search-input");


[prettier] reported by reviewdog 🐶

e.preventDefault();


[prettier] reported by reviewdog 🐶


[prettier] reported by reviewdog 🐶

const query = searchBox.value.toLowerCase();
filteredProjects = parsedProjectsData.filter((project) => project.name.toLowerCase().includes(query));


[prettier] reported by reviewdog 🐶

export const reportHeadingTemplate = function(data) {
return `


[prettier] reported by reviewdog 🐶

<a href="/metrics/${ data.owner }/${ data.name }/" class="href-home">


[prettier] reported by reviewdog 🐶

<h2 class="usa-card__heading">${ data.name }</h2>


[prettier] reported by reviewdog 🐶

<div>${ description }</div>


[prettier] reported by reviewdog 🐶

<span> ${ data.stargazers_count } </span>


[prettier] reported by reviewdog 🐶

<span> ${ data.forks_count } </span>


[prettier] reported by reviewdog 🐶

<svg class="usa-icon" aria-labelledby="issue-count-${ data.name }-title" role="img">


[prettier] reported by reviewdog 🐶

<span> ${ data.issues_count } </span>


[prettier] reported by reviewdog 🐶

<span> ${ data.pull_requests_count } </span>


[prettier] reported by reviewdog 🐶

<span> ${ data.watchers_count } </span>


[prettier] reported by reviewdog 🐶

@@ -71,6 +71,7 @@ module.exports = function (eleventyConfig) {

eleventyConfig.addPassthroughCopy({
"src/img": "assets/img",
"src/js" : "src/js",
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
"src/js" : "src/js",
"src/js": "src/js",

@@ -88,7 +89,7 @@
"stroke-width": 2,
})

const pathPrefix = process.env.NODE_ENV === "production" ? "/metrics" : ""
const pathPrefix = process.env.NODE_ENV.includes("production") ? "/metrics" : ""
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
const pathPrefix = process.env.NODE_ENV.includes("production") ? "/metrics" : ""
const pathPrefix = process.env.NODE_ENV.includes("production")
? "/metrics"
: ""

@@ -100,4 +101,5 @@
</div>
</div>
</div>
</section> {% endcomment %}
</section>
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
</section>
</section>

<div class="usa-card-outer">
<div class="usa-card-middle">
<a href="{{ base_url }}/{{ repo.owner }}/{{ repo.name }}/" class="text-no-underline">

Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change

<div class="usa-card__header">
<h2 class="usa-card__heading">
{{ repo.name }}
<!-- <a href="{{ base_url }}/{{ repo.owner }}/{{ repo.name }}/" class="text-no-underline">{{ repo.name }}</a> -->
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
<!-- <a href="{{ base_url }}/{{ repo.owner }}/{{ repo.name }}/" class="text-no-underline">{{ repo.name }}</a> -->
<!--
<a href="{{ base_url }}/{{ repo.owner }}/{{ repo.name }}/" class="text-no-underline">{{ repo.name }}</a>
-->

}

.href-home:focus {
outline:none;
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
outline:none;
outline: none;


.usa-card__container {
align-items: center;
background-color: #E0EAF8;
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
background-color: #E0EAF8;
background-color: #e0eaf8;

/* Footer */
.usa-identifier {
display: flex;
background-color: #E0EAF8;
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
background-color: #E0EAF8;
background-color: #e0eaf8;

Comment on lines +227 to +229
.usa-identifier__required-link.usa-link{
color:#000;
display:inline-block;
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
.usa-identifier__required-link.usa-link{
color:#000;
display:inline-block;
.usa-identifier__required-link.usa-link {
color: #000;
display: inline-block;

Comment on lines +232 to +233
.usa-identifier__required-link.usa-link:visited{
color:#494949;
Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

Suggested change
.usa-identifier__required-link.usa-link:visited{
color:#494949;
.usa-identifier__required-link.usa-link:visited {
color: #494949;

Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

const orgProject = findObject(parsedOrgsData, org);
const orgHeading = reportHeadingTemplate(orgProject);
const projectSectionsTemplate = document.createElement('div');
projectSectionsTemplate.className = 'project_section';
templateDiv.append(projectSectionsTemplate);
const reportHeading = document.createElement('div');
reportHeading.className = "report_heading";
reportHeading.innerHTML = DOMPurify.sanitize(orgHeading);
projectSectionsTemplate.appendChild(reportHeading);
const projectCards = document.createElement('ul');
projectCards.className = "usa-card-group flex-align-stretch";
projectSectionsTemplate.appendChild(projectCards);
groupedByOrg[org].forEach(repoData => {
repoData.url = siteData.baseurl;
const projectCard = document.createElement('li');
projectCard.className = 'usa-card project-card tablet:grid-col-12';
projectCard.id = repoData.name;
projectCard.setAttribute('org-name', repoData.owner);
projectCard.innerHTML = DOMPurify.sanitize(projectCardTemplate(repoData));
projectCards.appendChild(projectCard);

Copy link
Contributor

Choose a reason for hiding this comment

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

[prettier] reported by reviewdog 🐶

const cardName = card.querySelector(".usa-card__heading").innerText;
const currentProject = parsedProjectsData.find((project) => project.name === cardName)
const matchesOrganization = selectedFiltersObject.organization.length === 0 || selectedFiltersObject.organization.includes(currentProject.owner);
const projectMaturityModelTier = "Tier " + currentProject.maturityModelTier;
const matchesMaturityModelTier = selectedFiltersObject.maturityModelTier.length === 0 || selectedFiltersObject.maturityModelTier.includes(projectMaturityModelTier);
const matchesFismaLevel = selectedFiltersObject.fismaLevel.length === 0 || selectedFiltersObject.fismaLevel.includes(currentProject.fismaLevel);
const matchesProjectType = selectedFiltersObject.projectType.length === 0 || selectedFiltersObject.projectType.includes(currentProject.projectType);
// Hide card if project does not match all filter categories
card.hidden = !(matchesOrganization && matchesMaturityModelTier && matchesFismaLevel && matchesProjectType);

@DinneK DinneK closed this Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request front-end javascript Pull requests that update Javascript code metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant