aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2017-10-12 15:31:14 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-10-16 11:08:02 +0200
commit14018e728e0d7314616aa2af79964f08c5a03e5d (patch)
treeeae292e973c548cd6744d1a1bd74659f7831d855 /server
parent62bd551bfb67b52848d3b04fcc1f6b33c9f2e263 (diff)
downloadsonarqube-14018e728e0d7314616aa2af79964f08c5a03e5d.tar.gz
sonarqube-14018e728e0d7314616aa2af79964f08c5a03e5d.zip
SONAR-9790 Add project context to a file permalink
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/App.js27
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js17
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/App-test.js.snap12
-rw-r--r--server/sonar-web/src/main/js/helpers/urls.ts4
4 files changed, 29 insertions, 31 deletions
diff --git a/server/sonar-web/src/main/js/apps/overview/components/App.js b/server/sonar-web/src/main/js/apps/overview/components/App.js
index f7f3dbf4e86..8ce26596388 100644
--- a/server/sonar-web/src/main/js/apps/overview/components/App.js
+++ b/server/sonar-web/src/main/js/apps/overview/components/App.js
@@ -23,14 +23,14 @@ import PropTypes from 'prop-types';
import OverviewApp from './OverviewApp';
import EmptyOverview from './EmptyOverview';
import { getBranchName, isShortLivingBranch } from '../../../helpers/branches';
-import { getProjectBranchUrl } from '../../../helpers/urls';
-import SourceViewer from '../../../components/SourceViewer/SourceViewer';
+import { getProjectBranchUrl, getCodeUrl } from '../../../helpers/urls';
/*::
type Props = {
branch?: { name: string },
component: {
analysisDate?: string,
+ breadcrumbs: Array<{ key: string }>,
id: string,
key: string,
qualifier: string,
@@ -50,14 +50,19 @@ export default class App extends React.PureComponent {
};
componentDidMount() {
+ const { branch, component } = this.props;
+
if (this.isPortfolio()) {
this.context.router.replace({
pathname: '/portfolio',
- query: { id: this.props.component.key }
+ query: { id: component.key }
});
- }
- if (isShortLivingBranch(this.props.branch) && !this.isFile()) {
- this.context.router.replace(getProjectBranchUrl(this.props.component.key, this.props.branch));
+ } else if (this.isFile()) {
+ this.context.router.replace(
+ getCodeUrl(component.breadcrumbs[0].key, getBranchName(branch), component.key)
+ );
+ } else if (isShortLivingBranch(branch)) {
+ this.context.router.replace(getProjectBranchUrl(component.key, branch));
}
}
@@ -72,18 +77,10 @@ export default class App extends React.PureComponent {
render() {
const { branch, component } = this.props;
- if (this.isPortfolio() || (isShortLivingBranch(branch) && !this.isFile())) {
+ if (this.isPortfolio() || this.isFile() || isShortLivingBranch(branch)) {
return null;
}
- if (['FIL', 'UTS'].includes(component.qualifier)) {
- return (
- <div className="page page-limited">
- <SourceViewer branch={branch && getBranchName(branch)} component={component.key} />
- </div>
- );
- }
-
if (!component.analysisDate) {
return <EmptyOverview component={component} />;
}
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js
index f2f2f34a1c4..c42d54126a7 100644
--- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js
+++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import { shallow } from 'enzyme';
+import { mount, shallow } from 'enzyme';
import App from '../App';
import OverviewApp from '../OverviewApp';
import EmptyOverview from '../EmptyOverview';
@@ -35,8 +35,17 @@ it('should render EmptyOverview', () => {
expect(output.type()).toBe(EmptyOverview);
});
-it('renders SourceViewer with branch', () => {
+it('redirects on Code page for files', () => {
const branch = { isMain: false, name: 'b' };
- const component = { key: 'foo', qualifier: 'FIL' };
- expect(shallow(<App branch={branch} component={component} />)).toMatchSnapshot();
+ const component = {
+ breadcrumbs: [{ key: 'project' }, { key: 'foo' }],
+ key: 'foo',
+ qualifier: 'FIL'
+ };
+ const replace = jest.fn();
+ mount(<App branch={branch} component={component} />, { context: { router: { replace } } });
+ expect(replace).toBeCalledWith({
+ pathname: '/code',
+ query: { branch: 'b', id: 'project', selected: 'foo' }
+ });
});
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/App-test.js.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/App-test.js.snap
deleted file mode 100644
index 7f7335f6860..00000000000
--- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/App-test.js.snap
+++ /dev/null
@@ -1,12 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`renders SourceViewer with branch 1`] = `
-<div
- className="page page-limited"
->
- <Connect(SourceViewerBase)
- branch="b"
- component="foo"
- />
-</div>
-`;
diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts
index 91c5bc35d35..aae5afb93bc 100644
--- a/server/sonar-web/src/main/js/helpers/urls.ts
+++ b/server/sonar-web/src/main/js/helpers/urls.ts
@@ -172,3 +172,7 @@ export function getDeprecatedActiveRulesUrl(query = {}, organization?: string |
export function getMarkdownHelpUrl(): string {
return getBaseUrl() + '/markdown/help';
}
+
+export function getCodeUrl(project: string, branch?: string, selected?: string) {
+ return { pathname: '/code', query: { id: project, branch, selected } };
+}