diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Policies.spec.js b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Policies.spec.js index 57357fcb4ff..72dfbe05e3c 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Policies.spec.js +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Policies.spec.js @@ -59,7 +59,7 @@ const addRule = (rulename, ruleDescription, descriptionIndex) => { .scrollIntoView() .type(ruleDescription); //Select resource dropdown - cy.get('[data-testid="resuorces"]') + cy.get('[data-testid="resources"]') .scrollIntoView() .should('be.visible') .click(); diff --git a/openmetadata-ui/src/main/resources/ui/src/locale/languages/en-us.json b/openmetadata-ui/src/main/resources/ui/src/locale/languages/en-us.json index 423bfaa797d..61d16862f58 100644 --- a/openmetadata-ui/src/main/resources/ui/src/locale/languages/en-us.json +++ b/openmetadata-ui/src/main/resources/ui/src/locale/languages/en-us.json @@ -201,7 +201,14 @@ "end-date": "End Date", "show-deleted": "Show deleted", "add-bot": "Add Bot", - "search-for-bots": "Search for bots..." + "search-for-bots": "Search for bots...", + "condition-is-invalid": "Condition is invalid", + "rule-name": "Rule Name", + "write-your-description": "Write your description", + "select-resource": "Select Resources", + "select-rule-effect": "Select Rule Effect", + "field-required": "{{field}} is required", + "field-required-plural": "{{field}} are required" }, "message": { "service-email-required": "Service account Email is required", diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/AddPolicyPage/AddPolicyPage.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/AddPolicyPage/AddPolicyPage.test.tsx index be6fa945531..a38a14320e4 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/AddPolicyPage/AddPolicyPage.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/AddPolicyPage/AddPolicyPage.test.tsx @@ -78,7 +78,7 @@ describe('Test Add Policy Page', () => { const ruleName = await screen.findByTestId('rule-name'); - const resources = await screen.findByTestId('resuorces'); + const resources = await screen.findByTestId('resources'); const operations = await screen.findByTestId('operations'); const effect = await screen.findByTestId('effect'); diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.test.tsx index ac739af97b8..9fee6d125ee 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.test.tsx @@ -65,7 +65,7 @@ describe('Test Rule Form Component', () => { const ruleName = await screen.findByTestId('rule-name'); - const resources = await screen.findByTestId('resuorces'); + const resources = await screen.findByTestId('resources'); const operations = await screen.findByTestId('operations'); const effect = await screen.findByTestId('effect'); diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.tsx index 2a4bd2fbf64..2228c663293 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/PoliciesPage/RuleForm/RuleForm.tsx @@ -16,6 +16,7 @@ import { BaseOptionType } from 'antd/lib/select'; import { AxiosError } from 'axios'; import { capitalize, startCase, uniq, uniqBy } from 'lodash'; import React, { FC, useEffect, useMemo, useState } from 'react'; +import { useTranslation } from 'react-i18next'; import { getPolicyFunctions, getPolicyResources, @@ -40,6 +41,7 @@ export interface RuleFormProps { } const RuleForm: FC = ({ ruleData, setRuleData }) => { + const { t } = useTranslation(); const [policyResources, setPolicyResources] = useState( [] ); @@ -51,8 +53,8 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { ); const [validationError, setValidationError] = useState(''); - const [isValidatingCondition, setIsvalidating] = useState(false); - const [isValidCondition, setIsvalidCondition] = useState(false); + const [isValidatingCondition, setIsValidating] = useState(false); + const [isValidCondition, setIsValidCondition] = useState(false); /** * Derive the resources from policy resources @@ -108,15 +110,18 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { return option; }, [ruleData.resources, policyResources]); - const getConditionOptions = (funtions: Function[]) => { - return funtions.reduce((prev: BaseOptionType[], curr: Function) => { - const currentValues = (curr.examples || []).map((example: string) => ({ - label: example, - value: example, - })); + const getConditionOptions = (conditionFunctions: Function[]) => { + return conditionFunctions.reduce( + (prev: BaseOptionType[], curr: Function) => { + const currentValues = (curr.examples || []).map((example: string) => ({ + label: example, + value: example, + })); - return uniqBy([...prev, ...currentValues], 'value'); - }, []); + return uniqBy([...prev, ...currentValues], 'value'); + }, + [] + ); }; const handleConditionSearch = (value: string) => { @@ -138,7 +143,7 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { } }; - const fetchPolicyFuntions = async () => { + const fetchPolicyFunctions = async () => { try { const data = await getPolicyFunctions(); setPolicyFunctions(data.data || []); @@ -148,9 +153,10 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { }; const handleConditionValidation = async (condition: string) => { - const defaultErrorText = 'Condition is invalid'; + const defaultErrorText = t('label.condition-is-invalid'); + if (condition) { - setIsvalidating(true); + setIsValidating(true); try { const response = await validateRuleCondition(condition); @@ -161,22 +167,22 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { const check = [200, 204].includes(response.status); if (check) { setValidationError(''); - setIsvalidCondition(true); + setIsValidCondition(true); } else { setValidationError(defaultErrorText); } } catch (error) { setValidationError(getErrorText(error as AxiosError, defaultErrorText)); - setIsvalidCondition(false); + setIsValidCondition(false); } finally { - setIsvalidating(false); + setIsValidating(false); } } }; useEffect(() => { fetchPolicyResources(); - fetchPolicyFuntions(); + fetchPolicyFunctions(); }, []); useEffect(() => { @@ -186,18 +192,19 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { return ( <> @@ -205,11 +212,11 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { } /> - + setRuleData((prev: Rule) => ({ ...prev, description: value })) @@ -217,18 +224,21 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { /> { @@ -240,11 +250,14 @@ const RuleForm: FC = ({ ruleData, setRuleData }) => { /> = ({ ruleData, setRuleData }) => { /> - + <>