aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-08-24 12:20:03 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-08-25 16:01:06 +0200
commit4f49fdb5b4596540bd15e4a3cebe533911e0e6db (patch)
treefe2c14f137908e555e4761e8d37d51c24ceb0315 /server/sonar-web/src
parent7d034a6d0d9991c251757eb9ab72bd37ac97b6ab (diff)
downloadsonarqube-4f49fdb5b4596540bd15e4a3cebe533911e0e6db.tar.gz
sonarqube-4f49fdb5b4596540bd15e4a3cebe533911e0e6db.zip
Migrate to ts and improve Checkbox
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.tsx (renamed from server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js)56
-rw-r--r--server/sonar-web/src/main/js/apps/web-api/components/Search.js69
-rw-r--r--server/sonar-web/src/main/js/components/controls/Checkbox.tsx (renamed from server/sonar-web/src/main/js/components/controls/Checkbox.js)56
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx (renamed from server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js)12
-rw-r--r--server/sonar-web/src/main/less/init/icons.less2
-rw-r--r--server/sonar-web/src/main/less/init/links.less10
6 files changed, 105 insertions, 100 deletions
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js b/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.tsx
index dbc2767f132..5b4ccbb090b 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.tsx
@@ -17,42 +17,32 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-/* @flow */
-import React from 'react';
+import * as React from 'react';
import Checkbox from '../../../components/controls/Checkbox';
import { CURRENTS } from '../constants';
+import { translate } from '../../../helpers/l10n';
-const CurrentsFilter = (
- { value, onChange } /*: { value: ?string, onChange: string => void } */
-) => {
- function handleChange(value) {
- const newValue = value ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL;
- onChange(newValue);
- }
+interface Props {
+ value?: string;
+ onChange: (value: string) => void;
+}
- function handleLabelClick(e) {
- const newValue = value === CURRENTS.ALL ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL;
+export default class CurrentsFilter extends React.PureComponent<Props> {
+ handleChange = (value: boolean) => {
+ const newValue = value ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL;
+ this.props.onChange(newValue);
+ };
- e.preventDefault();
- onChange(newValue);
+ render() {
+ const checked = this.props.value === CURRENTS.ONLY_CURRENTS;
+ return (
+ <div className="bt-search-form-field">
+ <Checkbox checked={checked} onCheck={this.handleChange}>
+ <span className="little-spacer-left">
+ {translate('yes')}
+ </span>
+ </Checkbox>
+ </div>
+ );
}
-
- const checked = value === CURRENTS.ONLY_CURRENTS;
-
- return (
- <div className="bt-search-form-field">
- <Checkbox checked={checked} onCheck={handleChange} />
- &nbsp;
- <label
- style={{ cursor: 'pointer' }}
- role="checkbox"
- tabIndex="0"
- aria-checked={checked ? 'true' : 'false'}
- onClick={handleLabelClick}>
- Yes
- </label>
- </div>
- );
-};
-
-export default CurrentsFilter;
+}
diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Search.js b/server/sonar-web/src/main/js/apps/web-api/components/Search.js
index 859ad7704e8..c08bbb8bb2e 100644
--- a/server/sonar-web/src/main/js/apps/web-api/components/Search.js
+++ b/server/sonar-web/src/main/js/apps/web-api/components/Search.js
@@ -21,7 +21,8 @@
import React from 'react';
import { debounce } from 'lodash';
import Checkbox from '../../../components/controls/Checkbox';
-import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin';
+import HelpIcon from '../../../components/icons-components/HelpIcon';
+import Tooltip from '../../../components/controls/Tooltip';
import { translate } from '../../../helpers/l10n';
/*::
@@ -78,53 +79,31 @@ export default class Search extends React.PureComponent {
/>
</div>
- <TooltipsContainer>
- <div className="big-spacer-top">
- <Checkbox
- checked={showInternal}
- className="little-spacer-right"
- onCheck={onToggleInternal}
- />
- <span
- style={{ cursor: 'pointer' }}
- title={translate('api_documentation.internal_tooltip')}
- tabIndex="0"
- role="checkbox"
- aria-checked={showInternal ? 'true' : 'false'}
- onClick={onToggleInternal}>
- Show Internal API
+ <div className="big-spacer-top">
+ <Checkbox checked={showInternal} onCheck={onToggleInternal}>
+ <span className="little-spacer-left">
+ {translate('api_documentation.show_deprecated')}
</span>
- <i
- className="icon-help spacer-left"
- title={translate('api_documentation.internal_tooltip')}
- data-toggle="tooltip"
- />
- </div>
- </TooltipsContainer>
+ </Checkbox>
+ <Tooltip overlay={translate('api_documentation.internal_tooltip')} placement="right">
+ <span>
+ <HelpIcon className="spacer-left text-info" />
+ </span>
+ </Tooltip>
+ </div>
- <TooltipsContainer>
- <div className="spacer-top">
- <Checkbox
- checked={showDeprecated}
- className="little-spacer-right"
- onCheck={onToggleDeprecated}
- />
- <span
- style={{ cursor: 'pointer' }}
- title={translate('api_documentation.deprecation_tooltip')}
- tabIndex="0"
- role="checkbox"
- aria-checked={showDeprecated ? 'true' : 'false'}
- onClick={onToggleDeprecated}>
- Show Deprecated API
+ <div className="spacer-top">
+ <Checkbox checked={showDeprecated} onCheck={onToggleDeprecated}>
+ <span className="little-spacer-left">
+ {translate('api_documentation.show_internal')}
</span>
- <i
- className="icon-help spacer-left"
- title={translate('api_documentation.deprecation_tooltip')}
- data-toggle="tooltip"
- />
- </div>
- </TooltipsContainer>
+ </Checkbox>
+ <Tooltip overlay={translate('api_documentation.deprecation_tooltip')} placement="right">
+ <span>
+ <HelpIcon className="spacer-left text-info" />
+ </span>
+ </Tooltip>
+ </div>
</div>
);
}
diff --git a/server/sonar-web/src/main/js/components/controls/Checkbox.js b/server/sonar-web/src/main/js/components/controls/Checkbox.tsx
index b1acc9f577e..1e5afe85195 100644
--- a/server/sonar-web/src/main/js/components/controls/Checkbox.js
+++ b/server/sonar-web/src/main/js/components/controls/Checkbox.tsx
@@ -17,39 +17,55 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import React from 'react';
-import PropTypes from 'prop-types';
-import classNames from 'classnames';
+import * as React from 'react';
+import * as classNames from 'classnames';
-export default class Checkbox extends React.PureComponent {
- static propTypes = {
- id: PropTypes.string,
- onCheck: PropTypes.func.isRequired,
- checked: PropTypes.bool.isRequired,
- thirdState: PropTypes.bool,
- className: PropTypes.any
- };
+interface Props {
+ checked: boolean;
+ children?: React.ReactElement<any>;
+ className?: string;
+ id?: string;
+ onCheck: (checked: boolean, id?: string) => void;
+ thirdState?: boolean;
+}
+export default class Checkbox extends React.PureComponent<Props> {
static defaultProps = {
thirdState: false
};
- componentWillMount() {
- this.handleClick = this.handleClick.bind(this);
- }
-
- handleClick(e) {
+ handleClick = (e: React.SyntheticEvent<HTMLElement>) => {
e.preventDefault();
- e.target.blur();
+ e.currentTarget.blur();
this.props.onCheck(!this.props.checked, this.props.id);
- }
+ };
render() {
- const className = classNames('icon-checkbox', this.props.className, {
+ const className = classNames('icon-checkbox', {
'icon-checkbox-checked': this.props.checked,
'icon-checkbox-single': this.props.thirdState
});
- return <a id={this.props.id} className={className} href="#" onClick={this.handleClick} />;
+ if (this.props.children) {
+ return (
+ <a
+ id={this.props.id}
+ className={classNames('link-checkbox', this.props.className)}
+ href="#"
+ onClick={this.handleClick}>
+ <i className={className} />
+ {this.props.children}
+ </a>
+ );
+ }
+
+ return (
+ <a
+ id={this.props.id}
+ className={classNames(className, this.props.className)}
+ href="#"
+ onClick={this.handleClick}
+ />
+ );
}
}
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx
index 8d299009cbd..b8680f25d09 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { shallow } from 'enzyme';
-import React from 'react';
+import * as React from 'react';
import Checkbox from '../Checkbox';
import { click } from '../../../helpers/testUtils';
@@ -44,6 +44,16 @@ it('should render checked third state', () => {
expect(checkbox.is('.icon-checkbox-checked')).toBe(true);
});
+it('should render children', () => {
+ const checkbox = shallow(
+ <Checkbox checked={false} onCheck={() => true}>
+ <span>foo</span>
+ </Checkbox>
+ );
+ expect(checkbox.hasClass('link-checkbox')).toBeTruthy();
+ expect(checkbox.find('span')).toHaveLength(1);
+});
+
it('should call onCheck', () => {
const onCheck = jest.fn();
const checkbox = shallow(<Checkbox checked={false} onCheck={onCheck} />);
diff --git a/server/sonar-web/src/main/less/init/icons.less b/server/sonar-web/src/main/less/init/icons.less
index c4c5d43a356..58171db82c6 100644
--- a/server/sonar-web/src/main/less/init/icons.less
+++ b/server/sonar-web/src/main/less/init/icons.less
@@ -264,7 +264,7 @@ a[class*=" icon-"] {
&:before {
content: " ";
- display: block;
+ display: inline-block;
width: 10px;
height: 10px;
border: 1px solid @darkBlue;
diff --git a/server/sonar-web/src/main/less/init/links.less b/server/sonar-web/src/main/less/init/links.less
index be43662f4f7..42e595415c7 100644
--- a/server/sonar-web/src/main/less/init/links.less
+++ b/server/sonar-web/src/main/less/init/links.less
@@ -73,6 +73,16 @@ a {
border-bottom: 1px solid @lightBlue;
}
+.link-checkbox {
+ color: inherit;
+ border-bottom: none;
+ &:hover,
+ &:active,
+ &:focus {
+ color: inherit;
+ }
+}
+
a.active-link,
.link-active {
.link-no-underline;