]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21303 Showcase the Checkbox component from Echoes in a few places
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Wed, 13 Mar 2024 16:38:21 +0000 (17:38 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 13 Mar 2024 20:02:31 +0000 (20:02 +0000)
server/sonar-web/config/jest/SetupTestEnvironment.ts
server/sonar-web/design-system/src/components/input/Checkbox.tsx
server/sonar-web/package.json
server/sonar-web/src/main/js/apps/account/notifications/NotificationsList.tsx
server/sonar-web/src/main/js/apps/issues/components/BulkChangeModal.tsx
server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx
server/sonar-web/src/main/js/apps/projectsManagement/ProjectRow.tsx
server/sonar-web/src/main/js/apps/web-api-v2/components/ApiSidebar.tsx
server/sonar-web/src/main/js/components/issue/components/IssueView.tsx
server/sonar-web/yarn.lock

index 2b376af2c1af260ecb327c5bddb582d604c748e5..a5d27ff84f8855106ec6d78d5ba6ca420ec83f1b 100644 (file)
@@ -51,6 +51,28 @@ const MockIntersectionObserverEntries = [{ isIntersecting: true }];
   return MockObserver;
 });
 
+// ResizeObserver
+
+const MockResizeObserverEntries = [
+  {
+    contentRect: {
+      width: 100,
+      height: 200,
+    },
+  },
+];
+
+const MockResizeObserver = {
+  observe: jest.fn(),
+  unobserve: jest.fn(),
+  disconnect: jest.fn(),
+};
+
+global.ResizeObserver = jest.fn().mockImplementation((callback) => {
+  callback(MockResizeObserverEntries, MockResizeObserver);
+  return MockResizeObserver;
+});
+
 // Copied from pollyfill.io
 // To be remove when upgrading jsdom https://github.com/jsdom/jsdom/releases/tag/22.1.0
 // jest-environment-jsdom to v30
index 72b4ba80da9f27f27943a5fa6f2742dca57c1df4..bb61804928b339a6655aa0fb6aaffe45306c697b 100644 (file)
@@ -41,6 +41,19 @@ interface Props {
   title?: string;
 }
 
