Skip to content

Commit

Permalink
For hosted policies, hide many context menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Apr 2, 2021
1 parent d3280ea commit a93dd8c
Showing 1 changed file with 62 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,74 +55,81 @@ const REFRESH_INTERVAL_MS = 30000;

const RowActions = React.memo<{
agent: Agent;
agentPolicy?: AgentPolicy;
refresh: () => void;
onReassignClick: () => void;
onUnenrollClick: () => void;
onUpgradeClick: () => void;
}>(({ agent, refresh, onReassignClick, onUnenrollClick, onUpgradeClick }) => {
}>(({ agent, agentPolicy, refresh, onReassignClick, onUnenrollClick, onUpgradeClick }) => {
const { getHref } = useLink();
const hasWriteCapabilites = useCapabilities().write;

const isUnenrolling = agent.status === 'unenrolling';
const kibanaVersion = useKibanaVersion();
const [isMenuOpen, setIsMenuOpen] = useState(false);
return (
<ContextMenuActions
isOpen={isMenuOpen}
onChange={(isOpen) => setIsMenuOpen(isOpen)}
items={[
<EuiContextMenuItem
icon="inspect"
href={getHref('fleet_agent_details', { agentId: agent.id })}
key="viewAgent"
>
<FormattedMessage id="xpack.fleet.agentList.viewActionText" defaultMessage="View agent" />
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="pencil"
onClick={() => {
onReassignClick();
}}
disabled={!agent.active}
key="reassignPolicy"
>
const menuItems = [
<EuiContextMenuItem
icon="inspect"
href={getHref('fleet_agent_details', { agentId: agent.id })}
key="viewAgent"
>
<FormattedMessage id="xpack.fleet.agentList.viewActionText" defaultMessage="View agent" />
</EuiContextMenuItem>,
];

if (agentPolicy?.is_managed === false) {
menuItems.push(
<EuiContextMenuItem
icon="pencil"
onClick={() => {
onReassignClick();
}}
disabled={!agent.active}
key="reassignPolicy"
>
<FormattedMessage
id="xpack.fleet.agentList.reassignActionText"
defaultMessage="Assign to new policy"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
disabled={!hasWriteCapabilites || !agent.active}
icon="trash"
onClick={() => {
onUnenrollClick();
}}
>
{isUnenrolling ? (
<FormattedMessage
id="xpack.fleet.agentList.reassignActionText"
defaultMessage="Assign to new policy"
id="xpack.fleet.agentList.forceUnenrollOneButton"
defaultMessage="Force unenroll"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
disabled={!hasWriteCapabilites || !agent.active}
icon="trash"
onClick={() => {
onUnenrollClick();
}}
>
{isUnenrolling ? (
<FormattedMessage
id="xpack.fleet.agentList.forceUnenrollOneButton"
defaultMessage="Force unenroll"
/>
) : (
<FormattedMessage
id="xpack.fleet.agentList.unenrollOneButton"
defaultMessage="Unenroll agent"
/>
)}
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="refresh"
disabled={!isAgentUpgradeable(agent, kibanaVersion)}
onClick={() => {
onUpgradeClick();
}}
>
) : (
<FormattedMessage
id="xpack.fleet.agentList.upgradeOneButton"
defaultMessage="Upgrade agent"
id="xpack.fleet.agentList.unenrollOneButton"
defaultMessage="Unenroll agent"
/>
</EuiContextMenuItem>,
]}
)}
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="refresh"
disabled={!isAgentUpgradeable(agent, kibanaVersion)}
onClick={() => {
onUpgradeClick();
}}
>
<FormattedMessage
id="xpack.fleet.agentList.upgradeOneButton"
defaultMessage="Upgrade agent"
/>
</EuiContextMenuItem>
);
}
return (
<ContextMenuActions
isOpen={isMenuOpen}
onChange={(isOpen) => setIsMenuOpen(isOpen)}
items={menuItems}
/>
);
});
Expand Down Expand Up @@ -456,6 +463,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
return (
<RowActions
agent={agent}
agentPolicy={agent.policy_id && agentPoliciesIndexedById[agent.policy_id]}
refresh={() => fetchData()}
onReassignClick={() => setAgentToReassign(agent)}
onUnenrollClick={() => setAgentToUnenroll(agent)}
Expand Down

0 comments on commit a93dd8c

Please sign in to comment.