@atlaskit/global-search
Version:
A cross-product search component (batteries included)
42 lines (39 loc) • 1.69 kB
JavaScript
import { ResultType, AnalyticsType, ContentType } from '../model/Result';
import { Scope } from './types';
export function removeHighlightTags(text) {
return text.replace(/@@@hl@@@|@@@endhl@@@/g, '');
}
function mapConfluenceItemToResultObject(item, experimentId) {
return {
resultId: item.content.id,
// content always available for pages/blogs/attachments
name: removeHighlightTags(item.title),
href: "".concat(item.baseUrl).concat(item.url),
containerName: item.container.title,
analyticsType: AnalyticsType.ResultConfluence,
contentType: "confluence-".concat(item.content.type),
resultType: ResultType.ConfluenceObjectResult,
containerId: item.content.space && item.content.space.id ? item.content.space.id : 'UNAVAILABLE',
iconClass: item.iconCssClass,
experimentId: experimentId,
friendlyLastModified: item.friendlyLastModified
};
}
function mapConfluenceItemToResultSpace(spaceItem, experimentId) {
return {
resultId: "space-".concat(spaceItem.space.key),
// space is always defined for space results
avatarUrl: "".concat(spaceItem.baseUrl).concat(spaceItem.space.icon.path),
name: spaceItem.container.title,
href: "".concat(spaceItem.baseUrl || '').concat(spaceItem.container.displayUrl),
analyticsType: AnalyticsType.ResultConfluence,
resultType: ResultType.GenericContainerResult,
contentType: ContentType.ConfluenceSpace,
experimentId: experimentId,
key: spaceItem.space.key
};
}
export function mapConfluenceItemToResult(scope, item) {
var mapper = scope === Scope.ConfluenceSpace ? mapConfluenceItemToResultSpace : mapConfluenceItemToResultObject;
return mapper(item);
}