Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix edit Silence durations fails with date math #2372

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Forms/Formik/FormikDurationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -93,8 +94,21 @@ export default function NotificationSilenceForm({
<Formik<Partial<SilenceNotificationRequest>>
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);
}}
>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Notifications/SilenceNotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default function SilenceNotificationsList({

const selectedNotificationSilenceId = searchParams.get("id") ?? undefined;

const { data: selectedNotificationSilence } = useQuery({
const { data: selectedNotificationSilence, refetch } = useQuery({
queryKey: ["notification_silences", selectedNotificationSilenceId],
enabled: !!selectedNotificationSilenceId,
queryFn: async () =>
Expand Down Expand Up @@ -264,9 +264,11 @@ export default function SilenceNotificationsList({
searchParams.delete("id");
setSearchParams(searchParams);
refresh();
refetch();
}}
onClose={() => {
searchParams.delete("id");
refetch();
setSearchParams(searchParams);
}}
data={selectedNotificationSilence}
Expand Down
Loading