UNPKG

coveo-search-ui-extensions

Version:

Small generic components to extend the functionality of Coveo's Search UI framework.

79 lines 3.83 kB
import { Component, ComponentOptions, Initialization, l } from 'coveo-search-ui'; import { UserActions } from '../UserActions/UserActions'; import { user } from '../../utils/icons'; import './Strings'; /** * The _ViewedByCustomer_ component allows your agents to see, within the Salesforce Lightning console, every result which the user clicked. It displays an icon and a label on each result, if already viewed by the customer who created the case (see [Coveo Component ViewedByCustomer](https://docs.coveo.com/en/3073/coveoforsalesforce/viewedbycustomercomponent)). * ```html * <div class="CoveoViewedByCustomer"></div> * ``` */ export class ViewedByCustomer extends Component { /** * Create an instance of {@link ViewedByCustomer}. * @param element Element on which to bind the component. * @param options Initialization options of the component. * @param bindings Bindings of the Search-UI environment. */ constructor(element, options, bindings, result) { super(element, ViewedByCustomer.ID, bindings); this.element = element; this.options = options; this.bindings = bindings; if (this.root.getElementsByClassName(Component.computeCssClassNameForType(UserActions.ID)).length === 0) { this.logger.warn('The ViewedByCustomer component has been detected without a UserActions component. You may encounter issues with the former.'); } this.options = ComponentOptions.initComponentOptions(element, ViewedByCustomer, options); result = result ? result : this.resolveResult(); if (!result) { throw new Error('No result found on result component ViewedByCustomer.'); } if (result.isUserActionView) { this.render(); } } render() { if (this.options.showIcon) { const iconElement = document.createElement('span'); iconElement.classList.add(ViewedByCustomer.ICON_CLASS); iconElement.innerHTML = user; this.element.appendChild(iconElement); } const labelElement = document.createElement('span'); labelElement.classList.add(ViewedByCustomer.LABEL_CLASS); labelElement.innerText = this.options.label; this.element.appendChild(labelElement); } /** * Generate a ViewedByCustomer in a preformated Dom ready to be inserted in a result * @param bindings bindings to be used by the {@link ViewedByCustomer} * @param result result to be used by the {@link ViewedByCustomer} */ static getViewedByCustomerResultRowDom(bindings, result) { const viewedByCustomerRow = document.createElement('div'); viewedByCustomerRow.classList.add('coveo-result-row'); const viewedByCustomerCell = document.createElement('div'); viewedByCustomerCell.classList.add('coveo-result-cell'); const viewedByCustomerElement = document.createElement('span'); new ViewedByCustomer(viewedByCustomerElement, undefined, bindings, result); viewedByCustomerCell.appendChild(viewedByCustomerElement); viewedByCustomerRow.appendChild(viewedByCustomerCell); return viewedByCustomerRow; } } /** * Unique Identifier used by the Search-UI. */ ViewedByCustomer.ID = 'ViewedByCustomer'; /** * Default options used by the component. */ ViewedByCustomer.options = { showIcon: ComponentOptions.buildBooleanOption({ defaultValue: true }), label: ComponentOptions.buildStringOption({ defaultValue: l(`${ViewedByCustomer.ID}_DefaultLabel`) }), }; // Internal CSS selectors. ViewedByCustomer.ICON_CLASS = 'viewed-by-customer-icon'; ViewedByCustomer.LABEL_CLASS = 'viewed-by-customer-label'; Initialization.registerAutoCreateComponent(ViewedByCustomer); //# sourceMappingURL=ViewedByCustomer.js.map