Skip to content

Commit

Permalink
fix name tag filtering functionality
Browse files Browse the repository at this point in the history
Quoted tags should match exact results. Name tags are unquoted _when sent to the backend_.
  • Loading branch information
ahmedhamidawan committed Mar 14, 2024
1 parent 5b51c80 commit 12d8b7d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ watch(operationMessage, () => {
:value="rowData[fieldEntry.key]"
:disabled="fieldEntry.disabled"
@input="onTagInput(rowData, $event, fieldEntry.handler)"
@tag-click="applyFilter('tag', $event)" />
@tag-click="applyFilter('tag', $event, true)" />
<span v-else v-localize> Not available. </span>
</div>
<FontAwesomeIcon v-else icon="fa-shield-alt" />
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/Workflow/WorkflowCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits<{
(e: "tagClick", tag: string): void;
(e: "refreshList", overlayLoading?: boolean, b?: boolean): void;
(e: "update-filter", key: string, value: any): void;
}>();
const userStore = useUserStore();
Expand Down Expand Up @@ -126,7 +127,10 @@ async function onTagClick(tag: string) {
<div>
<div class="d-flex justify-content-between align-items-center mb-1">
<div>
<WorkflowIndicators :workflow="workflow" :published-view="publishedView" />
<WorkflowIndicators
:workflow="workflow"
:published-view="publishedView"
@update-filter="(k, v) => emit('update-filter', k, v)" />

<span class="workflow-name font-weight-bold">
{{ workflow.name }}
Expand Down
6 changes: 6 additions & 0 deletions client/src/components/Workflow/WorkflowIndicators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interface Props {
const props = defineProps<Props>();
const emit = defineEmits<{
(e: "update-filter", key: string, value: any): void;
}>();
const router = useRouter();
const userStore = useUserStore();
Expand Down Expand Up @@ -69,10 +73,12 @@ function onCopyLink() {
function onViewMySharedByUser() {
router.push(`/workflows/list_shared_with_me?owner=${props.workflow.owner}`);
emit("update-filter", "user", `'${props.workflow.owner}'`);
}
function onViewUserPublished() {
router.push(`/workflows/list_published?owner=${props.workflow.owner}`);
emit("update-filter", "user", `'${props.workflow.owner}'`);
}
</script>

Expand Down
11 changes: 6 additions & 5 deletions client/src/components/Workflow/WorkflowList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ watch([filterText, sortBy, sortDesc, showBookmarked], async () => {
onMounted(() => {
if (router.currentRoute.query.owner) {
updateFilterValue("user", router.currentRoute.query.owner);
updateFilterValue("user", `'${router.currentRoute.query.owner}'`);
}
load();
});
Expand Down Expand Up @@ -273,9 +273,9 @@ onMounted(() => {
>: {{ value }}
</li>
</ul>
<a href="javascript:void(0)" class="ui-link" @click="filterText = validatedFilterText()"
>Remove invalid filters from query</a
>
<a href="javascript:void(0)" class="ui-link" @click="filterText = validatedFilterText()">
Remove invalid filters from query
</a>
</BAlert>
</span>

Expand All @@ -294,7 +294,8 @@ onMounted(() => {
:grid-view="view === 'grid'"
:class="view === 'grid' ? 'grid-view' : 'list-view'"
@refreshList="load"
@tagClick="(tag) => updateFilterValue('tag', tag)" />
@tagClick="(tag) => updateFilterValue('tag', `'${tag}'`)"
@update-filter="updateFilterValue" />

<BPagination
v-if="!loading && totalWorkflows > limit"
Expand Down
13 changes: 7 additions & 6 deletions client/src/utils/filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function toLowerNoQuotes<T>(value: T): string {

/** Converts name tags starting with '#' to 'name:'
* @param value
* @returns Lowercase value with 'name:' replaced with '#'
* @returns String value with 'name:' replaced with '#'
* */
export function expandNameTag<T>(value: T): string {
if (value && typeof value === "string") {
Expand All @@ -114,7 +114,7 @@ export function expandNameTag<T>(value: T): string {
value = value.replace(/^#/, "name:") as T;
}
}
return toLower(value);
return value as string;
}

/** Converts string alias to string operator, e.g.: 'gt' to '>'
Expand Down Expand Up @@ -233,7 +233,9 @@ export function compare<T>(attribute: string, variant: string, converter?: Conve
* @param validAliases: Array of valid aliases for filters
* @param quoteStrings: Whether to auto quote filter strings in the query
* @param nameMatching: Whether to apply name filter for unspecified filterText
* (e.g. filterText = 'foo' -> 'name:foo')
* (e.g. filterText = 'foo' -> 'name:foo').
* Typically, when this is false, we index every field in
* the backend for unspecified filterText.
* @returns Filtering object
* */
export default class Filtering<T> {
Expand Down Expand Up @@ -588,11 +590,10 @@ export default class Filtering<T> {
if (converter) {
if (
(converter == toBool && filterValue == "any") ||
(!backendFormatted && /^(['"]).*\1$/.test(filterValue as string))
(!backendFormatted && /^(['"]).*\1$/.test(filterValue as string)) ||
(!backendFormatted && ([expandNameTag, toDate] as Converter<T>[]).includes(converter))
) {
return filterValue;
} else if (!backendFormatted && ([expandNameTag, toDate] as Converter<T>[]).includes(converter)) {
return toLower(filterValue) as T;
}
return converter(filterValue);
} else {
Expand Down

0 comments on commit 12d8b7d

Please sign in to comment.