From a18a3d76280739b9e05de4282ec15f1773444a81 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:41:18 +0200 Subject: [PATCH] Show No attempts instead of OK when there is no attempt for notifier (#56494) --- .../components/receivers/ReceiversTable.tsx | 88 +++++++++++++------ 1 file changed, 63 insertions(+), 25 deletions(-) diff --git a/public/app/features/alerting/unified/components/receivers/ReceiversTable.tsx b/public/app/features/alerting/unified/components/receivers/ReceiversTable.tsx index cd6cb19e950..1068733f06e 100644 --- a/public/app/features/alerting/unified/components/receivers/ReceiversTable.tsx +++ b/public/app/features/alerting/unified/components/receivers/ReceiversTable.tsx @@ -87,23 +87,40 @@ function ReceiverError({ errorCount, errorDetail }: ReceiverErrorProps) { color="orange" icon="exclamation-triangle" text={`${errorCount} ${pluralize('error', errorCount)}`} - tooltip={errorDetail} + tooltip={errorDetail ?? 'Error'} /> ); } -interface ReceiverHealthProps { - errorsByReceiver: number; +interface NotifierHealthProps { + errorsByNotifier: number; errorDetail?: string; + lastNotify: string; } -function ReceiverHealth({ errorsByReceiver, errorDetail }: ReceiverHealthProps) { - return errorsByReceiver > 0 ? ( - +function NotifierHealth({ errorsByNotifier, errorDetail, lastNotify }: NotifierHealthProps) { + const noErrorsColor = isLastNotifyNullDate(lastNotify) ? 'orange' : 'green'; + const noErrorsText = isLastNotifyNullDate(lastNotify) ? 'No attempts' : 'OK'; + return errorsByNotifier > 0 ? ( + ) : ( - + ); } +interface ReceiverHealthProps { + errorsByReceiver: number; + someWithNoAttempt: boolean; +} + +function ReceiverHealth({ errorsByReceiver, someWithNoAttempt }: ReceiverHealthProps) { + const noErrorsColor = someWithNoAttempt ? 'orange' : 'green'; + const noErrorsText = someWithNoAttempt ? 'No attempts' : 'OK'; + return errorsByReceiver > 0 ? ( + + ) : ( + + ); +} const useContactPointsState = (alertManagerName: string) => { const contactPointsStateRequest = useUnifiedAlertingSelector((state) => state.contactPointsState); const { result: contactPointsState } = (alertManagerName && contactPointsStateRequest) || initialAsyncRequestState; @@ -135,11 +152,10 @@ type NotifierItemTableProps = DynamicTableItemProps; interface NotifiersTableProps { notifiersState: NotifiersState; } +const isLastNotifyNullDate = (lastNotify: string) => lastNotify === '0001-01-01T00:00:00.000Z'; function LastNotify({ lastNotifyDate }: { lastNotifyDate: string }) { - const isLastNotifyNullDate = lastNotifyDate === '0001-01-01T00:00:00.000Z'; - - if (isLastNotifyNullDate) { + if (isLastNotifyNullDate(lastNotifyDate)) { return <>{'-'}; } else { return ( @@ -158,8 +174,14 @@ function NotifiersTable({ notifiersState }: NotifiersTableProps) { { id: 'health', label: 'Health', - renderCell: ({ data: { lastError } }) => { - return ; + renderCell: ({ data: { lastError, lastNotify } }) => { + return ( + + ); }, size: 0.5, }, @@ -190,16 +212,18 @@ function NotifiersTable({ notifiersState }: NotifiersTableProps) { ]; } const notifierRows: NotifierItemTableProps[] = Object.entries(notifiersState).flatMap((typeState) => - typeState[1].map((notifierStatus, index) => ({ - id: index, - data: { - type: typeState[0], - lastError: notifierStatus.lastNotifyAttemptError, - lastNotify: notifierStatus.lastNotifyAttempt, - lastNotifyDuration: notifierStatus.lastNotifyAttemptDuration, - sendResolved: notifierStatus.sendResolved, - }, - })) + typeState[1].map((notifierStatus, index) => { + return { + id: index, + data: { + type: typeState[0], + lastError: notifierStatus.lastNotifyAttemptError, + lastNotify: notifierStatus.lastNotifyAttempt, + lastNotifyDuration: notifierStatus.lastNotifyAttemptDuration, + sendResolved: notifierStatus.sendResolved, + }, + }; + }) ); return ; @@ -317,6 +341,15 @@ export const ReceiversTable: FC = ({ config, alertManagerName }) => { ); }; +const errorsByReceiver = (contactPointsState: ContactPointsState, receiverName: string) => + contactPointsState?.receivers[receiverName]?.errorCount ?? 0; + +const someNotifiersWithNoAttempt = (contactPointsState: ContactPointsState, receiverName: string) => { + const notifiers = Object.values(contactPointsState?.receivers[receiverName]?.notifiers ?? {}); + const hasSomeWitNoAttempt = + notifiers.length === 0 || notifiers.flat().some((status) => isLastNotifyNullDate(status.lastNotifyAttempt)); + return hasSomeWitNoAttempt; +}; function useGetColumns( alertManagerName: string, @@ -354,9 +387,14 @@ function useGetColumns( id: 'health', label: 'Health', renderCell: ({ data: { name } }) => { - const errorsByReceiver = (contactPointsState: ContactPointsState, receiverName: string) => - contactPointsState?.receivers[receiverName]?.errorCount ?? 0; - return contactPointsState && ; + return ( + contactPointsState && ( + + ) + ); }, size: 1, };