-
Notifications
You must be signed in to change notification settings - Fork 297
/
index.js
77 lines (68 loc) · 2.62 KB
/
index.js
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
import React, { useContext } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { DropdownItem, DropdownSeparator } from '@patternfly/react-core';
import { CubeIcon, UndoIcon, RedoIcon } from '@patternfly/react-icons';
import { translate as __ } from 'foremanReact/common/I18n';
import { HOST_DETAILS_KEY } from 'foremanReact/components/HostDetails/consts';
import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
import { foremanUrl } from 'foremanReact/common/helpers';
import { selectHostDetails } from '../HostDetailsSelectors';
import { useRexJobPolling } from '../Tabs/RemoteExecutionHooks';
import { runSubmanRepos } from '../Cards/ContentViewDetailsCard/HostContentViewActions';
import { hasRequiredPermissions as can, userPermissionsFromHostDetails } from '../hostDetailsHelpers';
const HostActionsBar = () => {
const hostDetails = useSelector(selectHostDetails);
const dispatch = useDispatch();
const hostname = hostDetails?.name;
const { onKebabToggle } = useContext(ForemanActionsBarContext);
const recalculateApplicability = ['edit_hosts', 'create_job_invocations'];
const showRecalculate =
can(recalculateApplicability, userPermissionsFromHostDetails({ hostDetails }));
const refreshHostDetails = () => dispatch({
type: 'API_GET',
payload: {
key: HOST_DETAILS_KEY,
url: `/api/hosts/${hostname}`,
},
});
const {
triggerJobStart: triggerRecalculate,
} = useRexJobPolling(() => runSubmanRepos(hostname, refreshHostDetails));
const handleRefreshApplicabilityClick = () => {
triggerRecalculate();
onKebabToggle();
};
return (
<>
<DropdownItem
ouiaId="katello-legacy-contenthost-ui"
key="katello-legacy-contenthost-ui"
href={foremanUrl(`/content_hosts/${hostDetails?.id}`)}
icon={<UndoIcon />}
>
{__('Legacy content host UI')}
</DropdownItem>
<DropdownSeparator key="separator" ouiaId="katello-separator" />
{showRecalculate && (
<DropdownItem
ouiaId="katello-refresh-applicability"
key="katello-refresh-applicability"
onClick={handleRefreshApplicabilityClick}
icon={<RedoIcon />}
>
{__('Refresh applicability')}
</DropdownItem>
)
}
<DropdownItem
ouiaId="katello-change-host-content-source"
key="katello-change-host-content-source"
href={foremanUrl(`/change_host_content_source?host_id=${hostDetails?.id}`)}
icon={<CubeIcon />}
>
{__('Change content source')}
</DropdownItem>
</>
);
};
export default HostActionsBar;