From 42145471c0db5b7ec917adf8fd68e7b519b724fe Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Wed, 10 Aug 2022 12:51:13 +0200 Subject: [PATCH] [NO-JIRA] Clean up components name and structure --- .../components/RuleDetailsDescription.tsx | 19 ++++++- .../coding-rules/components/RuleTabViewer.tsx | 48 ----------------- .../apps/issues/components/IssueTabViewer.tsx | 53 ------------------- .../js/apps/issues/components/IssuesApp.tsx | 47 +++++++++------- .../{TabViewer.tsx => RuleTabViewer.tsx} | 10 ++-- 5 files changed, 50 insertions(+), 127 deletions(-) delete mode 100644 server/sonar-web/src/main/js/apps/coding-rules/components/RuleTabViewer.tsx delete mode 100644 server/sonar-web/src/main/js/apps/issues/components/IssueTabViewer.tsx rename server/sonar-web/src/main/js/components/rules/{TabViewer.tsx => RuleTabViewer.tsx} (97%) diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx index 8da3e5384e1..060277b5577 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx @@ -21,12 +21,12 @@ import * as React from 'react'; import { updateRule } from '../../../api/rules'; import FormattingTips from '../../../components/common/FormattingTips'; import { Button, ResetButtonLink } from '../../../components/controls/buttons'; +import RuleTabViewer from '../../../components/rules/RuleTabViewer'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; import { RuleDetails } from '../../../types/types'; import { RuleDescriptionSections } from '../rule'; import RemoveExtendedDescriptionModal from './RemoveExtendedDescriptionModal'; -import RuleTabViewer from './RuleTabViewer'; interface Props { canWrite: boolean | undefined; @@ -203,6 +203,10 @@ export default class RuleDetailsDescription extends React.PureComponent section.key === RuleDescriptionSections.INTRODUCTION + )?.content; + return (
{defaultSection && ( @@ -214,7 +218,18 @@ export default class RuleDetailsDescription extends React.PureComponent )} - {hasDescriptionSection && !defaultSection && } + {hasDescriptionSection && !defaultSection && ( + <> + {introductionSection && ( +
+ )} + + + )} {ruleDetails.isExternal && (
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleTabViewer.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleTabViewer.tsx deleted file mode 100644 index 3a5c4b2d1b4..00000000000 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleTabViewer.tsx +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 TabViewer from '../../../components/rules/TabViewer'; -import { sanitizeString } from '../../../helpers/sanitize'; -import { RuleDetails } from '../../../types/types'; -import { RuleDescriptionSections } from '../rule'; - -export interface RuleTabViewerProps { - ruleDetails: RuleDetails; -} - -export default function RuleTabViewer(props: RuleTabViewerProps) { - const { ruleDetails } = props; - const introduction = ruleDetails.descriptionSections?.find( - section => section.key === RuleDescriptionSections.INTRODUCTION - )?.content; - - return ( - <> - {introduction && ( -
- )} - - - ); -} diff --git a/server/sonar-web/src/main/js/apps/issues/components/IssueTabViewer.tsx b/server/sonar-web/src/main/js/apps/issues/components/IssueTabViewer.tsx deleted file mode 100644 index 303e2339ad1..00000000000 --- a/server/sonar-web/src/main/js/apps/issues/components/IssueTabViewer.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 TabViewer from '../../../components/rules/TabViewer'; -import { BranchLike } from '../../../types/branch-like'; -import { Issue, RuleDetails } from '../../../types/types'; -import IssueHeader from './IssueHeader'; - -interface IssueViewerTabsProps { - branchLike?: BranchLike; - issue: Issue; - codeTabContent: React.ReactNode; - ruleDetails: RuleDetails; - onIssueChange: (issue: Issue) => void; -} - -export default function IssueViewerTabs(props: IssueViewerTabsProps) { - const { ruleDetails, issue, codeTabContent, branchLike } = props; - return ( - <> - - - - ); -} diff --git a/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx b/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx index 7f902a2dd3b..46fea9e8fb1 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx @@ -41,6 +41,7 @@ import ListFooter from '../../../components/controls/ListFooter'; import Suggestions from '../../../components/embed-docs-modal/Suggestions'; import withIndexationGuard from '../../../components/hoc/withIndexationGuard'; import { Location, Router, withRouter } from '../../../components/hoc/withRouter'; +import RuleTabViewer from '../../../components/rules/RuleTabViewer'; import '../../../components/search-navigator.css'; import { Alert } from '../../../components/ui/Alert'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; @@ -96,9 +97,9 @@ import { STANDARDS } from '../utils'; import BulkChangeModal, { MAX_PAGE_SIZE } from './BulkChangeModal'; +import IssueHeader from './IssueHeader'; import IssuesList from './IssuesList'; import IssuesSourceViewer from './IssuesSourceViewer'; -import IssueTabViewer from './IssueTabViewer'; import NoIssues from './NoIssues'; import NoMyIssues from './NoMyIssues'; import PageActions from './PageActions'; @@ -1105,24 +1106,32 @@ export class App extends React.PureComponent {
{openIssue && openRuleDetails ? ( - - } - issue={openIssue} - ruleDetails={openRuleDetails} - branchLike={fillBranchLike(openIssue.branch, openIssue.pullRequest)} - onIssueChange={this.handleIssueChange} - /> + <> + + + } + scrollInTab={true} + /> + ) : ( {checkAll && paging && paging.total > MAX_PAGE_SIZE && ( diff --git a/server/sonar-web/src/main/js/components/rules/TabViewer.tsx b/server/sonar-web/src/main/js/components/rules/RuleTabViewer.tsx similarity index 97% rename from server/sonar-web/src/main/js/components/rules/TabViewer.tsx rename to server/sonar-web/src/main/js/components/rules/RuleTabViewer.tsx index f03307c16ed..f4b9cdf4f1d 100644 --- a/server/sonar-web/src/main/js/components/rules/TabViewer.tsx +++ b/server/sonar-web/src/main/js/components/rules/RuleTabViewer.tsx @@ -32,7 +32,7 @@ import MoreInfoRuleDescription from './MoreInfoRuleDescription'; import RuleDescription from './RuleDescription'; import './style.css'; -interface TabViewerProps extends CurrentUserContextInterface { +interface RuleTabViewerProps extends CurrentUserContextInterface { ruleDetails: RuleDetails; extendedDescription?: string; ruleDescriptionContextKey?: string; @@ -63,14 +63,14 @@ export enum TabKeys { const DEBOUNCE_FOR_SCROLL = 250; -export class TabViewer extends React.PureComponent { +export class RuleTabViewer extends React.PureComponent { state: State = { tabs: [] }; educationPrinciplesRef: React.RefObject; - constructor(props: TabViewerProps) { + constructor(props: RuleTabViewerProps) { super(props); this.educationPrinciplesRef = React.createRef(); this.checkIfEducationPrinciplesAreVisible = debounce( @@ -84,7 +84,7 @@ export class TabViewer extends React.PureComponent { this.attachScrollEvent(); } - componentDidUpdate(prevProps: TabViewerProps, prevState: State) { + componentDidUpdate(prevProps: RuleTabViewerProps, prevState: State) { const { ruleDetails, codeTabContent, ruleDescriptionContextKey, currentUser } = this.props; const { selectedTab } = this.state; @@ -325,4 +325,4 @@ export class TabViewer extends React.PureComponent { } } -export default withCurrentUserContext(TabViewer); +export default withCurrentUserContext(RuleTabViewer); -- 2.39.5