aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/code/components
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-01-07 14:34:43 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-01-07 14:34:43 +0100
commit45983670fed129aca63dedacb6387b271c66bd50 (patch)
treea1d52cfd39ef7f60bf167f2dc21dbc8946c698c6 /server/sonar-web/src/main/js/apps/code/components
parent31a27608e429bb5962512ef7e3a01b12b49a01f8 (diff)
downloadsonarqube-45983670fed129aca63dedacb6387b271c66bd50.tar.gz
sonarqube-45983670fed129aca63dedacb6387b271c66bd50.zip
SONAR-7143 improve display of directories list
Diffstat (limited to 'server/sonar-web/src/main/js/apps/code/components')
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/Component.js3
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/ComponentName.js30
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/Components.js4
3 files changed, 31 insertions, 6 deletions
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 }) => (
<tr>
<td className="thin nowrap">
<span className="spacer-right">
@@ -34,6 +34,7 @@ const Component = ({ component, coverageMetric, onBrowse }) => (
<td className="code-name-cell">
<ComponentName
component={component}
+ previous={previous}
onBrowse={onBrowse}/>
</td>
<td className="thin nowrap text-right">
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 ? (
+ <span>
+ <span style={{ color: '#777' }}>{prefix}</span>
+ <span>{component.name.substr(prefix.length)}</span>
+ </span>
+ ) : component.name;
+
return (
<Truncated title={getTooltip(component)}>
<QualifierIcon qualifier={component.qualifier}/>
@@ -47,11 +71,11 @@ const Component = ({ component, onBrowse }) => {
<a
onClick={handleClick}
href="#">
- {component.name}
+ {name}
</a>
) : (
<span>
- {component.name}
+ {name}
</span>
)}
</Truncated>
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 }) =>
)}
<tbody>
{components.length ? (
- components.map(component => (
+ components.map((component, index, list) => (
<Component
key={component.key}
component={component}
+ previous={index > 0 ? list[index - 1] : null}
coverageMetric={coverageMetric}
onBrowse={onBrowse}/>
))