Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(search): format document names in server search results (#4633)

gbirman84d9429ca963
diff --git a/js/app/packages/queries/soup/transform-utils.ts b/js/app/packages/queries/soup/transform-utils.ts
index b074222225..9a8cdc0dfb 100644
--- a/js/app/packages/queries/soup/transform-utils.ts
+++ b/js/app/packages/queries/soup/transform-utils.ts
@@ -43,6 +43,7 @@ import type {
SoupPage,
} from '@service-storage/generated/schemas';
import type { ChannelType } from '@service-storage/generated/schemas/channelType';
+import { formatDocumentName } from '@service-storage/util/filename';
import type { UseQueryResult } from '@tanstack/solid-query';
import { differenceInMilliseconds } from 'date-fns';
import { match } from 'ts-pattern';
@@ -280,6 +281,9 @@ export function mapChannelSearchResultItem(
});
}
+const formatDisplayName = (text: string, fileType?: string | null) =>
+ formatDocumentName(text, fileType, { fullyQualifiedBlockName: true });
+
export const useSearchResponseItemMapper = () => {
const channelsContext = useChannelsContext();
const channels = channelsContext.channels;
@@ -345,6 +349,17 @@ export const useSearchResponseItemMapper = () => {
results: result.document_search_results,
});
}
+ // The index stores unformatted document names, so server name
+ // highlights lack the extension suffix the display name carries.
+ if (search.nameHighlight) {
+ search = {
+ ...search,
+ nameHighlight: formatDisplayName(
+ search.nameHighlight,
+ result.file_type
+ ),
+ };
+ }
const properties = result.properties ?? undefined;
return [
{
@@ -356,7 +371,10 @@ export const useSearchResponseItemMapper = () => {
? { type: 'snippet' }
: null,
id: result.document_id,
- name: result.name || blockNameToDefaultFile(result.file_type),
+ name: formatDisplayName(
+ result.name || blockNameToDefaultFile(result.file_type),
+ result.file_type
+ ),
ownerId: result.owner_id,
createdAt: result.metadata?.created_at,
updatedAt: result.metadata?.updated_at,