Skip to content

Commit

Permalink
allow partial matches in workflow name tag search
Browse files Browse the repository at this point in the history
do not require quotations for name tags
  • Loading branch information
ahmedhamidawan committed Oct 16, 2023
1 parent 7c013cc commit fab8b6c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Page/PageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import StatelessTags from "components/TagsMultiselect/StatelessTags";
import UtcDate from "components/UtcDate";
import paginationMixin from "components/Workflow/paginationMixin";
import { getAppRoot } from "onload/loadConfig";
import Filtering, { contains, equals, expandNameTagWithQuotes, toBool } from "utils/filtering";
import Filtering, { contains, equals, expandNameTag, toBool } from "utils/filtering";
import _l from "utils/localization";
import { useRouter } from "vue-router/composables";
Expand Down Expand Up @@ -155,7 +155,7 @@ const validFilters = {
tag: {
placeholder: "tag(s)",
type: "MultiTags",
handler: contains("tag", "tag", expandNameTagWithQuotes),
handler: contains("tag", "tag", expandNameTag),
menuItem: true,
},
published: {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Workflow/WorkflowFilters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Filtering, { contains, equals, expandNameTagWithQuotes, toBool } from "utils/filtering";
import Filtering, { contains, equals, expandNameTag, toBool } from "utils/filtering";

export const helpHtml = `<div>
<p>This input can be used to filter the workflows displayed.</p>
Expand Down Expand Up @@ -56,7 +56,7 @@ const validFilters = {
tag: {
placeholder: "tag(s)",
type: "MultiTags",
handler: contains("tag", "tag", expandNameTagWithQuotes),
handler: contains("tag", "tag", expandNameTag),
menuItem: true,
},
published: {
Expand Down
24 changes: 5 additions & 19 deletions client/src/utils/filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,13 @@ export function toLowerNoQuotes<T>(value: T): string {
* */
export function expandNameTag<T>(value: T): string {
if (value && typeof value === "string") {
value = value.replace(/^#/, "name:") as T;
}
return toLower(value);
}

/** Converts name tags starting with "#" to "'name:...'"; forces quotation marks
* and **is also case-sensitive**
* @param value
* @returns Lowercase value with 'name:' replaced with '#'
*/
export function expandNameTagWithQuotes<T>(value: T): string {
if (value && typeof value === "string") {
if (value.startsWith("'#") && value.endsWith("'")) {
value = value.replace(/^'#/g, "'name:") as T;
} else if (value.startsWith("#")) {
value = `'name:${value.slice(1)}'` as T;
if ((value.startsWith("'#") || value.startsWith('"#')) && (value.endsWith('"') || value.endsWith("'"))) {
value = value.replace(/^['"]#/g, "'name:") as T;
} else {
value = value.replace(/^#/, "name:") as T;
}
}
return value as string;
return toLower(value);
}

/** Converts string alias to string operator, e.g.: 'gt' to '>'
Expand Down Expand Up @@ -569,8 +557,6 @@ export default class Filtering<T> {
return filterValue;
} else if (!backendFormatted && ([expandNameTag, toDate] as Converter<T>[]).includes(converter)) {
return toLower(filterValue) as T;
} else if (!backendFormatted && converter == expandNameTagWithQuotes) {
return (filterValue as string).startsWith("#") ? (`'${filterValue}'` as T) : filterValue;
}
return converter(filterValue);
} else {
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/util/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parse_filters_structured(
search_space = search_term.replace('"', "'")
filters = filters or {}
filter_keys = "|".join(list(filters.keys()))
pattern = rf"({filter_keys}):(?:\s+)?([\w-]+|\'.*?\')"
pattern = rf"({filter_keys}):(?:\s+)?([\w-]+|'.*?')(:\w+)?"
reserved = re.compile(pattern)
parsed_search = ParsedSearch()
while True:
Expand All @@ -52,8 +52,11 @@ def parse_filters_structured(
else:
first_group = match.groups()[0]
if first_group in filters:
if match.groups()[0] == "tag" and match.groups()[1] == "name" and match.groups()[2] is not None:
group = match.groups()[1] + match.groups()[2].strip()
else:
group = match.groups()[1].strip()
filter_as = filters[first_group]
group = match.groups()[1].strip()
quoted = preserve_quotes and group.startswith("'")
parsed_search.add_keyed_term(filter_as, group.replace("'", ""), quoted)
parsed_search.add_unfiltered_text_terms(search_space[0 : match.start()])
Expand Down

0 comments on commit fab8b6c

Please sign in to comment.