From: Stas Vilchik Date: Thu, 7 Jan 2016 13:34:43 +0000 (+0100) Subject: SONAR-7143 improve display of directories list X-Git-Tag: 5.4-M4~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=45983670fed129aca63dedacb6387b271c66bd50;p=sonarqube.git SONAR-7143 improve display of directories list --- diff --git a/server/sonar-web/src/main/js/apps/code/components/Component.js b/server/sonar-web/src/main/js/apps/code/components/Component.js index 3956bb78395..de9a7e1055f 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Component.js +++ b/server/sonar-web/src/main/js/apps/code/components/Component.js @@ -24,7 +24,7 @@ import ComponentMeasure from './ComponentMeasure'; import ComponentDetach from './ComponentDetach'; -const Component = ({ component, coverageMetric, onBrowse }) => ( +const Component = ({ component, previous, coverageMetric, onBrowse }) => ( @@ -34,6 +34,7 @@ const Component = ({ component, coverageMetric, onBrowse }) => ( diff --git a/server/sonar-web/src/main/js/apps/code/components/ComponentName.js b/server/sonar-web/src/main/js/apps/code/components/ComponentName.js index f8b02d6b87f..51ba9af79df 100644 --- a/server/sonar-web/src/main/js/apps/code/components/ComponentName.js +++ b/server/sonar-web/src/main/js/apps/code/components/ComponentName.js @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import _ from 'underscore'; import React from 'react'; import Truncated from './Truncated'; @@ -32,13 +33,36 @@ function getTooltip (component) { } } +function mostCommitPrefix (strings) { + var sortedStrings = strings.slice(0).sort(), + firstString = sortedStrings[0], + firstStringLength = firstString.length, + lastString = sortedStrings[sortedStrings.length - 1], + i = 0; + while (i < firstStringLength && firstString.charAt(i) === lastString.charAt(i)) { + i++; + } + var prefix = firstString.substr(0, i), + lastPrefixPart = _.last(prefix.split(/[\s\\\/]/)); + return prefix.substr(0, prefix.length - lastPrefixPart.length); +} -const Component = ({ component, onBrowse }) => { + +const Component = ({ component, previous, onBrowse }) => { const handleClick = (e) => { e.preventDefault(); onBrowse(component); }; + const areBothDirs = component.qualifier === 'DIR' && previous && previous.qualifier === 'DIR'; + const prefix = areBothDirs ? mostCommitPrefix([component.name + '/', previous.name + '/']) : ''; + const name = prefix ? ( + + {prefix} + {component.name.substr(prefix.length)} + + ) : component.name; + return ( @@ -47,11 +71,11 @@ const Component = ({ component, onBrowse }) => { - {component.name} + {name} ) : ( - {component.name} + {name} )} diff --git a/server/sonar-web/src/main/js/apps/code/components/Components.js b/server/sonar-web/src/main/js/apps/code/components/Components.js index 4752e06b749..15fd5c7d854 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Components.js +++ b/server/sonar-web/src/main/js/apps/code/components/Components.js @@ -22,7 +22,6 @@ import React from 'react'; import Component from './Component'; import ComponentsEmpty from './ComponentsEmpty'; import ComponentsHeader from './ComponentsHeader'; -import { translate } from '../../../helpers/l10n'; const Components = ({ baseComponent, components, coverageMetric, onBrowse }) => ( @@ -41,10 +40,11 @@ const Components = ({ baseComponent, components, coverageMetric, onBrowse }) => )} {components.length ? ( - components.map(component => ( + components.map((component, index, list) => ( 0 ? list[index - 1] : null} coverageMetric={coverageMetric} onBrowse={onBrowse}/> )) diff --git a/server/sonar-web/tests/apps/code/components-test.js b/server/sonar-web/tests/apps/code/components-test.js index cf9fac7bb4b..7729bf7b5ab 100644 --- a/server/sonar-web/tests/apps/code/components-test.js +++ b/server/sonar-web/tests/apps/code/components-test.js @@ -103,7 +103,7 @@ describe('Code :: Components', () => { expect(findings) .to.have.length(1); expect(findings.first().props()) - .to.deep.equal({ component: exampleComponent, onBrowse: exampleOnBrowse }); + .to.deep.equal({ component: exampleComponent, previous: undefined, onBrowse: exampleOnBrowse }); }); it('should render s', () => {