From: Grégoire Aubert Date: Tue, 16 Jan 2018 10:40:04 +0000 (+0100) Subject: Make branch parameter optional in some helper functions X-Git-Tag: 7.5~1779 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e85902788fd722f1c17d214d8be15eea5cf276e0;p=sonarqube.git Make branch parameter optional in some helper functions --- diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx index e4d0b410a3d..1a303440818 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx @@ -168,7 +168,7 @@ export default class ComponentNavBranchesMenu extends React.PureComponent { 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; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx index 5f07856c3fd..564a54ea318 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx @@ -78,7 +78,7 @@ export default class ComponentNavMenu extends React.PureComponent { } 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 { 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 { 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 { } 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 { 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 { 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 { } 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 { 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 { const isSettingsActive = SETTINGS_URLS.some(url => window.location.href.indexOf(url) !== -1); - if (branch && isLongLivingBranch(branch)) { + if (isLongLivingBranch(branch)) { return (
  • { to={{ pathname: '/project/settings', query: { - branch: this.props.branch && getBranchName(this.props.branch), + branch: getBranchName(this.props.branch), id: this.props.component.key } }} diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx index c77c9db1fe8..42ab6e09378 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx @@ -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 ( diff --git a/server/sonar-web/src/main/js/apps/code/components/App.tsx b/server/sonar-web/src/main/js/apps/code/components/App.tsx index 7ad3c99b908..f6fa32269a2 100644 --- a/server/sonar-web/src/main/js/apps/code/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/App.tsx @@ -87,7 +87,7 @@ export default class App extends React.PureComponent { 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 { 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 { 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 { total, sourceViewer } = this.state; - const branchName = branch && getBranchName(branch); + const branchName = getBranchName(branch); const shouldShowBreadcrumbs = breadcrumbs.length > 1; diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/App.js b/server/sonar-web/src/main/js/apps/component-measures/components/App.js index c821156e564..dbd68e8f276 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/App.js +++ b/server/sonar-web/src/main/js/apps/component-measures/components/App.js @@ -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 && ( {paging.total > 0 && ( {openIssue ? ( 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 } }); diff --git a/server/sonar-web/src/main/js/helpers/branches.ts b/server/sonar-web/src/main/js/helpers/branches.ts index 65e17cc0040..195b5a95a0e 100644 --- a/server/sonar-web/src/main/js/helpers/branches.ts +++ b/server/sonar-web/src/main/js/helpers/branches.ts @@ -20,16 +20,16 @@ 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[] {