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

Partner news block #6

Merged
merged 47 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
71c5307
partner news block
draganalilly021 Mar 12, 2024
29ebda2
Merge branch 'main' into partner-news-block
draganalilly021 Mar 12, 2024
d4d0303
redirect to first page after sorting
draganalilly021 Mar 12, 2024
fdfc8fb
small css fix
draganalilly021 Mar 12, 2024
bb18ca7
small code fix
draganalilly021 Mar 12, 2024
749b5f0
pagination, filtering, sorting, responsive - in progress
draganalilly021 Mar 25, 2024
0242e1e
filtering fix
draganalilly021 Mar 29, 2024
41bb93b
filters search params
draganalilly021 Apr 4, 2024
3b95643
demo api
draganalilly021 Apr 4, 2024
4efea6e
fixed filters with new api
draganalilly021 Apr 4, 2024
ac5438f
fixed filters with new api2
draganalilly021 Apr 4, 2024
225b47f
date filter; extended classes for pagination (load more or numeric)
draganalilly021 Apr 12, 2024
aa1dc08
date filter; extended classes for pagination (load more or numeric)
draganalilly021 Apr 12, 2024
f0d0071
clear all includes date filter reset
draganalilly021 Apr 12, 2024
3229d57
localization added; small refactoring
draganalilly021 May 8, 2024
28cfc5f
Merge remote-tracking branch 'origin/stage' into partner-news-block
draganalilly021 May 9, 2024
063cc10
Merge branch 'stage' into partner-news-block
draganalilly021 May 9, 2024
02b4836
contrast-ratio font fix
draganalilly021 May 10, 2024
25a7edd
aria-labels for buttons
draganalilly021 May 10, 2024
f904f13
default localization
draganalilly021 May 13, 2024
c6fab3b
picker position; removed unused sort items
draganalilly021 May 14, 2024
ab29aa9
fixed bug with filters mobile - safari
draganalilly021 May 15, 2024
daac63d
safari iphone 12 - background color
draganalilly021 May 15, 2024
cc3c354
safari iphone 12 - opacity
draganalilly021 May 15, 2024
43c7c3b
safari iphone 12 - bug fix 3
draganalilly021 May 15, 2024
d763019
safari iphone 12 - bug fix 4
draganalilly021 May 15, 2024
4736292
safari iphone 12 - bug fix 5
draganalilly021 May 15, 2024
dead46c
safari iphone 12 - bug fix 6
draganalilly021 May 15, 2024
27ea33a
fixed pagination counter; fixed filters and search params bug; optimi…
draganalilly021 May 22, 2024
fa814e2
Merge branch 'stage' into partner-news-block
draganalilly021 May 22, 2024
fbc969e
merge stage into branch
draganalilly021 May 22, 2024
e0360a8
icons path fix
draganalilly021 May 22, 2024
89ea3aa
unit test for partner-news component
draganalilly021 May 23, 2024
a2ae801
unit test for knowledge-base-overview component
draganalilly021 May 24, 2024
6844d75
resolved comments 1
draganalilly021 May 27, 2024
3e359e9
resolved comments 2
draganalilly021 May 27, 2024
a5858bb
resolved comments 3
draganalilly021 May 27, 2024
0c5707b
resolved comments 4
draganalilly021 May 27, 2024
f9241fa
resolved comments 5 - search params
draganalilly021 May 28, 2024
a2241c0
Merge branch 'stage' into partner-news-block
draganalilly021 May 28, 2024
9caf801
bug fix - update pagination if params exist on load
draganalilly021 May 28, 2024
6ec3952
unit test fix
draganalilly021 May 29, 2024
5a9d2fc
unit test fix2
draganalilly021 May 29, 2024
e7aa1a6
added authored field cards per page
draganalilly021 May 29, 2024
0cac90f
sort element text-transform consistency
draganalilly021 May 29, 2024
bb704ac
if not authored sort is hidden
draganalilly021 May 29, 2024
28df742
sort small style fix
draganalilly021 May 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
86 changes: 86 additions & 0 deletions eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { getLibs } from './../../scripts/utils.js';
const miloLibs = getLibs();
const { html, css, repeat } = await import (`${miloLibs}/deps/lit-all.min.js`);
import { numericPaginationStyles } from './../../components/PartnerCardsStyles.js';
import { PartnerCards } from "./../../components/PartnerCards.js";

export class KnowledgeBaseOverview extends PartnerCards {

static properties = {
...PartnerCards.properties,
totalPages: { type: Number },
};

constructor() {
super();
this.totalPages = 0;
}

static styles = [
PartnerCards.styles,
css`${numericPaginationStyles}`
];

get paginationList() {
if (!this.cards.length) return;

const min = 1;
this.totalPages = Math.ceil(this.cards.length / this.cardsPerPage);

const pagesNumArray = Array.from({ length: this.totalPages }, (_, i) => i + min);
return html`${repeat(
pagesNumArray,
(pageNum) => pageNum,
(pageNum) => html`<button
class="page-btn ${this.paginationCounter === pageNum ? 'selected' : ''}"
@click="${() => this.handlePageNum(pageNum)}"
aria-label="${this.blockData.localizedText['{{page}}']} ${pageNum}">
${pageNum}
</button>`
)}`;
}

get pagination() {
return html `
<div class="pagination-pages-list">
<button class="pagination-prev-btn ${this.paginationCounter === 1 || !this.paginatedCards?.length ? 'disabled' : ''}" @click="${this.handlePrevPage}" aria-label="${this.blockData.localizedText['{{previous-page}}']}">
${this.blockData.localizedText['{{prev}}']}</button>
${this.paginationList}
<button class="pagination-next-btn ${this.paginationCounter === this.totalPages || !this.paginatedCards?.length ? 'disabled': ''}" @click="${this.handleNextPage}" aria-label="${this.blockData.localizedText['{{next-page}}']}">
${this.blockData.localizedText['{{next}}']}</button>
</div>
`;
}

handleActions() {
super.handleActions();
this.updatePaginatedCards();
}

updatePaginatedCards() {
const startIndex = (this.paginationCounter - 1) * this.cardsPerPage;
const endIndex = this.paginationCounter * this.cardsPerPage;
this.paginatedCards = this.cards.slice(startIndex, endIndex);
}

handlePageNum(pageNum) {
if (this.paginationCounter !== pageNum) {
this.paginationCounter = pageNum;
this.handleActions();
}
}

handlePrevPage() {
if ( this.paginationCounter > 1 ) {
this.paginationCounter--;
this.handleActions();
}
}

handleNextPage() {
if (this.paginationCounter < this.totalPages) {
this.paginationCounter++;
this.handleActions();
}
}
}
Empty file.
133 changes: 133 additions & 0 deletions eds/blocks/knowledge-base-overview/knowledge-base-overview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { getLibs, replaceText, getConfig } from './../../scripts/utils.js';
import { KnowledgeBaseOverview } from './KnowledgeBaseOverview.js';

