-
-
Notifications
You must be signed in to change notification settings - Fork 16
fix: show active filter indicators #231
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
Changes from all commits
88f2efb
d63d236
3c7c03c
dbe33e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -743,6 +743,7 @@ function updateVisibilityAndSort() { | |||||||||||||||||||||||||||||||||||||||
| renderCards(sortedUsers); | ||||||||||||||||||||||||||||||||||||||||
| updateCounts(sortedUsers); | ||||||||||||||||||||||||||||||||||||||||
| updateResultsMessage(sortedUsers); | ||||||||||||||||||||||||||||||||||||||||
| updateActiveFilterIndicators(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1030,32 +1031,118 @@ function updateResultsMessage(sortedUsers) { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||
| // ACTIVE FILTER INDICATORS | ||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||
| const DEFAULT_FILTER_VALUES = { | ||||||||||||||||||||||||||||||||||||||||
| searchInput: '', | ||||||||||||||||||||||||||||||||||||||||
| sortBy: 'followers-desc', | ||||||||||||||||||||||||||||||||||||||||
| followersFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| maxFollowersFilter: '999999999', | ||||||||||||||||||||||||||||||||||||||||
| minReposFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| maxReposFilter: '999999', | ||||||||||||||||||||||||||||||||||||||||
| minForksFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| maxForksFilter: '999999', | ||||||||||||||||||||||||||||||||||||||||
| sponsorsFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| sponsoringFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| avatarAgeFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| minStarsFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| languageFilter: '', | ||||||||||||||||||||||||||||||||||||||||
| lastRepoActivityFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| lastCommitFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const FILTER_LABELS = { | ||||||||||||||||||||||||||||||||||||||||
| searchInput: 'Search', | ||||||||||||||||||||||||||||||||||||||||
| sortBy: 'Sort', | ||||||||||||||||||||||||||||||||||||||||
| followersFilter: 'Min followers', | ||||||||||||||||||||||||||||||||||||||||
| maxFollowersFilter: 'Max followers', | ||||||||||||||||||||||||||||||||||||||||
| minReposFilter: 'Min repos', | ||||||||||||||||||||||||||||||||||||||||
| maxReposFilter: 'Max repos', | ||||||||||||||||||||||||||||||||||||||||
| minForksFilter: 'Min forks', | ||||||||||||||||||||||||||||||||||||||||
| maxForksFilter: 'Max forks', | ||||||||||||||||||||||||||||||||||||||||
| sponsorsFilter: 'Sponsors', | ||||||||||||||||||||||||||||||||||||||||
| sponsoringFilter: 'Sponsoring', | ||||||||||||||||||||||||||||||||||||||||
| avatarAgeFilter: 'Avatar updated', | ||||||||||||||||||||||||||||||||||||||||
| minStarsFilter: 'Min stars', | ||||||||||||||||||||||||||||||||||||||||
| languageFilter: 'Language', | ||||||||||||||||||||||||||||||||||||||||
| lastRepoActivityFilter: 'Repo activity', | ||||||||||||||||||||||||||||||||||||||||
| lastCommitFilter: 'Public commit', | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function getControlDisplayValue(element) { | ||||||||||||||||||||||||||||||||||||||||
| if (!element) return ''; | ||||||||||||||||||||||||||||||||||||||||
| if (element.tagName === 'SELECT') { | ||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||
| element.options[element.selectedIndex]?.textContent.trim() || element.value | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return element.value.trim(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function getActiveFilterSummaries() { | ||||||||||||||||||||||||||||||||||||||||
| return Object.entries(DEFAULT_FILTER_VALUES) | ||||||||||||||||||||||||||||||||||||||||
| .map(([id, defaultValue]) => { | ||||||||||||||||||||||||||||||||||||||||
| const element = document.getElementById(id); | ||||||||||||||||||||||||||||||||||||||||
| if (!element || element.value === defaultValue) return null; | ||||||||||||||||||||||||||||||||||||||||
| const displayValue = getControlDisplayValue(element); | ||||||||||||||||||||||||||||||||||||||||
| return displayValue ? `${FILTER_LABELS[id]}: ${displayValue}` : null; | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
| .filter(Boolean); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1083
to
+1092
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function renderActiveFilterIndicator(container, activeFilters) { | ||||||||||||||||||||||||||||||||||||||||
| if (!container) return; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (!activeFilters.length) { | ||||||||||||||||||||||||||||||||||||||||
| container.style.display = 'none'; | ||||||||||||||||||||||||||||||||||||||||
| container.replaceChildren(); | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| container.style.display = 'flex'; | ||||||||||||||||||||||||||||||||||||||||
| container.replaceChildren(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const label = document.createElement('span'); | ||||||||||||||||||||||||||||||||||||||||
| label.className = 'active-filters-label'; | ||||||||||||||||||||||||||||||||||||||||
| label.textContent = 'Active:'; | ||||||||||||||||||||||||||||||||||||||||
| container.appendChild(label); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| activeFilters.forEach((filterText) => { | ||||||||||||||||||||||||||||||||||||||||
| const badge = document.createElement('span'); | ||||||||||||||||||||||||||||||||||||||||
| badge.className = 'active-filter-badge'; | ||||||||||||||||||||||||||||||||||||||||
| badge.textContent = filterText; | ||||||||||||||||||||||||||||||||||||||||
| container.appendChild(badge); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const clearButton = document.createElement('button'); | ||||||||||||||||||||||||||||||||||||||||
| clearButton.type = 'button'; | ||||||||||||||||||||||||||||||||||||||||
| clearButton.className = 'active-filters-clear'; | ||||||||||||||||||||||||||||||||||||||||
| clearButton.textContent = 'Clear all'; | ||||||||||||||||||||||||||||||||||||||||
| clearButton.addEventListener('click', resetFilters); | ||||||||||||||||||||||||||||||||||||||||
| container.appendChild(clearButton); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function updateActiveFilterIndicators() { | ||||||||||||||||||||||||||||||||||||||||
| const activeFilters = getActiveFilterSummaries(); | ||||||||||||||||||||||||||||||||||||||||
| renderActiveFilterIndicator( | ||||||||||||||||||||||||||||||||||||||||
| document.getElementById('activeFiltersSummary'), | ||||||||||||||||||||||||||||||||||||||||
| activeFilters, | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| renderActiveFilterIndicator( | ||||||||||||||||||||||||||||||||||||||||
| document.getElementById('activeFiltersSummaryDesktop'), | ||||||||||||||||||||||||||||||||||||||||
| activeFilters, | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1126
to
+1136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calculate the active filter summaries once and pass them to the rendering functions to improve efficiency and avoid redundant DOM lookups and string processing. function updateActiveFilterIndicators() {
const activeFilters = getActiveFilterSummaries();
renderActiveFilterIndicator(
document.getElementById('activeFiltersSummary'),
activeFilters,
);
renderActiveFilterIndicator(
document.getElementById('activeFiltersSummaryDesktop'),
activeFilters,
);
} |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||
| // RESET FILTERS | ||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Reset all filters to default values | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| function resetFilters() { | ||||||||||||||||||||||||||||||||||||||||
| const defaults = { | ||||||||||||||||||||||||||||||||||||||||
| searchInput: '', | ||||||||||||||||||||||||||||||||||||||||
| sortBy: 'followers-desc', | ||||||||||||||||||||||||||||||||||||||||
| followersFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| maxFollowersFilter: '999999999', | ||||||||||||||||||||||||||||||||||||||||
| minReposFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| maxReposFilter: '999999', | ||||||||||||||||||||||||||||||||||||||||
| minForksFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| maxForksFilter: '999999', | ||||||||||||||||||||||||||||||||||||||||
| sponsorsFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| sponsoringFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| avatarAgeFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| minStarsFilter: '0', | ||||||||||||||||||||||||||||||||||||||||
| languageFilter: '', | ||||||||||||||||||||||||||||||||||||||||
| lastRepoActivityFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| lastCommitFilter: 'any', | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Object.entries(defaults).forEach(([id, value]) => { | ||||||||||||||||||||||||||||||||||||||||
| Object.entries(DEFAULT_FILTER_VALUES).forEach(([id, value]) => { | ||||||||||||||||||||||||||||||||||||||||
| const element = document.getElementById(id); | ||||||||||||||||||||||||||||||||||||||||
| if (element) element.value = value; | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getActiveFilterSummaries()trims the displayed value for text inputs, but it decides “active vs default” using the rawelement.value. ForsearchInput, the filter logic currently uses.value.toLowerCase()without.trim()(seegetActiveFilters()), so whitespace-only input will (a) filter out results while (b) producing no active badge becausedisplayValuebecomes empty and is dropped. Consider trimmingsearchInputin the filter logic and using the same trimmed value when determining whether a text input deviates from its default, so the indicator and filtering behavior stay consistent.