-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from GSA/207_sort_and_filter_component
[207] Sort and Filter Component
- Loading branch information
Showing
11 changed files
with
426 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// app/javascript/controllers/sort_filter_menu_controller.js | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["menuItem"] | ||
|
||
connect() { | ||
this.updateCheckmarks() | ||
} | ||
|
||
toggle(event) { | ||
event.preventDefault() | ||
const clickedItem = event.currentTarget | ||
const filterValue = clickedItem.dataset.filterValue | ||
|
||
const currentUrl = new URL(window.location.href) | ||
const [param, value] = filterValue.split('=') | ||
|
||
if (currentUrl.searchParams.get(param) === value) { | ||
this.clearAllFilters() | ||
} else { | ||
this.applyFilter(filterValue) | ||
} | ||
} | ||
|
||
applyFilter(filterValue) { | ||
const currentUrl = new URL(window.location.href) | ||
const [param, value] = filterValue.split('=') | ||
|
||
this.removeExistingParams(currentUrl) | ||
currentUrl.searchParams.set(param, value) | ||
window.location.href = currentUrl.toString() | ||
} | ||
|
||
clearAllFilters() { | ||
const currentUrl = new URL(window.location.href) | ||
this.removeExistingParams(currentUrl) | ||
window.location.href = currentUrl.toString() | ||
} | ||
|
||
removeExistingParams(url) { | ||
const paramsToRemove = ['status', 'eligible_for_evaluation', 'selected_to_advance', 'sort'] | ||
paramsToRemove.forEach(key => { | ||
url.searchParams.delete(key) | ||
}) | ||
} | ||
|
||
updateCheckmarks() { | ||
const currentUrl = new URL(window.location.href) | ||
this.menuItemTargets.forEach(item => { | ||
const checkmark = item.querySelector('.checkmark') | ||
const [param, value] = item.dataset.filterValue.split('=') | ||
if (currentUrl.searchParams.get(param) === value) { | ||
checkmark.style.display = 'inline' | ||
} else { | ||
checkmark.style.display = 'none' | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<div class="grid-container padding-x-0"> | ||
<div class="grid-row"> | ||
<div class="grid-col-12 display-flex flex-column flex-align-start padding-top-105"> | ||
<nav aria-label="Sort and filter options" class="tablet:usa-nav display-flex" data-controller="sort-filter-menu"> | ||
<ul class="usa-nav__primary usa-accordion" style="position: relative;"> | ||
<li class="radius-md"> | ||
<button | ||
type="button" | ||
class="usa-accordion__button" | ||
aria-expanded="false" | ||
aria-controls="sort-and-filter" | ||
style="background-color: white; border: none; padding: 0;" | ||
> | ||
<span class="text-primary text-bold font-sans-md text-underline" style="text-decoration-thickness: 2px;">Sort & Filter</span> | ||
<%= image_tag "images/usa-icons/arrow_drop_down.svg", | ||
class: "usa-icon icon-down", | ||
alt: "", | ||
aria: { hidden: true } %> | ||
<%= image_tag "images/usa-icons/arrow_drop_up.svg", | ||
class: "usa-icon icon-up", | ||
alt: "", | ||
aria: { hidden: true } %> | ||
</button> | ||
<ul id="sort-and-filter" class="usa-nav__submenu text-no-wrap bg-white font-sans-xs width-auto" | ||
style="position: absolute; top: 100%; left: 0; z-index: 1000; max-height: 80vh; overflow-y: auto;"> | ||
<% menu_items = [ | ||
{ label: "Evaluation progress: Completed", value: "status=completed" }, | ||
{ label: "Evaluation progress: In progress", value: "status=in_progress" }, | ||
{ label: "Evaluation progress: Not started", value: "status=not_started" }, | ||
{ label: "Evaluation progress: Recused", value: "status=recused" }, | ||
{ label: "Eligible for Evaluation", value: "eligible_for_evaluation=true" }, | ||
{ label: "Selected to Advance", value: "selected_to_advance=true" }, | ||
{ label: "Average score: high to low", value: "sort=average_score_high_to_low" }, | ||
{ label: "Average score: low to high", value: "sort=average_score_low_to_high" }, | ||
{ label: "Submission ID: high to low", value: "sort=submission_id_high_to_low" }, | ||
{ label: "Submission ID: low to high", value: "sort=submission_id_low_to_high" } | ||
] %> | ||
<% menu_items.each do |item| %> | ||
<li class="usa-nav__submenu-item bg-primary-darker margin-y-2px"> | ||
<a href="#" class="text-white text-no-underline menu-item display-flex flex-align-center padding-y-05 padding-x-105 width-full" | ||
data-action="click->sort-filter-menu#toggle" | ||
data-sort-filter-menu-target="menuItem" | ||
data-filter-value="<%= item[:value] %>"> | ||
<%= image_tag "images/usa-icons/check.svg", | ||
width: 18, | ||
height: 18, | ||
alt: "Selected", | ||
class: "icon-white checkmark margin-left-neg-3 padding-top-2px tablet:padding-top-05 tablet:margin-left-neg-1", | ||
style: "display: none;" %> | ||
<span class="text-white"><%= item[:label] %></span> | ||
</a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.