From 34caa99d1d08fc909c24d18d7cc1862021b7e28f Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Wed, 5 Aug 2020 18:01:59 +0200 Subject: [PATCH] SONAR-13720 File and Directory facets' search doesn't pass any branch parameters --- .../sonar-web/src/main/js/api/components.ts | 16 +------- .../main/js/apps/issues/components/App.tsx | 3 +- .../js/apps/issues/sidebar/DirectoryFacet.tsx | 9 ++++- .../main/js/apps/issues/sidebar/FileFacet.tsx | 9 ++++- .../main/js/apps/issues/sidebar/Sidebar.tsx | 9 ++++- .../sidebar/__tests__/DirectoryFacet-test.tsx | 37 ++++++++++++++++++- .../sidebar/__tests__/FileFacet-test.tsx | 37 ++++++++++++++++++- .../sonar-web/src/main/js/types/component.ts | 14 +++++++ 8 files changed, 110 insertions(+), 24 deletions(-) diff --git a/server/sonar-web/src/main/js/api/components.ts b/server/sonar-web/src/main/js/api/components.ts index 86cd1968ce1..4d913580e8b 100644 --- a/server/sonar-web/src/main/js/api/components.ts +++ b/server/sonar-web/src/main/js/api/components.ts @@ -20,7 +20,7 @@ import { getJSON, post, postJSON, RequestData } from 'sonar-ui-common/helpers/request'; import throwGlobalError from '../app/utils/throwGlobalError'; import { BranchParameters } from '../types/branch-like'; -import { ComponentQualifier } from '../types/component'; +import { ComponentQualifier, TreeComponent, TreeComponentWithPath } from '../types/component'; export interface BaseSearchProjectsParameters { analyzedBefore?: string; @@ -132,20 +132,6 @@ export function getComponent( return getJSON('/api/measures/component', data); } -export interface TreeComponent extends T.LightComponent { - id?: string; - name: string; - path?: string; - refId?: string; - refKey?: string; - tags?: string[]; - visibility: T.Visibility; -} - -export interface TreeComponentWithPath extends TreeComponent { - path: string; -} - type GetTreeParams = { asc?: boolean; component: string; diff --git a/server/sonar-web/src/main/js/apps/issues/components/App.tsx b/server/sonar-web/src/main/js/apps/issues/components/App.tsx index d93cfe3ac7c..129267a72f4 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/App.tsx @@ -928,7 +928,7 @@ export default class App extends React.PureComponent { } renderFacets() { - const { component, currentUser, userOrganizations } = this.props; + const { component, currentUser, userOrganizations, branchLike } = this.props; const { query } = this.state; const organizationKey = @@ -953,6 +953,7 @@ export default class App extends React.PureComponent { )} { }; handleSearch = (query: string, page: number) => { + const { branchLike } = this.props; + return getDirectories({ component: this.props.componentKey, + ...getBranchLikeQuery(branchLike), q: query, p: page, ps: 30 diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx index 719c73db4f6..451aef2dd6c 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/FileFacet.tsx @@ -24,11 +24,15 @@ import { translate } from 'sonar-ui-common/helpers/l10n'; import { collapsePath } from 'sonar-ui-common/helpers/path'; import { highlightTerm } from 'sonar-ui-common/helpers/search'; import { isDefined } from 'sonar-ui-common/helpers/types'; -import { getFiles, TreeComponentWithPath } from '../../../api/components'; +import { getFiles } from '../../../api/components'; import ListStyleFacet from '../../../components/facet/ListStyleFacet'; +import { getBranchLikeQuery } from '../../../helpers/branch-like'; +import { BranchLike } from '../../../types/branch-like'; +import { TreeComponentWithPath } from '../../../types/component'; import { Facet, Query, ReferencedComponent } from '../utils'; interface Props { + branchLike?: BranchLike; componentKey: string; fetching: boolean; fileUuids: string[]; @@ -72,8 +76,11 @@ export default class FileFacet extends React.PureComponent { }; handleSearch = (query: string, page: number) => { + const { branchLike } = this.props; + return getFiles({ component: this.props.componentKey, + ...getBranchLikeQuery(branchLike), q: query, p: page, ps: 30 diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx index e1bc2790ebd..8890583195b 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx @@ -20,6 +20,8 @@ import * as React from 'react'; import { connect } from 'react-redux'; import { getGlobalSettingValue, Store } from '../../../store/rootReducer'; +import { BranchLike } from '../../../types/branch-like'; +import { ComponentQualifier } from '../../../types/component'; import { Facet, Query, ReferencedComponent, ReferencedLanguage, ReferencedRule } from '../utils'; import AssigneeFacet from './AssigneeFacet'; import AuthorFacet from './AuthorFacet'; @@ -37,6 +39,7 @@ import TagFacet from './TagFacet'; import TypeFacet from './TypeFacet'; export interface Props { + branchLike?: BranchLike; component: T.Component | undefined; facets: T.Dict; hideAuthorFacet?: boolean; @@ -58,7 +61,7 @@ export interface Props { export class Sidebar extends React.PureComponent { renderComponentFacets() { - const { component, facets, loadingFacets, openFacets, query } = this.props; + const { component, facets, loadingFacets, openFacets, query, branchLike } = this.props; if (!component) { return null; } @@ -71,8 +74,9 @@ export class Sidebar extends React.PureComponent { }; return ( <> - {component.qualifier !== 'DIR' && ( + {component.qualifier !== ComponentQualifier.Directory && ( { /> )} ({ + getDirectories: jest.fn().mockResolvedValue({}) +})); + +beforeEach(() => jest.clearAllMocks()); + +const branch = mockBranch(); +const component = mockComponent(); + it('should render correctly', () => { const wrapper = shallowRender(); const instance = wrapper.instance(); @@ -33,6 +46,25 @@ it('should render correctly', () => { expect(instance.renderFacetItem('foo/bar')).toMatchSnapshot(); }); +it('should properly search for directory', () => { + const wrapper = shallowRender(); + + const query = 'foo'; + + wrapper + .find(ListStyleFacet) + .props() + .onSearch(query); + + expect(getDirectories).toHaveBeenCalledWith({ + branch: branch.name, + component: component.key, + q: query, + ps: 30, + p: undefined + }); +}); + describe("ListStyleFacet's callback props", () => { const wrapper = shallowRender(); const instance = wrapper.instance(); @@ -55,7 +87,8 @@ describe("ListStyleFacet's callback props", () => { function shallowRender(props: Partial = {}) { return shallow( ({ + getFiles: jest.fn().mockResolvedValue({}) +})); + +beforeEach(() => jest.clearAllMocks()); + +const branch = mockBranch(); +const component = mockComponent(); + it('should render correctly', () => { const wrapper = shallowRender(); const instance = wrapper.instance(); @@ -33,6 +46,25 @@ it('should render correctly', () => { expect(instance.renderFacetItem('fooUuid')).toMatchSnapshot(); }); +it('should properly search for file', () => { + const wrapper = shallowRender(); + + const query = 'foo'; + + wrapper + .find(ListStyleFacet) + .props() + .onSearch(query); + + expect(getFiles).toHaveBeenCalledWith({ + branch: branch.name, + component: component.key, + q: query, + ps: 30, + p: undefined + }); +}); + describe("ListStyleFacet's callback props", () => { const wrapper = shallowRender(); const instance = wrapper.instance(); @@ -57,7 +89,8 @@ describe("ListStyleFacet's callback props", () => { function shallowRender(props: Partial = {}) { return shallow(