123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- /*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info 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 { LargeCenteredLayout, PageContentFontWrapper } from 'design-system';
- import * as React from 'react';
- import { Helmet } from 'react-helmet-async';
- import { getSystemInfo } from '../../../api/system';
- import UpdateNotification from '../../../app/components/update-notification/UpdateNotification';
- import Suggestions from '../../../components/embed-docs-modal/Suggestions';
- import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
- import { translate } from '../../../helpers/l10n';
- import { SysInfoCluster, SysInfoStandalone } from '../../../types/types';
- import '../styles.css';
- import {
- Query,
- getClusterVersion,
- getServerId,
- getSystemLogsLevel,
- getVersion,
- isCluster,
- parseQuery,
- serializeQuery,
- } from '../utils';
- import ClusterSysInfos from './ClusterSysInfos';
- import PageHeader from './PageHeader';
- import StandaloneSysInfos from './StandaloneSysInfos';
-
- interface Props {
- location: Location;
- router: Router;
- }
-
- interface State {
- loading: boolean;
- sysInfoData?: SysInfoCluster | SysInfoStandalone;
- }
-
- class SystemApp extends React.PureComponent<Props, State> {
- mounted = false;
- state: State = { loading: true };
-
- componentDidMount() {
- this.mounted = true;
- this.fetchSysInfo();
- }
-
- componentWillUnmount() {
- this.mounted = false;
- }
-
- fetchSysInfo = () => {
- this.setState({ loading: true });
- getSystemInfo().then(
- (sysInfoData) => {
- if (this.mounted) {
- this.setState({ loading: false, sysInfoData });
- }
- },
- () => {
- if (this.mounted) {
- this.setState({ loading: false });
- }
- },
- );
- };
-
- toggleSysInfoCards = (toggledCard: string) => {
- const query = parseQuery(this.props.location.query);
- let expandedCards;
- if (query.expandedCards.includes(toggledCard)) {
- expandedCards = query.expandedCards.filter((card) => card !== toggledCard);
- } else {
- expandedCards = query.expandedCards.concat(toggledCard);
- }
- this.updateQuery({ expandedCards });
- };
-
- updateQuery = (newQuery: Query) => {
- const query = serializeQuery({ ...parseQuery(this.props.location.query), ...newQuery });
- this.props.router.replace({ pathname: this.props.location.pathname, query });
- };
-
- renderSysInfo() {
- const { sysInfoData } = this.state;
- if (!sysInfoData) {
- return null;
- }
-
- const query = parseQuery(this.props.location.query);
- if (isCluster(sysInfoData)) {
- return (
- <ClusterSysInfos
- expandedCards={query.expandedCards}
- sysInfoData={sysInfoData}
- toggleCard={this.toggleSysInfoCards}
- />
- );
- }
- return (
- <StandaloneSysInfos
- expandedCards={query.expandedCards}
- sysInfoData={sysInfoData}
- toggleCard={this.toggleSysInfoCards}
- />
- );
- }
-
- render() {
- const { loading, sysInfoData } = this.state;
- return (
- <LargeCenteredLayout as="main">
- <Suggestions suggestions="system_info" />
- <Helmet defer={false} title={translate('system_info.page')} />
- <PageContentFontWrapper className="sw-body-sm sw-pb-8">
- <div>
- <UpdateNotification />
- </div>
- {sysInfoData && (
- <PageHeader
- isCluster={isCluster(sysInfoData)}
- loading={loading}
- logLevel={getSystemLogsLevel(sysInfoData)}
- onLogLevelChange={this.fetchSysInfo}
- serverId={getServerId(sysInfoData)}
- version={
- isCluster(sysInfoData) ? getClusterVersion(sysInfoData) : getVersion(sysInfoData)
- }
- />
- )}
- {this.renderSysInfo()}
- </PageContentFontWrapper>
- </LargeCenteredLayout>
- );
- }
- }
-
- export default withRouter(SystemApp);
|