Skip to content

Commit

Permalink
Better search stuff in Tool Shed 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 23, 2024
1 parent 93df8de commit 251410b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
10 changes: 7 additions & 3 deletions lib/tool_shed/util/shed_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def build_index(whoosh_index_dir, file_path, hgweb_config_dir, hgweb_repo_prefix
execution_timer = ExecutionTimer()
with repo_index.searcher() as searcher:
for repo in get_repos(sa_session, file_path, hgweb_config_dir, hgweb_repo_prefix, **kwargs):
if repo is None:
continue
tools_list = repo.pop("tools_list")
repo_id = repo["id"]
indexed_document = searcher.document(id=repo_id)
Expand Down Expand Up @@ -119,9 +121,11 @@ def get_repos(sa_session, file_path, hgweb_config_dir, hgweb_repo_prefix, **kwar
full_last_updated = repo.update_time.strftime("%Y-%m-%d %I:%M %p")

# Load all changesets of the repo for lineage.
repo_path = os.path.join(
hgweb_config_dir, hgwcm.get_entry(os.path.join(hgweb_repo_prefix, repo.user.username, repo.name))
)
try:
entry = hgwcm.get_entry(os.path.join(hgweb_repo_prefix, repo.user.username, repo.name))
except Exception:
return None
repo_path = os.path.join(hgweb_config_dir, entry)
hg_repo = hg.repository(ui.ui(), repo_path.encode("utf-8"))
lineage = []
for changeset in hg_repo.changelog:
Expand Down
22 changes: 19 additions & 3 deletions lib/tool_shed/webapp/frontend/src/components/RepositoriesGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface RepositoriesGridProps {
rows: Array<RepositoryGridItem>
noDataLabel?: string
debug?: boolean
allowSearch?: boolean
}
interface ScrollDetails {
Expand All @@ -29,6 +30,7 @@ const compProps = withDefaults(defineProps<RepositoriesGridProps>(), {
debug: false,
onScroll: null as OnScroll | null,
noDataLabel: "No repositories found",
allowSearch: false,
})
const pagination = { rowsPerPage: 0 }
Expand All @@ -44,7 +46,7 @@ const NAME_COLUMN: QTableColumn = {
name: "name",
label: "Name",
align: "left",
field: "name",
field: "effectiveName",
}
const columns = computed(() => {
Expand All @@ -71,10 +73,14 @@ async function onVirtualScroll(details: ScrollDetails) {
}
}
const search = ref("")
// Adapt the rows with doubleIndex so
const adaptedRows = computed(() =>
compProps.rows.map((r) => {
return { doubleIndex: r.index * 2, ...r }
// create this effective name so we are filtering on this when searching...
const effectiveName = r.owner + " " + r.name
return { doubleIndex: r.index * 2, effectiveName: effectiveName, ...r }
})
)
</script>
Expand All @@ -83,10 +89,10 @@ const adaptedRows = computed(() =>
<q-table
v-if="loading || rows.length > 0"
style="height: 85vh"
:title="title"
:rows="adaptedRows"
:columns="columns"
:loading="tableLoading"
:filter="search"
row-key="newIndex"
virtual-scroll
:virtual-scroll-item-size="48"
Expand All @@ -98,6 +104,16 @@ const adaptedRows = computed(() =>
hide-header
hide-bottom
>
<template #top>
<div class="row col-12">
<div class="q-table__control col-8">
<div class="q-table__title">{{ title }}</div>
</div>
<div class="col-4 justify-end q-pa-md" v-if="allowSearch">
<q-input v-model="search" autogrow label="Filter"></q-input>
</div>
</div>
</template>
<template #body="props">
<q-tr :props="props" :key="`m_${props.row.index}`">
<q-td v-for="col in props.cols" :key="col.name" :props="props">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { computed } from "vue"
import { computed, ref } from "vue"
import { useCategoriesStore } from "@/stores"
import RepositoriesGrid from "@/components/RepositoriesGrid.vue"
import { nodeToRow } from "@/components/RepositoriesGridInterface"
import { nodeToRow, type RepositoryGridItem } from "@/components/RepositoriesGridInterface"
import ErrorBanner from "@/components/ErrorBanner.vue"
import LoadingDiv from "@/components/LoadingDiv.vue"
import { graphql } from "@/gql"
Expand Down Expand Up @@ -67,6 +67,11 @@ const rows = computed(() => {
<loading-div v-if="loading" />
<error-banner error="Failed to load repository" v-else-if="error"> </error-banner>
<q-page class="q-pa-md" v-if="categoryName">
<repositories-grid :title="`Repositories for ${categoryName}`" :rows="rows" :on-scroll="onScroll" />
<repositories-grid
:title="`Repositories for ${categoryName}`"
:rows="rows"
:on-scroll="onScroll"
:allow-search="true"
/>
</q-page>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import { notifyOnCatch } from "@/util"
const query = ref("")
const page = ref(1)
const searching = ref(false)
const fetchedLastPage = ref(false)
const hits = ref([] as Array<RepositorySearchHit>)
type RepositorySearchHit = components["schemas"]["RepositorySearchHit"]
async function doQuery() {
const queryValue = query.value
if (!queryValue) {
hits.value = []
return
}
searching.value = true
try {
const { data } = await ToolShedApi().GET("/api/repositories", {
params: {
Expand All @@ -39,10 +44,12 @@ async function doQuery() {
}
page.value = page.value + 1
} else {
throw Error("Server response structure error.")
throw Error("Server response structure error for [" + queryValue + "]")
}
} catch (e) {
notifyOnCatch(e)
} finally {
searching.value = false
}
}
Expand Down Expand Up @@ -88,12 +95,26 @@ function rowsFunc() {
return rows
}*/
const noDataLabel = computed<string>(() => {
if (searching.value) {
return "Searching..."
} else {
return "No repositories matching query"
}
})
const rows = realRows
</script>
<template>
<page-container>
<q-input debounce="20" filled v-model="query" label="Search Repositories" />
<repository-grid v-if="query && query.length > 1" :rows="rows" title="Search Results" :on-scroll="OnScrollImpl">
<repository-grid
v-if="query && query.length > 1"
:rows="rows"
title="Search Results"
:on-scroll="OnScrollImpl"
:no-data-label="noDataLabel"
>
</repository-grid>
</page-container>
</template>

0 comments on commit 251410b

Please sign in to comment.