forked from theforeman/foreman_rh_cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (77 loc) · 2.65 KB
/
index.js
File metadata and controls
87 lines (77 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React from 'react';
import PropTypes from 'prop-types';
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
import { Link } from 'react-router-dom';
import { translate as __ } from 'foremanReact/common/I18n';
import { propsToCamelCase } from 'foremanReact/common/helpers';
import { CVECountCell } from '../InsightsVulnerabilityHostIndexExtensions/CVECountCell';
const HostedRecommendationsCell = ({ hostDetails }) => {
const insightsAttributes = propsToCamelCase(
// eslint-disable-next-line camelcase
hostDetails?.insights_attributes ?? {}
);
const { insightsHitsCount: hitsCount } = insightsAttributes;
if (hitsCount === undefined || hitsCount === null) return '—';
const hostname = hostDetails?.name;
const encodedHostname = encodeURIComponent(hostname);
const hitsUrl = `/foreman_rh_cloud/insights_cloud?search=hostname+%3D+${encodedHostname}`;
return <a href={hitsUrl}>{hitsCount}</a>;
};
HostedRecommendationsCell.propTypes = {
hostDetails: PropTypes.object.isRequired,
};
const IopRecommendationsCell = ({ hostDetails }) => {
// eslint-disable-next-line camelcase
const uuid = hostDetails?.insights_attributes?.uuid;
const { response } = useAPI(
uuid ? 'get' : null,
`/insights_cloud/api/insights/v1/system/${uuid}`,
{ key: `HOST_RECS_COUNT_${uuid}` }
);
const hits = response?.hits;
return hits === undefined ? (
'—'
) : (
<Link to={`hosts/${hostDetails.name}#/Insights`}>{hits}</Link>
);
};
IopRecommendationsCell.propTypes = {
hostDetails: PropTypes.object.isRequired,
};
const RecommendationsCell = hostDetails => {
const insightsAttributes = propsToCamelCase(
// eslint-disable-next-line camelcase
hostDetails?.insights_attributes ?? {}
);
return insightsAttributes.useIopMode ? (
<IopRecommendationsCell hostDetails={hostDetails} />
) : (
<HostedRecommendationsCell hostDetails={hostDetails} />
);
};
const insightsCategoryName = __('Insights');
const hostsIndexColumnExtensions = [
{
columnName: 'insights_recommendations_count',
title: __('Recommendations'),
wrapper: RecommendationsCell,
weight: 1500,
isSorted: true,
tableName: 'hosts',
categoryName: insightsCategoryName,
categoryKey: 'insights',
},
{
columnName: 'cves_count',
title: __('Total CVEs'),
wrapper: hostDetails => <CVECountCell hostDetails={hostDetails} />,
weight: 1600,
tableName: 'hosts',
categoryName: insightsCategoryName,
categoryKey: 'insights',
isSorted: false,
// eslint-disable-next-line camelcase
isRelevant: contextData => contextData?.metadata?.foreman_rh_cloud?.iop,
},
];
export default hostsIndexColumnExtensions;