From 4ba012ab8e289a82bf08cc0d5710d6c4d53b6818 Mon Sep 17 00:00:00 2001 From: Qian Deng Date: Mon, 4 Mar 2019 10:47:54 +0800 Subject: [PATCH] Fix: global search not work issue Both Frontend and Backend should not send chart data when chartmusuem not enabled Signed-off-by: Qian Deng --- src/core/api/search.go | 4 ++-- .../src/app/base/global-search/search-result.component.ts | 7 ++++++- src/portal/src/app/base/global-search/search-results.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/api/search.go b/src/core/api/search.go index eb821ee0e..58cfa483a 100644 --- a/src/core/api/search.go +++ b/src/core/api/search.go @@ -33,7 +33,7 @@ type chartSearchHandler func(string, []string) ([]*search.Result, error) var searchHandler chartSearchHandler -// SearchAPI handles requesst to /api/search +// SearchAPI handles request to /api/search type SearchAPI struct { BaseController } @@ -41,7 +41,7 @@ type SearchAPI struct { type searchResult struct { Project []*models.Project `json:"project"` Repository []map[string]interface{} `json:"repository"` - Chart []*search.Result + Chart []*search.Result `json:"chart,omitempty"` } // Get ... diff --git a/src/portal/src/app/base/global-search/search-result.component.ts b/src/portal/src/app/base/global-search/search-result.component.ts index 3a73e8e73..51e29a017 100644 --- a/src/portal/src/app/base/global-search/search-result.component.ts +++ b/src/portal/src/app/base/global-search/search-result.component.ts @@ -78,7 +78,9 @@ export class SearchResultComponent implements OnInit, OnDestroy { if (src) { src.project.forEach(pro => res.project.push(Object.assign({}, pro))); src.repository.forEach(repo => res.repository.push(Object.assign({}, repo))); - src.Chart.forEach(chart => res.Chart.push(JSON.parse(JSON.stringify(chart)))); + if (this.withHelmChart) { + src.chart.forEach(chart => res.chart.push(JSON.parse(JSON.stringify(chart)))); + } return res; } @@ -129,6 +131,9 @@ export class SearchResultComponent implements OnInit, OnDestroy { if (term === "") { this.searchResults.project = []; this.searchResults.repository = []; + if (this.withHelmChart) { + this.searchResults.chart = []; + } return; } // Show spinner diff --git a/src/portal/src/app/base/global-search/search-results.ts b/src/portal/src/app/base/global-search/search-results.ts index 0548a01ef..ae9eae7b2 100644 --- a/src/portal/src/app/base/global-search/search-results.ts +++ b/src/portal/src/app/base/global-search/search-results.ts @@ -18,10 +18,10 @@ export class SearchResults { constructor() { this.project = []; this.repository = []; - this.Chart = []; + this.chart = []; } project: Project[]; repository: Repository[]; - Chart: HelmChartSearchResultItem[]; + chart: HelmChartSearchResultItem[]; }