diff --git a/hivemq-edge/src/frontend/src/extensions/datahub/components/controls/DeleteListener.tsx b/hivemq-edge/src/frontend/src/extensions/datahub/components/controls/DeleteListener.tsx index 76c30ea8e9..13739059ce 100644 --- a/hivemq-edge/src/frontend/src/extensions/datahub/components/controls/DeleteListener.tsx +++ b/hivemq-edge/src/frontend/src/extensions/datahub/components/controls/DeleteListener.tsx @@ -67,7 +67,7 @@ const DeleteListener: FC = () => { status: 'error', description: ( - {t('workspace.deletion.guards.message', { count: SelectedElementsCount })} + {t('workspace.guards.delete.message', { count: SelectedElementsCount })} {allErrors.map((error, index) => ( {error} diff --git a/hivemq-edge/src/frontend/src/extensions/datahub/hooks/usePolicyGuards.tsx b/hivemq-edge/src/frontend/src/extensions/datahub/hooks/usePolicyGuards.tsx index bf4e764fcf..6b773c662c 100644 --- a/hivemq-edge/src/frontend/src/extensions/datahub/hooks/usePolicyGuards.tsx +++ b/hivemq-edge/src/frontend/src/extensions/datahub/hooks/usePolicyGuards.tsx @@ -1,11 +1,13 @@ -import useDataHubDraftStore from '@datahub/hooks/useDataHubDraftStore.ts' +import { useTranslation } from 'react-i18next' import { useMemo } from 'react' import { Node } from 'reactflow' +import { Alert, AlertDescription, AlertIcon, AlertTitle } from '@chakra-ui/react' +import useDataHubDraftStore from '@datahub/hooks/useDataHubDraftStore.ts' import { DesignerStatus, TopicFilterData } from '@datahub/types.ts' import { canDeleteNode } from '@datahub/utils/node.utils.ts' -import { Alert, AlertIcon, AlertTitle } from '@chakra-ui/react' export const usePolicyGuards = (selectedNode: string) => { + const { t } = useTranslation('datahub') const { status } = useDataHubDraftStore() const { nodes } = useDataHubDraftStore() @@ -16,23 +18,22 @@ export const usePolicyGuards = (selectedNode: string) => { const isPolicyEditable = useMemo(() => status !== DesignerStatus.LOADED, [status]) const protectedNode = adapterNode && canDeleteNode(adapterNode, status) - console.log('XXXXXX isPolicyEditable', isPolicyEditable, protectedNode) let guardAlert = null if (!isPolicyEditable) { guardAlert = ( - The policy is in read-only mode - The element cannot be modified + {t('workspace.guards.readonly.title')} + {t('workspace.guards.readonly.message')} ) } else if (protectedNode && !protectedNode.delete) { guardAlert = ( - The element is protected - {protectedNode?.error} + {t('workspace.guards.protected.title')} + {t('workspace.guards.protected.message')} ) } diff --git a/hivemq-edge/src/frontend/src/extensions/datahub/locales/en/datahub.json b/hivemq-edge/src/frontend/src/extensions/datahub/locales/en/datahub.json index a8dacbb91a..661345f413 100644 --- a/hivemq-edge/src/frontend/src/extensions/datahub/locales/en/datahub.json +++ b/hivemq-edge/src/frontend/src/extensions/datahub/locales/en/datahub.json @@ -297,12 +297,22 @@ "message_MODE_ONLY_one": "Are you sure you want to delete {{ count }} node? The operation cannot be reversed.", "message_MODE_ONLY_other": "Are you sure you want to delete {{ count }} nodes? The operation cannot be reversed.", "message_BOTH": "Are you sure you want to delete {{ count }} nodes and connections? The operation cannot be reversed." - }, - "guards": { + } + }, + "guards": { + "delete": { "message_one": "The selected element cannot be deleted because of some constraints", "message_other": "The selected elements cannot be deleted because of some constraints", "topicFilter": "Topic filter cannot be modified once published", "policyNode": "Policy node cannot be deleted once published" + }, + "readonly": { + "title": "The policy is in read-only mode", + "message": "The element cannot be modified" + }, + "protected": { + "title": "The element is protected", + "message": "The element cannot be modified" } } }, diff --git a/hivemq-edge/src/frontend/src/extensions/datahub/utils/node.utils.ts b/hivemq-edge/src/frontend/src/extensions/datahub/utils/node.utils.ts index 85169a6f55..87629eb61e 100644 --- a/hivemq-edge/src/frontend/src/extensions/datahub/utils/node.utils.ts +++ b/hivemq-edge/src/frontend/src/extensions/datahub/utils/node.utils.ts @@ -309,10 +309,10 @@ export const canDeleteNode = (node: Node, status?: DesignerStatus): { delete: bo return { delete: true } } if (isTopicFilterNodeType(node)) { - return { delete: false, error: i18n.t('datahub:workspace.deletion.guards.topicFilter') } + return { delete: false, error: i18n.t('datahub:workspace.guards.delete.topicFilter') } } if (isBehaviorPolicyNodeType(node) || isDataPolicyNodeType(node)) { - return { delete: false, error: i18n.t('datahub:workspace.deletion.guards.policyNode') } + return { delete: false, error: i18n.t('datahub:workspace.guards.delete.policyNode') } } return { delete: true } } @@ -328,7 +328,7 @@ export const canDeleteEdge = ( const source = nodes.find((node) => node.id === edge.source) const target = nodes.find((node) => node.id === edge.target) if (source && target && isDataPolicyNodeType(target) && isTopicFilterNodeType(source)) - return { delete: false, error: i18n.t('datahub:workspace.deletion.guards.topicFilter') } + return { delete: false, error: i18n.t('datahub:workspace.guards.delete.topicFilter') } } return { delete: true } }