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