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.

SystemApp.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 { LargeCenteredLayout, PageContentFontWrapper } from 'design-system';
  21. import * as React from 'react';
  22. import { Helmet } from 'react-helmet-async';
  23. import { getSystemInfo } from '../../../api/system';
  24. import UpdateNotification from '../../../app/components/update-notification/UpdateNotification';
  25. import Suggestions from '../../../components/embed-docs-modal/Suggestions';
  26. import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
  27. import { translate } from '../../../helpers/l10n';
  28. import { SysInfoCluster, SysInfoStandalone } from '../../../types/types';
  29. import '../styles.css';
  30. import {
  31. Query,
  32. getClusterVersion,
  33. getServerId,
  34. getSystemLogsLevel,
  35. getVersion,
  36. isCluster,
  37. parseQuery,
  38. serializeQuery,
  39. } from '../utils';
  40. import ClusterSysInfos from './ClusterSysInfos';
  41. import PageHeader from './PageHeader';
  42. import StandaloneSysInfos from './StandaloneSysInfos';
  43. interface Props {
  44. location: Location;
  45. router: Router;
  46. }
  47. interface State {
  48. loading: boolean;
  49. sysInfoData?: SysInfoCluster | SysInfoStandalone;
  50. }
  51. class SystemApp extends React.PureComponent<Props, State> {
  52. mounted = false;
  53. state: State = { loading: true };
  54. componentDidMount() {
  55. this.mounted = true;
  56. this.fetchSysInfo();
  57. }
  58. componentWillUnmount() {
  59. this.mounted = false;
  60. }
  61. fetchSysInfo = () => {
  62. this.setState({ loading: true });
  63. getSystemInfo().then(
  64. (sysInfoData) => {
  65. if (this.mounted) {
  66. this.setState({ loading: false, sysInfoData });
  67. }
  68. },
  69. () => {
  70. if (this.mounted) {
  71. this.setState({ loading: false });
  72. }
  73. },
  74. );
  75. };
  76. toggleSysInfoCards = (toggledCard: string) => {
  77. const query = parseQuery(this.props.location.query);
  78. let expandedCards;
  79. if (query.expandedCards.includes(toggledCard)) {
  80. expandedCards = query.expandedCards.filter((card) => card !== toggledCard);
  81. } else {
  82. expandedCards = query.expandedCards.concat(toggledCard);
  83. }
  84. this.updateQuery({ expandedCards });
  85. };
  86. updateQuery = (newQuery: Query) => {
  87. const query = serializeQuery({ ...parseQuery(this.props.location.query), ...newQuery });
  88. this.props.router.replace({ pathname: this.props.location.pathname, query });
  89. };
  90. renderSysInfo() {
  91. const { sysInfoData } = this.state;
  92. if (!sysInfoData) {
  93. return null;
  94. }
  95. const query = parseQuery(this.props.location.query);
  96. if (isCluster(sysInfoData)) {
  97. return (
  98. <ClusterSysInfos
  99. expandedCards={query.expandedCards}
  100. sysInfoData={sysInfoData}
  101. toggleCard={this.toggleSysInfoCards}
  102. />
  103. );
  104. }
  105. return (
  106. <StandaloneSysInfos
  107. expandedCards={query.expandedCards}
  108. sysInfoData={sysInfoData}
  109. toggleCard={this.toggleSysInfoCards}
  110. />
  111. );
  112. }
  113. render() {
  114. const { loading, sysInfoData } = this.state;
  115. return (
  116. <LargeCenteredLayout as="main">
  117. <Suggestions suggestions="system_info" />
  118. <Helmet defer={false} title={translate('system_info.page')} />
  119. <PageContentFontWrapper className="sw-body-sm sw-pb-8">
  120. <div>
  121. <UpdateNotification />
  122. </div>
  123. {sysInfoData && (
  124. <PageHeader
  125. isCluster={isCluster(sysInfoData)}
  126. loading={loading}
  127. logLevel={getSystemLogsLevel(sysInfoData)}
  128. onLogLevelChange={this.fetchSysInfo}
  129. serverId={getServerId(sysInfoData)}
  130. version={
  131. isCluster(sysInfoData) ? getClusterVersion(sysInfoData) : getVersion(sysInfoData)
  132. }
  133. />
  134. )}
  135. {this.renderSysInfo()}
  136. </PageContentFontWrapper>
  137. </LargeCenteredLayout>
  138. );
  139. }
  140. }
  141. export default withRouter(SystemApp);