From 20abfe1035dfaa47000c82a25db1602739724602 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Wed, 23 Oct 2024 19:52:38 +0300 Subject: [PATCH] fix: fix edit Silence durations fails with date math Fixes #2369 --- .../Forms/Formik/FormikDurationPicker.tsx | 1 - .../NotificationSilenceForm.tsx | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/Forms/Formik/FormikDurationPicker.tsx b/src/components/Forms/Formik/FormikDurationPicker.tsx index 702b3757c..88390c2c8 100644 --- a/src/components/Forms/Formik/FormikDurationPicker.tsx +++ b/src/components/Forms/Formik/FormikDurationPicker.tsx @@ -61,7 +61,6 @@ export default function FormikDurationPicker({ value={value} placeholder={placeholder} onChange={(value) => { - console.log(value, "value"); if (value.type === "absolute") { setFieldValue(from, value.from); setFieldValue(to, value.to); diff --git a/src/components/Notifications/SilenceNotificationForm/NotificationSilenceForm.tsx b/src/components/Notifications/SilenceNotificationForm/NotificationSilenceForm.tsx index a8fca2f30..bdd31fcaf 100644 --- a/src/components/Notifications/SilenceNotificationForm/NotificationSilenceForm.tsx +++ b/src/components/Notifications/SilenceNotificationForm/NotificationSilenceForm.tsx @@ -13,6 +13,7 @@ import FormikTextArea from "@flanksource-ui/components/Forms/Formik/FormikTextAr import FormikNotificationResourceField from "@flanksource-ui/components/Notifications/SilenceNotificationForm/FormikNotificationField"; import { toastError } from "@flanksource-ui/components/Toast/toast"; import { Button } from "@flanksource-ui/ui/Buttons/Button"; +import { parseDateMath } from "@flanksource-ui/ui/Dates/TimeRangePicker/parseDateMath"; import { useMutation } from "@tanstack/react-query"; import { AxiosError } from "axios"; import { Form, Formik } from "formik"; @@ -93,8 +94,21 @@ export default function NotificationSilenceForm({ > initialValues={initialValues} onSubmit={(v) => { + // Before submitting, we need to parse the date math expressions, if + // any are present in the from and until fields. + const { from, until } = v; + const fromTime = from?.includes("now") + ? parseDateMath(from, false) + : from; + + const untilTime = until?.includes("now") + ? parseDateMath(until, false) + : until; + return mutate({ - ...v + ...v, + from: fromTime, + until: untilTime } as SilenceNotificationRequest); }} >