MCPcopy Create free account
hub / github.com/emwalker/digraph / buildPath

Function buildPath

next/components/SearchBox/buildPath.ts:6–27  ·  view source on GitHub ↗
(
  searchTerms: string[],
  queryInfo: QueryInfo,
  newQueryInfo: Map<string, string>
)

Source from the content-addressed store, hash-verified

4type QueryInfo = SearchBoxQuery['view']['queryInfo']
5
6export function buildPath(
7 searchTerms: string[],
8 queryInfo: QueryInfo,
9 newQueryInfo: Map<string, string>
10): string {
11 const displayNamesToIds: Map<string, string> = new Map(newQueryInfo)
12
13 queryInfo.topics.forEach((topic) => {
14 displayNamesToIds.set(topic.displayName, topic.id)
15 })
16
17 const topicIds = searchTerms.map((name) => displayNamesToIds.get(name)).filter(Boolean)
18 const parentTopicId = topicIds.length < 1 ? ROOT_TOPIC_ID : topicIds[0]
19 const phrases = searchTerms.filter((name) => !displayNamesToIds.has(name))
20 const q = topicIds.slice(1).map((id) => `in:${id}`).concat(phrases).join(' ')
21
22 if (q.length > 0) {
23 return `/topics/${parentTopicId}/q/${q}`
24 }
25
26 return `/topics/${parentTopicId}`
27}

Callers 2

buildPath.test.tsFile · 0.90
SearchBoxFunction · 0.90

Calls 1

getMethod · 0.45

Tested by

no test coverage detected