function declareKnowledgeBaseOverview() {
if (customElements.get('knowledge-base-overview')) return;
customElements.define('knowledge-base-overview', KnowledgeBaseOverview);
}

async function localizationPromises(localizedText, config) {
return Promise.all(Object.keys(localizedText).map(async (key) => {
const value = await replaceText(key, config);
if (value.length) localizedText[key] = value;
}));
}

export default async function init(el) {
performance.mark('knowledge-base-overview:start');

const miloLibs = getLibs();
const config = getConfig();

const sectionIndex = el.parentNode.getAttribute('data-idx');

let blockData = {
'title': '',
'filters': [],
'sort': {
'default': {},
items: []
},
'cardsPerPage': 9
}

let localizedText = {
'{{apply}}': 'Apply',
'{{back}}': 'Back',
'{{clear-all}}': 'Clear all',
'{{filter}}': 'Filter',
'{{filter-by}}': 'Filter by',
'{{filters}}': 'Filters',
'{{next}}': 'Next',
'{{next-page}}': 'Next Page',
'{{no-results-description}}': 'Try checking your spelling or broadening your search.',
'{{no-results-title}}': 'No Results Found',
'{{of}}': 'Of',
'{{page}}': 'Page',
'{{prev}}': 'Prev',
'{{previous-page}}': 'Previous Page',
'{{results}}': 'Results',
'{{search}}': 'Search',
};

const blockDataActions = {
'title': (cols) => {
const [titleEl] = cols;
blockData.title = titleEl.innerText.trim();
},
'filter': (cols) => {
const [filterKeyEl, filterValueEl, filterTagsKeysEl, filterTagsValueEl] = cols;
const filterKey = filterKeyEl.innerText.trim().toLowerCase();
const filterValue = filterValueEl.innerText.trim();
const filterTagsKeys = Array.from(filterTagsKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase());
const filterTagsValue = Array.from(filterTagsValueEl.querySelectorAll('li'), (li) => li.innerText.trim());

if (!filterKey || !filterTagsKeys.length) return;

let filterObj = {
key: filterKey,
value: filterValue,
tags: filterTagsKeys.map((tagKey, tagIndex) => ({
key: tagKey.replaceAll(' ', '-'),
parentKey: filterKey,
value: filterTagsValue[tagIndex],
checked: false
}))
};
blockData.filters.push(filterObj);
},
'sort': (cols) => {
const [sortKeysEl, sortValuesEl] = cols;
const sortKeys = Array.from(sortKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase());
const sortValues = Array.from(sortValuesEl.querySelectorAll('li'), (li) => li.innerText.trim());

const sortItems = sortKeys.map((sortKey, sortIndex) => ({
key: sortKey.endsWith('_default') ? sortKey.slice(0, -8) : sortKey,
value: sortValues[sortIndex]
}));

const defaultKey = sortKeys.find(key => key.endsWith('_default')).slice(0, -8) || sortKeys[0];
const defaultValue = sortItems.find(e => e.key === defaultKey).value;

blockData.sort = { items: sortItems, default: { key: defaultKey, value: defaultValue }};
},
'cards per page': (cols) => {
const [cardsPerPageEl] = cols;
const cardsPerPageStr = cardsPerPageEl.innerText.trim();
const cardsPerPageNum = parseInt(cardsPerPageStr);
if (cardsPerPageNum) blockData.cardsPerPage = cardsPerPageNum;
}
}

const rows = Array.from(el.children);
rows.forEach((row) => {
const cols = Array.from(row.children);
const rowTitle = cols[0].innerText.trim().toLowerCase();
const colsContent = cols.slice(1);
if (blockDataActions[rowTitle]) blockDataActions[rowTitle](colsContent);
})

const deps = await Promise.all([
localizationPromises(localizedText, config),
import(`${miloLibs}/features/spectrum-web-components/dist/theme.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/search.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/checkbox.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/button.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/progress-circle.js`),
]);

declareKnowledgeBaseOverview();

blockData.localizedText = localizedText;

const app = document.createElement('knowledge-base-overview');
app.className = 'content knowledge-base-overview-wrapper';
app.blockData = blockData;
app.setAttribute('data-idx', sectionIndex);
el.replaceWith(app);

await deps;
draganatrajkovic marked this conversation as resolved.
Show resolved Hide resolved
performance.mark('knowledge-base-overview:end');
performance.measure('knowledge-base-overview block', 'knowledge-base-overview:start', 'knowledge-base-overview:end');
return app;
}
Loading
Loading