aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-07-29 16:08:36 +0200
committerGitHub <noreply@github.com>2016-07-29 16:08:36 +0200
commit0b1226871a26f136739f29050de52088b2aa1c3e (patch)
tree1124abd73a6cf58d45e17cc0fb075a4076ca4320 /server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js
parent3e3e4b1e16c0e5ebf8a485d3014cb7bd2577e192 (diff)
downloadsonarqube-0b1226871a26f136739f29050de52088b2aa1c3e.tar.gz
sonarqube-0b1226871a26f136739f29050de52088b2aa1c3e.zip
SONAR-7920 Rewrite Links project page (#1127)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js')
-rw-r--r--server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js113
1 files changed, 113 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js b/server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js
new file mode 100644
index 00000000000..e55651dce89
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/project-admin/links/LinkRow.js
@@ -0,0 +1,113 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import React from 'react';
+import shallowCompare from 'react-addons-shallow-compare';
+import { isProvided, isClickable } from './utils';
+import { translate } from '../../../helpers/l10n';
+
+export default class LinkRow extends React.Component {
+ static propTypes = {
+ link: React.PropTypes.object.isRequired,
+ onDelete: React.PropTypes.func.isRequired
+ };
+
+ shouldComponentUpdate (nextProps, nextState) {
+ return shallowCompare(this, nextProps, nextState);
+ }
+
+ handleDeleteClick (e) {
+ e.preventDefault();
+ e.target.blur();
+ this.props.onDelete();
+ }
+
+ renderIcon (iconClassName) {
+ return (
+ <div className="display-inline-block text-top spacer-right">
+ <i className={iconClassName}/>
+ </div>
+ );
+ }
+
+ renderNameForProvided (link) {
+ return (
+ <div>
+ {this.renderIcon(`icon-${link.type}`)}
+ <div className="display-inline-block text-top">
+ <div>
+ <span className="js-name">{link.name}</span>
+ </div>
+ <div className="note little-spacer-top">
+ <span className="js-type">{`sonar.links.${link.type}`}</span>
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ renderName (link) {
+ if (isProvided(link)) {
+ return this.renderNameForProvided(link);
+ }
+
+ return (
+ <div>
+ {this.renderIcon('icon-detach')}
+ <div className="display-inline-block text-top">
+ <span className="js-name">{link.name}</span>
+ </div>
+ </div>
+ );
+ }
+
+ renderUrl (link) {
+ if (isClickable(link)) {
+ return <a href={link.url} target="_blank">{link.url}</a>;
+ }
+
+ return link.url;
+ }
+
+ renderDeleteButton (link) {
+ if (isProvided(link)) {
+ return null;
+ }
+
+ return (
+ <button
+ className="button-red js-delete-button"
+ onClick={this.handleDeleteClick.bind(this)}>
+ {translate('delete')}
+ </button>
+ );
+ }
+
+ render () {
+ const { link } = this.props;
+
+ return (
+ <tr data-name={link.name}>
+ <td className="nowrap">{this.renderName(link)}</td>
+ <td className="nowrap js-url">{this.renderUrl(link)}</td>
+ <td className="thin nowrap">{this.renderDeleteButton(link)}</td>
+ </tr>
+ );
+ }
+}