generated from openshift/console-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jason Madigan <[email protected]>
- Loading branch information
1 parent
17a5d6f
commit 95dea1e
Showing
11 changed files
with
800 additions
and
499 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as React from 'react'; | ||
import { EllipsisVIcon } from '@patternfly/react-icons'; | ||
import { Dropdown, DropdownItem, DropdownList, MenuToggle, MenuToggleElement, Button, ButtonVariant } from '@patternfly/react-core'; | ||
import { Modal, ModalBody, ModalFooter, ModalHeader } from '@patternfly/react-core/next'; | ||
import { k8sDelete, K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk'; | ||
import getModelFromResource from '../utils/getModelFromResource'; // Assume you have a utility for getting the model from the resource | ||
|
||
type DropdownWithKebabProps = { | ||
obj: K8sResourceCommon; | ||
}; | ||
|
||
const DropdownWithKebab: React.FC<DropdownWithKebabProps> = ({ obj }) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [isDeleteModalOpen, setIsDeleteModalOpen] = React.useState(false); | ||
|
||
const onToggleClick = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const onDeleteConfirm = async () => { | ||
try { | ||
const model = getModelFromResource(obj); | ||
await k8sDelete({ model, resource: obj }); | ||
console.log('Successfully deleted', obj.metadata.name); | ||
} catch (error) { | ||
console.error('Failed to delete', obj.metadata.name, error); | ||
} finally { | ||
setIsDeleteModalOpen(false); | ||
} | ||
}; | ||
|
||
const onDeleteClick = () => { | ||
setIsDeleteModalOpen(true); | ||
}; | ||
|
||
const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => { | ||
setIsOpen(false); | ||
if (value === 'delete') { | ||
onDeleteClick(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Dropdown | ||
isOpen={isOpen} | ||
onSelect={onSelect} | ||
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)} | ||
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( | ||
<MenuToggle | ||
ref={toggleRef} | ||
aria-label="kebab dropdown toggle" | ||
variant="plain" | ||
onClick={onToggleClick} | ||
isExpanded={isOpen} | ||
> | ||
<EllipsisVIcon /> | ||
</MenuToggle> | ||
)} | ||
shouldFocusToggleOnSelect | ||
> | ||
<DropdownList> | ||
<DropdownItem value="edit" key="edit"> | ||
Edit | ||
</DropdownItem> | ||
<DropdownItem value="delete" key="delete"> | ||
Delete | ||
</DropdownItem> | ||
</DropdownList> | ||
</Dropdown> | ||
|
||
<Modal | ||
isOpen={isDeleteModalOpen} | ||
onClose={() => setIsDeleteModalOpen(false)} | ||
aria-labelledby="delete-modal-title" | ||
aria-describedby="delete-modal-body" | ||
variant="medium" | ||
> | ||
<ModalHeader title="Confirm Delete" /> | ||
<ModalBody> | ||
Are you sure you want to delete the resource <b>{obj.metadata.name}</b>? | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button key="confirm" variant={ButtonVariant.danger} onClick={onDeleteConfirm}> | ||
Delete | ||
</Button> | ||
<Button key="cancel" variant={ButtonVariant.link} onClick={() => setIsDeleteModalOpen(false)}> | ||
Cancel | ||
</Button> | ||
</ModalFooter> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default DropdownWithKebab; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.