diff --git a/frontend/src/components/config/index.tsx b/frontend/src/components/config/index.tsx index 1fa2ae523..7f42adb17 100644 --- a/frontend/src/components/config/index.tsx +++ b/frontend/src/components/config/index.tsx @@ -68,11 +68,13 @@ export const Config = ({ set, onSave, components, + selector, }: { config: T; update: Partial; set: React.Dispatch>>; onSave: () => void; + selector?: ReactNode; components: Record< string, Record< @@ -85,6 +87,7 @@ export const Config = ({ > >; }) => { + console.log(selector); const [show, setShow] = useState(keys(components)[0]); return ( @@ -93,18 +96,21 @@ export const Config = ({ onConfirm={onSave} onReset={() => set({})} selector={ - +
+ {selector} + +
} >
diff --git a/frontend/src/components/resources/alerter/config.tsx b/frontend/src/components/resources/alerter/config.tsx index 86ab5cfdb..5080b7e2f 100644 --- a/frontend/src/components/resources/alerter/config.tsx +++ b/frontend/src/components/resources/alerter/config.tsx @@ -1,17 +1,22 @@ import { Config } from "@components/config"; import { useRead, useWrite } from "@lib/hooks"; import { Types } from "@monitor/client"; -import { useState } from "react"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@ui/select"; +import { useEffect, useState } from "react"; export const AlerterConfig = ({ id }: { id: string }) => { const config = useRead("GetAlerter", { alerter: id }).data?.config; - if (config?.type === "Slack") return ; - if (config?.type === "Custom") return ; -}; - -const SlackAlerterConfig = ({ id }: { id: string }) => { - const config = useRead("GetAlerter", { alerter: id }).data?.config; - const [update, set] = useState>({}); + const [type, setType] = useState(); + useEffect(() => config?.type && setType(config.type), [config?.type]); + const [update, setConfig] = useState< + Partial + >({}); const { mutate } = useWrite("UpdateAlerter"); if (!config) return null; @@ -19,32 +24,8 @@ const SlackAlerterConfig = ({ id }: { id: string }) => { mutate({ id, config: { type: "Slack", params: update } })} - components={{ - general: { - general: { - url: true, - enabled: true, - }, - }, - }} - /> - ); -}; - -const CustomAlerterConfig = ({ id }: { id: string }) => { - const config = useRead("GetAlerter", { alerter: id }).data?.config; - const [update, set] = useState>({}); - const { mutate } = useWrite("UpdateAlerter"); - if (!config) return null; - - return ( - mutate({ id, config: { type: "Custom", params: update } })} + set={setConfig} + onSave={() => type && mutate({ id, config: { type, params: update } })} components={{ general: { general: { @@ -53,6 +34,32 @@ const CustomAlerterConfig = ({ id }: { id: string }) => { }, }, }} + selector={ +
+ Alerter Type: + +
+ } /> ); }; diff --git a/frontend/src/components/resources/alerter/index.tsx b/frontend/src/components/resources/alerter/index.tsx index 00a826ac1..16a893bcc 100644 --- a/frontend/src/components/resources/alerter/index.tsx +++ b/frontend/src/components/resources/alerter/index.tsx @@ -27,8 +27,13 @@ export const AlerterComponents: RequiredResourceComponents = { Name: ({ id }: { id: string }) => <>{useAlerter(id)?.name}, Icon: () => , Link: ({ id }) => , - Info: [], - Status: () => <>, + Info: [ + ({ id }) => { + const alerter = useAlerter(id); + return
Type: {alerter?.info.alerter_type}
; + }, + ], + Status: () => <>Alerter, Page: { Config: AlerterConfig, Danger: ({ id }) => (