From 45adb5c4f365e84b992990c578d34032d7d84471 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 13 Jun 2023 08:55:32 +0200 Subject: [PATCH] [NO JIRA] Fix Code Smells --- .../src/main/js/apps/projectKey/UpdateForm.tsx | 13 ++++++------- .../apps/projects/filters/SearchFilterContainer.tsx | 2 +- .../src/main/js/apps/projectsManagement/Header.tsx | 2 +- .../js/components/activity-graph/DataTableModal.tsx | 4 ++-- .../js/components/activity-graph/GraphsHistory.tsx | 2 +- .../sonar-web/src/main/js/components/hoc/utils.ts | 2 +- .../js/components/tutorials/other/TokenStep.tsx | 10 +++++----- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projectKey/UpdateForm.tsx b/server/sonar-web/src/main/js/apps/projectKey/UpdateForm.tsx index 1f962e7e50a..b30a0b824f9 100644 --- a/server/sonar-web/src/main/js/apps/projectKey/UpdateForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectKey/UpdateForm.tsx @@ -19,8 +19,8 @@ */ import * as React from 'react'; import ProjectKeyInput from '../../components/common/ProjectKeyInput'; -import { Button, SubmitButton } from '../../components/controls/buttons'; import ConfirmButton from '../../components/controls/ConfirmButton'; +import { Button, SubmitButton } from '../../components/controls/buttons'; import MandatoryFieldsExplanation from '../../components/ui/MandatoryFieldsExplanation'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { validateProjectKey } from '../../helpers/projects'; @@ -34,11 +34,10 @@ export interface UpdateFormProps { export default function UpdateForm(props: UpdateFormProps) { const { component } = props; - const [newKey, setNewKey] = React.useState(undefined); - const value = newKey !== undefined ? newKey : component.key; - const hasChanged = value !== component.key; + const [newKey, setNewKey] = React.useState(component.key); + const hasChanged = newKey !== component.key; - const validationResult = validateProjectKey(value); + const validationResult = validateProjectKey(newKey); const error = validationResult === ProjectKeyValidationResult.Valid ? undefined @@ -78,7 +77,7 @@ export default function UpdateForm(props: UpdateFormProps) { }} touched={hasChanged} placeholder={translate('update_key.new_key')} - projectKey={value} + projectKey={newKey} autofocus /> @@ -92,7 +91,7 @@ export default function UpdateForm(props: UpdateFormProps) { disabled={!hasChanged} id="update-key-reset" onClick={() => { - setNewKey(undefined); + setNewKey(component.key); }} type="reset" > diff --git a/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.tsx b/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.tsx index 65ce2841139..b22eaaccdca 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.tsx @@ -38,7 +38,7 @@ export default class SearchFilterContainer extends React.PureComponent { minLength={2} onChange={this.handleSearch} placeholder={translate('projects.search')} - value={this.props.query.search || ''} + value={this.props.query.search ?? ''} /> ); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/Header.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/Header.tsx index de75e3e9713..1c3dd413f3c 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/Header.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/Header.tsx @@ -79,7 +79,7 @@ export default class Header extends React.PureComponent { {visibilityForm && ( diff --git a/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx b/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx index 4c40977f44c..eee2bdbfca3 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx @@ -23,8 +23,8 @@ import { FormattedMessage } from 'react-intl'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { formatMeasure } from '../../helpers/measures'; import { ParsedAnalysis, Serie } from '../../types/project-activity'; -import { Button } from '../controls/buttons'; import Modal from '../controls/Modal'; +import { Button } from '../controls/buttons'; import DateFormatter from '../intl/DateFormatter'; import TimeFormatter from '../intl/TimeFormatter'; import { Alert } from '../ui/Alert'; @@ -101,7 +101,7 @@ export default function DataTableModal(props: DataTableModalProps) { {metrics.map((metric) => ( - {values[metric] || '-'} + {values[metric] ?? '-'} ))} diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx index a3c8aeae3bc..b9790af566d 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx @@ -122,7 +122,7 @@ export default class GraphsHistory extends React.PureComponent { selectedDate={this.state.selectedDate} series={graphSeries} graphDescription={ - ariaLabel || + ariaLabel ?? translateWithParameters( 'project_activity.graphs.explanation_x', uniqBy(graphSeries, 'name') diff --git a/server/sonar-web/src/main/js/components/hoc/utils.ts b/server/sonar-web/src/main/js/components/hoc/utils.ts index c86c6e99aea..ce211c3244a 100644 --- a/server/sonar-web/src/main/js/components/hoc/utils.ts +++ b/server/sonar-web/src/main/js/components/hoc/utils.ts @@ -21,6 +21,6 @@ export function getWrappedDisplayName

( WrappedComponent: React.ComponentType

, hocName: string ) { - const wrappedDisplayName = WrappedComponent.displayName || WrappedComponent.name || 'Component'; + const wrappedDisplayName = WrappedComponent.displayName ?? WrappedComponent.name ?? 'Component'; return `${hocName}(${wrappedDisplayName})`; } diff --git a/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx b/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx index 1610bdfb021..9eb8e33cb6c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx @@ -22,17 +22,17 @@ import { FormattedMessage } from 'react-intl'; import { generateToken, getTokens, revokeToken } from '../../../api/user-tokens'; import { translate } from '../../../helpers/l10n'; import { - computeTokenExpirationDate, EXPIRATION_OPTIONS, + computeTokenExpirationDate, getAvailableExpirationOptions, } from '../../../helpers/tokens'; import { TokenExpiration, TokenType, UserToken } from '../../../types/token'; import { LoggedInUser } from '../../../types/users'; import DocumentationTooltip from '../../common/DocumentationTooltip'; import Link from '../../common/Link'; -import { Button, DeleteButton, SubmitButton } from '../../controls/buttons'; import Radio from '../../controls/Radio'; import Select from '../../controls/Select'; +import { Button, DeleteButton, SubmitButton } from '../../controls/buttons'; import AlertErrorIcon from '../../icons/AlertErrorIcon'; import AlertSuccessIcon from '../../icons/AlertSuccessIcon'; import ProjectTokenScopeInfo from '../components/ProjectTokenScopeInfo'; @@ -109,7 +109,7 @@ export default class TokenStep extends React.PureComponent { canContinue = () => { const { existingToken, selection, token } = this.state; - const validExistingToken = existingToken.match(TOKEN_FORMAT_REGEX) != null; + const validExistingToken = TOKEN_FORMAT_REGEX.exec(existingToken) != null; return ( (selection === 'generate' && token != null) || (selection === 'use-existing' && existingToken && validExistingToken) @@ -222,7 +222,7 @@ export default class TokenStep extends React.PureComponent { onChange={this.handleTokenNameChange} required type="text" - value={tokenName || ''} + value={tokenName ?? ''} />

@@ -260,7 +260,7 @@ export default class TokenStep extends React.PureComponent { renderUseExistingOption = () => { const { existingToken } = this.state; - const validInput = !existingToken || existingToken.match(TOKEN_FORMAT_REGEX) != null; + const validInput = !existingToken || TOKEN_FORMAT_REGEX.exec(existingToken) != null; return (
-- 2.39.5