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