mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-30 18:13:23 +08:00
Allow search datasets by name tag using #
Also allow search by `contains` instead of `equals` tag name match
This commit is contained in:
@@ -30,10 +30,19 @@ function toLowerNoQuotes(value) {
|
||||
return toLower(value).replaceAll("'", "");
|
||||
}
|
||||
|
||||
/** Converts name tags starting with '#' to 'name:' */
|
||||
function expandNameTag(value) {
|
||||
if (value && typeof value === "string" && value.startsWith("#")) {
|
||||
value = value.replace("#", "name:");
|
||||
}
|
||||
return toLower(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a query value is equal to the item value
|
||||
* @param {*} attribute of the content item
|
||||
* @param {*} query parameter if the attribute does not match the server query key
|
||||
* @param {*} converter if item attribute value has to be transformed e.g. to a date.
|
||||
*/
|
||||
function equals(attribute, query = null, converter = null) {
|
||||
return {
|
||||
@@ -49,12 +58,19 @@ function equals(attribute, query = null, converter = null) {
|
||||
/**
|
||||
* Checks if a query value is part of the item value
|
||||
* @param {*} attribute of the content item
|
||||
* @param {*} query parameter if the attribute does not match the server query key
|
||||
* @param {*} converter if item attribute value has to be transformed e.g. to a date.
|
||||
*/
|
||||
function contains(attribute, query = null) {
|
||||
function contains(attribute, query = null, converter = null) {
|
||||
return {
|
||||
attribute,
|
||||
converter,
|
||||
query: query || `${attribute}-contains`,
|
||||
handler: (v, q) => {
|
||||
if (converter) {
|
||||
v = converter(v);
|
||||
q = converter(q);
|
||||
}
|
||||
return toLower(v).includes(toLower(q));
|
||||
},
|
||||
};
|
||||
@@ -107,7 +123,7 @@ const validFilters = {
|
||||
visible: equals("visible", "visible", toBool),
|
||||
name: contains("name"),
|
||||
state: equals("state"),
|
||||
tag: contains("tags", "tag"),
|
||||
tag: contains("tags", "tag-contains", expandNameTag),
|
||||
update_time: compare("update_time", "le", toDate),
|
||||
update_time_ge: compare("update_time", "ge", toDate),
|
||||
update_time_gt: compare("update_time", "gt", toDate),
|
||||
|
||||
@@ -54,7 +54,7 @@ describe("filtering", () => {
|
||||
expect(queryDict["update_time-lt"]).toBe(1640995200);
|
||||
expect(queryDict["state-eq"]).toBe("success");
|
||||
expect(queryDict["extension-eq"]).toBe("ext");
|
||||
expect(queryDict["tag"]).toBe("first");
|
||||
expect(queryDict["tag-contains"]).toBe("first");
|
||||
expect(queryDict["deleted"]).toBe(false);
|
||||
expect(queryDict["visible"]).toBe(true);
|
||||
});
|
||||
@@ -106,4 +106,11 @@ describe("filtering", () => {
|
||||
expect(toAlias(getFilters(filterTexts[index]))).toEqual(parsedFilterSettings);
|
||||
});
|
||||
});
|
||||
test("named tag (hash) conversion", () => {
|
||||
const filters = getFilters("tag=#test");
|
||||
expect(filters[0][0]).toBe("tag");
|
||||
expect(filters[0][1]).toBe("#test");
|
||||
const queryDict = getQueryDict("tag=#test");
|
||||
expect(queryDict["tag-contains"]).toBe("name:test");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user