You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectCard.tsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { Link } from 'react-router';
  22. import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip';
  23. import Tooltip from 'sonar-ui-common/components/controls/Tooltip';
  24. import Level from 'sonar-ui-common/components/ui/Level';
  25. import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
  26. import DateFromNow from '../../../components/intl/DateFromNow';
  27. import DateTimeFormatter from '../../../components/intl/DateTimeFormatter';
  28. import MetaLink from '../../overview/meta/MetaLink';
  29. import { orderLinks } from '../../projectLinks/utils';
  30. interface Props {
  31. project: T.MyProject;
  32. }
  33. export default function ProjectCard({ project }: Props) {
  34. const { links } = project;
  35. const orderedLinks: T.ProjectLink[] = orderLinks(
  36. links.map((link, i) => {
  37. const { href, name, type } = link;
  38. return {
  39. id: `link-${i}`,
  40. name,
  41. type,
  42. url: href
  43. };
  44. })
  45. );
  46. const { lastAnalysisDate } = project;
  47. return (
  48. <div className="account-project-card clearfix">
  49. <aside className="account-project-side">
  50. {lastAnalysisDate !== undefined ? (
  51. <div className="account-project-analysis">
  52. <DateFromNow date={lastAnalysisDate}>
  53. {fromNow => (
  54. <Tooltip overlay={<DateTimeFormatter date={lastAnalysisDate} />}>
  55. <span>{translateWithParameters('my_account.projects.analyzed_x', fromNow)}</span>
  56. </Tooltip>
  57. )}
  58. </DateFromNow>
  59. </div>
  60. ) : (
  61. <div className="account-project-analysis">
  62. {translate('my_account.projects.never_analyzed')}
  63. </div>
  64. )}
  65. {project.qualityGate !== undefined && (
  66. <div className="account-project-quality-gate">
  67. {project.qualityGate === 'WARN' && (
  68. <HelpTooltip
  69. className="little-spacer-right"
  70. overlay={translate('quality_gates.conditions.warning.tooltip')}
  71. />
  72. )}
  73. <Level aria-label={translate('quality_gates.status')} level={project.qualityGate} />
  74. </div>
  75. )}
  76. </aside>
  77. <h3 className="account-project-name">
  78. <Link to={{ pathname: '/dashboard', query: { id: project.key } }}>{project.name}</Link>
  79. </h3>
  80. {orderedLinks.length > 0 && (
  81. <div className="account-project-links">
  82. <ul className="list-inline">
  83. {orderedLinks.map(link => (
  84. <MetaLink iconOnly={true} key={link.id} link={link} />
  85. ))}
  86. </ul>
  87. </div>
  88. )}
  89. <div className="account-project-key">{project.key}</div>
  90. {!!project.description && (
  91. <div className="account-project-description">{project.description}</div>
  92. )}
  93. </div>
  94. );
  95. }