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-34548 : Update the Collection API Endpoints #39

Merged
merged 20 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0e9d792
Check in working code with hardcoded collectionId urn:cid:aem:8f67c49…
TyroneAEM Feb 8, 2024
6d14883
In collection.js added new function export async function searchListC…
TyroneAEM Feb 14, 2024
6382b6f
Fixed pagination logic for this.lastPage
TyroneAEM Feb 14, 2024
9c58a11
/blocks/adp-infinite-results-collection/CollectionDatasource.js => Pa…
TyroneAEM Feb 16, 2024
cc386d6
Updated deleteCollection function, added etag parameter as it require…
TyroneAEM Feb 20, 2024
e430330
Updated function patchCollection API URL from ${getBaseAssetsCollec…
TyroneAEM Feb 20, 2024
6c464cf
/scripts/collections.js ==> Updated function searchListCollection(lim…
TyroneAEM Feb 20, 2024
b4a57d2
Check in latest collection modal code
TyroneAEM Feb 21, 2024
1967b56
Deleted/removed Caching for JSON data for when the app is run on loca…
TyroneAEM Feb 21, 2024
2e4adf0
/scripts/scripts.js Restored the caching of collection data for loca…
TyroneAEM Feb 21, 2024
de461a6
Added code to get the Search Collection Index from the configuration…
TyroneAEM Feb 22, 2024
2046580
Updated function loadMoreData to get all the collections to populate …
TyroneAEM Feb 23, 2024
8c595f8
Deleted event listener dropdownSelect.addEventListener('scroll' .. …
TyroneAEM Feb 23, 2024
40e0f7f
Fixed lint errors
TyroneAEM Feb 23, 2024
495779c
Pull Request code changes.
TyroneAEM Feb 26, 2024
a105b10
PR review code change to remove redundant code
TyroneAEM Feb 26, 2024
4433aef
Removed redundant if statement
TyroneAEM Feb 26, 2024
0070e5e
Removed 'x-ch-Request': 'search' from header of Search Collectio…
TyroneAEM Feb 29, 2024
ebba3a1
Replaced with 'x-api-key': getBackendApiKey(),
TyroneAEM Feb 29, 2024
a880f11
Added 'x-adp-request': 'search' to the header for the Search Col…
TyroneAEM Feb 29, 2024
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
37 changes: 9 additions & 28 deletions blocks/adp-add-to-collection-modal/adp-add-to-collection-modal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decorateIcons } from '../../scripts/lib-franklin.js';
import {
listCollection, createCollection, patchCollection, getCollection,
searchListCollection, createCollection, patchCollection, getCollection,
} from '../../scripts/collections.js';
import { getSelectedAssetsFromInfiniteResultsBlock, populateAssetViewLeftDialog } from '../../scripts/scripts.js';
import createMultiSelectedAssetsTable from '../../scripts/multi-selected-assets-table.js';
Expand Down Expand Up @@ -43,38 +43,18 @@ async function createDropdown(addToExistingRadioDropboxContainer) {
dropdownSelect.classList.add('add-to-existing-dropdown'); // Add the new class

// Function to load more data when reaching the end of the dropdown
const loadMoreData = async (cursor) => {
const collectionData = await listCollection({ cursor, limit: 10 }); // Adjust the limit as needed
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);
return collectionData;
};

let cursor = null;

// Event listener to detect scroll and load more data when at the bottom
dropdownSelect.addEventListener('scroll', async () => {
if (dropdownSelect.scrollTop + dropdownSelect.clientHeight >= dropdownSelect.scrollHeight) {
const moreData = await loadMoreData(cursor);
if (moreData.items.length > 0) {
// Update the cursor for the next load
cursor = moreData.cursor;

// Populate the options in the dropdown from the additional data
moreData.items.forEach((collection) => {
const option = document.createElement('option');
option.value = collection.id;
option.textContent = collection.title;
dropdownSelect.appendChild(option);
});
}
}
});

const page = 0;
// Initial data loading
const initialData = await loadMoreData(cursor);
const initialData = await loadMoreData(page);
if (initialData.items.length > 0) {
// Update the cursor for the next load
cursor = initialData.cursor;

// Populate the options in the dropdown with the initial data
initialData.items.forEach((collection) => {
const option = document.createElement('option');
Expand Down Expand Up @@ -160,6 +140,7 @@ export async function openModal(items) {
const { etag } = collection;
patchCollection(collectionId, etag, payload);
});

resetDialogState();
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/adp-collection-header/adp-collection-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function createCollectionInfoHeader(collectionInfoHeader, collection) {
'Delete collection',
`Are you sure you want to delete the collection "${collection.title}"?`,
async () => {
await deleteCollection(collectionId, collection.title);
await deleteCollection(collectionId, collection.title, collection.etag);
navigateTo(createLinkHref('/collections'));
},
'Proceed',
Expand Down
23 changes: 15 additions & 8 deletions blocks/adp-infinite-results-collections/CollectionsDatasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
import {
getCollectionID,
getCollectionTitle,
listCollection,
searchListCollection,
} from '../../scripts/collections.js';
import { createCollectionCardElement } from '../../scripts/card-html-builder.js';

export default class CollectionsDatasource {
cursor;

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
const list = await listCollection(5, this.cursor);
this.cursor = list.cursor;

const list = await searchListCollection(5, this.pageNumber);

this.pageNumber += 1;

if (this.pageNumber >= list.nbPages){

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

View workflow job for this annotation

GitHub Actions / build

Missing space before opening brace
this.lastPage = true;
}

this.infiniteResultsContainer.resultsCallback(
this.container,
list.items,
Expand All @@ -31,14 +37,15 @@
}

isLastPage() {
return !this.cursor;
return this.lastPage;
}

async registerResultsCallback(container, infiniteResultsContainer) {
this.infiniteResultsContainer = infiniteResultsContainer;
this.container = container;
const list = await listCollection(5, this.cursor);
this.cursor = list.cursor;

const list = await searchListCollection(5, this.pageNumber);

infiniteResultsContainer.resultsCallback(
container,
list.items,
Expand Down
Loading
Loading