Skip to content

Commit 1b40760

Browse files
authored
Merge pull request #21 from mulesoft/persistent_filters
Persistent filters
2 parents 5672356 + 45be9a9 commit 1b40760

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

scripts/portal_generator/assets/portal.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,35 @@ function filterByTags() {
961961

962962
// Update results count and type
963963
updateResultsCount(visibleApis + visibleSkills, selectedType);
964+
965+
// Update URL with current filter
966+
updateURLWithFilter(selectedType);
967+
}
968+
969+
function updateURLWithFilter(filterType) {
970+
const url = new URL(window.location);
971+
if (filterType && filterType !== 'all') {
972+
url.searchParams.set('filter', filterType);
973+
localStorage.setItem('homepage-filter', filterType);
974+
} else {
975+
url.searchParams.delete('filter');
976+
localStorage.removeItem('homepage-filter');
977+
}
978+
console.log('Updating URL to:', url.toString());
979+
window.history.replaceState({}, '', url);
980+
}
981+
982+
function getFilterFromURL() {
983+
const url = new URL(window.location);
984+
const urlFilter = url.searchParams.get('filter');
985+
986+
// Priority: URL parameter > localStorage > default 'all'
987+
if (urlFilter) {
988+
return urlFilter;
989+
}
990+
991+
const savedFilter = localStorage.getItem('homepage-filter');
992+
return savedFilter || 'all';
964993
}
965994

966995
function updateResultsCount(count, filterType) {
@@ -1127,6 +1156,19 @@ document.addEventListener('DOMContentLoaded', () => {
11271156
});
11281157
});
11291158

1159+
// Initialize filter from URL on page load
1160+
const urlFilter = getFilterFromURL();
1161+
console.log('URL filter:', urlFilter);
1162+
if (urlFilter !== 'all') {
1163+
const targetTab = document.querySelector(`.hero-tab[data-filter="${urlFilter}"]`);
1164+
console.log('Target tab:', targetTab);
1165+
if (targetTab) {
1166+
heroTabs.forEach(t => t.classList.remove('active'));
1167+
targetTab.classList.add('active');
1168+
filterByTags();
1169+
}
1170+
}
1171+
11301172
// Set up tag search input
11311173
const tagSearchInput = document.getElementById('tagSearchInput');
11321174
const tagSearchContainer = document.getElementById('tagSearchInputContainer');
@@ -7133,6 +7175,22 @@ function toggleParamDescription(button) {
71337175
return direction === 'asc'
71347176
? aValue.localeCompare(bValue)
71357177
: bValue.localeCompare(aValue);
7178+
} else if (sortBy === 'type') {
7179+
aValue = a.getAttribute('data-type') || '';
7180+
bValue = b.getAttribute('data-type') || '';
7181+
// Sort by type, then by name as secondary sort
7182+
const typeCompare = direction === 'asc'
7183+
? aValue.localeCompare(bValue)
7184+
: bValue.localeCompare(aValue);
7185+
7186+
if (typeCompare !== 0) {
7187+
return typeCompare;
7188+
}
7189+
7190+
// Secondary sort by name
7191+
const aName = a.getAttribute('data-name') || '';
7192+
const bName = b.getAttribute('data-name') || '';
7193+
return aName.localeCompare(bName);
71367194
} else if (sortBy === 'endpoints') {
71377195
// Extract count from the badge text (endpoints for APIs, steps for Skills)
71387196
const aCard = a.querySelector('.badge-count');

scripts/portal_generator/assets/styles.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ code {
11361136
font-weight: var(--font-weight-semibold);
11371137
color: var(--color-gray-900);
11381138
margin: 0 0 20px 0;
1139+
border-bottom: 1px solid var(--color-gray-300);
11391140
}
11401141

11411142
.sort-modal-field {
@@ -6328,7 +6329,8 @@ details[open] .examples-toggle-icon {
63286329
display: flex;
63296330
flex-direction: column;
63306331
flex: 1;
6331-
min-height: 200px; /* Ensure content area has minimum height */
6332+
min-height: 200px;
6333+
/* Ensure content area has minimum height */
63326334
}
63336335

63346336
.try-response-body,
@@ -6347,7 +6349,8 @@ details[open] .examples-toggle-icon {
63476349
white-space: pre-wrap;
63486350
word-break: break-word;
63496351
flex: 1;
6350-
min-height: 200px; /* Ensure ACE editor has minimum height */
6352+
min-height: 200px;
6353+
/* Ensure ACE editor has minimum height */
63516354
}
63526355

63536356
.try-response-body.active,

scripts/portal_generator/templates/homepage.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ <h3 class="sort-modal-title">Sort</h3>
6565
<label for="sortBy" class="sort-modal-label">Sort by</label>
6666
<select id="sortBy" class="sort-modal-select">
6767
<option value="name">Name</option>
68+
<option value="type">Type</option>
6869
<option value="endpoints">Endpoints</option>
6970
</select>
7071
</div>

0 commit comments

Comments
 (0)