From 8e3c5b650572586b5fdb59ff835cfdfd5312b8b3 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Sat, 12 Apr 2025 05:06:34 +0530 Subject: [PATCH] handle error cases in PolicyManager --- src/features/admin/policy-manager.tsx | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/features/admin/policy-manager.tsx b/src/features/admin/policy-manager.tsx index 5ad28d9c5..c62acd355 100644 --- a/src/features/admin/policy-manager.tsx +++ b/src/features/admin/policy-manager.tsx @@ -26,6 +26,7 @@ const messages = defineMessages({ helpTitle: { id: 'admin.policies.help.title', defaultMessage: 'Help' }, helpButton: { id: 'admin.policies.help.button', defaultMessage: 'Help' }, okay: { id: 'admin.policies.help.okay', defaultMessage: 'Okay' }, + policyExists: { id: 'admin.policies.policy_exists', defaultMessage: 'Policy already exists!' }, }); const PolicySuggestion: FC<{ item: PolicyItem }> = ({ item }) => { @@ -41,7 +42,18 @@ const PolicyManager: FC = () => { const intl = useIntl(); const [showHelpModal, setShowHelpModal] = useState(false); const [isWelcomeDialog, setIsWelcomeDialog] = useState(false); - const { allPolicies = [], isLoading, isFetched, storedPolicies, updatePolicy, isUpdating } = useModerationPolicies(); + const { + allPolicies = [], + isLoading, + isFetched, + storedPolicies, + updatePolicy, + isUpdating, + allPoliciesError, + storedPoliciesError, + allPoliciesIsError, + storedPoliciesIsError, + } = useModerationPolicies(); // get the current set of policies out of the API response const initialPolicies = storedPolicies?.spec?.policies ?? []; @@ -157,7 +169,7 @@ const PolicyManager: FC = () => { const newPolicy: PolicySpecItem = { name: policy.internalName, params: {} }; dispatch({ type: 'ADD_POLICY', policy: newPolicy }); } else { - toast.error('Policy already exists!'); + toast.error(intl.formatMessage(messages.policyExists)); } } clear(); // clear the text field @@ -178,6 +190,18 @@ const PolicyManager: FC = () => { {intl.formatMessage(messages.noPolicyConfigured)} ); + } else if (allPoliciesIsError) { + return ( + + {allPoliciesError?.message} + + ); + } else if (storedPoliciesIsError) { + return ( + + {storedPoliciesError?.message} + + ); } else { // If we're not loading but data isn't fetched yet, this prevents flashing "no policies" return (