@jbrowse/plugin-linear-genome-view
Version:
JBrowse 2 linear genome view
54 lines (53 loc) • 1.77 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFiltered = getFiltered;
exports.aggregateResults = aggregateResults;
exports.getDeduplicatedResult = getDeduplicatedResult;
const BaseResults_1 = __importDefault(require("@jbrowse/core/TextSearch/BaseResults"));
function filterOptions(options, searchQuery) {
return options.filter(({ result }) => result.getLabel().toLowerCase().includes(searchQuery) ||
result.matchedObject);
}
function getFiltered(opts, inputValue) {
const filtered = filterOptions(opts, inputValue.toLocaleLowerCase());
return [
...filtered.slice(0, 100),
...(filtered.length > 100
? [
{
group: 'limitOption',
result: new BaseResults_1.default({
label: 'keep typing for more results',
}),
},
]
: []),
];
}
function aggregateResults(results) {
const m = {};
for (const result of results) {
const displayString = result.getDisplayString();
if (!m[displayString]) {
m[displayString] = [];
}
m[displayString].push(result);
}
return m;
}
function getDeduplicatedResult(results) {
return Object.entries(aggregateResults(results)).map(([displayString, results]) => results.length === 1
? {
result: results[0],
}
: {
result: new BaseResults_1.default({
displayString,
results,
label: displayString,
}),
});
}