fix(web): sort title matches by recent activity (#13219)
This commit is contained in:
1 parent
829af7b73a
commit
b21c545654
2 files changed
+56
-1
No files matched your search
@@ -440,6 +440,54 @@ describe("buildThreadActionItems", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("orders title matches by recent activity before older prefix matches", () => {
|
||||
const threads = [
|
||||
makeThread({
|
||||
id: ThreadId.make("old-prefix"),
|
||||
title: "Convex InvalidCursor in Convex threads query",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-02T00:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
id: ThreadId.make("recent-title"),
|
||||
title: "Disable Convex schema validation",
|
||||
createdAt: "2025-12-01T00:00:00.000Z",
|
||||
updatedAt: "2026-03-24T00:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
id: ThreadId.make("recent-content"),
|
||||
title: "Fix schema validation",
|
||||
createdAt: "2026-03-25T00:00:00.000Z",
|
||||
updatedAt: "2026-03-25T00:00:00.000Z",
|
||||
}),
|
||||
];
|
||||
const items = buildThreadActionItems({
|
||||
threads,
|
||||
projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
|
||||
sortOrder: "created_at",
|
||||
icon: null,
|
||||
getContentMatch: (thread) =>
|
||||
thread.id === ThreadId.make("recent-content")
|
||||
? { source: "user", snippet: "Please check Convex", query: "convex" }
|
||||
: undefined,
|
||||
runThread: async () => undefined,
|
||||
});
|
||||
|
||||
const groups = filterCommandPaletteGroups({
|
||||
activeGroups: [],
|
||||
query: "convex",
|
||||
isInSubmenu: false,
|
||||
projectSearchItems: [],
|
||||
threadSearchItems: items,
|
||||
});
|
||||
|
||||
expect(groups[0]?.items.map((item) => item.value)).toEqual([
|
||||
"thread:recent-title",
|
||||
"thread:old-prefix",
|
||||
"thread:recent-content",
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves thread project-name matches when there is no stronger title match", () => {
|
||||
const group: CommandPaletteGroup = {
|
||||
value: "threads-search",
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { SidebarThreadSortOrder } from "@t3tools/contracts/settings";
|
||||
import * as Arr from "effect/Array";
|
||||
import * as Result from "effect/Result";
|
||||
import { type ReactNode } from "react";
|
||||
import { sortThreads } from "../lib/threadSort";
|
||||
import { getThreadSortTimestamp, sortThreads } from "../lib/threadSort";
|
||||
import { normalizeSearchText } from "../lib/utils";
|
||||
import { formatRelativeTimeLabel } from "../timestampFormat";
|
||||
import { type Project, type SidebarThreadSummary, type Thread } from "../types";
|
||||
@@ -135,6 +135,7 @@ export interface CommandPaletteItem {
|
||||
readonly description?: ReactNode;
|
||||
readonly threadContentMatch?: CommandPaletteThreadContentMatch;
|
||||
readonly timestamp?: string;
|
||||
readonly searchRecency?: number;
|
||||
readonly icon: ReactNode;
|
||||
readonly disabled?: boolean;
|
||||
/** Optional content rendered inline before the title text. */
|
||||
@@ -315,6 +316,7 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
|
||||
timestamp: formatRelativeTimeLabel(
|
||||
thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
|
||||
),
|
||||
searchRecency: getThreadSortTimestamp(thread, "updated_at"),
|
||||
icon: input.icon,
|
||||
},
|
||||
leadingContent ? { titleLeadingContent: leadingContent } : {},
|
||||
@@ -366,6 +368,10 @@ function rankCommandPaletteItemMatch(
|
||||
for (const [index, field] of terms.entries()) {
|
||||
const fieldRank = rankSearchFieldMatch(field, normalizedQuery, queryTokens);
|
||||
if (fieldRank !== Number.NEGATIVE_INFINITY) {
|
||||
if (index === 0 && item.searchRecency !== undefined) {
|
||||
// All non-exact thread title matches share a tier so recency breaks the tie.
|
||||
return 1_000 + Number(fieldRank === 3);
|
||||
}
|
||||
return 1_000 - index * 100 + fieldRank;
|
||||
}
|
||||
}
|
||||
@@ -442,6 +448,7 @@ export function filterCommandPaletteGroups(input: {
|
||||
(left, right) =>
|
||||
Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
|
||||
right.rank - left.rank ||
|
||||
(right.item.searchRecency ?? 0) - (left.item.searchRecency ?? 0) ||
|
||||
left.index - right.index,
|
||||
)
|
||||
.map((entry) => entry.item);
|
||||
|
||||
Reference in new issue
Block a user