UNPKG

@atlaskit/global-search

Version:

A cross-product search component (batteries included)

83 lines (74 loc) 2.85 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React from 'react'; import { FormattedMessage } from 'react-intl'; import ResultGroup from '../ResultGroup'; import { PreQueryAnalyticsComponent, PostQueryAnalyticsComponent } from './ScreenAnalyticsHelper'; export let ResultGroupType; (function (ResultGroupType) { ResultGroupType["PreQuery"] = "PreQuery"; ResultGroupType["PostQuery"] = "PostQuery"; })(ResultGroupType || (ResultGroupType = {})); export default class ResultGroupsComponent extends React.Component { constructor(...args) { super(...args); _defineProperty(this, "mapGroupsToSections", (resultsToShow, analyticsData) => { const { onShowMoreClicked, onSearchMoreAdvancedSearchClicked, query } = this.props; return resultsToShow.filter(({ items }) => items && items.length).map((group, index) => /*#__PURE__*/React.createElement(ResultGroup, { key: `${group.key}-${index}`, title: group.title ? /*#__PURE__*/React.createElement(FormattedMessage, group.title) : undefined, results: group.items, sectionIndex: index, analyticsData: analyticsData, showTotalSize: group.showTotalSize, totalSize: group.totalSize, showMoreButton: group.showTotalSize, onShowMoreClicked: () => onShowMoreClicked(group.key), onSearchMoreAdvancedSearch: onSearchMoreAdvancedSearchClicked, query: query })); }); _defineProperty(this, "getAnalyticsData", () => ({ resultCount: this.props.resultsGroups.map(({ items }) => items.length).reduce((total, count) => total + count, 0) })); } getAnalyticsComponent() { const { searchSessionId, screenCounter, referralContextIdentifiers, type } = this.props; switch (type) { case ResultGroupType.PreQuery: return /*#__PURE__*/React.createElement(PreQueryAnalyticsComponent, { key: "pre-query-analytics", screenCounter: screenCounter, searchSessionId: searchSessionId, referralContextIdentifiers: referralContextIdentifiers }); case ResultGroupType.PostQuery: return /*#__PURE__*/React.createElement(PostQueryAnalyticsComponent, { key: "post-query-analytics", screenCounter: screenCounter, searchSessionId: searchSessionId, referralContextIdentifiers: referralContextIdentifiers }); } } render() { const { renderAdvancedSearch, resultsGroups } = this.props; const analyticsData = this.getAnalyticsData(); return /*#__PURE__*/React.createElement(React.Fragment, null, this.mapGroupsToSections(resultsGroups, analyticsData), renderAdvancedSearch(analyticsData), this.getAnalyticsComponent()); } }