From 013b23bc034097f5f42d02017f8e5d5256cb2f91 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 11 Feb 2025 17:24:32 -0800 Subject: [PATCH 1/4] sort by url --- backend/btrixcloud/colls.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/btrixcloud/colls.py b/backend/btrixcloud/colls.py index 468207adbf..d98857eade 100644 --- a/backend/btrixcloud/colls.py +++ b/backend/btrixcloud/colls.py @@ -755,7 +755,7 @@ async def list_urls_in_collection( page_size: int = DEFAULT_PAGE_SIZE, page: int = 1, ) -> Tuple[List[PageUrlCount], int]: - """List all URLs in collection sorted desc by snapshot count""" + """List all URLs in collection sorted desc by snapshot count unless prefix is specified""" # pylint: disable=duplicate-code, too-many-locals, too-many-branches, too-many-statements # Zero-index page for query page = page - 1 @@ -764,11 +764,13 @@ async def list_urls_in_collection( crawl_ids = await self.get_collection_crawl_ids(coll_id) match_query: dict[str, object] = {"oid": oid, "crawl_id": {"$in": crawl_ids}} + sort_query: dict[str, int] = {"count": -1, "url": -1} if url_prefix: url_prefix = urllib.parse.unquote(url_prefix) regex_pattern = f"^{re.escape(url_prefix)}" match_query["url"] = {"$regex": regex_pattern, "$options": "i"} + sort_query = {"url": -1} aggregate = [{"$match": match_query}] @@ -781,7 +783,7 @@ async def list_urls_in_collection( "count": {"$sum": 1}, }, }, - {"$sort": {"count": -1}}, + {"$sort": sort_query}, {"$set": {"url": "$_id"}}, { "$facet": { From 8a2e97cfd06604d0ba505fcfe698375cf081d8e3 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 11 Feb 2025 17:41:00 -0800 Subject: [PATCH 2/4] stable sort --- backend/btrixcloud/colls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/btrixcloud/colls.py b/backend/btrixcloud/colls.py index d98857eade..d919d72bd8 100644 --- a/backend/btrixcloud/colls.py +++ b/backend/btrixcloud/colls.py @@ -764,13 +764,13 @@ async def list_urls_in_collection( crawl_ids = await self.get_collection_crawl_ids(coll_id) match_query: dict[str, object] = {"oid": oid, "crawl_id": {"$in": crawl_ids}} - sort_query: dict[str, int] = {"count": -1, "url": -1} + sort_query: dict[str, int] = {"count": -1, "_id": 1} if url_prefix: url_prefix = urllib.parse.unquote(url_prefix) regex_pattern = f"^{re.escape(url_prefix)}" match_query["url"] = {"$regex": regex_pattern, "$options": "i"} - sort_query = {"url": -1} + sort_query = {"_id": 1} aggregate = [{"$match": match_query}] From 23a8275360cecb944e02dceb86d0c2d6644de796 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 11 Feb 2025 17:51:40 -0800 Subject: [PATCH 3/4] fix dropdown shift --- .../collections/select-collection-page.ts | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/frontend/src/features/collections/select-collection-page.ts b/frontend/src/features/collections/select-collection-page.ts index efbd266ba8..6ff78849d1 100644 --- a/frontend/src/features/collections/select-collection-page.ts +++ b/frontend/src/features/collections/select-collection-page.ts @@ -357,44 +357,52 @@ export class SelectCollectionPage extends BtrixElement { private renderSearchResults() { return this.searchResults.render({ - pending: () => html` + pending: () => + this.renderItems( + // Render previous value so that dropdown doesn't shift while typing + this.searchResults.value, + ), + complete: this.renderItems, + }); + } + + private readonly renderItems = ( + results: SelectCollectionPage["searchResults"]["value"], + ) => { + if (!results) return; + + const { items } = results; + + if (!items.length) { + return html` - + ${msg("No matching page found.")} - `, - complete: ({ items }) => { - if (!items.length) { - return html` - - ${msg("No matching page found.")} - - `; - } + `; + } + return html` + ${items.map((item: Page) => { return html` - ${items.map((item: Page) => { - return html` - { - if (this.input) { - this.input.value = item.url; - } - - this.selectedPage = this.formatPage(item); - - this.combobox?.hide(); - - this.selectedSnapshot = this.selectedPage.snapshots[0]; - }} - >${item.url} - - `; - })} + { + if (this.input) { + this.input.value = item.url; + } + + this.selectedPage = this.formatPage(item); + + this.combobox?.hide(); + + this.selectedSnapshot = this.selectedPage.snapshots[0]; + }} + >${item.url} + `; - }, - }); - } + })} + `; + }; private readonly onSearchInput = debounce(400)(() => { const value = this.input?.value; From 472cbb2461a278a3bf32862f34d1a00a754a1b9f Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Wed, 12 Feb 2025 10:38:09 -0500 Subject: [PATCH 4/4] Attempt to fix aggregate typing --- backend/btrixcloud/colls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/btrixcloud/colls.py b/backend/btrixcloud/colls.py index d919d72bd8..0ea137a0d3 100644 --- a/backend/btrixcloud/colls.py +++ b/backend/btrixcloud/colls.py @@ -772,7 +772,7 @@ async def list_urls_in_collection( match_query["url"] = {"$regex": regex_pattern, "$options": "i"} sort_query = {"_id": 1} - aggregate = [{"$match": match_query}] + aggregate: List[Dict[str, Union[int, object]]] = [{"$match": match_query}] aggregate.extend( [