mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-19 02:21:32 +08:00
Merge pull request #16543 from ahmedhamidawan/add_id_to_panel_tool_search
Make tool id searchable in side panel search
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
import { orderBy } from "lodash";
|
||||
import levenshteinDistance from "utils/levenshtein";
|
||||
|
||||
const TOOL_ID_KEYS = ["id", "tool_id"];
|
||||
const TOOLS_RESULTS_SORT_LABEL = "apiSort";
|
||||
const TOOLS_RESULTS_SECTIONS_HIDE = ["Expression Tools"];
|
||||
const STRING_REPLACEMENTS = [" ", "-", "(", ")", "'", ":"];
|
||||
const STRING_REPLACEMENTS = [" ", "-", "(", ")", "'", ":", `"`];
|
||||
|
||||
// Converts filterSettings { key: value } to query = "key:value"
|
||||
export function createWorkflowQuery(filterSettings) {
|
||||
@@ -132,6 +133,11 @@ export function hasResults(results) {
|
||||
export function searchToolsByKeys(tools, keys, query, usesDL = false) {
|
||||
let returnedTools = [];
|
||||
let closestTerm = null;
|
||||
const id = processForId(query, TOOL_ID_KEYS);
|
||||
if (id) {
|
||||
query = id;
|
||||
keys = { id: 1 };
|
||||
}
|
||||
const queryValue = sanitizeString(query.trim().toLowerCase(), STRING_REPLACEMENTS);
|
||||
const minimumQueryLength = 5; // for DL
|
||||
for (const tool of tools) {
|
||||
@@ -170,7 +176,7 @@ export function searchToolsByKeys(tools, keys, query, usesDL = false) {
|
||||
}
|
||||
}
|
||||
// no results with string.match(): recursive call with usesDL
|
||||
if (!usesDL && returnedTools.length == 0) {
|
||||
if (!id && !usesDL && returnedTools.length == 0) {
|
||||
return searchToolsByKeys(tools, keys, query, true);
|
||||
}
|
||||
// sorting results by indexed order of keys
|
||||
@@ -279,6 +285,22 @@ function sanitizeString(value, targets = [], substitute = "") {
|
||||
return sanitized.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the query is of the form "id:1234" (or "tool_id:1234"), return the id.
|
||||
* Otherwise, return null.
|
||||
* @param {String} query - the raw query
|
||||
* @param {Array} keys - Optional: keys to check for (default: ["id"])
|
||||
* @returns id or null
|
||||
*/
|
||||
function processForId(query, keys = ["id"]) {
|
||||
for (const key of keys) {
|
||||
if (query.includes(`${key}:`)) {
|
||||
return query.split(`${key}:`)[1].trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function flattenToolsSection(section) {
|
||||
const flattenTools = [];
|
||||
if (section.elems) {
|
||||
|
||||
@@ -108,6 +108,30 @@ describe("test helpers in tool searching utilities", () => {
|
||||
keys: { description: 1, name: 2 },
|
||||
list: tempToolsList,
|
||||
},
|
||||
{
|
||||
// id is not searchable if not identified by colon
|
||||
q: "__ZIP_COLLECTION__",
|
||||
expectedResults: [],
|
||||
keys: { description: 1, name: 2 },
|
||||
list: toolsList,
|
||||
},
|
||||
{
|
||||
// id is searchable if provided "id:"
|
||||
q: "id:__ZIP_COLLECTION__",
|
||||
expectedResults: ["__ZIP_COLLECTION__"],
|
||||
keys: { description: 1, name: 2 },
|
||||
list: toolsList,
|
||||
},
|
||||
{
|
||||
// id is searchable if provided "tool_id:"
|
||||
q: "tool_id:umi_tools",
|
||||
expectedResults: [
|
||||
"toolshed.g2.bx.psu.edu/repos/iuc/umi_tools_extract/umi_tools_extract/1.1.2+galaxy2",
|
||||
"umi_tools_reduplicate",
|
||||
],
|
||||
keys: { description: 1, name: 2 },
|
||||
list: tempToolsList,
|
||||
},
|
||||
];
|
||||
searches.forEach((search) => {
|
||||
const { results } = searchToolsByKeys(flattenTools(search.list), search.keys, search.q);
|
||||
|
||||
Reference in New Issue
Block a user