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