]> source.dussan.org Git - sonarqube.git/commitdiff
Make branch parameter optional in some helper functions
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 16 Jan 2018 10:40:04 +0000 (11:40 +0100)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 25 Jan 2018 14:16:50 +0000 (15:16 +0100)
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx
server/sonar-web/src/main/js/apps/code/components/App.tsx
server/sonar-web/src/main/js/apps/component-measures/components/App.js
server/sonar-web/src/main/js/apps/issues/components/App.js
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js
server/sonar-web/src/main/js/helpers/branches.ts

index e4d0b410a3defb54b18850adcf14e3b697582876..1a3034408185359d48c9a4af238d907a86948268 100644 (file)
@@ -168,7 +168,7 @@ export default class ComponentNavBranchesMenu extends React.PureComponent<Props,
 
     const items = branches.map((branch, index) => {
       const isOrphan = isShortLivingBranch(branch) && branch.isOrphan;
-      const previous = index > 0 ? branches[index - 1] : null;
+      const previous = index > 0 ? branches[index - 1] : undefined;
       const isPreviousOrphan = isShortLivingBranch(previous) ? previous.isOrphan : false;
       const showDivider = isLongLivingBranch(branch) || (isOrphan && !isPreviousOrphan);
       const showOrphanHeader = isOrphan && !isPreviousOrphan;
index 5f07856c3fd742e373c770974b7bc08ba2bd4797..564a54ea3180c3680971104444b6b558d2787f48 100644 (file)
@@ -78,7 +78,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
   }
 
   renderDashboardLink() {
-    if (this.props.branch && isShortLivingBranch(this.props.branch)) {
+    if (isShortLivingBranch(this.props.branch)) {
       return null;
     }
 
@@ -89,7 +89,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
           to={{
             pathname,
             query: {
-              branch: this.props.branch && getBranchName(this.props.branch),
+              branch: getBranchName(this.props.branch),
               id: this.props.component.key
             }
           }}
@@ -111,7 +111,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
           to={{
             pathname: '/code',
             query: {
-              branch: this.props.branch && getBranchName(this.props.branch),
+              branch: getBranchName(this.props.branch),
               id: this.props.component.key
             }
           }}
@@ -125,7 +125,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
   }
 
   renderActivityLink() {
-    if (this.props.branch && isShortLivingBranch(this.props.branch)) {
+    if (isShortLivingBranch(this.props.branch)) {
       return null;
     }
 
@@ -135,7 +135,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
           to={{
             pathname: '/project/activity',
             query: {
-              branch: this.props.branch && getBranchName(this.props.branch),
+              branch: getBranchName(this.props.branch),
               id: this.props.component.key
             }
           }}
@@ -153,7 +153,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
           to={{
             pathname: '/project/issues',
             query: {
-              branch: this.props.branch && getBranchName(this.props.branch),
+              branch: getBranchName(this.props.branch),
               id: this.props.component.key,
               resolved: 'false'
             }
@@ -166,7 +166,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
   }
 
   renderComponentMeasuresLink() {
-    if (this.props.branch && isShortLivingBranch(this.props.branch)) {
+    if (isShortLivingBranch(this.props.branch)) {
       return null;
     }
 
@@ -176,7 +176,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
           to={{
             pathname: '/component_measures',
             query: {
-              branch: this.props.branch && getBranchName(this.props.branch),
+              branch: getBranchName(this.props.branch),
               id: this.props.component.key
             }
           }}
@@ -196,7 +196,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
 
     const isSettingsActive = SETTINGS_URLS.some(url => window.location.href.indexOf(url) !== -1);
 
-    if (branch && isLongLivingBranch(branch)) {
+    if (isLongLivingBranch(branch)) {
       return (
         <li>
           <Link
@@ -258,7 +258,7 @@ export default class ComponentNavMenu extends React.PureComponent<Props> {
           to={{
             pathname: '/project/settings',
             query: {
-              branch: this.props.branch && getBranchName(this.props.branch),
+              branch: getBranchName(this.props.branch),
               id: this.props.component.key
             }
           }}
index c77c9db1fe82b687a38c648187ad32efaf8d8689..42ab6e0937838115c90eca6d304469d626d868c4 100644 (file)
@@ -39,7 +39,7 @@ interface Props extends StateProps {
 }
 
 export function ComponentNavMeta({ branch, component, currentUser }: Props) {
-  const shortBranch = branch && isShortLivingBranch(branch);
+  const shortBranch = isShortLivingBranch(branch);
   const mainBranch = !branch || branch.isMain;
 
   return (
index 7ad3c99b9088ac39169254811d0f95c7cb97f6cd..f6fa32269a2c2866ebfe3da92bb7160527f4beee 100644 (file)
@@ -87,7 +87,7 @@ export default class App extends React.PureComponent<Props, State> {
 
     this.setState({ loading: true });
     const isPortfolio = ['VW', 'SVW'].includes(component.qualifier);
-    retrieveComponentChildren(component.key, isPortfolio, branch && getBranchName(branch))
+    retrieveComponentChildren(component.key, isPortfolio, getBranchName(branch))
       .then(() => {
         addComponent(component);
         if (this.mounted) {
@@ -106,11 +106,7 @@ export default class App extends React.PureComponent<Props, State> {
     this.setState({ loading: true });
 
     const isPortfolio = ['VW', 'SVW'].includes(this.props.component.qualifier);
-    retrieveComponent(
-      componentKey,
-      isPortfolio,
-      this.props.branch && getBranchName(this.props.branch)
-    )
+    retrieveComponent(componentKey, isPortfolio, getBranchName(this.props.branch))
       .then(r => {
         if (this.mounted) {
           if (['FIL', 'UTS'].includes(r.component.qualifier)) {
@@ -156,12 +152,7 @@ export default class App extends React.PureComponent<Props, State> {
       return;
     }
     const isPortfolio = ['VW', 'SVW'].includes(this.props.component.qualifier);
-    loadMoreChildren(
-      baseComponent.key,
-      page + 1,
-      isPortfolio,
-      this.props.branch && getBranchName(this.props.branch)
-    )
+    loadMoreChildren(baseComponent.key, page + 1, isPortfolio, getBranchName(this.props.branch))
       .then(r => {
         if (this.mounted) {
           this.setState({
@@ -196,7 +187,7 @@ export default class App extends React.PureComponent<Props, State> {
       total,
       sourceViewer
     } = this.state;
-    const branchName = branch && getBranchName(branch);
+    const branchName = getBranchName(branch);
 
     const shouldShowBreadcrumbs = breadcrumbs.length > 1;
 
index c821156e5648ac0667493f61c5c843917cfb53ff..dbd68e8f27623347dc7bfe6e5966099a7d6b49a7 100644 (file)
@@ -111,7 +111,7 @@ export default class App extends React.PureComponent {
     const filteredKeys = metricsKey.filter(
       key => !metrics[key].hidden && !['DATA', 'DISTRIB'].includes(metrics[key].type)
     );
-    fetchMeasures(component.key, filteredKeys, branch && getBranchName(branch)).then(
+    fetchMeasures(component.key, filteredKeys, getBranchName(branch)).then(
       ({ measures, leakPeriod }) => {
         if (this.mounted) {
           this.setState({
@@ -138,7 +138,7 @@ export default class App extends React.PureComponent {
       pathname: this.props.location.pathname,
       query: {
         ...query,
-        branch: this.props.branch && getBranchName(this.props.branch),
+        branch: getBranchName(this.props.branch),
         id: this.props.component.key
       }
     });
@@ -175,7 +175,7 @@ export default class App extends React.PureComponent {
 
         {metric != null && (
           <MeasureContentContainer
-            branch={branch && getBranchName(branch)}
+            branch={getBranchName(branch)}
             className="layout-page-main"
             currentUser={this.props.currentUser}
             rootComponent={component}
@@ -192,7 +192,7 @@ export default class App extends React.PureComponent {
         {metric == null &&
           hasBubbleChart(query.metric) && (
             <MeasureOverviewContainer
-              branch={branch && getBranchName(branch)}
+              branch={getBranchName(branch)}
               className="layout-page-main"
               rootComponent={component}
               currentUser={this.props.currentUser}
index 65c3a828b64daf0b31025b5d4ea0fdd3c1ac2b9a..4b9c092a2754dc94a64da7cf9b05021d4cafb863 100644 (file)
@@ -333,7 +333,7 @@ export default class App extends React.PureComponent {
       pathname: this.props.location.pathname,
       query: {
         ...serializeQuery(this.state.query),
-        branch: this.props.branch && getBranchName(this.props.branch),
+        branch: getBranchName(this.props.branch),
         id: this.props.component && this.props.component.key,
         myIssues: this.state.myIssues ? 'true' : undefined,
         open: issue
@@ -352,7 +352,7 @@ export default class App extends React.PureComponent {
         pathname: this.props.location.pathname,
         query: {
           ...serializeQuery(this.state.query),
-          branch: this.props.branch && getBranchName(this.props.branch),
+          branch: getBranchName(this.props.branch),
           id: this.props.component && this.props.component.key,
           myIssues: this.state.myIssues ? 'true' : undefined,
           open: undefined
@@ -395,7 +395,7 @@ export default class App extends React.PureComponent {
       : undefined;
 
     const parameters = {
-      branch: this.props.branch && getBranchName(this.props.branch),
+      branch: getBranchName(this.props.branch),
       componentKeys: component && component.key,
       s: 'FILE_LINE',
       ...serializeQuery(query),
@@ -590,7 +590,7 @@ export default class App extends React.PureComponent {
       pathname: this.props.location.pathname,
       query: {
         ...serializeQuery({ ...this.state.query, ...changes }),
-        branch: this.props.branch && getBranchName(this.props.branch),
+        branch: getBranchName(this.props.branch),
         id: this.props.component && this.props.component.key,
         myIssues: this.state.myIssues ? 'true' : undefined
       }
@@ -606,7 +606,7 @@ export default class App extends React.PureComponent {
       pathname: this.props.location.pathname,
       query: {
         ...serializeQuery({ ...this.state.query, assigned: true, assignees: [] }),
-        branch: this.props.branch && getBranchName(this.props.branch),
+        branch: getBranchName(this.props.branch),
         id: this.props.component && this.props.component.key,
         myIssues: myIssues ? 'true' : undefined
       }
@@ -633,7 +633,7 @@ export default class App extends React.PureComponent {
       pathname: this.props.location.pathname,
       query: {
         ...DEFAULT_QUERY,
-        branch: this.props.branch && getBranchName(this.props.branch),
+        branch: getBranchName(this.props.branch),
         id: this.props.component && this.props.component.key,
         myIssues: this.state.myIssues ? 'true' : undefined
       }
@@ -857,7 +857,7 @@ export default class App extends React.PureComponent {
       <div>
         {paging.total > 0 && (
           <IssuesList
-            branch={this.props.branch && getBranchName(branch)}
+            branch={getBranchName(branch)}
             checked={this.state.checked}
             component={component}
             issues={issues}
@@ -922,7 +922,7 @@ export default class App extends React.PureComponent {
                 {openIssue != null ? (
                   <div className="pull-left width-60">
                     <ComponentBreadcrumbs
-                      branch={this.props.branch && getBranchName(this.props.branch)}
+                      branch={getBranchName(this.props.branch)}
                       component={component}
                       issue={openIssue}
                       organization={this.props.organization}
@@ -952,7 +952,7 @@ export default class App extends React.PureComponent {
             <div>
               {openIssue ? (
                 <IssuesSourceViewer
-                  branch={this.props.branch && getBranchName(this.props.branch)}
+                  branch={getBranchName(this.props.branch)}
                   component={component}
                   openIssue={openIssue}
                   loadIssues={this.fetchIssuesForComponent}
index f7d8fcfa2512a0629f8b2caec23d605722ca1f11..25157da7d59bab33aac7353c66663857c7e48bad 100644 (file)
@@ -103,7 +103,7 @@ export default class ProjectActivityAppContainer extends React.PureComponent {
         pathname: this.props.location.pathname,
         query: {
           ...serializeUrlQuery(newQuery),
-          branch: this.props.branch && getBranchName(this.props.branch)
+          branch: getBranchName(this.props.branch)
         }
       });
     } else {
@@ -173,7 +173,7 @@ export default class ProjectActivityAppContainer extends React.PureComponent {
       project,
       p,
       ps,
-      branch: this.props.branch && getBranchName(this.props.branch)
+      branch: getBranchName(this.props.branch)
     };
     return api
       .getProjectActivity({ ...additional, ...parameters })
@@ -188,7 +188,7 @@ export default class ProjectActivityAppContainer extends React.PureComponent {
       return Promise.resolve([]);
     }
     return getAllTimeMachineData(this.props.component.key, metrics, {
-      branch: this.props.branch && getBranchName(this.props.branch)
+      branch: getBranchName(this.props.branch)
     }).then(
       ({ measures }) =>
         measures.map(measure => ({
@@ -300,7 +300,7 @@ export default class ProjectActivityAppContainer extends React.PureComponent {
       pathname: this.props.location.pathname,
       query: {
         ...query,
-        branch: this.props.branch && getBranchName(this.props.branch),
+        branch: getBranchName(this.props.branch),
         id: this.props.component.key
       }
     });
index 65e17cc00406a0f588664362086abc3f481bba69..195b5a95a0e30096d41624b6c6d3fdbba58e6fcf 100644 (file)
 import { sortBy } from 'lodash';
 import { Branch, BranchType, ShortLivingBranch, LongLivingBranch } from '../app/types';
 
-export function isShortLivingBranch(branch: Branch | null): branch is ShortLivingBranch {
-  return branch != null && !branch.isMain && branch.type === BranchType.SHORT;
+export function isShortLivingBranch(branch?: Branch): branch is ShortLivingBranch {
+  return branch !== undefined && !branch.isMain && branch.type === BranchType.SHORT;
 }
 
-export function isLongLivingBranch(branch: Branch | null): branch is LongLivingBranch {
-  return branch != null && !branch.isMain && branch.type === BranchType.LONG;
+export function isLongLivingBranch(branch?: Branch): branch is LongLivingBranch {
+  return branch !== undefined && !branch.isMain && branch.type === BranchType.LONG;
 }
 
-export function getBranchName(branch: Branch): string | undefined {
-  return branch.isMain ? undefined : branch.name;
+export function getBranchName(branch?: Branch): string | undefined {
+  return !branch || branch.isMain ? undefined : branch.name;
 }
 
 export function sortBranchesAsTree(branches: Branch[]): Branch[] {