@atlaskit/global-search
Version:
A cross-product search component (batteries included)
129 lines (109 loc) • 5.11 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapSearchResultsToUIGroups = exports.mapRecentResultsToUIGroups = exports.MAX_RECENT_RESULTS_TO_SHOW = exports.MAX_PEOPLE = exports.MAX_SPACES = exports.DEFAULT_MAX_OBJECTS = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _messages = require("../../messages");
var _contextIdentifiersHelper = require("../common/contextIdentifiersHelper");
var _SearchResultsUtil = require("../SearchResultsUtil");
var _experimentUtils = require("../../util/experiment-utils");
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 DEFAULT_MAX_OBJECTS = 10;
exports.DEFAULT_MAX_OBJECTS = DEFAULT_MAX_OBJECTS;
var MAX_SPACES = 3;
exports.MAX_SPACES = MAX_SPACES;
var MAX_PEOPLE = 3;
exports.MAX_PEOPLE = MAX_PEOPLE;
var MAX_RECENT_RESULTS_TO_SHOW = 3;
exports.MAX_RECENT_RESULTS_TO_SHOW = MAX_RECENT_RESULTS_TO_SHOW;
var EMPTY_CONFLUENCE_RESULT = {
people: {
items: [],
totalSize: 0
},
objects: {
items: [],
totalSize: 0
},
spaces: {
items: [],
totalSize: 0
}
};
var sliceResults = function sliceResults(resultsMap, features) {
if (!resultsMap) {
return EMPTY_CONFLUENCE_RESULT;
}
var people = resultsMap.people,
objects = resultsMap.objects,
spaces = resultsMap.spaces;
return {
objects: _objectSpread(_objectSpread({}, objects), {}, {
items: (0, _SearchResultsUtil.take)(objects.items, (0, _experimentUtils.getConfluenceMaxObjects)(features.abTest, objects.numberOfCurrentItems || _experimentUtils.CONF_OBJECTS_ITEMS_PER_PAGE)),
numberOfCurrentItems: objects.numberOfCurrentItems || Math.min(_experimentUtils.CONF_OBJECTS_ITEMS_PER_PAGE, objects.items.length || 0)
}),
spaces: _objectSpread(_objectSpread({}, spaces), {}, {
items: (0, _SearchResultsUtil.take)(spaces.items, MAX_SPACES)
}),
people: _objectSpread(_objectSpread({}, people), {}, {
items: (0, _SearchResultsUtil.take)(people.items, MAX_PEOPLE)
})
};
};
var mapRecentResultsToUIGroups = function mapRecentResultsToUIGroups(recentlyViewedObjects, features, searchSessionId) {
var sliced = sliceResults(recentlyViewedObjects, features);
var _attachConfluenceCont = (0, _contextIdentifiersHelper.attachConfluenceContextIdentifiers)(searchSessionId, sliced),
people = _attachConfluenceCont.people,
objects = _attachConfluenceCont.objects,
spaces = _attachConfluenceCont.spaces;
return [{
items: objects.items,
key: 'objects',
title: _messages.messages.confluence_recent_pages_heading,
totalSize: objects.totalSize,
showTotalSize: false
}, {
items: spaces.items,
key: 'spaces',
title: _messages.messages.confluence_recent_spaces_heading,
totalSize: spaces.totalSize,
showTotalSize: false
}, {
items: people.items,
key: 'people',
title: _messages.messages.people_recent_people_heading,
totalSize: people.totalSize,
showTotalSize: false
}];
};
exports.mapRecentResultsToUIGroups = mapRecentResultsToUIGroups;
var mapSearchResultsToUIGroups = function mapSearchResultsToUIGroups(searchResultsObjects, features, searchSessionId, hideAllSizeLozenge) {
var sliced = sliceResults(searchResultsObjects, features);
var _attachConfluenceCont2 = (0, _contextIdentifiersHelper.attachConfluenceContextIdentifiers)(searchSessionId, sliced),
people = _attachConfluenceCont2.people,
objects = _attachConfluenceCont2.objects,
spaces = _attachConfluenceCont2.spaces;
return [{
items: objects.items,
key: 'objects',
title: _messages.messages.confluence_confluence_objects_heading,
totalSize: objects.totalSize,
showTotalSize: !hideAllSizeLozenge
}, {
items: spaces.items,
key: 'spaces',
title: _messages.messages.confluence_spaces_heading,
totalSize: spaces.totalSize,
showTotalSize: false
}, {
items: people.items,
key: 'people',
title: _messages.messages.people_people_heading,
totalSize: people.totalSize,
showTotalSize: false
}];
};
exports.mapSearchResultsToUIGroups = mapSearchResultsToUIGroups;