From d8e32cc92988215fa71ac7b8b3a0cdbd00ddabc9 Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Tue, 21 Mar 2023 12:12:25 +0100 Subject: [PATCH] Alerting: Prometheus-compatible Alertmanager timings editor (#64526) * Change Alertmanager timings editor * Update timing inputs for default policy editor * Switch prom duration inputs in notification policy form * Fix a11y issues * Fix validation * Add timings forms tests * Fix default policy form and add more tests * Add notification policy form tests * Add todo item * Remove unused code * Use default timings object to fill placeholder values --- public/app/features/alerting/unified/TODO.md | 1 + .../EditDefaultPolicyForm.test.tsx | 131 ++++++++++++++ .../EditDefaultPolicyForm.tsx | 166 ++++++------------ .../EditNotificationPolicyForm.test.tsx | 127 ++++++++++++++ .../EditNotificationPolicyForm.tsx | 131 +++----------- .../notification-policies/Filters.tsx | 1 + .../notification-policies/Modals.tsx | 3 +- .../notification-policies/Policy.tsx | 22 +-- .../PromDurationDocs.tsx | 68 +++++++ .../PromDurationInput.tsx | 25 +++ .../notification-policies/formStyles.ts | 8 +- .../notification-policies/timingOptions.ts | 11 ++ .../alerting/unified/types/amroutes.ts | 3 - .../alerting/unified/utils/amroutes.ts | 61 ++----- .../features/alerting/unified/utils/time.ts | 5 - 15 files changed, 467 insertions(+), 296 deletions(-) create mode 100644 public/app/features/alerting/unified/components/notification-policies/EditDefaultPolicyForm.test.tsx create mode 100644 public/app/features/alerting/unified/components/notification-policies/EditNotificationPolicyForm.test.tsx create mode 100644 public/app/features/alerting/unified/components/notification-policies/PromDurationDocs.tsx create mode 100644 public/app/features/alerting/unified/components/notification-policies/PromDurationInput.tsx create mode 100644 public/app/features/alerting/unified/components/notification-policies/timingOptions.ts diff --git a/public/app/features/alerting/unified/TODO.md b/public/app/features/alerting/unified/TODO.md index 872f725b53d..180125b1701 100644 --- a/public/app/features/alerting/unified/TODO.md +++ b/public/app/features/alerting/unified/TODO.md @@ -18,6 +18,7 @@ If the item needs more rationale and you feel like a single sentence is inedequa - Get rid of "+ Add new" in drop-downs : Let's see if is there a way we can make it work with ` - )} - control={control} - name="groupWaitValue" - rules={{ - validate: optionalPositiveInteger, - }} - /> - ( - - )} - control={control} - name="groupIntervalValue" - rules={{ - validate: optionalPositiveInteger, - }} - /> - ( - - )} - control={control} - name="repeatIntervalValue" - rules={{ - validate: optionalPositiveInteger, - }} - /> - ( - {/* @ts-ignore-check: react-hook-form made me do this */} @@ -96,7 +94,6 @@ export const AmRoutesExpandedForm = ({ {fields.length > 0 && (
{fields.map((field, index) => { - const localPath = `object_matchers[${index}]`; return ( @@ -134,7 +131,7 @@ export const AmRoutesExpandedForm = ({ error={errors.object_matchers?.[index]?.value?.message} > @@ -225,38 +222,11 @@ export const AmRoutesExpandedForm = ({ invalid={!!errors.groupWaitValue} error={errors.groupWaitValue?.message} > - <> -
- ( - - )} - control={control} - name="groupWaitValue" - rules={{ - validate: optionalPositiveInteger, - }} - /> - ( - - )} - control={control} - name="groupIntervalValue" - rules={{ - validate: optionalPositiveInteger, - }} - /> - ( - - )} - control={control} - name="repeatIntervalValue" - rules={{ - validate: optionalPositiveInteger, - }} - /> - ( - { diff --git a/public/app/features/alerting/unified/components/notification-policies/Modals.tsx b/public/app/features/alerting/unified/components/notification-policies/Modals.tsx index 29bebec48c7..074ba61b7d0 100644 --- a/public/app/features/alerting/unified/components/notification-policies/Modals.tsx +++ b/public/app/features/alerting/unified/components/notification-policies/Modals.tsx @@ -21,6 +21,7 @@ import { AmRoutesExpandedForm } from './EditNotificationPolicyForm'; import { Matchers } from './Matchers'; type ModalHook = [JSX.Element, (item: T) => void, () => void]; +type EditModalHook = [JSX.Element, (item: RouteWithID, isDefaultRoute?: boolean) => void, () => void]; const useAddPolicyModal = ( receivers: Receiver[] = [], @@ -81,7 +82,7 @@ const useEditPolicyModal = ( receivers: Receiver[], handleSave: (route: Partial) => void, loading: boolean -): ModalHook => { +): EditModalHook => { const [showModal, setShowModal] = useState(false); const [isDefaultPolicy, setIsDefaultPolicy] = useState(false); const [route, setRoute] = useState(); diff --git a/public/app/features/alerting/unified/components/notification-policies/Policy.tsx b/public/app/features/alerting/unified/components/notification-policies/Policy.tsx index 06b04a18396..6fbeba09612 100644 --- a/public/app/features/alerting/unified/components/notification-policies/Policy.tsx +++ b/public/app/features/alerting/unified/components/notification-policies/Policy.tsx @@ -30,12 +30,7 @@ import { Spacer } from '../Spacer'; import { Strong } from '../Strong'; import { Matchers } from './Matchers'; - -type TimingOptions = { - group_wait?: string; - group_interval?: string; - repeat_interval?: string; -}; +import { TimingOptions, TIMING_OPTIONS_DEFAULTS } from './timingOptions'; type InhertitableProperties = Pick< Route, @@ -184,7 +179,14 @@ const Policy: FC = ({ } > -