UNPKG

@atlaskit/global-search

Version:

A cross-product search component (batteries included)

107 lines (90 loc) 4.08 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import uuid from 'uuid'; import { ResultType, ContentType } from '../model/Result'; export var mapJiraItemToResult = function mapJiraItemToResult(analyticsType) { return function (item) { return item.attributes && item.attributes['@type'] ? mapJiraItemToResultV2(item, analyticsType) : mapJiraItemToResultV1(item, analyticsType); }; }; var extractSpecificAttributes = function extractSpecificAttributes(attributes) { var type = attributes['@type']; switch (type) { case 'issue': return { objectKey: attributes.key, containerName: attributes.container && attributes.container.title }; case 'board': return { containerName: attributes.containerName, containerId: attributes.containerId }; case 'filter': return { containerName: attributes.ownerName }; case 'project': return { containerName: attributes.projectType, projectType: attributes.projectType // projectType maps directly to JiraProjectType enum at the moment for convenience }; } return null; }; var extractAvatarUrl = function extractAvatarUrl() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$url = _ref.url, url = _ref$url === void 0 ? '' : _ref$url, _ref$urls = _ref.urls, urls = _ref$urls === void 0 ? {} : _ref$urls; if (url) { return url; } return urls['48x48'] || urls[Object.keys(urls)[0]]; }; var JIRA_TYPE_TO_CONTENT_TYPE = { issue: ContentType.JiraIssue, board: ContentType.JiraBoard, filter: ContentType.JiraFilter, project: ContentType.JiraProject }; var mapJiraItemToResultV2 = function mapJiraItemToResultV2(item, analyticsType) { var id = item.id, name = item.name, url = item.url, attributes = item.attributes; var contentType = JIRA_TYPE_TO_CONTENT_TYPE[attributes['@type']]; var resultType = contentType === ContentType.JiraProject ? ResultType.JiraProjectResult : ResultType.JiraObjectResult; return _objectSpread(_objectSpread({ resultId: id, key: uuid(), name: name, href: url, resultType: resultType, containerId: attributes.container && attributes.container.id, analyticsType: analyticsType }, extractSpecificAttributes(attributes)), {}, { avatarUrl: attributes.avatar && extractAvatarUrl(attributes.avatar), contentType: contentType, isRecentResult: mapAnalyticsTypeToRecentResult(analyticsType) }); }; var mapJiraItemToResultV1 = function mapJiraItemToResultV1(item, analyticsType) { return { resultId: item.key, avatarUrl: item.fields.issuetype.iconUrl, name: item.fields.summary, href: "/browse/".concat(item.key), containerName: item.fields.project.name, objectKey: item.key, analyticsType: analyticsType, resultType: ResultType.JiraObjectResult, contentType: ContentType.JiraIssue, isRecentResult: mapAnalyticsTypeToRecentResult(analyticsType) }; }; var mapAnalyticsTypeToRecentResult = function mapAnalyticsTypeToRecentResult(analyticsType) { return analyticsType.startsWith('recent'); };