+/** @deprecated Use Checkbox from Echoes instead.
+ *
+ * Some of the props have changed or been renamed:
+ * - ~`aria-disabled`~ is now inferred from `isDisabled`
+ * - `ariaLabel` is now mandatory in the absence of `label`
+ * - ~`children`~ has been removed
+ * - `disabled` is now `isDisabled`
+ * - `label` is no longer used in the aria-label but displayed next to the checkbox
+ * - `loading` is now `isLoading`
+ * - ~`onClick`~ has been removed
+ * - ~`right`~ has been removed
+ * - `thirdState` is now represented by the `indeterminate` value of the `checked` prop
+ */
 export function Checkbox({
   checked,
   disabled,
index 648cb572bf0058f6bae9a013907ddba87537b10d..50acc8d91885bccb4e5e8fd4b66cc808d7e77022 100644 (file)
@@ -13,7 +13,7 @@
     "@primer/octicons-react": "19.8.0",
     "@react-spring/rafz": "9.7.3",
     "@react-spring/web": "9.7.3",
-    "@sonarsource/echoes-react": "0.1.1",
+    "@sonarsource/echoes-react": "0.1.2",
     "@tanstack/react-query": "5.18.1",
     "axios": "1.6.7",
     "classnames": "2.5.1",
index c1748be30eb21f0af886e70118e1b1df2c0e64f4..946ac7030fd6a0a8f14b3a8ef39156e3903e3141 100644 (file)
@@ -18,7 +18,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-import { CellComponent, Checkbox, TableRowInteractive } from 'design-system';
+import { Checkbox } from '@sonarsource/echoes-react';
+import { CellComponent, TableRowInteractive } from 'design-system';
 import * as React from 'react';
 import { hasMessage, translate, translateWithParameters } from '../../../helpers/l10n';
 import {
@@ -77,13 +78,13 @@ export default function NotificationsList({
         <CellComponent className="sw-py-0 sw-border-0" key={channel}>
           <div className="sw-justify-end sw-flex sw-items-center">
             <Checkbox
-              checked={isEnabled(type, channel)}
-              id={checkboxId(type, channel)}
-              label={translateWithParameters(
+              ariaLabel={translateWithParameters(
                 'notification.dispatcher.description_x',
                 getDispatcherLabel(type),
               )}
-              onCheck={(checked) => handleCheck(type, channel, checked)}
+              checked={isEnabled(type, channel)}
+              id={checkboxId(type, channel)}
+              onCheck={(checked) => handleCheck(type, channel, checked as boolean)}
             />
           </div>
         </CellComponent>
index d7f476524217abb9b24b2c8ded7a2c0f14f6b8e7..e0cd92c98dfc7897a932907eb2dd0057d641653e 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
+import { Checkbox, Spinner } from '@sonarsource/echoes-react';
 import {
   ButtonPrimary,
-  Checkbox,
   FlagMessage,
   FormField,
   Highlight,
@@ -28,7 +29,6 @@ import {
   LightLabel,
   Modal,
   RadioButton,
-  Spinner,
 } from 'design-system';
 import { countBy, flattenDeep, pickBy, sortBy } from 'lodash';
 import * as React from 'react';
@@ -351,17 +351,12 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
   };
 
   renderNotificationsField = () => (
-    <div>
-      <Checkbox
-        checked={this.state.notifications !== undefined}
-        className="sw-my-2 sw-gap-1/2"
-        id="send-notifications"
-        onCheck={this.handleFieldCheck('notifications')}
-        right
-      >
-        {translate('issue.send_notifications')}
-      </Checkbox>
-    </div>
+    <Checkbox
+      checked={this.state.notifications !== undefined}
+      id="send-notifications"
+      label={translate('issue.send_notifications')}
+      onCheck={this.handleFieldCheck('notifications')}
+    />
   );
 
   renderForm = () => {
@@ -371,7 +366,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
     const limitReached = paging && paging.total > MAX_PAGE_SIZE;
 
     return (
-      <Spinner loading={loading}>
+      <Spinner isLoading={loading}>
         <form id="bulk-change-form" onSubmit={this.handleSubmit} className="sw-mr-4">
           {limitReached && (
             <FlagMessage className="sw-mb-4" variant="warning">
index f9f16a25f180e245a97dcdcc03d51bab4ec6fc8a..0f8307aa4a8168c34c53c722205db827e32a1664 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
 import styled from '@emotion/styled';
+import { Checkbox, Spinner } from '@sonarsource/echoes-react';
 import classNames from 'classnames';
 import {
   ButtonSecondary,
-  Checkbox,
   FlagMessage,
   LAYOUT_FOOTER_HEIGHT,
   LargeCenteredLayout,
   PageContentFontWrapper,
-  Spinner,
   ToggleButton,
   themeBorder,
   themeColor,
@@ -955,12 +955,12 @@ export class App extends React.PureComponent<Props, State> {
     return (
       <div className="sw-float-left sw-flex sw-items-center">
         <Checkbox
-          checked={isChecked}
+          ariaLabel={translate('issues.select_all_issues')}
+          checked={thirdState ? 'indeterminate' : isChecked}
           className="sw-mr-2"
-          disabled={issues.length === 0}
           id="issues-selection"
+          isDisabled={issues.length === 0}
           onCheck={this.handleCheckAll}
-          thirdState={thirdState}
           title={translate('issues.select_all_issues')}
         />
 
@@ -1227,7 +1227,7 @@ export class App extends React.PureComponent<Props, State> {
           >
             {this.renderHeader({ openIssue, paging })}
 
-            <Spinner loading={loadingRule}>
+            <Spinner isLoading={loadingRule}>
               {openIssue && openRuleDetails ? (
                 <IssueTabViewer
                   activityTabContent={
@@ -1264,7 +1264,7 @@ export class App extends React.PureComponent<Props, State> {
                   <Spinner
                     ariaLabel={translate('issues.loading_issues')}
                     className="sw-mt-4"
-                    loading={loading}
+                    isLoading={loading}
                   >
                     {checkAll && paging && paging.total > MAX_PAGE_SIZE && (
                       <div className="sw-mt-3">
index 3c1e3d0fea265f1f10cd8682f15c0dbdf77e5aed..4aff6bcc288ae96e7f067f3f2af39a88e16a0836 100644 (file)
@@ -17,7 +17,9 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { ActionCell, Badge, Checkbox, ContentCell, HoverLink, Note, TableRow } from 'design-system';
+
+import { Checkbox, LinkHighlight, LinkStandalone } from '@sonarsource/echoes-react';
+import { ActionCell, Badge, ContentCell, Note, TableRow } from 'design-system';
 import * as React from 'react';
 import { Project } from '../../api/project-management';
 import PrivacyBadgeContainer from '../../components/common/PrivacyBadgeContainer';
@@ -37,7 +39,7 @@ interface Props {
   selected: boolean;
 }
 
-export default function ProjectRow(props: Props) {
+export default function ProjectRow(props: Readonly<Props>) {
   const { currentUser, project, selected } = props;
   const { data: githubProvisioningEnabled } = useGithubProvisioningEnabledQuery();
 
@@ -49,17 +51,20 @@ export default function ProjectRow(props: Props) {
     <TableRow data-project-key={project.key}>
       <ContentCell>
         <Checkbox
-          label={translateWithParameters('projects_management.select_project', project.name)}
+          ariaLabel={translateWithParameters('projects_management.select_project', project.name)}
           checked={selected}
           onCheck={handleProjectCheck}
         />
       </ContentCell>
       <ContentCell className="it__project-row-text-cell">
-        <HoverLink to={getComponentOverviewUrl(project.key, project.qualifier)}>
+        <LinkStandalone
+          highlight={LinkHighlight.CurrentColor}
+          to={getComponentOverviewUrl(project.key, project.qualifier)}
+        >
           <Tooltip overlay={project.name} placement="left">
             <span>{project.name}</span>
           </Tooltip>
-        </HoverLink>
+        </LinkStandalone>
         {project.qualifier === ComponentQualifier.Project &&
           githubProvisioningEnabled &&
           !project.managed && <Badge className="sw-ml-1">{translate('local')}</Badge>}
index 39f3f0bf5d28052ae3ede132de9e44799f1c2642..dda53c788360180b1463dc6bd0a53cf00ca0aaa2 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+import { Checkbox } from '@sonarsource/echoes-react';
 import {
   Badge,
   BasicSeparator,
-  Checkbox,
   HelperHintIcon,
   InputSearch,
   SubnavigationAccordion,
@@ -104,9 +104,11 @@ export default function ApiSidebar({ apisList, docInfo }: Readonly<Props>) {
       />
 
       <div className="sw-mt-4 sw-flex sw-items-center">
-        <Checkbox checked={showInternal} onCheck={() => setShowInternal((prev) => !prev)}>
-          <span className="sw-ml-2">{translate('api_documentation.show_internal_v2')}</span>
-        </Checkbox>
+        <Checkbox
+          checked={showInternal}
+          label={translate('api_documentation.show_internal_v2')}
+          onCheck={() => setShowInternal((prev) => !prev)}
+        />
 
         <HelpTooltip
           className="sw-ml-2"
index 241e717a33c9c0e4d2529a0fadfe5311f96d2977..553324baa11023244f572d5fcde1e5c98c881d85 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
 import styled from '@emotion/styled';
+import { Checkbox } from '@sonarsource/echoes-react';
 import classNames from 'classnames';
-import { BasicSeparator, Checkbox, themeBorder } from 'design-system';
+import { BasicSeparator, themeBorder } from 'design-system';
 import * as React from 'react';
 import { deleteIssueComment, editIssueComment } from '../../../api/issues';
 import { translate, translateWithParameters } from '../../../helpers/l10n';
@@ -100,9 +102,9 @@ export default class IssueView extends React.PureComponent<Props> {
           {hasCheckbox && (
             <span className="sw-mt-1/2 sw-ml-1 sw-self-start">
               <Checkbox
+                ariaLabel={translateWithParameters('issues.action_select.label', issue.message)}
                 checked={checked ?? false}
                 onCheck={this.handleCheck}
-                label={translateWithParameters('issues.action_select.label', issue.message)}
                 title={translate('issues.action_select')}
               />
             </span>
index d9169ab780e0a82fb3b390036d8a92e693ccb1ab..e9f0af5c1b8906cb64c27df71c16bc13b336e963 100644 (file)
@@ -4533,9 +4533,9 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@sonarsource/echoes-react@npm:0.1.1":
-  version: 0.1.1
-  resolution: "@sonarsource/echoes-react@npm:0.1.1"
+"@sonarsource/echoes-react@npm:0.1.2":
+  version: 0.1.2
+  resolution: "@sonarsource/echoes-react@npm:0.1.2"
   dependencies:
     "@primer/octicons-react": "npm:19.8.0"
     "@radix-ui/react-checkbox": "npm:1.0.4"
@@ -4547,7 +4547,7 @@ __metadata:
     react-dom: ^17.0.0 || ^18.0.0
     react-intl: ^6.0.0
     react-router-dom: ^6.0.0
-  checksum: 10/9d9901397aeef7faba3262281b919a186aeba5aaf3f27073a7895a0fe96fc2a2a5fb1ba9a4959401d11396e585075065cc4f18cff2ce8eabc48235032239d130
+  checksum: 10/fc25b30ed8ffa0186eb206ef2e71b444c334b4a350eb3e9e71874a064b9fe590b525ad2f1459d5d9de7882fb8be899a2a9e6154df758406900a5380f8e3810c2
   languageName: node
   linkType: hard
 
@@ -5749,7 +5749,7 @@ __metadata:
     "@primer/octicons-react": "npm:19.8.0"
     "@react-spring/rafz": "npm:9.7.3"
     "@react-spring/web": "npm:9.7.3"
-    "@sonarsource/echoes-react": "npm:0.1.1"
+    "@sonarsource/echoes-react": "npm:0.1.2"
     "@swc/core": "npm:1.4.0"
     "@swc/jest": "npm:0.2.36"
     "@tanstack/react-query": "npm:5.18.1"