Skip to content

Open-source status page, incident response and uptime monitoring

fix: add auto region (#155)

Maximilian Kaskebb44ffde4820
diff --git a/apps/web/src/components/forms/montitor-form.tsx b/apps/web/src/components/forms/montitor-form.tsx
index 7c0d0beb4..a993920ea 100644
--- a/apps/web/src/components/forms/montitor-form.tsx
+++ b/apps/web/src/components/forms/montitor-form.tsx
@@ -2,7 +2,6 @@
import * as React from "react";
import { zodResolver } from "@hookform/resolvers/zod";
-import { Check, ChevronsUpDown } from "lucide-react";
import { useForm } from "react-hook-form";
import type * as z from "zod";
@@ -12,14 +11,6 @@ import {
} from "@openstatus/db/src/schema";
import { allPlans } from "@openstatus/plans";
-import { Button } from "@/components/ui/button";
-import {
- Command,
- CommandEmpty,
- CommandGroup,
- CommandInput,
- CommandItem,
-} from "@/components/ui/command";
import {
Form,
FormControl,
@@ -30,11 +21,6 @@ import {
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/components/ui/popover";
import {
Select,
SelectContent,
@@ -43,8 +29,6 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
-import { regionsDict } from "@/data/regions-dictionary";
-import { cn } from "@/lib/utils";
const limit = allPlans.free.limits.periodicity;
const cronJobs = [
@@ -71,7 +55,6 @@ export function MonitorForm({ id, defaultValues, onSubmit }: Props) {
periodicity: defaultValues?.periodicity || undefined,
active: defaultValues?.active || true,
id: defaultValues?.id || undefined,
- regions: defaultValues?.regions || [],
},
});
@@ -149,72 +132,6 @@ export function MonitorForm({ id, defaultValues, onSubmit }: Props) {
</FormItem>
)}
/>
- <FormField
- control={form.control}
- name="regions"
- render={({ field }) => (
- <FormItem className="flex flex-col">
- <FormLabel>Regions</FormLabel>
- <Popover>
- <PopoverTrigger asChild>
- <FormControl>
- <Button
- variant="outline"
- role="combobox"
- className={cn(
- "w-full justify-between",
- !field.value && "text-muted-foreground",
- )}
- >
- {/* This is a hotfix */}
- {field.value?.length === 1 && field.value[0].length > 0
- ? regionsDict[
- field.value[0] as keyof typeof regionsDict
- ].location
- : "Select region"}
- <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
- </Button>
- </FormControl>
- </PopoverTrigger>
- <PopoverContent className="w-full p-0">
- <Command>
- <CommandInput placeholder="Select a region..." />
- <CommandEmpty>No regions found.</CommandEmpty>
- <CommandGroup>
- {Object.keys(regionsDict).map((region) => {
- const { code, location } =
- regionsDict[region as keyof typeof regionsDict];
- const isSelected = field.value?.includes(code);
- return (
- <CommandItem
- value={code}
- key={code}
- onSelect={() => {
- form.setValue("regions", [code]); // TODO: allow more than one to be selected in the future
- }}
- >
- <Check
- className={cn(
- "mr-2 h-4 w-4",
- isSelected ? "opacity-100" : "opacity-0",
- )}
- />
- {location}
- </CommandItem>
- );
- })}
- </CommandGroup>
- </Command>
- </PopoverContent>
- </Popover>
- <FormDescription>
- Select the regions you want to monitor, or leave it blank for
- randomly picked regions.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
<FormField
control={form.control}
name="periodicity"
diff --git a/apps/web/src/data/regions-dictionary.ts b/apps/web/src/data/regions-dictionary.ts
index 966ed0dbd..ccc17eff8 100644
--- a/apps/web/src/data/regions-dictionary.ts
+++ b/apps/web/src/data/regions-dictionary.ts
@@ -1,8 +1,16 @@
/**
- * AWS data center informations from 17 regions, supported by vercel.
+ * AWS data center informations from 18 regions, supported by vercel.
* https://vercel.com/docs/concepts/edge-network/regions#region-list
*/
export const regionsDict = {
+ /**
+ * A random location will be chosen
+ */
+ auto: {
+ code: "auto",
+ name: "random",
+ location: "Random",
+ },
arn1: {
code: "arn1",
name: "eu-north-1",
diff --git a/packages/db/src/schema/monitor.ts b/packages/db/src/schema/monitor.ts
index 6ff484308..5b7508e34 100644
--- a/packages/db/src/schema/monitor.ts
+++ b/packages/db/src/schema/monitor.ts
@@ -12,6 +12,7 @@ import { page } from "./page";
import { workspace } from "./workspace";
export const availableRegions = [
+ "auto", // randomly choose region
"arn1",
"bom1",
"cdg1",