aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/controls
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-09-18 17:43:42 +0200
committerSonarTech <sonartech@sonarsource.com>2018-09-25 20:21:00 +0200
commitabb68832ff18c47f502cd2ab097b5b4b9fc3a509 (patch)
treedacf53d56390dc2855fa3d8c04ec02c25000beb9 /server/sonar-web/src/main/js/components/controls
parentc003387eb63a644d9e887dcb7799d962ec27310c (diff)
downloadsonarqube-abb68832ff18c47f502cd2ab097b5b4b9fc3a509.tar.gz
sonarqube-abb68832ff18c47f502cd2ab097b5b4b9fc3a509.zip
SONARCLOUD-43 Allow users to select the plan when creating an org (#705)
Diffstat (limited to 'server/sonar-web/src/main/js/components/controls')
-rw-r--r--server/sonar-web/src/main/js/components/controls/Radio.tsx56
-rw-r--r--server/sonar-web/src/main/js/components/controls/ValidationForm.tsx26
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/Radio-test.tsx34
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/Radio-test.tsx.snap29
4 files changed, 136 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/components/controls/Radio.tsx b/server/sonar-web/src/main/js/components/controls/Radio.tsx
new file mode 100644
index 00000000000..9209ad32c68
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/controls/Radio.tsx
@@ -0,0 +1,56 @@
+/*
+ * 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 * as classNames from 'classnames';
+
+interface Props {
+ checked: boolean;
+ className?: string;
+ onCheck: () => void;
+}
+
+export default class Radio extends React.PureComponent<Props> {
+ handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
+ event.preventDefault();
+ event.currentTarget.blur();
+ this.props.onCheck();
+ };
+
+ render() {
+ return (
+ <a
+ aria-checked={this.props.checked}
+ className={classNames(
+ 'display-inline-flex-center link-base-color link-no-underline',
+ this.props.className
+ )}
+ href="#"
+ onClick={this.handleClick}
+ role="radio">
+ <i
+ className={classNames('icon-radio', 'spacer-right', {
+ 'is-checked': this.props.checked
+ })}
+ />
+ {this.props.children}
+ </a>
+ );
+ }
+}
diff --git a/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx b/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx
index 5f33868b67b..b4e061b3924 100644
--- a/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx
+++ b/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx
@@ -32,20 +32,28 @@ interface Props<V> {
}
export default class ValidationForm<V> extends React.Component<Props<V>> {
+ mounted = false;
+
+ componentDidMount() {
+ this.mounted = true;
+ }
+
+ componentWillUnmount() {
+ this.mounted = false;
+ }
+
handleSubmit = (data: V, { setSubmitting }: FormikActions<V>) => {
const result = this.props.onSubmit(data);
+ const stopSubmitting = () => {
+ if (this.mounted) {
+ setSubmitting(false);
+ }
+ };
if (result) {
- result.then(
- () => {
- setSubmitting(false);
- },
- () => {
- setSubmitting(false);
- }
- );
+ result.then(stopSubmitting, stopSubmitting);
} else {
- setSubmitting(false);
+ stopSubmitting();
}
};
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Radio-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Radio-test.tsx
new file mode 100644
index 00000000000..8d4a4f79aa8
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/Radio-test.tsx
@@ -0,0 +1,34 @@
+/*
+ * 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 { shallow } from 'enzyme';
+import Radio from '../Radio';
+import { click } from '../../../helpers/testUtils';
+
+it('should render and check', () => {
+ const onCheck = jest.fn();
+ const wrapper = shallow(<Radio checked={false} onCheck={onCheck} />);
+ expect(wrapper).toMatchSnapshot();
+
+ click(wrapper);
+ expect(onCheck).toBeCalled();
+ wrapper.setProps({ checked: true });
+ expect(wrapper).toMatchSnapshot();
+});
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/Radio-test.tsx.snap b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/Radio-test.tsx.snap
new file mode 100644
index 00000000000..92e8076ce5e
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/Radio-test.tsx.snap
@@ -0,0 +1,29 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render and check 1`] = `
+<a
+ aria-checked={false}
+ className="display-inline-flex-center link-base-color link-no-underline"
+ href="#"
+ onClick={[Function]}
+ role="radio"
+>
+ <i
+ className="icon-radio spacer-right"
+ />
+</a>
+`;
+
+exports[`should render and check 2`] = `
+<a
+ aria-checked={true}
+ className="display-inline-flex-center link-base-color link-no-underline"
+ href="#"
+ onClick={[Function]}
+ role="radio"
+>
+ <i
+ className="icon-radio spacer-right is-checked"
+ />
+</a>
+`;