From e3e4973f25300949c8cf43c4bc40ac33a62ec806 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Mon, 17 Jun 2019 17:43:47 +0200 Subject: [PATCH] SONAR-11830 Don't show empty cell on projects and applications There are no individual files on applications and portfolios. Hence, they can never be pinned. Because of this, we can remove the empty cell at the start of each row. --- .../js/apps/code/components/Component.tsx | 30 +++++++++++-------- .../js/apps/code/components/Components.tsx | 7 ++++- .../apps/code/components/ComponentsEmpty.tsx | 8 +++-- .../apps/code/components/ComponentsHeader.tsx | 10 +++++-- .../__snapshots__/Component-test.tsx.snap | 6 +--- .../__snapshots__/Components-test.tsx.snap | 6 ++++ 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/code/components/Component.tsx b/server/sonar-web/src/main/js/apps/code/components/Component.tsx index 6391a622928..52b01fc1436 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Component.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/Component.tsx @@ -27,6 +27,7 @@ import { withScrollTo } from '../../../components/hoc/withScrollTo'; interface Props { branchLike?: T.BranchLike; + canBePinned?: boolean; canBrowse?: boolean; component: T.ComponentMeasure; metrics: T.Metric[]; @@ -39,6 +40,7 @@ export class Component extends React.PureComponent { render() { const { branchLike, + canBePinned = true, canBrowse = false, component, metrics, @@ -52,21 +54,23 @@ export class Component extends React.PureComponent { return ( - - + {canBePinned && ( + {isFile && ( - - {({ openComponent }) => ( - - )} - + + + {({ openComponent }) => ( + + )} + + )} - - + + )} { ); const metrics = metricKeys.map(metric => this.props.metrics[metric]); const colSpan = metrics.length + 4; + const canBePinned = baseComponent && !['APP', 'VW', 'SVW'].includes(baseComponent.qualifier); + return ( {baseComponent && ( @@ -56,6 +59,7 @@ export class Components extends React.PureComponent { { components.map((component, index, list) => ( { /> )) ) : ( - + )} diff --git a/server/sonar-web/src/main/js/apps/code/components/ComponentsEmpty.tsx b/server/sonar-web/src/main/js/apps/code/components/ComponentsEmpty.tsx index 3c3e4fab144..6f314ebf25d 100644 --- a/server/sonar-web/src/main/js/apps/code/components/ComponentsEmpty.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/ComponentsEmpty.tsx @@ -20,10 +20,14 @@ import * as React from 'react'; import { translate } from '../../../helpers/l10n'; -export default function ComponentsEmpty() { +interface Props { + canBePinned?: boolean; +} + +export default function ComponentsEmpty({ canBePinned = true }: Props) { return ( - diff --git a/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx b/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx index 81de436c90f..ca8123fa5b8 100644 --- a/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx @@ -23,6 +23,7 @@ import { translate } from '../../../helpers/l10n'; interface Props { baseComponent?: T.ComponentMeasure; + canBePinned?: boolean; metrics: string[]; rootComponent: T.ComponentMeasure; } @@ -34,7 +35,12 @@ const SHORT_NAME_METRICS = [ 'new_duplicated_lines_density' ]; -export default function ComponentsHeader({ baseComponent, metrics, rootComponent }: Props) { +export default function ComponentsHeader({ + baseComponent, + canBePinned = true, + metrics, + rootComponent +}: Props) { const isPortfolio = ['VW', 'SVW'].includes(rootComponent.qualifier); let columns: string[] = []; if (isPortfolio) { @@ -54,7 +60,7 @@ export default function ComponentsHeader({ baseComponent, metrics, rootComponent return ( - + />
+ {canBePinned && } {translate('no_results')}
+ {baseComponent && columns.map((column, index) => ( diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap index d7a9a10ec89..138b237b2e5 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Component-test.tsx.snap @@ -9,11 +9,7 @@ exports[`should render correctly 1`] = ` /> - - diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap index 668294412ec..b7df151910c 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/Components-test.tsx.snap @@ -12,6 +12,7 @@ exports[`renders correctly 1`] = ` "qualifier": "TRK", } } + canBePinned={true} metrics={ Array [ "coverage", @@ -27,6 +28,7 @@ exports[`renders correctly 1`] = ` />