diff --git a/i18n/en.pot b/i18n/en.pot index a46ec1f..6786514 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-12-11T00:48:22.223Z\n" -"PO-Revision-Date: 2024-12-11T00:48:22.223Z\n" +"POT-Creation-Date: 2024-12-11T01:36:42.741Z\n" +"PO-Revision-Date: 2024-12-11T01:36:42.741Z\n" msgid "View keys" msgstr "View keys" @@ -23,6 +23,24 @@ msgstr "An error occurred" msgid "Error" msgstr "Error" +msgid "Add New Namespace" +msgstr "Add New Namespace" + +msgid "Add New Key" +msgstr "Add New Key" + +msgid "Add Namespace" +msgstr "Add Namespace" + +msgid "Add Key" +msgstr "Add Key" + +msgid "New namespace" +msgstr "New namespace" + +msgid "New key" +msgstr "New key" + msgid "Namespace" msgstr "Namespace" @@ -32,6 +50,12 @@ msgstr "Key" msgid "Cancel" msgstr "Cancel" +msgid "This will delete all the keys in this namespace" +msgstr "This will delete all the keys in this namespace" + +msgid "Delete" +msgstr "Delete" + msgid "Key successfully updated" msgstr "Key successfully updated" @@ -59,20 +83,5 @@ msgstr "Search" msgid "Key created successfully" msgstr "Key created successfully" -msgid "Add New Namespace" -msgstr "Add New Namespace" - -msgid "Add New Key" -msgstr "Add New Key" - -msgid "Add Namespace" -msgstr "Add Namespace" - -msgid "Add Key" -msgstr "Add Key" - -msgid "New namespace" -msgstr "New namespace" - -msgid "New key" -msgstr "New key" +msgid "There was an error creating the key" +msgstr "There was an error creating the key" diff --git a/src/components/Panel.module.css b/src/components/Panel.module.css index 05d03f1..fa496b7 100644 --- a/src/components/Panel.module.css +++ b/src/components/Panel.module.css @@ -34,6 +34,7 @@ margin: 0.5em 0 0.3em 0; width: 100%; border: none; + justify-content: start; } .sidebarList ul { @@ -97,3 +98,11 @@ .navLink.active:hover { background: var(--colors-teal050); } + +/* context menu */ +.contextMenu button { + background-color: transparent; + border: none; + width: 100%; + justify-content: start; +} diff --git a/src/components/modals/CreateModal.tsx b/src/components/modals/CreateModal.tsx index acff421..dc872b5 100644 --- a/src/components/modals/CreateModal.tsx +++ b/src/components/modals/CreateModal.tsx @@ -8,6 +8,7 @@ import { InputField, } from '@dhis2/ui' import React from 'react' +import { useSidePanelContext } from '../../context/SidePanelContext' import i18n from '../../locales' import { CreateFieldValues } from '../sidepanel/SidePanel' @@ -16,9 +17,6 @@ type CreateModalProps = { values: CreateFieldValues setValues: (values) => void closeModal: () => void - title: string - type: string - buttonLabel: string } const CreateModal = ({ @@ -26,12 +24,18 @@ const CreateModal = ({ values, setValues, closeModal, - title, - type, - buttonLabel, }: CreateModalProps) => { + const { panelType: type } = useSidePanelContext() + + const title = + type === 'namespace' + ? i18n.t('Add New Namespace') + : i18n.t('Add New Key') + const buttonLabel = + type === 'namespace' ? i18n.t('Add Namespace') : i18n.t('Add Key') + return ( - + {title} {type === 'namespace' && ( diff --git a/src/components/modals/DeleteModal.tsx b/src/components/modals/DeleteModal.tsx new file mode 100644 index 0000000..5d8b7b0 --- /dev/null +++ b/src/components/modals/DeleteModal.tsx @@ -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 ( + + {title} + + {type === 'namespace' && ( + <> +

+ {i18n.t( + `Are you sure you want to delete '${value}'?` + )} +

+

+ {i18n.t( + `This will delete all the keys in this namespace` + )} +

+ + )} + {type === 'keys' && ( + <> +

+ {i18n.t( + `Are you sure you want to delete '${value}' in ${currentNamespace}?` + )} +

+ {totalItems < 2 && ( +

+ {i18n.t( + `This will also delete the namespace '${currentNamespace}'` + )} +

+ )} + + )} +
+ + + + + + +
+ ) +} +export default DeleteModal diff --git a/src/components/panels/EditPanel.tsx b/src/components/panels/EditPanel.tsx index 741ee0d..4156b58 100644 --- a/src/components/panels/EditPanel.tsx +++ b/src/components/panels/EditPanel.tsx @@ -75,6 +75,7 @@ const EditPanel = () => { }) } catch (error) { // setUpdateError(error.message) + console.error(error.message) const message = i18n.t('There was an error updating the key') showError(message) } diff --git a/src/components/sidepanel/ContextButton.tsx b/src/components/sidepanel/ContextButton.tsx new file mode 100644 index 0000000..4d9603a --- /dev/null +++ b/src/components/sidepanel/ContextButton.tsx @@ -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 ( +
+ +
+ + )} + + ) +} + +export default ContextMenuButton diff --git a/src/components/sidepanel/CreateButton.tsx b/src/components/sidepanel/CreateButton.tsx index 071bfd3..6736dbd 100644 --- a/src/components/sidepanel/CreateButton.tsx +++ b/src/components/sidepanel/CreateButton.tsx @@ -1,15 +1,18 @@ import { Button } from '@dhis2/ui' import { IconAdd16 } from '@dhis2/ui-icons' import React from 'react' +import { useSidePanelContext } from '../../context/SidePanelContext' import i18n from '../../locales' import classes from '../Panel.module.css' type CreateButtonProps = { - label: string handleClick: () => void } -const CreateButton = ({ label, handleClick }: CreateButtonProps) => { +const CreateButton = ({ handleClick }: CreateButtonProps) => { + const { panelType: type } = useSidePanelContext() + const label = + type === 'namespace' ? i18n.t('New namespace') : i18n.t('New key') return (