Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 2104859: Add "Copy SSH command" to VM actions
Add "Copy SSH command" option to kebab menu for the actions in the VM list, also to Actions button in the VM details view/tabs. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2104859
- Loading branch information
Showing
6 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/views/virtualmachines/actions/components/VirtualMachineActions/VirtualMachineActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as React from 'react'; | ||
|
||
import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt'; | ||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { getContentScrollableElement } from '@kubevirt-utils/utils/utils'; | ||
import { Action } from '@openshift-console/dynamic-plugin-sdk'; | ||
// import { LazyActionMenu } from '@openshift-console/dynamic-plugin-sdk-internal'; | ||
import { | ||
Dropdown, | ||
DropdownItem, | ||
DropdownPosition, | ||
DropdownToggle, | ||
KebabToggle, | ||
} from '@patternfly/react-core'; | ||
|
||
import useVirtualMachineActionsProvider from '../../hooks/useVirtualMachineActionsProvider'; | ||
|
||
type VirtualMachinesInsanceActionsProps = { vm: V1VirtualMachine; isKebabToggle?: boolean }; | ||
|
||
const VirtualMachineActions: React.FC<VirtualMachinesInsanceActionsProps> = ({ | ||
vm, | ||
isKebabToggle, | ||
}) => { | ||
const { t } = useKubevirtTranslation(); | ||
// TODO: use LazyActionMenu when fixed | ||
// return ( | ||
// <LazyActionMenu | ||
// variant={variant} | ||
// key={vm?.metadata?.name} | ||
// context={{ [VirtualMachineModelRef]: vm }} | ||
// /> | ||
// ); | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [actions] = useVirtualMachineActionsProvider(vm); | ||
|
||
const handleClick = (action: Action) => { | ||
if (typeof action?.cta === 'function') { | ||
action?.cta(); | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dropdown | ||
menuAppendTo={getContentScrollableElement} | ||
data-test-id="virtual-machine-actions" | ||
isPlain={isKebabToggle} | ||
isOpen={isOpen} | ||
position={DropdownPosition.right} | ||
toggle={ | ||
isKebabToggle ? ( | ||
<KebabToggle onToggle={setIsOpen} /> | ||
) : ( | ||
<DropdownToggle onToggle={setIsOpen}>{t('Actions')}</DropdownToggle> | ||
) | ||
} | ||
dropdownItems={actions?.map((action) => ( | ||
<DropdownItem | ||
data-test-id={`${action.id}`} | ||
key={action?.id} | ||
onClick={() => handleClick(action)} | ||
isDisabled={action?.disabled} | ||
description={action?.description} | ||
> | ||
{action?.label} | ||
{action?.icon && <span className="text-muted"> {action.icon}</span>} | ||
</DropdownItem> | ||
))} | ||
/> | ||
); | ||
}; | ||
|
||
export default VirtualMachineActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters