diff --git a/web/src/components/alerting/AlertRulesPage.tsx b/web/src/components/alerting/AlertRulesPage.tsx index 5f1af6c9..ec700e20 100644 --- a/web/src/components/alerting/AlertRulesPage.tsx +++ b/web/src/components/alerting/AlertRulesPage.tsx @@ -202,7 +202,9 @@ const AlertRulesPage_: FC = () => { onFilterChange={onFilterChange} rowFilters={rowFilters} /> - {silences?.loadError && } + {silences?.loadError && !rulesAlertLoading?.loadError && ( + + )}
aria-label={t('Alerting rules')} diff --git a/web/src/components/alerting/AlertsPage.tsx b/web/src/components/alerting/AlertsPage.tsx index c35c9a72..3010d268 100644 --- a/web/src/components/alerting/AlertsPage.tsx +++ b/web/src/components/alerting/AlertsPage.tsx @@ -28,10 +28,10 @@ import { severityRowFilter, SilencesNotLoadedWarning, } from './AlertUtils'; -import Error from './Error'; import useSelectedFilters from './useSelectedFilters'; import { MonitoringProvider } from '../../contexts/MonitoringContext'; import { useAlerts } from '../../hooks/useAlerts'; +import { AccessDenied } from '../console/console-shared/src/components/empty-state/AccessDenied'; const AlertsPage_: FC = () => { const { t } = useTranslation(process.env.I18N_NAMESPACE); @@ -115,7 +115,7 @@ const AlertsPage_: FC = () => { const filteredAggregatedAlerts = getAggregateAlertsLists(filteredData); const loaded = !!rulesAlertLoading?.loaded; - const loadError = rulesAlertLoading?.loadError ? rulesAlertLoading.loadError : null; + const loadError = rulesAlertLoading?.loadError ? rulesAlertLoading.loadError : undefined; return ( <> @@ -135,10 +135,11 @@ const AlertsPage_: FC = () => { )} - {silences?.loadError && ( + {/* Only show the silences error when the alerts have loaded, since failing to load the + silences doesn't matter if the alerts haven't loaded*/} + {silences?.loadError && !loadError && ( )} - {filteredAggregatedAlerts?.length > 0 && loaded && ( @@ -159,8 +160,7 @@ const AlertsPage_: FC = () => { ))}
)} - - {loadError && } + {loadError && } {loaded && filteredAggregatedAlerts?.length === 0 && !loadError && ( )} diff --git a/web/src/components/alerting/Error.tsx b/web/src/components/alerting/Error.tsx deleted file mode 100644 index 954631e8..00000000 --- a/web/src/components/alerting/Error.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { - Alert, - AlertVariant, - Panel, - PanelMain, - PanelMainBody, - Title, -} from '@patternfly/react-core'; -import { FC } from 'react'; -import { useTranslation } from 'react-i18next'; - -type ErrorProps = { - error?: any; -}; - -const Error: FC = ({ error }) => { - const { t } = useTranslation(process.env.I18N_NAMESPACE); - - const status = error?.response?.status; - - if (status === 404) { - return ( - - - - {t('404: Not Found')} - - - - ); - } - return ( - - {error?.message} - - ); -}; - -export default Error; diff --git a/web/src/components/console/console-shared/src/components/empty-state/AccessDenied.tsx b/web/src/components/console/console-shared/src/components/empty-state/AccessDenied.tsx index 18136fbe..1a63482b 100644 --- a/web/src/components/console/console-shared/src/components/empty-state/AccessDenied.tsx +++ b/web/src/components/console/console-shared/src/components/empty-state/AccessDenied.tsx @@ -1,35 +1,26 @@ -import type { FC } from 'react'; -import { Alert, Flex, FlexItem } from '@patternfly/react-core'; +import { Alert, EmptyState, Flex, FlexItem } from '@patternfly/react-core'; import { useTranslation } from 'react-i18next'; -import { ConsoleEmptyState } from './ConsoleEmptyState'; -import * as restrictedSignImg from '../../../../imgs/restricted-sign.svg'; +import RestrictedSignImg from '../../../../imgs/restricted-sign.svg'; const RestrictedSignIcon = () => { const { t } = useTranslation(process.env.I18N_NAMESPACE); - return {t('Restricted; + return {t('Restricted; }; -export const AccessDenied: FC = ({ children }) => { +export const AccessDenied = ({ message }: { message: string }) => { const { t } = useTranslation(process.env.I18N_NAMESPACE); return ( - + {t("You don't have access to this section due to cluster policy")} - {children && ( - - - {children} - - - )} + + + {message} + + - + ); }; -AccessDenied.displayName = 'AccessDenied'; diff --git a/web/src/components/console/console-shared/src/components/status/StatusBox.tsx b/web/src/components/console/console-shared/src/components/status/StatusBox.tsx index 07015fe6..fd397775 100644 --- a/web/src/components/console/console-shared/src/components/status/StatusBox.tsx +++ b/web/src/components/console/console-shared/src/components/status/StatusBox.tsx @@ -54,7 +54,7 @@ export const StatusBox: FC = (props) => { ); } if (status === 403) { - return {loadError.message}; + return ; } if (loadError instanceof IncompleteDataError && !_.isEmpty(data)) { diff --git a/web/src/store/thunks.ts b/web/src/store/thunks.ts index e4c8052d..b7824f55 100644 --- a/web/src/store/thunks.ts +++ b/web/src/store/thunks.ts @@ -33,6 +33,13 @@ export const fetchAlertingData = ]); if (rulesResponse.status === 'rejected') { + if (rulesResponse.reason?.response) { + // Set the error message to be the RBAC denial reason + const responseText = await rulesResponse.reason?.response?.text(); + if (responseText) { + rulesResponse.reason.message = responseText; + } + } dispatch(alertingSetErrored(prometheus, namespace, rulesResponse.reason)); } else { const { alerts, rules } = getAlertsAndRules(rulesResponse.value.data); @@ -40,6 +47,13 @@ export const fetchAlertingData = } if (silencesResponse.status === 'rejected') { + if (silencesResponse.reason?.response) { + // Set the error message to be the RBAC denial reason + const responseText = await silencesResponse.reason?.response?.text(); + if (responseText) { + silencesResponse.reason.message = responseText; + } + } dispatch(alertingSetSilencesErrored(prometheus, namespace, silencesResponse.reason)); } else { const silences = silencesResponse.value.map((silence) => ({