Skip to content

Commit

Permalink
Fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TyroneAEM committed Feb 23, 2024
1 parent 8c595f8 commit 40e0f7f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ async function createDropdown(addToExistingRadioDropboxContainer) {

// Function to load more data when reaching the end of the dropdown
const loadMoreData = async (page) => {
//Call to get the nbHits for the total number of Collections
const collectionMax = await searchListCollection(0,0);
//Get all the collections
const collectionData = await searchListCollection(collectionMax.nbHits,page);
// Call to get the nbHits for the total number of Collections
const collectionMax = await searchListCollection(0, 0);
// Get all the collections
const collectionData = await searchListCollection(collectionMax.nbHits, page);
return collectionData;
};

const page = 0;
// Initial data loading
const initialData = await loadMoreData(page);
if (initialData.items.length > 0) {

// Populate the options in the dropdown with the initial data
initialData.items.forEach((collection) => {
const option = document.createElement('option');
Expand Down
1 change: 0 additions & 1 deletion blocks/adp-collection-header/adp-collection-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { decorateIcons } from '../../scripts/lib-franklin.js';
import { createLinkHref, navigateTo } from '../../scripts/scripts.js';

function createCollectionInfoHeader(collectionInfoHeader, collection) {

// include back to collections listing similar to hide filters button
collectionInfoHeader.innerHTML = `
<div class="adp-collection-header-left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default class CollectionsDatasource {
}

async createItemElement(item, infiniteResultsContainer) {

const assetJSON = await getAssetMetadata(getAssetIdFromCollectionItem(item));
const assetId = this.getItemId(item);
const card = await createAssetCardElement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
import { createCollectionCardElement } from '../../scripts/card-html-builder.js';

export default class CollectionsDatasource {

infiniteResultsContainer = null;

container = null;

pageNumber = 0;

lastPage = false;

async showMore() {

Check failure on line 18 in blocks/adp-infinite-results-collections/CollectionsDatasource.js

View workflow job for this annotation

GitHub Actions / build

Block must not be padded by blank lines
Expand Down
66 changes: 32 additions & 34 deletions scripts/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
import { getPathParams, logError } from './scripts.js';
import { emitEvent, EventNames } from './events.js';

import {
getAdminConfig, } from './site-config.js';
import { getAdminConfig } from './site-config.js';

export function getCollectionIdFromURL() {
if (window.location.pathname.includes('/collection/')) {
Expand Down Expand Up @@ -36,7 +35,7 @@ async function getRequestHeadersSearchCollections() {
return {
'Content-Type': 'application/json',
'x-api-key': 'asset_search_service',
'Authorization': token,
Authorization: token,
'x-ch-Request': 'search',
'x-adobe-accept-experimental': '1',
};
Expand All @@ -49,7 +48,7 @@ async function getRequestHeaders() {
return {
'Content-Type': 'application/json',
'x-api-key': await getAssetHandlerApiKey(),
'Authorization': token,
Authorization: token,
'X-Adobe-Accept-Experimental': '1',
};
}
Expand All @@ -61,7 +60,7 @@ async function getRequestHeadersWithEtag(etag) {
return {
'Content-Type': 'application/json',
'x-api-key': await getAssetHandlerApiKey(),
'Authorization': token,
Authorization: token,
'X-Adobe-Accept-Experimental': '1',
'If-Match': etag,
};
Expand All @@ -72,7 +71,7 @@ async function getRequestHeadersWithIfMatchPatchJSON(etag) {
return {
'Content-Type': 'application/json-patch+json',
'x-api-key': await getAssetHandlerApiKey(),
'Authorization': token,
Authorization: token,
'X-Adobe-Accept-Experimental': '1',
'If-Match': etag,
};
Expand Down Expand Up @@ -129,13 +128,14 @@ export async function getCollection(collectionId) {
// Handle response codes
if (response.status === 200) {

let responseBody = await response.json();
const responseBody = await response.json();

responseBody.etag = response.headers.get('Etag');
if (responseBody.self[0].collectionMetadata.title)
responseBody.title = responseBody.self[0].collectionMetadata.title;
else
responseBody.title = '';
responseBody.etag = response.headers.get('Etag');
if (responseBody.self[0].collectionMetadata.title) {
responseBody.title = responseBody.self[0].collectionMetadata.title;
} else {
responseBody.title = '';
}

return responseBody;
} if (response.status === 404) {
Expand Down Expand Up @@ -229,25 +229,24 @@ export async function searchListCollection(limit = undefined, page = 0) {
queryParams.append('page', page);
}

const adminConfig=await getAdminConfig();
const indexName=adminConfig.searchCollectionIndex;

const adminConfig = await getAdminConfig();
const indexName = adminConfig.searchCollectionIndex;
const data = {
"requests": [
{
"indexName": indexName,
"params": {
"facets": [],
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
"hitsPerPage": limit,
"page": page,
"query": "",
"tagFilters": ""
}
}
]
};
requests: [
{
indexName: indexName,
params: {
facets: [],
highlightPostTag: '__/ais-highlight__',
highlightPreTag: '__ais-highlight__',
hitsPerPage: limit,
page: page,
query: '',
tagFilters: ''
}
}
]
};

const options = {
method: 'POST',
Expand All @@ -267,7 +266,7 @@ export async function searchListCollection(limit = undefined, page = 0) {
const responseBody = await response.json();

// Transform the data
let transformedData = {
const transformedData = {
page: responseBody.results[0].page,
nbHits: responseBody.results[0].nbHits,
nbPages: responseBody.results[0].nbPages,
Expand Down Expand Up @@ -304,16 +303,15 @@ export async function patchCollection(collectionId, etag, addOperation = '', del
const patchOperations = [];
if (addOperation) {
for (const op of addOperation) {
patchOperations.push({'op':'add', 'id':op.value.id, 'type': 'asset'});
patchOperations.push({ 'op': 'add', 'id': op.value.id, 'type': 'asset' });
}
}
if (deleteOperation) {
for (const op of deleteOperation) {
patchOperations.push({'op':'remove', 'id':op.value.id, 'type': 'asset'});
patchOperations.push({ 'op': 'remove', 'id': op.value.id, 'type': 'asset' });
}
}


const options = {
method: 'POST',
headers: await getRequestHeadersWithIfMatchPatchJSON(etag),
Expand Down

0 comments on commit 40e0f7f

Please sign in to comment.