@atlaskit/global-search
Version:
A cross-product search component (batteries included)
120 lines (97 loc) • 4.47 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapJiraItemToResult = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _uuid = _interopRequireDefault(require("uuid"));
var _Result = require("../model/Result");
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) { (0, _defineProperty2.default)(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; }
var mapJiraItemToResult = function mapJiraItemToResult(analyticsType) {
return function (item) {
return item.attributes && item.attributes['@type'] ? mapJiraItemToResultV2(item, analyticsType) : mapJiraItemToResultV1(item, analyticsType);
};
};
exports.mapJiraItemToResult = mapJiraItemToResult;
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: _Result.ContentType.JiraIssue,
board: _Result.ContentType.JiraBoard,
filter: _Result.ContentType.JiraFilter,
project: _Result.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 === _Result.ContentType.JiraProject ? _Result.ResultType.JiraProjectResult : _Result.ResultType.JiraObjectResult;
return _objectSpread(_objectSpread({
resultId: id,
key: (0, _uuid.default)(),
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: _Result.ResultType.JiraObjectResult,
contentType: _Result.ContentType.JiraIssue,
isRecentResult: mapAnalyticsTypeToRecentResult(analyticsType)
};
};
var mapAnalyticsTypeToRecentResult = function mapAnalyticsTypeToRecentResult(analyticsType) {
return analyticsType.startsWith('recent');
};