Skip to content

Commit

Permalink
refactor(29444): fix translations
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Jan 15, 2025
1 parent 3c5218c commit 828aca0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const DeleteListener: FC = () => {
status: 'error',
description: (
<VStack alignItems="flex-start">
<Text>{t('workspace.deletion.guards.message', { count: SelectedElementsCount })}</Text>
<Text>{t('workspace.guards.delete.message', { count: SelectedElementsCount })}</Text>
<UnorderedList>
{allErrors.map((error, index) => (
<ListItem key={`toto-${index}`}>{error}</ListItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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 = (
<Alert status="info" mb={5}>
<AlertIcon />
<AlertTitle>The policy is in read-only mode</AlertTitle>
The element cannot be modified
<AlertTitle>{t('workspace.guards.readonly.title')}</AlertTitle>
<AlertDescription>{t('workspace.guards.readonly.message')}</AlertDescription>
</Alert>
)
} else if (protectedNode && !protectedNode.delete) {
guardAlert = (
<Alert status="info" mb={5}>
<AlertIcon />
<AlertTitle>The element is protected</AlertTitle>
{protectedNode?.error}
<AlertTitle>{t('workspace.guards.protected.title')}</AlertTitle>
<AlertDescription>{t('workspace.guards.protected.message')}</AlertDescription>
</Alert>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -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 }
}
Expand Down

0 comments on commit 828aca0

Please sign in to comment.