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

Assets 98985 #193

Open
wants to merge 6 commits into
base: rc
Choose a base branch
from
Open
Show file tree
Hide file tree
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
update filter UI
  • Loading branch information
mdickson-adbe committed Jan 17, 2025
commit 294a57bd8ee24a47f62c667083a9f4b95b0c447b
4 changes: 3 additions & 1 deletion blocks/gmo-program-header/gmo-program-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function toggleDropdown(element) {
dropdown.classList.toggle('active');
}

function toggleOption(optionValue, optionType) {
export function toggleOption(optionValue, optionType) {
const currentlySelected = document.querySelector(`.dropoption.selected[data-type='${optionType}']`);
if (currentlySelected && currentlySelected.dataset.value !== optionValue) {
currentlySelected.classList.remove('selected'); // Remove the 'selected' class from the previously selected option
Expand Down Expand Up @@ -356,6 +356,8 @@ function dropdownButtonClickHandler(event) {
}

function dropOptionClickHandler(event) {
console.log(event.target.dataset.value);
console.log(event.target.dataset.type);
toggleOption(event.target.dataset.value, event.target.dataset.type);
toggleDropdown(event.target); // Closes the dropdown list
}
Expand Down
22 changes: 18 additions & 4 deletions blocks/gmo-program-list/gmo-program-list.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { readBlockConfig } from '../../scripts/lib-franklin.js';
import { decorateIcons } from '../../scripts/lib-franklin.js';
import { graphqlAllCampaignsFilter, graphqlCampaignCount, generateFilterJSON } from '../../scripts/graphql.js';
import { getProductMapping, checkBlankString, statusMapping, dateFormat, showLoadingOverlay, hideLoadingOverlay } from '../../scripts/shared-program.js'
import { getBaseConfigPath } from '../../scripts/site-config.js';
import { searchAsset } from '../../scripts/assets.js';
import { toggleOption } from '../gmo-program-header/gmo-program-header.js';
import {
getProductMapping, checkBlankString, statusMapping,
dateFormat, showLoadingOverlay, hideLoadingOverlay,
div, span
} from '../../scripts/shared-program.js'

const headerConfig = [
{
Expand Down Expand Up @@ -60,7 +65,6 @@ document.addEventListener('gmoCampaignListBlock', async function() {
}

currentGraphqlFilter= generateFilterJSON(graphQLFilterArray);
console.log(currentGraphqlFilter);
const block = document.querySelector('.gmo-program-list.block');
//Get Campaign Count for pagination
campaignCount = graphqlCampaignCount(currentGraphqlFilter);
Expand All @@ -85,15 +89,15 @@ export default async function decorate(block, numPerPage = currentNumberPerPage,
// check if this was a 'back' from details. if so, retrieve search params from cookie
const params = new URLSearchParams(window.location.search);
const isBack = params.get('isBack');
console.log(`Back? ${isBack}`);
// clear the params from the url
clearURLParams();
// retrieve previous search from cookie
if (isBack) {
const filterValue = getFilterFromCookie();
if (filterValue) graphQLFilter = JSON.parse(filterValue);
// add filter values to filter list
displayFilterSelections(graphQLFilter);
}
console.log(graphQLFilter);

const campaignPaginatedResponse = await graphqlAllCampaignsFilter(numPerPage, cursor,graphQLFilter);
const campaigns = campaignPaginatedResponse.data.programPaginated.edges;
Expand Down Expand Up @@ -588,4 +592,14 @@ function clearURLParams() {
const currentUrl = window.location.href;
const baseUrl = currentUrl.split('?')[0];
history.replaceState(null, '', baseUrl);
}

function displayFilterSelections(filterObj) {

for (const key in filterObj) {
if (filterObj[key]._expressions && Array.isArray(filterObj[key]._expressions)) {
const value = filterObj[key]._expressions[0].value;
toggleOption(value, key);
}
}
}