LCOV - code coverage report
Current view: top level - pkg/systemd/overview-cards - insights.jsx Coverage Total Hit
Test: cockpit Lines: 97.6 % 42 41
Test Date: 2026-06-16 14:09:37

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2020 Red Hat, Inc.
       3              :  * SPDX-License-Identifier: LGPL-2.1-or-later
       4              :  */
       5              : 
       6           35 : import React from 'react';
       7              : import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js";
       8              : import { Flex } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js";
       9              : import { CheckIcon, ExclamationTriangleIcon } from '@patternfly/react-icons';
      10              : import { Icon } from "@patternfly/react-core/dist/esm/components/Icon/index.js";
      11              : 
      12           35 : import cockpit from "cockpit";
      13              : import * as service from "service.js";
      14              : 
      15              : import "./insights.scss";
      16              : 
      17           35 : const _ = cockpit.gettext;
      18              : 
      19           35 : export class InsightsStatus extends React.Component {
      20           35 :     constructor() {
      21           35 :         super();
      22              : 
      23           35 :         this.subman_supports_insights = (cockpit.manifests.subscriptions &&
      24            6 :                                          cockpit.manifests.subscriptions.features &&
      25            6 :                                          cockpit.manifests.subscriptions.features.insights);
      26              : 
      27           35 :         this.insights_client_timer = service.proxy("insights-client.timer");
      28           27 :         this.insights_client_timer.addEventListener("changed", () => this.setState({}));
      29           35 :     }
      30              : 
      31           35 :     render() {
      32            6 :         if (!this.insights_client_timer) {
      33              :             // Not mounted yet
      34            6 :             return null;
      35            6 :         }
      36              : 
      37           35 :         if (!this.insights_client_timer.exists) {
      38              :             // insights-client is not installed
      39           35 :             return null;
      40           35 :         }
      41              : 
      42            6 :         let text = _("Connected to Insights");
      43            6 :         let icon = <Icon status='success'><CheckIcon className="ct-check-circle" /></Icon>;
      44              : 
      45            6 :         if (!this.insights_client_timer.enabled) {
      46              :             // machine is not registered with Insights
      47            6 :             if (this.subman_supports_insights) {
      48              :                 // subscriptions page can register us
      49            6 :                 text = _("Not connected to Insights");
      50            6 :                 icon = <Icon status='warning'><ExclamationTriangleIcon className="ct-exclamation-triangle" /></Icon>;
      51            6 :             } else
      52            6 :                 return null;
      53            6 :         }
      54              : 
      55            6 :         const subman_installed = cockpit.manifests?.subscriptions;
      56              : 
      57           35 :         return (
      58           35 :             <li className="system-health-insights">
      59           35 :                 <Flex flexWrap={{ default: 'nowrap' }} spaceItems={{ default: 'spaceItemsSm' }} alignItems={{ default: 'alignItemsCenter' }}>
      60           35 :                     {icon}
      61           35 :                     <Button isInline variant="link" component="a"
      62            0 :                         onClick={ev => { ev.preventDefault(); cockpit.jump("/subscriptions") }}
      63           35 :                         isDisabled={!subman_installed}
      64              :                     >
      65           35 :                         {text}
      66           35 :                     </Button>
      67           35 :                 </Flex>
      68           35 :             </li>
      69              :         );
      70           35 :     }
      71           35 : }
        

Generated by: LCOV version 2.0-1