Skip to content

Commit

Permalink
#1320 Branch result
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 8, 2024
1 parent 93028d9 commit a964817
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ constructor(
companion object {
const val SEARCH_RESULT_ITEM = "item"
const val SEARCH_RESULT_PROJECT = "project"
const val SEARCH_RESULT_BRANCH = "branch"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class BranchSearchProvider(
) : SearchIndexer<BranchSearchItem>, EventListener {

override val searchResultType = SearchResultType(
feature = CoreExtensionFeature.INSTANCE.featureDescription,
id = BRANCH_SEARCH_RESULT_TYPE,
name = "Branch",
description = "Branch name in Ontrack"
feature = CoreExtensionFeature.INSTANCE.featureDescription,
id = BRANCH_SEARCH_RESULT_TYPE,
name = "Branch",
description = "Branch name in Ontrack"
)

override val indexerName: String = "Branches"
Expand All @@ -41,27 +41,32 @@ class BranchSearchProvider(
}

override fun toSearchResult(id: String, score: Double, source: JsonNode): SearchResult? =
structureService.findBranchByID(ID.of(id.toInt()))?.run {
SearchResult(
title = entityDisplayName,
description = description ?: "",
uri = uriBuilder.getEntityURI(this),
page = uriBuilder.getEntityPage(this),
accuracy = score,
type = searchResultType
structureService.findBranchByID(ID.of(id.toInt()))?.run {
SearchResult(
title = entityDisplayName,
description = description ?: "",
uri = uriBuilder.getEntityURI(this),
page = uriBuilder.getEntityPage(this),
accuracy = score,
type = searchResultType,
data = mapOf(
SearchResult.SEARCH_RESULT_BRANCH to this
)
}
)
}

override fun onEvent(event: Event) {
when (event.eventType) {
EventFactory.NEW_BRANCH -> {
val branch = event.getEntity<Branch>(ProjectEntityType.BRANCH)
searchIndexService.createSearchIndex(this, branch.asSearchItem())
}

EventFactory.UPDATE_BRANCH -> {
val branch = event.getEntity<Branch>(ProjectEntityType.BRANCH)
searchIndexService.updateSearchIndex(this, branch.asSearchItem())
}

EventFactory.DELETE_BRANCH -> {
val branchId = event.getIntValue("BRANCH_ID")
searchIndexService.deleteSearchIndex(this, branchId)
Expand All @@ -83,22 +88,22 @@ const val BRANCH_SEARCH_INDEX = "branches"
const val BRANCH_SEARCH_RESULT_TYPE = "branch"

class BranchSearchItem(
override val id: String,
val name: String,
val description: String,
val project: String
override val id: String,
val name: String,
val description: String,
val project: String
) : SearchItem {

constructor(branch: Branch) : this(
id = branch.id.toString(),
name = branch.name,
description = branch.description ?: "",
project = branch.project.name
id = branch.id.toString(),
name = branch.name,
description = branch.description ?: "",
project = branch.project.name
)

override val fields: Map<String, Any> = mapOf(
"name" to name,
"description" to description,
"project" to project
"name" to name,
"description" to description,
"project" to project
)
}
15 changes: 13 additions & 2 deletions ontrack-web-core/components/framework/search/branch/Result.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import SearchResultComponent from "@components/framework/search/SearchResultComponent";
import BranchLink from "@components/branches/BranchLink";
import {Space, Typography} from "antd";
import ProjectLink from "@components/projects/ProjectLink";

export default function Result({data}) {
return <SearchResultComponent
title="TODO"
description={JSON.stringify(data)}
title={
<>
<Space>
<ProjectLink project={data.branch.project}/>
<Typography.Text type="secondary">/</Typography.Text>
<BranchLink branch={data.branch}/>
</Space>
</>
}
description={data.branch.description}
/>
}

0 comments on commit a964817

Please sign in to comment.