From: Mathieu Suen Date: Wed, 13 May 2020 13:23:07 +0000 (+0200) Subject: SONAR-13291 Remove file reference in global search. X-Git-Tag: 8.4.0.35506~131 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5e9d00966008decae9ae040fa6701ee7e9da0545;p=sonarqube.git SONAR-13291 Remove file reference in global search. --- diff --git a/server/sonar-web/src/main/js/app/components/search/Search.tsx b/server/sonar-web/src/main/js/app/components/search/Search.tsx index ef00d7b8fad..f9ab024bf7b 100644 --- a/server/sonar-web/src/main/js/app/components/search/Search.tsx +++ b/server/sonar-web/src/main/js/app/components/search/Search.tsx @@ -31,7 +31,7 @@ import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; import { scrollToElement } from 'sonar-ui-common/helpers/scrolling'; import { getSuggestions } from '../../../api/components'; -import { getCodeUrl, getComponentOverviewUrl } from '../../../helpers/urls'; +import { getComponentOverviewUrl } from '../../../helpers/urls'; import { ComponentQualifier } from '../../../types/component'; import RecentHistory from '../RecentHistory'; import './Search.css'; @@ -163,23 +163,6 @@ export class Search extends React.PureComponent { return next; }, []); - findFile = (key: string) => { - const findInResults = (results: ComponentResult[] | undefined) => - results && results.find(r => r.key === key); - - const file = findInResults(this.state.results['FIL']); - if (file) { - return file; - } - - const test = findInResults(this.state.results['UTS']); - if (test) { - return test; - } - - return undefined; - }; - stopLoading = () => { if (this.mounted) { this.setState({ loading: false }); @@ -285,20 +268,16 @@ export class Search extends React.PureComponent { if (selected.startsWith('qualifier###')) { this.searchMore(selected.substr(12)); } else { - const file = this.findFile(selected); - if (file) { - this.props.router.push(getCodeUrl(file.project!, undefined, file.key)); - } else { - let qualifier = ComponentQualifier.Project; - - if ((results[ComponentQualifier.Portfolio] ?? []).find(r => r.key === selected)) { - qualifier = ComponentQualifier.Portfolio; - } else if ((results[ComponentQualifier.SubPortfolio] ?? []).find(r => r.key === selected)) { - qualifier = ComponentQualifier.SubPortfolio; - } + let qualifier = ComponentQualifier.Project; - this.props.router.push(getComponentOverviewUrl(selected, qualifier)); + if ((results[ComponentQualifier.Portfolio] ?? []).find(r => r.key === selected)) { + qualifier = ComponentQualifier.Portfolio; + } else if ((results[ComponentQualifier.SubPortfolio] ?? []).find(r => r.key === selected)) { + qualifier = ComponentQualifier.SubPortfolio; } + + this.props.router.push(getComponentOverviewUrl(selected, qualifier)); + this.closeSearch(); } }; diff --git a/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx b/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx index 7f99d49e15d..a2d703e86a8 100644 --- a/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx +++ b/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx @@ -23,7 +23,8 @@ import Tooltip from 'sonar-ui-common/components/controls/Tooltip'; import ClockIcon from 'sonar-ui-common/components/icons/ClockIcon'; import FavoriteIcon from 'sonar-ui-common/components/icons/FavoriteIcon'; import QualifierIcon from 'sonar-ui-common/components/icons/QualifierIcon'; -import { getCodeUrl, getComponentOverviewUrl } from '../../../helpers/urls'; +import { ComponentQualifier } from '../../../../js/types/component'; +import { getComponentOverviewUrl } from '../../../helpers/urls'; import { ComponentResult } from './utils'; interface Props { @@ -82,23 +83,11 @@ export default class SearchResult extends React.PureComponent { this.props.onSelect(this.props.component.key); }; - renderOrganization = (component: ComponentResult) => { - if (!this.props.appState.organizationsEnabled) { - return null; - } - - if (!['VW', 'SVW', 'APP', 'TRK'].includes(component.qualifier) || !component.organization) { - return null; - } - - const organization = this.props.organizations[component.organization]; - return organization ? ( -
{organization.name}
- ) : null; - }; - renderProject = (component: ComponentResult) => { - if (!['BRC', 'FIL', 'UTS'].includes(component.qualifier) || component.project == null) { + if ( + ComponentQualifier.SubProject !== (component.qualifier as ComponentQualifier) || + component.project == null + ) { return null; } @@ -111,10 +100,7 @@ export default class SearchResult extends React.PureComponent { render() { const { component } = this.props; - const isFile = component.qualifier === 'FIL' || component.qualifier === 'UTS'; - const to = isFile - ? getCodeUrl(component.project!, undefined, component.key) - : getComponentOverviewUrl(component.key, component.qualifier); + const to = getComponentOverviewUrl(component.key, component.qualifier); return (
  • { {component.name} )} - {this.renderOrganization(component)} {this.renderProject(component)} diff --git a/server/sonar-web/src/main/js/app/components/search/__tests__/SearchResult-test.tsx b/server/sonar-web/src/main/js/app/components/search/__tests__/SearchResult-test.tsx index 3ad14dc3570..4d33b5b23d7 100644 --- a/server/sonar-web/src/main/js/app/components/search/__tests__/SearchResult-test.tsx +++ b/server/sonar-web/src/main/js/app/components/search/__tests__/SearchResult-test.tsx @@ -78,20 +78,6 @@ it('renders projects', () => { expect(wrapper).toMatchSnapshot(); }); -it('renders organizations', () => { - const component = { - isRecentlyBrowsed: true, - key: 'foo', - name: 'foo', - qualifier: 'TRK', - organization: 'bar' - }; - const wrapper = shallowRender({ appState: { organizationsEnabled: true }, component }); - expect(wrapper).toMatchSnapshot(); - wrapper.setProps({ appState: { organizationsEnabled: false } }); - expect(wrapper).toMatchSnapshot(); -}); - it('shows tooltip after delay', () => { const wrapper = shallowRender(); expect(wrapper.find('Tooltip').prop('visible')).toBe(false); diff --git a/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap b/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap index db6ada7d8ae..e67b6cdc0c8 100644 --- a/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap @@ -101,111 +101,6 @@ exports[`renders match 1`] = `
  • `; -exports[`renders organizations 1`] = ` -
  • - - - - - - - - - foo - -
    - bar -
    -
    - -
    -
  • -`; - -exports[`renders organizations 2`] = ` -
  • - - - - - - - - - foo - - - - -
  • -`; - exports[`renders projects 1`] = `
  • +
  • + qualifiers.FIL +
  • + + zux + +
  • qux -
  • -
  • - qualifiers.FIL -
  • - - zux - `; diff --git a/server/sonar-web/src/main/js/app/components/search/utils.ts b/server/sonar-web/src/main/js/app/components/search/utils.ts index 977aa22d79f..2a577efa990 100644 --- a/server/sonar-web/src/main/js/app/components/search/utils.ts +++ b/server/sonar-web/src/main/js/app/components/search/utils.ts @@ -18,11 +18,19 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { sortBy } from 'lodash'; +import { ComponentQualifier } from '../../../../js/types/component'; -const ORDER = ['DEV', 'VW', 'SVW', 'APP', 'TRK', 'BRC', 'FIL', 'UTS']; +const ORDER = [ + ComponentQualifier.Developper, + ComponentQualifier.Portfolio, + ComponentQualifier.SubPortfolio, + ComponentQualifier.Application, + ComponentQualifier.Project, + ComponentQualifier.SubProject +]; export function sortQualifiers(qualifiers: string[]) { - return sortBy(qualifiers, qualifier => ORDER.indexOf(qualifier)); + return sortBy(qualifiers, qualifier => ORDER.indexOf(qualifier as ComponentQualifier)); } export interface ComponentResult { diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index a7acab3b9f6..7affd182602 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1159,7 +1159,7 @@ property.category.housekeeping.branchesAndPullRequests=Branches and Pull Request #------------------------------------------------------------------------------ search.shortcut_hint=Hint: Press {shortcut} from anywhere to open this search bar. search.show_more.hint=Press {key} to display -search.placeholder=Search for projects and files... +search.placeholder=Search for projects... search.search_for_projects=Search for projects... search.search_for_members=Search for members... search.search_for_users=Search for users...