@open-mercato/search 0.6.7-develop.6785.1.1dd7cfac55 → 0.6.7-develop.6795.1.8a3f27921c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/AGENTS.md +1 -0
- package/dist/lib/presenter-enricher.js +12 -12
- package/dist/lib/presenter-enricher.js.map +2 -2
- package/dist/modules/search/frontend/components/GlobalSearchDialog.js +2 -9
- package/dist/modules/search/frontend/components/GlobalSearchDialog.js.map +2 -2
- package/dist/modules/search/frontend/components/HybridSearchTable.js +2 -11
- package/dist/modules/search/frontend/components/HybridSearchTable.js.map +2 -2
- package/dist/modules/search/frontend/components/TopbarSearchInline.js +2 -9
- package/dist/modules/search/frontend/components/TopbarSearchInline.js.map +2 -2
- package/dist/modules/search/frontend/lib/entityTypeLabel.js +19 -0
- package/dist/modules/search/frontend/lib/entityTypeLabel.js.map +7 -0
- package/dist/modules/search/i18n/de.json +47 -0
- package/dist/modules/search/i18n/en.json +47 -0
- package/dist/modules/search/i18n/es.json +47 -0
- package/dist/modules/search/i18n/pl.json +47 -0
- package/dist/service.js +2 -5
- package/dist/service.js.map +2 -2
- package/package.json +9 -9
- package/src/__tests__/presenter-enricher.test.ts +48 -0
- package/src/__tests__/presenter-locale.test.ts +76 -0
- package/src/lib/presenter-enricher.ts +14 -14
- package/src/modules/search/api/__tests__/global-search.routes.test.ts +167 -0
- package/src/modules/search/frontend/components/GlobalSearchDialog.tsx +2 -15
- package/src/modules/search/frontend/components/HybridSearchTable.tsx +2 -17
- package/src/modules/search/frontend/components/TopbarSearchInline.tsx +2 -15
- package/src/modules/search/frontend/lib/__tests__/entityTypeLabel.test.ts +25 -0
- package/src/modules/search/frontend/lib/entityTypeLabel.ts +22 -0
- package/src/modules/search/i18n/de.json +47 -0
- package/src/modules/search/i18n/en.json +47 -0
- package/src/modules/search/i18n/es.json +47 -0
- package/src/modules/search/i18n/pl.json +47 -0
- package/src/service.ts +2 -7
|
@@ -3,6 +3,7 @@ import type { Kysely } from 'kysely'
|
|
|
3
3
|
import type { SearchEntityConfig } from '../types'
|
|
4
4
|
import type { QueryEngine } from '@open-mercato/shared/lib/query/types'
|
|
5
5
|
import type { SearchResult } from '@open-mercato/shared/modules/search'
|
|
6
|
+
import type { EntityId } from '@open-mercato/shared/modules/entities'
|
|
6
7
|
import { decryptIndexDocForSearch } from '@open-mercato/shared/lib/encryption/indexDoc'
|
|
7
8
|
import { createPresenterEnricher } from '../lib/presenter-enricher'
|
|
8
9
|
|
|
@@ -142,4 +143,51 @@ describe('createPresenterEnricher', () => {
|
|
|
142
143
|
expect(resolveLinks).toHaveBeenCalled()
|
|
143
144
|
expect(enriched.links).toEqual([{ href: '/backend/customers/person-1', label: 'View', kind: 'primary' }])
|
|
144
145
|
})
|
|
146
|
+
|
|
147
|
+
it('re-renders a result that already has a stored presenter when the entity has a config', async () => {
|
|
148
|
+
const doc = { id: 'rec-1', display_name: 'Ada' }
|
|
149
|
+
mockedDecryptIndexDocForSearch.mockResolvedValue(doc)
|
|
150
|
+
|
|
151
|
+
const formatResult = jest.fn(async () => ({ title: 'Fresh Title', badge: 'Fresh' }))
|
|
152
|
+
const config = createConfig({
|
|
153
|
+
entityId: 'customers:customer_person_profile' as EntityId,
|
|
154
|
+
enabled: true,
|
|
155
|
+
formatResult,
|
|
156
|
+
})
|
|
157
|
+
const entityConfigMap = new Map<EntityId, SearchEntityConfig>([[config.entityId, config]])
|
|
158
|
+
const db = createKyselyMock([
|
|
159
|
+
{ entity_type: 'customers:customer_person_profile', entity_id: 'rec-1', doc },
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
const enrich = createPresenterEnricher(db, entityConfigMap)
|
|
163
|
+
const results: SearchResult[] = [{
|
|
164
|
+
entityId: 'customers:customer_person_profile' as EntityId,
|
|
165
|
+
recordId: 'rec-1',
|
|
166
|
+
score: 1,
|
|
167
|
+
source: 'fulltext',
|
|
168
|
+
presenter: { title: 'Stale English Title' },
|
|
169
|
+
url: '/x',
|
|
170
|
+
}]
|
|
171
|
+
|
|
172
|
+
const [enriched] = await enrich(results, 'tenant-1', null)
|
|
173
|
+
|
|
174
|
+
expect(formatResult).toHaveBeenCalledTimes(1)
|
|
175
|
+
expect(enriched.presenter?.title).toBe('Fresh Title')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('keeps the stored presenter when the entity has no config', async () => {
|
|
179
|
+
const db = createKyselyMock([])
|
|
180
|
+
const enrich = createPresenterEnricher(db, new Map(), undefined)
|
|
181
|
+
const results: SearchResult[] = [{
|
|
182
|
+
entityId: 'unknown:thing' as EntityId,
|
|
183
|
+
recordId: 'rec-9',
|
|
184
|
+
score: 1,
|
|
185
|
+
source: 'fulltext',
|
|
186
|
+
presenter: { title: 'Stored' },
|
|
187
|
+
url: '/y',
|
|
188
|
+
}]
|
|
189
|
+
|
|
190
|
+
const [enriched] = await enrich(results, 'tenant-1', null)
|
|
191
|
+
expect(enriched.presenter?.title).toBe('Stored')
|
|
192
|
+
})
|
|
145
193
|
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
jest.mock('next/headers', () => ({
|
|
2
|
+
cookies: async () => ({ get: (name: string) => (name === 'locale' ? { value: 'pl' } : undefined) }),
|
|
3
|
+
headers: async () => ({ get: () => '' }),
|
|
4
|
+
}))
|
|
5
|
+
|
|
6
|
+
import type { Kysely } from 'kysely'
|
|
7
|
+
import { createPresenterEnricher } from '../lib/presenter-enricher'
|
|
8
|
+
import { registerModules, resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
9
|
+
import type { EntityId } from '@open-mercato/shared/modules/entities'
|
|
10
|
+
import type { Module } from '@open-mercato/shared/modules/registry'
|
|
11
|
+
import type { SearchEntityConfig, SearchResult } from '../types'
|
|
12
|
+
|
|
13
|
+
const DEMO_ENTITY_ID = 'demo:thing' as EntityId
|
|
14
|
+
|
|
15
|
+
function makeDbReturning(rows: Array<{ entity_type: string; entity_id: string; doc: Record<string, unknown> }>) {
|
|
16
|
+
const chain = {
|
|
17
|
+
selectFrom: () => chain,
|
|
18
|
+
select: () => chain,
|
|
19
|
+
where: () => chain,
|
|
20
|
+
execute: async () => rows,
|
|
21
|
+
}
|
|
22
|
+
return chain as unknown as Kysely<Record<string, never>>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('request-time presenter localization', () => {
|
|
26
|
+
beforeAll(() => {
|
|
27
|
+
registerModules([
|
|
28
|
+
{
|
|
29
|
+
id: 'demo',
|
|
30
|
+
translations: {
|
|
31
|
+
en: { 'demo.search.badge': 'Person', 'demo.search.link.open': 'Open person' },
|
|
32
|
+
pl: { 'demo.search.badge': 'Osoba', 'demo.search.link.open': 'Otwórz osobę' },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
] satisfies Module[])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('renders the presenter badge and link label in the request locale (pl)', async () => {
|
|
39
|
+
const { locale, t } = await resolveTranslations()
|
|
40
|
+
expect(locale).toBe('pl')
|
|
41
|
+
expect(t('demo.search.badge', 'Person')).toBe('Osoba')
|
|
42
|
+
|
|
43
|
+
const config: SearchEntityConfig = {
|
|
44
|
+
entityId: DEMO_ENTITY_ID,
|
|
45
|
+
enabled: true,
|
|
46
|
+
formatResult: async () => {
|
|
47
|
+
const { t: translate } = await resolveTranslations()
|
|
48
|
+
return { title: 'Ada', badge: translate('demo.search.badge', 'Person') }
|
|
49
|
+
},
|
|
50
|
+
resolveLinks: async () => {
|
|
51
|
+
const { t: translate } = await resolveTranslations()
|
|
52
|
+
return [{ href: '/x', label: translate('demo.search.link.open', 'Open person') }]
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const entityConfigMap = new Map<EntityId, SearchEntityConfig>([[DEMO_ENTITY_ID, config]])
|
|
57
|
+
const db = makeDbReturning([
|
|
58
|
+
{ entity_type: 'demo:thing', entity_id: 'rec-1', doc: { id: 'rec-1', display_name: 'Ada' } },
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
const enrich = createPresenterEnricher(db, entityConfigMap)
|
|
62
|
+
const results: SearchResult[] = [{
|
|
63
|
+
entityId: DEMO_ENTITY_ID,
|
|
64
|
+
recordId: 'rec-1',
|
|
65
|
+
score: 1,
|
|
66
|
+
source: 'fulltext',
|
|
67
|
+
presenter: { title: 'Ada', badge: 'Person' },
|
|
68
|
+
links: [{ href: '/x', label: 'Open person', kind: 'primary' }],
|
|
69
|
+
}]
|
|
70
|
+
|
|
71
|
+
const [enriched] = await enrich(results, 'tenant-1', null)
|
|
72
|
+
|
|
73
|
+
expect(enriched.presenter?.badge).toBe('Osoba')
|
|
74
|
+
expect(enriched.links?.[0]?.label).toBe('Otwórz osobę')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -137,23 +137,22 @@ async function computePresenterAndLinks(
|
|
|
137
137
|
queryEngine,
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
// If search.ts config exists, use formatResult/buildSource for presenter
|
|
141
140
|
if (config?.formatResult || config?.buildSource) {
|
|
142
|
-
if (config.
|
|
141
|
+
if (config.formatResult) {
|
|
143
142
|
try {
|
|
144
|
-
|
|
145
|
-
if (source?.presenter) presenter = source.presenter
|
|
146
|
-
if (source?.links) links = source.links
|
|
143
|
+
presenter = (await config.formatResult(buildContext)) ?? null
|
|
147
144
|
} catch (err) {
|
|
148
|
-
logWarning('
|
|
145
|
+
logWarning('formatResult failed', { entityId, recordId, err })
|
|
149
146
|
}
|
|
150
147
|
}
|
|
151
148
|
|
|
152
|
-
if (!presenter && config.
|
|
149
|
+
if (!presenter && config.buildSource) {
|
|
153
150
|
try {
|
|
154
|
-
|
|
151
|
+
const source = await config.buildSource(buildContext)
|
|
152
|
+
if (source?.presenter) presenter = source.presenter
|
|
153
|
+
if (source?.links) links = source.links
|
|
155
154
|
} catch (err) {
|
|
156
|
-
logWarning('
|
|
155
|
+
logWarning('buildSource failed', { entityId, recordId, err })
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
158
|
}
|
|
@@ -203,8 +202,10 @@ export function createPresenterEnricher(
|
|
|
203
202
|
encryptionService?: TenantDataEncryptionService | null,
|
|
204
203
|
): PresenterEnricherFn {
|
|
205
204
|
return async (results, tenantId, organizationId) => {
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
const shouldEnrich = (result: SearchResult): boolean =>
|
|
206
|
+
needsSearchResultEnrichment(result) || entityConfigMap.has(result.entityId as EntityId)
|
|
207
|
+
|
|
208
|
+
const missingResults = results.filter(shouldEnrich)
|
|
208
209
|
if (missingResults.length === 0) return results
|
|
209
210
|
|
|
210
211
|
// Group by entity type for config lookup
|
|
@@ -285,16 +286,15 @@ export function createPresenterEnricher(
|
|
|
285
286
|
|
|
286
287
|
// Enrich results with computed presenter, URL, and links
|
|
287
288
|
return results.map((result) => {
|
|
288
|
-
if (!
|
|
289
|
+
if (!shouldEnrich(result)) return result
|
|
289
290
|
const key = `${result.entityId}:${result.recordId}`
|
|
290
291
|
const enriched = enrichmentMap.get(key)
|
|
291
292
|
if (!enriched) return result
|
|
292
|
-
const hasExistingLinks = Array.isArray(result.links) && result.links.length > 0
|
|
293
293
|
return {
|
|
294
294
|
...result,
|
|
295
295
|
presenter: enriched.presenter ?? result.presenter,
|
|
296
296
|
url: result.url ?? enriched.url,
|
|
297
|
-
links:
|
|
297
|
+
links: enriched.links ?? result.links,
|
|
298
298
|
}
|
|
299
299
|
})
|
|
300
300
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const mockGetAuthFromRequest = jest.fn()
|
|
2
|
+
jest.mock('@open-mercato/shared/lib/auth/server', () => ({
|
|
3
|
+
getAuthFromRequest: (...args: unknown[]) => mockGetAuthFromRequest(...args),
|
|
4
|
+
}))
|
|
5
|
+
|
|
6
|
+
const mockCreateRequestContainer = jest.fn()
|
|
7
|
+
jest.mock('@open-mercato/shared/lib/di/container', () => ({
|
|
8
|
+
createRequestContainer: (...args: unknown[]) => mockCreateRequestContainer(...args),
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
const mockResolveOrganizationScopeForRequest = jest.fn()
|
|
12
|
+
jest.mock('@open-mercato/core/modules/directory/utils/organizationScope', () => ({
|
|
13
|
+
resolveOrganizationScopeForRequest: (...args: unknown[]) => mockResolveOrganizationScopeForRequest(...args),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
jest.mock('../../lib/embedding-config', () => ({
|
|
17
|
+
resolveEmbeddingConfig: jest.fn().mockResolvedValue(null),
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
jest.mock('../../lib/global-search-config', () => ({
|
|
21
|
+
resolveGlobalSearchStrategies: jest.fn().mockResolvedValue(['fulltext', 'vector', 'tokens']),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
jest.mock('next/headers', () => ({
|
|
25
|
+
cookies: async () => ({ get: () => undefined }),
|
|
26
|
+
headers: async () => ({ get: (name: string) => (name === 'accept-language' ? 'pl-PL' : null) }),
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
import type { Kysely } from 'kysely'
|
|
30
|
+
import type { EntityId } from '@open-mercato/shared/modules/entities'
|
|
31
|
+
import type { Module } from '@open-mercato/shared/modules/registry'
|
|
32
|
+
import type { SearchEntityConfig, SearchResult, SearchStrategy, SearchStrategyId } from '../../../../types'
|
|
33
|
+
import { registerModules, resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
34
|
+
import { SearchService } from '../../../../service'
|
|
35
|
+
import { createPresenterEnricher } from '../../../../lib/presenter-enricher'
|
|
36
|
+
import { GET } from '../search/global/route'
|
|
37
|
+
|
|
38
|
+
const DEMO_ENTITY_ID = 'demo:thing' as EntityId
|
|
39
|
+
|
|
40
|
+
function createDatabase(rows: Array<{ entity_type: string; entity_id: string; doc: Record<string, unknown> }>) {
|
|
41
|
+
const chain = {
|
|
42
|
+
selectFrom: () => chain,
|
|
43
|
+
select: () => chain,
|
|
44
|
+
where: () => chain,
|
|
45
|
+
execute: async () => rows,
|
|
46
|
+
}
|
|
47
|
+
return chain as unknown as Kysely<Record<string, never>>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createStrategy(source: SearchStrategyId, recordId: string): SearchStrategy {
|
|
51
|
+
const result: SearchResult = {
|
|
52
|
+
entityId: DEMO_ENTITY_ID,
|
|
53
|
+
recordId,
|
|
54
|
+
organizationId: 'org-1',
|
|
55
|
+
score: 1,
|
|
56
|
+
source,
|
|
57
|
+
presenter: { title: recordId, badge: 'Person' },
|
|
58
|
+
links: [{ href: `/backend/demo/${recordId}`, label: 'Open person', kind: 'primary' }],
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
id: source,
|
|
63
|
+
name: source,
|
|
64
|
+
priority: 10,
|
|
65
|
+
isAvailable: async () => true,
|
|
66
|
+
ensureReady: async () => undefined,
|
|
67
|
+
search: async () => [result],
|
|
68
|
+
index: async () => undefined,
|
|
69
|
+
delete: async () => undefined,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('GET /api/search/search/global presenter localization', () => {
|
|
74
|
+
beforeAll(() => {
|
|
75
|
+
registerModules([
|
|
76
|
+
{
|
|
77
|
+
id: 'demo',
|
|
78
|
+
translations: {
|
|
79
|
+
en: {
|
|
80
|
+
'demo.search.badge': 'Person',
|
|
81
|
+
'demo.search.link.open': 'Open person',
|
|
82
|
+
},
|
|
83
|
+
pl: {
|
|
84
|
+
'demo.search.badge': 'Osoba',
|
|
85
|
+
'demo.search.link.open': 'Otwórz osobę',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
] satisfies Module[])
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
jest.clearAllMocks()
|
|
94
|
+
mockGetAuthFromRequest.mockResolvedValue({
|
|
95
|
+
tenantId: 'tenant-1',
|
|
96
|
+
orgId: 'org-1',
|
|
97
|
+
sub: 'user-1',
|
|
98
|
+
isSuperAdmin: false,
|
|
99
|
+
})
|
|
100
|
+
mockResolveOrganizationScopeForRequest.mockResolvedValue({
|
|
101
|
+
selectedId: 'org-1',
|
|
102
|
+
filterIds: ['org-1'],
|
|
103
|
+
allowedIds: ['org-1'],
|
|
104
|
+
tenantId: 'tenant-1',
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('replaces frozen presenters and links for fulltext, vector, and tokens using Accept-Language', async () => {
|
|
109
|
+
const rows = ['fulltext-record', 'vector-record', 'tokens-record'].map((recordId) => ({
|
|
110
|
+
entity_type: DEMO_ENTITY_ID,
|
|
111
|
+
entity_id: recordId,
|
|
112
|
+
doc: { id: recordId, title: recordId },
|
|
113
|
+
}))
|
|
114
|
+
const config: SearchEntityConfig = {
|
|
115
|
+
entityId: DEMO_ENTITY_ID,
|
|
116
|
+
enabled: true,
|
|
117
|
+
formatResult: async (context) => {
|
|
118
|
+
const { t } = await resolveTranslations()
|
|
119
|
+
return {
|
|
120
|
+
title: String(context.record.title),
|
|
121
|
+
badge: t('demo.search.badge', 'Person'),
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
resolveLinks: async (context) => {
|
|
125
|
+
const { t } = await resolveTranslations()
|
|
126
|
+
return [{
|
|
127
|
+
href: `/backend/demo/${String(context.record.id)}`,
|
|
128
|
+
label: t('demo.search.link.open', 'Open person'),
|
|
129
|
+
kind: 'primary',
|
|
130
|
+
}]
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
const configMap = new Map<EntityId, SearchEntityConfig>([[DEMO_ENTITY_ID, config]])
|
|
134
|
+
const presenterEnricher = createPresenterEnricher(createDatabase(rows), configMap)
|
|
135
|
+
const searchService = new SearchService({
|
|
136
|
+
strategies: [
|
|
137
|
+
createStrategy('fulltext', 'fulltext-record'),
|
|
138
|
+
createStrategy('vector', 'vector-record'),
|
|
139
|
+
createStrategy('tokens', 'tokens-record'),
|
|
140
|
+
],
|
|
141
|
+
defaultStrategies: ['fulltext', 'vector', 'tokens'],
|
|
142
|
+
presenterEnricher,
|
|
143
|
+
})
|
|
144
|
+
const container = {
|
|
145
|
+
resolve: jest.fn((name: string) => (name === 'searchService' ? searchService : undefined)),
|
|
146
|
+
dispose: jest.fn().mockResolvedValue(undefined),
|
|
147
|
+
}
|
|
148
|
+
mockCreateRequestContainer.mockResolvedValue(container)
|
|
149
|
+
|
|
150
|
+
const request = new Request('http://localhost/api/search/search/global?q=person', {
|
|
151
|
+
headers: { 'accept-language': 'pl-PL' },
|
|
152
|
+
})
|
|
153
|
+
const response = await GET(request)
|
|
154
|
+
const body = await response.json() as {
|
|
155
|
+
results: SearchResult[]
|
|
156
|
+
strategiesUsed: SearchStrategyId[]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
expect(response.status).toBe(200)
|
|
160
|
+
expect(body.results).toHaveLength(3)
|
|
161
|
+
expect(body.strategiesUsed).toEqual(expect.arrayContaining(['fulltext', 'vector', 'tokens']))
|
|
162
|
+
for (const result of body.results) {
|
|
163
|
+
expect(result.presenter?.badge).toBe('Osoba')
|
|
164
|
+
expect(result.links?.[0]?.label).toBe('Otwórz osobę')
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
})
|
|
@@ -49,6 +49,7 @@ import { Button } from '@open-mercato/ui/primitives/button'
|
|
|
49
49
|
import { cn } from '@open-mercato/shared/lib/utils'
|
|
50
50
|
import type { SearchResult, SearchResultLink, SearchStrategyId } from '@open-mercato/shared/modules/search'
|
|
51
51
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
52
|
+
import { resolveEntityTypeLabel } from '../lib/entityTypeLabel'
|
|
52
53
|
import {
|
|
53
54
|
getCurrentOrganizationScope,
|
|
54
55
|
subscribeOrganizationScopeChanged,
|
|
@@ -87,14 +88,6 @@ function hasActiveOrganizationSelection(): boolean {
|
|
|
87
88
|
return !isAllOrganizationsSelection(cookieValue);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
function humanizeSegment(segment: string): string {
|
|
91
|
-
return segment
|
|
92
|
-
.split(/[_-]+/)
|
|
93
|
-
.filter(Boolean)
|
|
94
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
95
|
-
.join(' ')
|
|
96
|
-
}
|
|
97
|
-
|
|
98
91
|
const ICON_MAP: Record<string, LucideIcon> = {
|
|
99
92
|
bolt: Zap,
|
|
100
93
|
zap: Zap,
|
|
@@ -140,12 +133,6 @@ function resolveIcon(name?: string): LucideIcon | null {
|
|
|
140
133
|
return ICON_MAP[name.toLowerCase()] ?? null
|
|
141
134
|
}
|
|
142
135
|
|
|
143
|
-
function formatEntityId(entityId: string): string {
|
|
144
|
-
if (!entityId.includes(':')) return humanizeSegment(entityId)
|
|
145
|
-
const [module, entity] = entityId.split(':')
|
|
146
|
-
return `${humanizeSegment(module)} · ${humanizeSegment(entity)}`
|
|
147
|
-
}
|
|
148
|
-
|
|
149
136
|
export type GlobalSearchDialogProps = {
|
|
150
137
|
/** Whether embedding provider is configured for vector search */
|
|
151
138
|
embeddingConfigured: boolean
|
|
@@ -423,7 +410,7 @@ export function GlobalSearchDialog({
|
|
|
423
410
|
<div className="flex flex-wrap items-center gap-2">
|
|
424
411
|
<span className={cn('font-medium text-base whitespace-normal break-all', !hasLink && 'text-muted-foreground')}>{presenter?.title ?? result.recordId}</span>
|
|
425
412
|
<span className="rounded-full border border-muted-foreground/30 px-2 py-0.5 text-xs text-muted-foreground">
|
|
426
|
-
{
|
|
413
|
+
{resolveEntityTypeLabel(t, result.entityId)}
|
|
427
414
|
</span>
|
|
428
415
|
{!hasLink && (
|
|
429
416
|
<span className="rounded-full border border-status-warning-border bg-status-warning-bg px-2 py-0.5 text-xs text-status-warning-text">
|
|
@@ -11,6 +11,7 @@ import type { SearchResult, SearchStrategyId } from '@open-mercato/shared/module
|
|
|
11
11
|
import { cn } from '@open-mercato/shared/lib/utils'
|
|
12
12
|
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
13
13
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
14
|
+
import { resolveEntityTypeLabel } from '../lib/entityTypeLabel'
|
|
14
15
|
import {
|
|
15
16
|
getCurrentOrganizationScope,
|
|
16
17
|
subscribeOrganizationScopeChanged,
|
|
@@ -60,7 +61,7 @@ function createColumns(t: Translator): ColumnDef<Row>[] {
|
|
|
60
61
|
const title = resolveRowTitle(item)
|
|
61
62
|
const iconName = item.presenter?.icon
|
|
62
63
|
const Icon = iconName ? resolveIcon(iconName) : null
|
|
63
|
-
const typeLabel =
|
|
64
|
+
const typeLabel = resolveEntityTypeLabel(t, item.entityId)
|
|
64
65
|
const snapshot = item.presenter?.subtitle ?? extractSnapshot(item.metadata)
|
|
65
66
|
const links = normalizeLinks(item.links)
|
|
66
67
|
return (
|
|
@@ -160,22 +161,6 @@ function resolveIcon(name?: string): LucideIcon | null {
|
|
|
160
161
|
return null
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
function humanizeSegment(segment: string): string {
|
|
164
|
-
return segment
|
|
165
|
-
.split(/[_-]+/)
|
|
166
|
-
.filter(Boolean)
|
|
167
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
168
|
-
.join(' ')
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function formatEntityId(entityId: string): string {
|
|
172
|
-
if (!entityId.includes(':')) return humanizeSegment(entityId)
|
|
173
|
-
const [module, entity] = entityId.split(':')
|
|
174
|
-
const moduleLabel = humanizeSegment(module)
|
|
175
|
-
const entityLabel = humanizeSegment(entity)
|
|
176
|
-
return `${moduleLabel} · ${entityLabel}`
|
|
177
|
-
}
|
|
178
|
-
|
|
179
164
|
function resolveRowTitle(row: Row): string {
|
|
180
165
|
const presenterTitle = row.presenter?.title
|
|
181
166
|
if (typeof presenterTitle === 'string') {
|
|
@@ -49,6 +49,7 @@ import type { LucideIcon } from 'lucide-react'
|
|
|
49
49
|
import { cn } from '@open-mercato/shared/lib/utils'
|
|
50
50
|
import type { SearchResult, SearchResultLink } from '@open-mercato/shared/modules/search'
|
|
51
51
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
52
|
+
import { resolveEntityTypeLabel } from '../lib/entityTypeLabel'
|
|
52
53
|
import {
|
|
53
54
|
getCurrentOrganizationScope,
|
|
54
55
|
subscribeOrganizationScopeChanged,
|
|
@@ -84,14 +85,6 @@ function hasActiveOrganizationSelection(): boolean {
|
|
|
84
85
|
return !isAllOrganizationsSelection(cookieValue)
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
function humanizeSegment(segment: string): string {
|
|
88
|
-
return segment
|
|
89
|
-
.split(/[_-]+/)
|
|
90
|
-
.filter(Boolean)
|
|
91
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
92
|
-
.join(' ')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
88
|
const ICON_MAP: Record<string, LucideIcon> = {
|
|
96
89
|
bolt: Zap,
|
|
97
90
|
zap: Zap,
|
|
@@ -137,12 +130,6 @@ function resolveIcon(name?: string): LucideIcon | null {
|
|
|
137
130
|
return ICON_MAP[name.toLowerCase()] ?? null
|
|
138
131
|
}
|
|
139
132
|
|
|
140
|
-
function formatEntityId(entityId: string): string {
|
|
141
|
-
if (!entityId.includes(':')) return humanizeSegment(entityId)
|
|
142
|
-
const [module, entity] = entityId.split(':')
|
|
143
|
-
return `${humanizeSegment(module)} · ${humanizeSegment(entity)}`
|
|
144
|
-
}
|
|
145
|
-
|
|
146
133
|
export type TopbarSearchInlineProps = {
|
|
147
134
|
/** Whether embedding provider is configured for vector search */
|
|
148
135
|
embeddingConfigured: boolean
|
|
@@ -521,7 +508,7 @@ export function TopbarSearchInline({
|
|
|
521
508
|
</span>
|
|
522
509
|
</span>
|
|
523
510
|
<span className="flex items-center gap-2 text-overline text-muted-foreground">
|
|
524
|
-
<span className="truncate">{
|
|
511
|
+
<span className="truncate">{resolveEntityTypeLabel(t, result.entityId)}</span>
|
|
525
512
|
{presenter?.subtitle ? (
|
|
526
513
|
<>
|
|
527
514
|
<span aria-hidden="true">·</span>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { formatEntityId, resolveEntityTypeLabel } from '../entityTypeLabel'
|
|
2
|
+
import type { TranslateFn } from '@open-mercato/shared/lib/i18n/context'
|
|
3
|
+
|
|
4
|
+
describe('formatEntityId', () => {
|
|
5
|
+
it('humanizes module · entity', () => {
|
|
6
|
+
expect(formatEntityId('customers:customer_person_profile')).toBe('Customers · Customer Person Profile')
|
|
7
|
+
})
|
|
8
|
+
it('humanizes a bare segment', () => {
|
|
9
|
+
expect(formatEntityId('messages')).toBe('Messages')
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('resolveEntityTypeLabel', () => {
|
|
14
|
+
const t: TranslateFn = (key, fallbackOrParams) =>
|
|
15
|
+
key === 'search.entityType.sales.sales_order'
|
|
16
|
+
? 'Order'
|
|
17
|
+
: (typeof fallbackOrParams === 'string' ? fallbackOrParams : key)
|
|
18
|
+
|
|
19
|
+
it('returns the translated label when a key exists', () => {
|
|
20
|
+
expect(resolveEntityTypeLabel(t, 'sales:sales_order')).toBe('Order')
|
|
21
|
+
})
|
|
22
|
+
it('falls back to the humanized string for unknown entity types', () => {
|
|
23
|
+
expect(resolveEntityTypeLabel(t, 'thirdparty:widget_thing')).toBe('Thirdparty · Widget Thing')
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TranslateFn } from '@open-mercato/shared/lib/i18n/context'
|
|
2
|
+
|
|
3
|
+
function humanizeSegment(segment: string): string {
|
|
4
|
+
return segment
|
|
5
|
+
.split(/[_-]+/)
|
|
6
|
+
.filter(Boolean)
|
|
7
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
8
|
+
.join(' ')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatEntityId(entityId: string): string {
|
|
12
|
+
if (!entityId.includes(':')) return humanizeSegment(entityId)
|
|
13
|
+
const [module, entity] = entityId.split(':')
|
|
14
|
+
return `${humanizeSegment(module)} · ${humanizeSegment(entity)}`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveEntityTypeLabel(t: TranslateFn, entityId: string): string {
|
|
18
|
+
const fallback = formatEntityId(entityId)
|
|
19
|
+
if (!entityId.includes(':')) return fallback
|
|
20
|
+
const [module, entity] = entityId.split(':')
|
|
21
|
+
return t(`search.entityType.${module}.${entity}`, fallback)
|
|
22
|
+
}
|
|
@@ -50,6 +50,53 @@
|
|
|
50
50
|
"search.dialog.strategies.toggle": "Suchoptionen",
|
|
51
51
|
"search.dialog.title": "Globale Suche",
|
|
52
52
|
"search.dialog.warnings.configureLink": "Sucheinstellungen konfigurieren",
|
|
53
|
+
"search.entityType.catalog.catalog_offer": "Angebot",
|
|
54
|
+
"search.entityType.catalog.catalog_option_schema_template": "Optionsvorlage",
|
|
55
|
+
"search.entityType.catalog.catalog_price_kind": "Preistyp",
|
|
56
|
+
"search.entityType.catalog.catalog_product": "Produkt",
|
|
57
|
+
"search.entityType.catalog.catalog_product_category": "Kategorie",
|
|
58
|
+
"search.entityType.catalog.catalog_product_tag": "Tag",
|
|
59
|
+
"search.entityType.catalog.catalog_product_unit_conversion": "Einheitenumrechnung",
|
|
60
|
+
"search.entityType.catalog.catalog_product_variant": "Variante",
|
|
61
|
+
"search.entityType.customer_accounts.customer_role": "Kundenrolle",
|
|
62
|
+
"search.entityType.customer_accounts.customer_user": "Kundenbenutzer",
|
|
63
|
+
"search.entityType.customers.customer_activity": "Aktivität",
|
|
64
|
+
"search.entityType.customers.customer_comment": "Kommentar",
|
|
65
|
+
"search.entityType.customers.customer_company_profile": "Unternehmen",
|
|
66
|
+
"search.entityType.customers.customer_deal": "Deal",
|
|
67
|
+
"search.entityType.customers.customer_entity": "Kunde",
|
|
68
|
+
"search.entityType.customers.customer_person_profile": "Person",
|
|
69
|
+
"search.entityType.customers.customer_todo_link": "Aufgabe",
|
|
70
|
+
"search.entityType.inbox_ops.inbox_proposal": "Posteingang-Vorschlag",
|
|
71
|
+
"search.entityType.messages.message": "Nachricht",
|
|
72
|
+
"search.entityType.planner.planner_availability_rule_set": "Verfügbarkeitsregeln",
|
|
73
|
+
"search.entityType.resources.resources_resource": "Ressource",
|
|
74
|
+
"search.entityType.resources.resources_resource_type": "Ressourcentyp",
|
|
75
|
+
"search.entityType.sales.sales_channel": "Kanal",
|
|
76
|
+
"search.entityType.sales.sales_credit_memo": "Gutschrift",
|
|
77
|
+
"search.entityType.sales.sales_credit_memo_line": "Gutschriftsposition",
|
|
78
|
+
"search.entityType.sales.sales_delivery_window": "Lieferfenster",
|
|
79
|
+
"search.entityType.sales.sales_document_address": "Dokumentadresse",
|
|
80
|
+
"search.entityType.sales.sales_document_tag": "Dokument-Tag",
|
|
81
|
+
"search.entityType.sales.sales_invoice": "Rechnung",
|
|
82
|
+
"search.entityType.sales.sales_invoice_line": "Rechnungsposition",
|
|
83
|
+
"search.entityType.sales.sales_note": "Notiz",
|
|
84
|
+
"search.entityType.sales.sales_order": "Bestellung",
|
|
85
|
+
"search.entityType.sales.sales_order_adjustment": "Bestellanpassung",
|
|
86
|
+
"search.entityType.sales.sales_order_line": "Bestellposition",
|
|
87
|
+
"search.entityType.sales.sales_payment": "Zahlung",
|
|
88
|
+
"search.entityType.sales.sales_payment_allocation": "Zahlungszuordnung",
|
|
89
|
+
"search.entityType.sales.sales_payment_method": "Zahlungsmethode",
|
|
90
|
+
"search.entityType.sales.sales_quote": "Angebot",
|
|
91
|
+
"search.entityType.sales.sales_quote_adjustment": "Angebotsanpassung",
|
|
92
|
+
"search.entityType.sales.sales_quote_line": "Angebotsposition",
|
|
93
|
+
"search.entityType.sales.sales_shipment": "Sendung",
|
|
94
|
+
"search.entityType.sales.sales_shipment_item": "Sendungsposition",
|
|
95
|
+
"search.entityType.sales.sales_shipping_method": "Versandart",
|
|
96
|
+
"search.entityType.sales.sales_tax_rate": "Steuersatz",
|
|
97
|
+
"search.entityType.staff.staff_team": "Team",
|
|
98
|
+
"search.entityType.staff.staff_team_member": "Teammitglied",
|
|
99
|
+
"search.entityType.staff.staff_team_role": "Teamrolle",
|
|
53
100
|
"search.messages.missingConfig": "Die Suche erfordert die Konfiguration eines Embedding-Anbieters für die semantische Suche.",
|
|
54
101
|
"search.nav.hybridSearch": "Suche",
|
|
55
102
|
"search.scopeHint.currentOrg": "Bereich: aktuelle Organisation",
|
|
@@ -50,6 +50,53 @@
|
|
|
50
50
|
"search.dialog.strategies.toggle": "Search options",
|
|
51
51
|
"search.dialog.title": "Global Search",
|
|
52
52
|
"search.dialog.warnings.configureLink": "Configure search settings",
|
|
53
|
+
"search.entityType.catalog.catalog_offer": "Offer",
|
|
54
|
+
"search.entityType.catalog.catalog_option_schema_template": "Option Template",
|
|
55
|
+
"search.entityType.catalog.catalog_price_kind": "Price Type",
|
|
56
|
+
"search.entityType.catalog.catalog_product": "Product",
|
|
57
|
+
"search.entityType.catalog.catalog_product_category": "Category",
|
|
58
|
+
"search.entityType.catalog.catalog_product_tag": "Tag",
|
|
59
|
+
"search.entityType.catalog.catalog_product_unit_conversion": "Unit Conversion",
|
|
60
|
+
"search.entityType.catalog.catalog_product_variant": "Variant",
|
|
61
|
+
"search.entityType.customer_accounts.customer_role": "Customer Role",
|
|
62
|
+
"search.entityType.customer_accounts.customer_user": "Customer User",
|
|
63
|
+
"search.entityType.customers.customer_activity": "Activity",
|
|
64
|
+
"search.entityType.customers.customer_comment": "Comment",
|
|
65
|
+
"search.entityType.customers.customer_company_profile": "Company",
|
|
66
|
+
"search.entityType.customers.customer_deal": "Deal",
|
|
67
|
+
"search.entityType.customers.customer_entity": "Customer",
|
|
68
|
+
"search.entityType.customers.customer_person_profile": "Person",
|
|
69
|
+
"search.entityType.customers.customer_todo_link": "Task",
|
|
70
|
+
"search.entityType.inbox_ops.inbox_proposal": "Inbox Proposal",
|
|
71
|
+
"search.entityType.messages.message": "Message",
|
|
72
|
+
"search.entityType.planner.planner_availability_rule_set": "Availability Rules",
|
|
73
|
+
"search.entityType.resources.resources_resource": "Resource",
|
|
74
|
+
"search.entityType.resources.resources_resource_type": "Resource Type",
|
|
75
|
+
"search.entityType.sales.sales_channel": "Channel",
|
|
76
|
+
"search.entityType.sales.sales_credit_memo": "Credit Memo",
|
|
77
|
+
"search.entityType.sales.sales_credit_memo_line": "Credit Memo Line",
|
|
78
|
+
"search.entityType.sales.sales_delivery_window": "Delivery Window",
|
|
79
|
+
"search.entityType.sales.sales_document_address": "Document Address",
|
|
80
|
+
"search.entityType.sales.sales_document_tag": "Document Tag",
|
|
81
|
+
"search.entityType.sales.sales_invoice": "Invoice",
|
|
82
|
+
"search.entityType.sales.sales_invoice_line": "Invoice Line",
|
|
83
|
+
"search.entityType.sales.sales_note": "Note",
|
|
84
|
+
"search.entityType.sales.sales_order": "Order",
|
|
85
|
+
"search.entityType.sales.sales_order_adjustment": "Order Adjustment",
|
|
86
|
+
"search.entityType.sales.sales_order_line": "Order Line",
|
|
87
|
+
"search.entityType.sales.sales_payment": "Payment",
|
|
88
|
+
"search.entityType.sales.sales_payment_allocation": "Payment Allocation",
|
|
89
|
+
"search.entityType.sales.sales_payment_method": "Payment Method",
|
|
90
|
+
"search.entityType.sales.sales_quote": "Quote",
|
|
91
|
+
"search.entityType.sales.sales_quote_adjustment": "Quote Adjustment",
|
|
92
|
+
"search.entityType.sales.sales_quote_line": "Quote Line",
|
|
93
|
+
"search.entityType.sales.sales_shipment": "Shipment",
|
|
94
|
+
"search.entityType.sales.sales_shipment_item": "Shipment Item",
|
|
95
|
+
"search.entityType.sales.sales_shipping_method": "Shipping Method",
|
|
96
|
+
"search.entityType.sales.sales_tax_rate": "Tax Rate",
|
|
97
|
+
"search.entityType.staff.staff_team": "Team",
|
|
98
|
+
"search.entityType.staff.staff_team_member": "Team Member",
|
|
99
|
+
"search.entityType.staff.staff_team_role": "Team Role",
|
|
53
100
|
"search.messages.missingConfig": "Search requires configuring an embedding provider for semantic search.",
|
|
54
101
|
"search.nav.hybridSearch": "Search",
|
|
55
102
|
"search.scopeHint.currentOrg": "Scoped to current organization",
|