From 8f37914e061783a4a32445b5238e8fa37666aaef Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 19 Jan 2017 11:18:43 +0100 Subject: [PATCH] SONAR-8661 Display organization in the search --- .../js/app/components/nav/component/ComponentNav.js | 7 ++++++- .../js/app/components/nav/component/RecentHistory.js | 7 ++++--- .../main/js/app/components/nav/global/SearchView.js | 12 ++++++++++++ .../app/components/nav/templates/nav-search-item.hbs | 6 ++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.js b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.js index cbaa9fb2520..303a45c6cc1 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.js +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.js @@ -56,7 +56,12 @@ export default React.createClass({ const { breadcrumbs } = this.props.component; const { qualifier } = breadcrumbs[breadcrumbs.length - 1]; if (['TRK', 'VW', 'DEV'].indexOf(qualifier) !== -1) { - RecentHistory.add(this.props.component.key, this.props.component.name, qualifier.toLowerCase()); + RecentHistory.add( + this.props.component.key, + this.props.component.name, + qualifier.toLowerCase(), + this.props.component.organization + ); } }, diff --git a/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js b/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js index d5bb1b2d587..56ac275736f 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js +++ b/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js @@ -24,7 +24,8 @@ const HISTORY_LIMIT = 10; type History = Array<{ key: string, name: string, - icon: string + icon: string, + organization?: string }>; export default class RecentHistory { @@ -51,9 +52,9 @@ export default class RecentHistory { localStorage.removeItem(STORAGE_KEY); } - static add (componentKey: string, componentName: string, icon: string): void { + static add (componentKey: string, componentName: string, icon: string, organization?: string): void { const sonarHistory = RecentHistory.get(); - const newEntry = { key: componentKey, name: componentName, icon }; + const newEntry = { key: componentKey, name: componentName, icon, organization }; let newHistory = sonarHistory.filter(entry => entry.key !== newEntry.key); newHistory.unshift(newEntry); newHistory = newHistory.slice(0, HISTORY_LIMIT); diff --git a/server/sonar-web/src/main/js/app/components/nav/global/SearchView.js b/server/sonar-web/src/main/js/app/components/nav/global/SearchView.js index 156266ff132..070d80e993c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/SearchView.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/SearchView.js @@ -31,6 +31,7 @@ import { translate } from '../../../../helpers/l10n'; import { isUserAdmin } from '../../../../helpers/users'; import { getFavorites } from '../../../../api/favorites'; import { getSuggestions } from '../../../../api/components'; +import { getOrganization, areThereCustomOrganizations } from '../../../../store/organizations/utils'; type Finding = { name: string, @@ -174,11 +175,17 @@ export default Marionette.LayoutView.extend({ resetResultsToDefault () { const recentHistory = RecentHistory.get(); + const customOrganizations = areThereCustomOrganizations(); const history = recentHistory.map((historyItem, index) => { const url = window.baseUrl + '/dashboard/index?id=' + encodeURIComponent(historyItem.key) + window.dashboardParameters(true); + const showOrganization = customOrganizations && historyItem.organization != null && + historyItem.icon.toUpperCase() === 'TRK'; + // $FlowFixMe flow doesn't check the above condition on `historyItem.organization != null` + const organization = showOrganization ? getOrganization(historyItem.organization) : null; return { url, + organization, name: historyItem.name, q: historyItem.icon, extra: index === 0 ? translate('browsed_recently') : null @@ -202,12 +209,17 @@ export default Marionette.LayoutView.extend({ return; } + const customOrganizations = areThereCustomOrganizations(); + const collection = []; r.results.forEach(({ items, q }) => { items.forEach((item, index) => { + const showOrganization = customOrganizations && item.organization != null && q === 'TRK'; + const organization = showOrganization ? getOrganization(item.organization) : null; collection.push({ ...item, q, + organization, extra: index === 0 ? translate('qualifiers', q) : null, url: window.baseUrl + '/dashboard?id=' + encodeURIComponent(item.key) }); diff --git a/server/sonar-web/src/main/js/app/components/nav/templates/nav-search-item.hbs b/server/sonar-web/src/main/js/app/components/nav/templates/nav-search-item.hbs index 25128ddfc20..890643d9237 100644 --- a/server/sonar-web/src/main/js/app/components/nav/templates/nav-search-item.hbs +++ b/server/sonar-web/src/main/js/app/components/nav/templates/nav-search-item.hbs @@ -19,4 +19,10 @@ {{name}} {{/eq}} {{/eq}} + + {{#if organization}} +
+ {{organization.name}} +
+ {{/if}} -- 2.39.5