Skip to content

Commit 6381442

Browse files
apply filter on click instead of routing with filter
1 parent f392f56 commit 6381442

3 files changed

Lines changed: 51 additions & 17 deletions

File tree

client/src/components/ToolsList/ToolsList.vue

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ const validFilters = computed<Record<string, ValidFilter<string>>>(() => {
6363
help: { placeholder: "help text", type: String, handler: contains("help"), menuItem: true },
6464
};
6565
});
66-
const ToolFilters = computed<Filtering<string>>(() => new Filtering(validFilters.value, undefined, true, false));
66+
// TODO: We need to use double quotes as opposed to the default single quotes in the Filtering class
67+
// (will need to implement this in the Filtering class). We need this because the whoosh query
68+
// requires double quotes for phrases.
69+
// See: https://whoosh.readthedocs.io/en/latest/querylang.html#query
70+
// For now, I've changed the `quoteStrings` param to `false` to avoid issues with the quotes, and added
71+
// a "hint" to the `FilterMenu` help text.
72+
const ToolFilters = computed<Filtering<string>>(() => new Filtering(validFilters.value, undefined, false, false));
6773
6874
// Scroll Variables
6975
const scrollContainer = ref<HTMLElement | null>(null);
@@ -98,6 +104,10 @@ watch(
98104
},
99105
{ deep: true, immediate: true }
100106
);
107+
108+
function applyFilter(filter: string, value: string) {
109+
filterText.value = ToolFilters.value.setFilterValue(filterText.value, filter, value);
110+
}
101111
</script>
102112

103113
<template>
@@ -127,12 +137,23 @@ watch(
127137
the results showing up in the center panel.
128138
</p>
129139

130-
<p>
131-
<i>
132-
(Clicking on the Section, Repo or Owner labels in the Search Results will activate the
133-
according filter)
134-
</i>
135-
</p>
140+
<div>
141+
Hints:
142+
<ul>
143+
<li>
144+
<i>
145+
Clicking on the Section, Repo or Owner labels in the Search Results will
146+
activate the according filter.
147+
</i>
148+
</li>
149+
<li>
150+
<i>
151+
To find exact matches, you need to use double quotes (e.g.:
152+
<code>"Get Data"</code>) around the search term.
153+
</i>
154+
</li>
155+
</ul>
156+
</div>
136157

137158
<p>The available tool search filters are:</p>
138159
<dl>
@@ -173,7 +194,7 @@ watch(
173194
No tools found for the entered filters.
174195
</BAlert>
175196
<div v-else>
176-
<ToolsListTable :tools="itemsLoaded" />
197+
<ToolsListTable :tools="itemsLoaded" @apply-filter="applyFilter" />
177198
</div>
178199
</div>
179200
<ScrollToTopButton :offset="scrollTop" @click="scrollToTop" />

client/src/components/ToolsList/ToolsListItem.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import {
33
faAngleDown,
44
faAngleUp,
@@ -8,18 +8,20 @@ import {
88
faWrench,
99
} from "@fortawesome/free-solid-svg-icons";
1010
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
11-
import ToolFavoriteButton from "components/Tool/Buttons/ToolFavoriteButton";
12-
import { useFormattedToolHelp } from "composables/formattedToolHelp";
1311
import { computed, ref } from "vue";
1412
13+
import { useFormattedToolHelp } from "@/composables/formattedToolHelp";
14+
1515
import GButton from "../BaseComponents/GButton.vue";
1616
import GLink from "@/components/BaseComponents/GLink.vue";
17+
import ToolFavoriteButton from "@/components/Tool/Buttons/ToolFavoriteButton.vue";
1718
19+
// TODO: Refactor props to use defineProps with types (best practices)
1820
const props = defineProps({
1921
id: { type: String, required: true },
2022
name: { type: String, required: true },
2123
section: { type: String, required: true },
22-
ontologies: { type: Array, default: null },
24+
ontologies: { type: Array<string>, default: null },
2325
description: { type: String, default: null },
2426
summary: { type: String, default: null },
2527
help: { type: String, default: null },
@@ -30,7 +32,11 @@ const props = defineProps({
3032
owner: { type: String, default: null },
3133
});
3234
33-
const emit = defineEmits(["open"]);
35+
// TODO: For tool open emit, consider adding event as param to allow for opening tool in new tab
36+
const emit = defineEmits<{
37+
(e: "open"): void;
38+
(e: "apply-filter", filter: string, value: string): void;
39+
}>();
3440
3541
const showHelp = ref(false);
3642
@@ -42,6 +48,10 @@ const formattedToolHelp = computed(() => {
4248
return "";
4349
}
4450
});
51+
52+
/** We add double quotes to the section filter since the backend Whoosh search
53+
* requires it for exact matches, and the `Filtering` class only does single quotes. */
54+
const quotedSection = computed(() => (props.section ? `"${props.section}"` : ""));
4555
</script>
4656

4757
<template>
@@ -86,7 +96,8 @@ const formattedToolHelp = computed(() => {
8696
<div class="tool-list-item-content">
8797
<div class="d-flex flex-gapx-1 py-2">
8898
<span v-if="props.section" class="tag info">
89-
<b>Section:</b> <GLink thin :to="`/tools/list?section=${props.section}`">{{ section }}</GLink>
99+
<b>Section:</b>
100+
<GLink thin @click="() => emit('apply-filter', 'section', quotedSection)">{{ section }}</GLink>
90101
</span>
91102

92103
<span v-if="!props.local" class="tag info">
@@ -101,12 +112,13 @@ const formattedToolHelp = computed(() => {
101112

102113
<span v-if="props.owner" class="tag success">
103114
<FontAwesomeIcon :icon="faUser" />
104-
<b>Owner:</b> <GLink thin :to="`/tools/list?owner=${props.owner}`">{{ props.owner }}</GLink>
115+
<b>Owner:</b>
116+
<GLink thin @click="() => emit('apply-filter', 'owner', props.owner)">{{ props.owner }}</GLink>
105117
</span>
106118

107119
<span v-if="props.ontologies && props.ontologies.length > 0">
108120
<span v-for="ontology in props.ontologies" :key="ontology" class="tag toggle">
109-
<GLink thin :to="`/tools/list?ontology=${ontology}`">{{ ontology }}</GLink>
121+
<GLink thin @click="() => emit('apply-filter', 'ontology', ontology)">{{ ontology }}</GLink>
110122
</span>
111123
</span>
112124
</div>

client/src/components/ToolsList/ToolsListTable.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
:owner="item.tool_shed_repository && item.tool_shed_repository.owner"
2020
:workflow-compatible="item.is_workflow_compatible"
2121
:version="item.version"
22-
@open="() => onOpen(item)" />
22+
@open="() => onOpen(item)"
23+
@apply-filter="(filter, value) => $emit('apply-filter', filter, value)" />
2324
<div>
2425
<div v-if="allLoaded" class="list-end my-2">- End of search results -</div>
2526
<b-overlay :show="busy" opacity="0.5" />

0 commit comments

Comments
 (0)