]> source.dussan.org Git - sonarqube.git/commitdiff
Migrate to ts and improve Checkbox
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 24 Aug 2017 10:20:03 +0000 (12:20 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 25 Aug 2017 14:01:06 +0000 (16:01 +0200)
server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js [deleted file]
server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/web-api/components/Search.js
server/sonar-web/src/main/js/components/controls/Checkbox.js [deleted file]
server/sonar-web/src/main/js/components/controls/Checkbox.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js [deleted file]
server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/less/init/icons.less
server/sonar-web/src/main/less/init/links.less
sonar-core/src/main/resources/org/sonar/l10n/core.properties

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.js
deleted file mode 100644 (file)
index dbc2767..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.
- */
-/* @flow */
-import React from 'react';
-import Checkbox from '../../../components/controls/Checkbox';
-import { CURRENTS } from '../constants';
-
-const CurrentsFilter = (
-  { value, onChange } /*: { value: ?string, onChange: string => void } */
-) => {
-  function handleChange(value) {
-    const newValue = value ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL;
-    onChange(newValue);
-  }
-
-  function handleLabelClick(e) {
-    const newValue = value === CURRENTS.ALL ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL;
-
-    e.preventDefault();
-    onChange(newValue);
-  }
-
-  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/background-tasks/components/CurrentsFilter.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.tsx
new file mode 100644 (file)
index 0000000..5b4ccbb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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 Checkbox from '../../../components/controls/Checkbox';
+import { CURRENTS } from '../constants';
+import { translate } from '../../../helpers/l10n';
+
+interface Props {
+  value?: string;
+  onChange: (value: string) => void;
+}
+
+export default class CurrentsFilter extends React.PureComponent<Props> {
+  handleChange = (value: boolean) => {
+    const newValue = value ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL;
+    this.props.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>
+    );
+  }
+}
index 859ad7704e82c73f3757d552fa41af5799d1b56d..c08bbb8bb2e8a7e0fc16fade442aaa658e5ebfe7 100644 (file)
@@ -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.js
deleted file mode 100644 (file)
index b1acc9f..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 React from 'react';
-import PropTypes from 'prop-types';
-import 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
-  };
-
-  static defaultProps = {
-    thirdState: false
-  };
-
-  componentWillMount() {
-    this.handleClick = this.handleClick.bind(this);
-  }
-
-  handleClick(e) {
-    e.preventDefault();
-    e.target.blur();
-    this.props.onCheck(!this.props.checked, this.props.id);
-  }
-
-  render() {
-    const className = classNames('icon-checkbox', this.props.className, {
-      'icon-checkbox-checked': this.props.checked,
-      'icon-checkbox-single': this.props.thirdState
-    });
-
-    return <a id={this.props.id} className={className} href="#" onClick={this.handleClick} />;
-  }
-}
diff --git a/server/sonar-web/src/main/js/components/controls/Checkbox.tsx b/server/sonar-web/src/main/js/components/controls/Checkbox.tsx
new file mode 100644 (file)
index 0000000..1e5afe8
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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;
+  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
+  };
+
+  handleClick = (e: React.SyntheticEvent<HTMLElement>) => {
+    e.preventDefault();
+    e.currentTarget.blur();
+    this.props.onCheck(!this.props.checked, this.props.id);
+  };
+
+  render() {
+    const className = classNames('icon-checkbox', {
+      'icon-checkbox-checked': this.props.checked,
+      'icon-checkbox-single': this.props.thirdState
+    });
+
+    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.js
deleted file mode 100644 (file)
index 8d29900..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 { shallow } from 'enzyme';
-import React from 'react';
-import Checkbox from '../Checkbox';
-import { click } from '../../../helpers/testUtils';
-
-it('should render unchecked', () => {
-  const checkbox = shallow(<Checkbox checked={false} onCheck={() => true} />);
-  expect(checkbox.is('.icon-checkbox-checked')).toBe(false);
-});
-
-it('should render checked', () => {
-  const checkbox = shallow(<Checkbox checked={true} onCheck={() => true} />);
-  expect(checkbox.is('.icon-checkbox-checked')).toBe(true);
-});
-
-it('should render unchecked third state', () => {
-  const checkbox = shallow(<Checkbox checked={false} thirdState={true} onCheck={() => true} />);
-  expect(checkbox.is('.icon-checkbox-single')).toBe(true);
-  expect(checkbox.is('.icon-checkbox-checked')).toBe(false);
-});
-
-it('should render checked  third state', () => {
-  const checkbox = shallow(<Checkbox checked={true} thirdState={true} onCheck={() => true} />);
-  expect(checkbox.is('.icon-checkbox-single')).toBe(true);
-  expect(checkbox.is('.icon-checkbox-checked')).toBe(true);
-});
-
-it('should call onCheck', () => {
-  const onCheck = jest.fn();
-  const checkbox = shallow(<Checkbox checked={false} onCheck={onCheck} />);
-  click(checkbox);
-  expect(onCheck).toBeCalledWith(true, undefined);
-});
-
-it('should call onCheck with id as second parameter', () => {
-  const onCheck = jest.fn();
-  const checkbox = shallow(<Checkbox id="foo" checked={false} onCheck={onCheck} />);
-  click(checkbox);
-  expect(onCheck).toBeCalledWith(true, 'foo');
-});
-
-it('should apply custom class', () => {
-  const checkbox = shallow(
-    <Checkbox className="customclass" checked={true} onCheck={() => true} />
-  );
-  expect(checkbox.is('.customclass')).toBe(true);
-});
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx
new file mode 100644 (file)
index 0000000..b8680f2
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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 { shallow } from 'enzyme';
+import * as React from 'react';
+import Checkbox from '../Checkbox';
+import { click } from '../../../helpers/testUtils';
+
+it('should render unchecked', () => {
+  const checkbox = shallow(<Checkbox checked={false} onCheck={() => true} />);
+  expect(checkbox.is('.icon-checkbox-checked')).toBe(false);
+});
+
+it('should render checked', () => {
+  const checkbox = shallow(<Checkbox checked={true} onCheck={() => true} />);
+  expect(checkbox.is('.icon-checkbox-checked')).toBe(true);
+});
+
+it('should render unchecked third state', () => {
+  const checkbox = shallow(<Checkbox checked={false} thirdState={true} onCheck={() => true} />);
+  expect(checkbox.is('.icon-checkbox-single')).toBe(true);
+  expect(checkbox.is('.icon-checkbox-checked')).toBe(false);
+});
+
+it('should render checked  third state', () => {
+  const checkbox = shallow(<Checkbox checked={true} thirdState={true} onCheck={() => true} />);
+  expect(checkbox.is('.icon-checkbox-single')).toBe(true);
+  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} />);
+  click(checkbox);
+  expect(onCheck).toBeCalledWith(true, undefined);
+});
+
+it('should call onCheck with id as second parameter', () => {
+  const onCheck = jest.fn();
+  const checkbox = shallow(<Checkbox id="foo" checked={false} onCheck={onCheck} />);
+  click(checkbox);
+  expect(onCheck).toBeCalledWith(true, 'foo');
+});
+
+it('should apply custom class', () => {
+  const checkbox = shallow(
+    <Checkbox className="customclass" checked={true} onCheck={() => true} />
+  );
+  expect(checkbox.is('.customclass')).toBe(true);
+});
index c4c5d43a35677b81c2c3203eb5cde68eba047785..58171db82c67c8d5db5bc843f3f753e4deafa17a 100644 (file)
@@ -264,7 +264,7 @@ a[class*=" icon-"] {
 
   &:before {
     content: " ";
-    display: block;
+    display: inline-block;
     width: 10px;
     height: 10px;
     border: 1px solid @darkBlue;
index be43662f4f793af152d09c6a1e39147a2274118a..42e595415c7037492952911599a0c88747561588 100644 (file)
@@ -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;
index bddfe89e72af0b46afba5d4cc2aa138db8889366..b494866ac8d77ec077512a199ac8ac2ec7a7ab87 100644 (file)
@@ -205,6 +205,7 @@ violations=Violations
 visibility=Visibility
 with=With
 worst=Worst
+yes=Yes
 
 
 
@@ -2872,6 +2873,8 @@ widget.events.show_all=Show All
 api_documentation.deprecation_tooltip=If an API is deprecated in version X.Y, this API will be dropped in version (X+2).0. Example: an API deprecated in 4.1 is supported in 4.2, 4.3, 5.0, 5.1, 5.2, 5.3 and is dropped in version 6.0.
 api_documentation.internal_tooltip=Use at your own risk; internal services are subject to change or removal without notice.
 api_documentation.page=Web API
+api_documentation.show_deprecated=Show Deprecated API
+api_documentation.show_internal=Show Internal API
 
 #------------------------------------------------------------------------------
 #