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

322-event-page-filtering #323

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
set url to map to selected items
  • Loading branch information
davenichols-DHLS committed Aug 22, 2024
commit 0d6258602d7d89a257a276b4713162b58b801e30
19 changes: 19 additions & 0 deletions blocks/events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

function filterUrl() {
function getUrlParameter(name) {
const newName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');

Check failure on line 24 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Unnecessary escape character: \[
const regex = new RegExp(`[\\?&]${newName}=([^&#]*)`);
const results = regex.exec(window.location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
Expand Down Expand Up @@ -186,6 +186,25 @@
filteredEvents = eventData.filter((data) => eventTypes
.includes(data.type) && regions.includes(data.region));
}

const urlParams = new URLSearchParams(window.location.search);
urlParams.delete('types');
if (eventTypes.length > 0) {
urlParams.set('type', eventTypes.map(type => type.toLowerCase()).join(','));

Check failure on line 193 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument
} else {
urlParams.delete('types');
}

if (regions.length > 0) {
urlParams.delete('region');
urlParams.set('region', regions.map(region => region.toLowerCase().replace(/[+\s]/g, '-')).join(','));

Check failure on line 200 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument
} else {
urlParams.delete('region');
}

const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
window.history.replaceState({}, '', newUrl);

Check failure on line 206 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Block must not be padded by blank lines

} else {
filteredEvents = eventData;
}
Expand Down Expand Up @@ -278,7 +297,7 @@

function handlePagination(page, events) {
currentPageNumber = page;
const filteredEvents = filterEvents(events, eventType, region);

Check failure on line 300 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

'filterEvents' is not defined

Check failure on line 300 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

'eventType' is not defined

Check failure on line 300 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

'region' is not defined
displayPage(currentPageNumber, filteredEvents); // Update UI with new page
}

Expand Down
Loading