aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-10-10 10:08:44 +0200
committerSonarTech <sonartech@sonarsource.com>2018-10-11 15:14:32 +0200
commitd234df518982af0f6194b457929786b06b7e32fe (patch)
tree9812a6b672f52a56e45942b5b8b3579a6bfd8000
parent1eac6fe58a79cc602b25cd919af98407648f0186 (diff)
downloadsonarqube-d234df518982af0f6194b457929786b06b7e32fe.tar.gz
sonarqube-d234df518982af0f6194b457929786b06b7e32fe.zip
SONAR-11311 fix rule permalink
-rw-r--r--server/sonar-web/src/main/js/components/withAppState.tsx43
-rw-r--r--server/sonar-web/src/main/js/components/workspace/WorkspaceRuleDetails.tsx14
-rw-r--r--server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx16
-rw-r--r--server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/components/workspace/__tests__/__snapshots__/WorkspaceRuleViewer-test.tsx.snap2
-rw-r--r--server/sonar-web/src/main/js/helpers/urls.ts4
6 files changed, 70 insertions, 12 deletions
diff --git a/server/sonar-web/src/main/js/components/withAppState.tsx b/server/sonar-web/src/main/js/components/withAppState.tsx
new file mode 100644
index 00000000000..958c37c441a
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/withAppState.tsx
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { connect } from 'react-redux';
+import { AppState } from '../app/types';
+import { Store, getAppState } from '../store/rootReducer';
+
+export function withAppState<P>(
+ WrappedComponent: React.ComponentClass<P & { appState: Partial<AppState> }>
+) {
+ const wrappedDisplayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
+
+ class Wrapper extends React.Component<P & { appState: AppState }> {
+ static displayName = `withAppState(${wrappedDisplayName})`;
+
+ render() {
+ return <WrappedComponent {...this.props} />;
+ }
+ }
+
+ function mapStateToProps(state: Store) {
+ return { appState: getAppState(state) };
+ }
+
+ return connect(mapStateToProps)(Wrapper);
+}
diff --git a/server/sonar-web/src/main/js/components/workspace/WorkspaceRuleDetails.tsx b/server/sonar-web/src/main/js/components/workspace/WorkspaceRuleDetails.tsx
index a1a62dcb3e5..d19a47f480c 100644
--- a/server/sonar-web/src/main/js/components/workspace/WorkspaceRuleDetails.tsx
+++ b/server/sonar-web/src/main/js/components/workspace/WorkspaceRuleDetails.tsx
@@ -19,14 +19,16 @@
*/
import * as React from 'react';
import { keyBy } from 'lodash';
+import { withAppState } from '../withAppState';
import DeferredSpinner from '../common/DeferredSpinner';
import RuleDetailsMeta from '../../apps/coding-rules/components/RuleDetailsMeta';
import RuleDetailsDescription from '../../apps/coding-rules/components/RuleDetailsDescription';
import { getRuleDetails, getRulesApp } from '../../api/rules';
-import { RuleDetails } from '../../app/types';
+import { RuleDetails, AppState } from '../../app/types';
import '../../apps/coding-rules/styles.css';
interface Props {
+ appState: Pick<AppState, 'organizationsEnabled'>;
onLoad: (details: { name: string }) => void;
organizationKey: string | undefined;
ruleKey: string;
@@ -38,7 +40,7 @@ interface State {
ruleDetails?: RuleDetails;
}
-export default class WorkspaceRuleDetails extends React.PureComponent<Props, State> {
+export class WorkspaceRuleDetails extends React.PureComponent<Props, State> {
mounted = false;
state: State = { loading: true, referencedRepositories: {} };
@@ -88,6 +90,8 @@ export default class WorkspaceRuleDetails extends React.PureComponent<Props, Sta
render() {
const { organizationKey } = this.props;
+ const { organizationsEnabled } = this.props.appState;
+ const organization = organizationsEnabled ? organizationKey : undefined;
return (
<DeferredSpinner loading={this.state.loading}>
@@ -98,14 +102,14 @@ export default class WorkspaceRuleDetails extends React.PureComponent<Props, Sta
hideSimilarRulesFilter={true}
onFilterChange={this.noOp}
onTagsChange={this.noOp}
- organization={organizationKey}
+ organization={organization}
referencedRepositories={this.state.referencedRepositories}
ruleDetails={this.state.ruleDetails}
/>
<RuleDetailsDescription
canWrite={false}
onChange={this.noOp}
- organization={organizationKey}
+ organization={organization}
ruleDetails={this.state.ruleDetails}
/>
</>
@@ -114,3 +118,5 @@ export default class WorkspaceRuleDetails extends React.PureComponent<Props, Sta
);
}
}
+
+export default withAppState(WorkspaceRuleDetails);
diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx
index 13ff053fcc3..074718a6d49 100644
--- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx
+++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx
@@ -19,7 +19,7 @@
*/
import * as React from 'react';
import { shallow } from 'enzyme';
-import WorkspaceRuleDetails from '../WorkspaceRuleDetails';
+import { WorkspaceRuleDetails } from '../WorkspaceRuleDetails';
import { waitAndUpdate } from '../../../helpers/testUtils';
jest.mock('../../../api/rules', () => ({
@@ -31,7 +31,12 @@ jest.mock('../../../api/rules', () => ({
it('should render', async () => {
const wrapper = shallow(
- <WorkspaceRuleDetails onLoad={jest.fn()} organizationKey={undefined} ruleKey="foo" />
+ <WorkspaceRuleDetails
+ appState={{ organizationsEnabled: false }}
+ onLoad={jest.fn()}
+ organizationKey={undefined}
+ ruleKey="foo"
+ />
);
expect(wrapper).toMatchSnapshot();
@@ -42,7 +47,12 @@ it('should render', async () => {
it('should call back on load', async () => {
const onLoad = jest.fn();
const wrapper = shallow(
- <WorkspaceRuleDetails onLoad={onLoad} organizationKey={undefined} ruleKey="foo" />
+ <WorkspaceRuleDetails
+ appState={{ organizationsEnabled: false }}
+ onLoad={onLoad}
+ organizationKey={undefined}
+ ruleKey="foo"
+ />
);
await waitAndUpdate(wrapper);
expect(onLoad).toBeCalledWith({ name: 'Foo' });
diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx
index 978b87768e4..9a6dfe29000 100644
--- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx
+++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx
@@ -35,7 +35,8 @@ it('should close', () => {
it('should call back after load', () => {
const onLoad = jest.fn();
const wrapper = shallowRender({ onLoad });
- wrapper.find('WorkspaceRuleDetails').prop<Function>('onLoad')({ name: 'Foo' });
+ const details = wrapper.findWhere(w => w.name().includes('WorkspaceRuleDetails'));
+ details.prop<Function>('onLoad')({ name: 'Foo' });
expect(onLoad).toBeCalledWith({ key: 'foo', name: 'Foo' });
});
diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/__snapshots__/WorkspaceRuleViewer-test.tsx.snap b/server/sonar-web/src/main/js/components/workspace/__tests__/__snapshots__/WorkspaceRuleViewer-test.tsx.snap
index 00b9e074c45..9af15132081 100644
--- a/server/sonar-web/src/main/js/components/workspace/__tests__/__snapshots__/WorkspaceRuleViewer-test.tsx.snap
+++ b/server/sonar-web/src/main/js/components/workspace/__tests__/__snapshots__/WorkspaceRuleViewer-test.tsx.snap
@@ -28,7 +28,7 @@ exports[`should render 1`] = `
}
}
>
- <WorkspaceRuleDetails
+ <Connect(withAppState(WorkspaceRuleDetails))
onLoad={[Function]}
organizationKey="org"
ruleKey="foo"
diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts
index cc207fd5c2b..ed5834e590e 100644
--- a/server/sonar-web/src/main/js/helpers/urls.ts
+++ b/server/sonar-web/src/main/js/helpers/urls.ts
@@ -211,9 +211,7 @@ export function getDeprecatedActiveRulesUrl(
}
export function getRuleUrl(rule: string, organization: string | undefined) {
- /* eslint-disable camelcase */
- return getRulesUrl({ open: rule, rule_key: rule }, organization);
- /* eslint-enable camelcase */
+ return getRulesUrl({ open: rule, rule_key: rule }, organization); // eslint-disable-line camelcase
}
export function getMarkdownHelpUrl(): string {