-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use context for Side Panel components - add delete modal to handle deletion of namespaces and keys - add context menu button on every rendered link `
- Loading branch information
Showing
13 changed files
with
350 additions
and
98 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,84 @@ | ||
import { | ||
Modal, | ||
ModalContent, | ||
ModalActions, | ||
ModalTitle, | ||
Button, | ||
ButtonStrip, | ||
} from '@dhis2/ui' | ||
import React from 'react' | ||
import { useParams } from 'react-router-dom' | ||
import { useSidePanelContext } from '../../context/SidePanelContext' | ||
import i18n from '../../locales' | ||
|
||
const DeleteModal = ({ | ||
handleDeleteAction, | ||
}: { | ||
handleDeleteAction: () => void | ||
}) => { | ||
const { | ||
panelType: type, | ||
totalItems, | ||
selectedLinkItem: value, | ||
setOpenDeleteModal, | ||
} = useSidePanelContext() | ||
const { namespace: currentNamespace } = useParams() | ||
|
||
const title = | ||
type === 'namespace' ? i18n.t('Delete Namespace') : i18n.t('Delete Key') | ||
|
||
return ( | ||
<Modal position="middle"> | ||
<ModalTitle>{title}</ModalTitle> | ||
<ModalContent> | ||
{type === 'namespace' && ( | ||
<> | ||
<p> | ||
{i18n.t( | ||
`Are you sure you want to delete '${value}'?` | ||
)} | ||
</p> | ||
<p> | ||
{i18n.t( | ||
`This will delete all the keys in this namespace` | ||
)} | ||
</p> | ||
</> | ||
)} | ||
{type === 'keys' && ( | ||
<> | ||
<p> | ||
{i18n.t( | ||
`Are you sure you want to delete '${value}' in ${currentNamespace}?` | ||
)} | ||
</p> | ||
{totalItems < 2 && ( | ||
<p> | ||
{i18n.t( | ||
`This will also delete the namespace '${currentNamespace}'` | ||
)} | ||
</p> | ||
)} | ||
</> | ||
)} | ||
</ModalContent> | ||
<ModalActions> | ||
<ButtonStrip end> | ||
<Button secondary onClick={() => setOpenDeleteModal(false)}> | ||
{i18n.t('Cancel')} | ||
</Button> | ||
<Button | ||
destructive | ||
onClick={() => { | ||
handleDeleteAction() | ||
setOpenDeleteModal(false) | ||
}} | ||
> | ||
{i18n.t('Delete')} | ||
</Button> | ||
</ButtonStrip> | ||
</ModalActions> | ||
</Modal> | ||
) | ||
} | ||
export default DeleteModal |
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,62 @@ | ||
import { Button, IconMore16, Popover, IconDelete16 } from '@dhis2/ui' | ||
import React, { useRef } from 'react' | ||
import { useSidePanelContext } from '../../context/SidePanelContext' | ||
import i18n from '../../locales' | ||
import classes from '../Panel.module.css' | ||
|
||
type ContextMenuButtonProps = { | ||
handleContextMenu: () => void | ||
openContextMenu: boolean | ||
setOpenContextMenu: (boolean) => void | ||
} | ||
|
||
const ContextMenuButton = ({ | ||
handleContextMenu, | ||
openContextMenu, | ||
setOpenContextMenu, | ||
}: ContextMenuButtonProps) => { | ||
const ref = useRef(null) | ||
const { setOpenDeleteModal } = useSidePanelContext() | ||
|
||
return ( | ||
<div ref={ref}> | ||
<Button | ||
aria-label="More" | ||
icon={<IconMore16 />} | ||
name="more" | ||
onClick={handleContextMenu} | ||
title="More" | ||
/> | ||
{openContextMenu && ( | ||
<Popover | ||
reference={ref} | ||
placement="right-start" | ||
onClickOutside={() => setOpenContextMenu(false)} | ||
> | ||
<div | ||
className={classes.contextMenu} | ||
style={{ | ||
width: '150px', | ||
padding: 6, | ||
}} | ||
> | ||
<Button | ||
aria-label={i18n.t('delete')} | ||
icon={<IconDelete16 />} | ||
name={i18n.t('delete')} | ||
onClick={() => { | ||
setOpenContextMenu(false) | ||
setOpenDeleteModal(true) | ||
}} | ||
title={i18n.t('delete')} | ||
> | ||
{i18n.t('Delete')} | ||
</Button> | ||
</div> | ||
</Popover> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default ContextMenuButton |
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
Oops, something went wrong.