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.

HealthCard.tsx 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 { map } from 'lodash';
  22. import { translate } from 'sonar-ui-common/helpers/l10n';
  23. import { Alert } from 'sonar-ui-common/components/ui/Alert';
  24. import BoxedGroupAccordion from 'sonar-ui-common/components/controls/BoxedGroupAccordion';
  25. import HealthItem from './HealthItem';
  26. import Section from './Section';
  27. import { LOGS_LEVELS, groupSections, getLogsLevel } from '../../utils';
  28. interface Props {
  29. biggerHealth?: boolean;
  30. health?: T.HealthType;
  31. healthCauses?: string[];
  32. onClick: (toggledCard: string) => void;
  33. open: boolean;
  34. name: string;
  35. sysInfoData: T.SysInfoValueObject;
  36. }
  37. export default function HealthCard({
  38. biggerHealth,
  39. health,
  40. healthCauses,
  41. onClick,
  42. open,
  43. name,
  44. sysInfoData
  45. }: Props) {
  46. const { mainSection, sections } = groupSections(sysInfoData);
  47. const showFields = open && mainSection && Object.keys(mainSection).length > 0;
  48. const showSections = open && sections;
  49. const logLevel = getLogsLevel(sysInfoData);
  50. const showLogLevelWarning = logLevel && logLevel !== LOGS_LEVELS[0];
  51. return (
  52. <BoxedGroupAccordion
  53. data={name}
  54. onClick={onClick}
  55. open={open}
  56. renderHeader={() => (
  57. <>
  58. {showLogLevelWarning && (
  59. <Alert
  60. className="boxed-group-accordion-alert spacer-left"
  61. display="inline"
  62. variant="warning">
  63. {translate('system.log_level.warning.short')}
  64. </Alert>
  65. )}
  66. {health && (
  67. <HealthItem
  68. biggerHealth={biggerHealth}
  69. className="pull-right"
  70. health={health}
  71. healthCauses={healthCauses}
  72. name={name}
  73. />
  74. )}
  75. </>
  76. )}
  77. title={name}>
  78. {showFields && <Section items={mainSection} />}
  79. {showSections &&
  80. map(sections, (section, name) => <Section items={section} key={name} name={name} />)}
  81. </BoxedGroupAccordion>
  82. );
  83. }