@atlaskit/global-search
Version:
A cross-product search component (batteries included)
130 lines (114 loc) • 4.32 kB
JavaScript
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import { utils } from '@atlaskit/util-service-support';
import { AnalyticsType, ContentType, ResultType } from '../model/Result';
var RECENT_PAGES_PATH = 'rest/recentlyviewed/1.0/recent';
var RECENT_SPACE_PATH = 'rest/recentlyviewed/1.0/recent/spaces';
var ConfluenceClientImpl = /*#__PURE__*/function () {
function ConfluenceClientImpl(url) {
_classCallCheck(this, ConfluenceClientImpl);
this.serviceConfig = {
url: url
};
}
_createClass(ConfluenceClientImpl, [{
key: "getRecentItems",
value: function () {
var _getRecentItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var recentPages, baseUrl;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return this.createRecentRequestPromise(RECENT_PAGES_PATH);
case 2:
recentPages = _context.sent;
baseUrl = this.serviceConfig.url;
return _context.abrupt("return", recentPages.filter(function (page) {
return !!page.title;
}).map(function (recentPage) {
return recentPageToResult(recentPage, baseUrl);
}));
case 5:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function getRecentItems() {
return _getRecentItems.apply(this, arguments);
}
return getRecentItems;
}()
}, {
key: "getRecentSpaces",
value: function () {
var _getRecentSpaces = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
var recentSpaces, baseUrl;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return this.createRecentRequestPromise(RECENT_SPACE_PATH);
case 2:
recentSpaces = _context2.sent;
baseUrl = this.serviceConfig.url;
return _context2.abrupt("return", recentSpaces.map(function (recentSpace) {
return recentSpaceToResult(recentSpace, baseUrl);
}));
case 5:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function getRecentSpaces() {
return _getRecentSpaces.apply(this, arguments);
}
return getRecentSpaces;
}()
}, {
key: "createRecentRequestPromise",
value: function createRecentRequestPromise(path) {
var options = {
path: path
};
return utils.requestService(this.serviceConfig, options);
}
}]);
return ConfluenceClientImpl;
}();
export { ConfluenceClientImpl as default };
function recentPageToResult(recentPage, baseUrl) {
return {
resultId: String(recentPage.id),
name: recentPage.title || '',
// This is a failsafe, there should be a filter to drop pages with no titles
href: "".concat(baseUrl).concat(recentPage.url),
containerName: recentPage.space,
analyticsType: AnalyticsType.RecentConfluence,
resultType: ResultType.ConfluenceObjectResult,
contentType: "confluence-".concat(recentPage.contentType),
iconClass: recentPage.iconClass,
containerId: recentPage.spaceKey,
isRecentResult: true,
friendlyLastModified: undefined // not available for recent results
};
}
function recentSpaceToResult(recentSpace, baseUrl) {
return {
resultId: recentSpace.id,
name: recentSpace.name,
href: "".concat(baseUrl, "/spaces/").concat(recentSpace.key, "/overview"),
avatarUrl: recentSpace.icon,
analyticsType: AnalyticsType.RecentConfluence,
resultType: ResultType.GenericContainerResult,
contentType: ContentType.ConfluenceSpace
};
}