diff --git a/webui/src/components/HooksFormList.tsx b/webui/src/components/HooksFormList.tsx
index d8ef0a88..60f4bb62 100644
--- a/webui/src/components/HooksFormList.tsx
+++ b/webui/src/components/HooksFormList.tsx
@@ -54,19 +54,23 @@ export const hooksListTooltipText = <>
* HooksFormList is a UI component for editing a list of hooks that can apply either at the repo level or at the plan level.
*/
export const HooksFormList = () => {
+ const form = Form.useFormInstance();
+
return
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field, index) => {
+ const hookData = form.getFieldValue(["hooks", field.name]) as HookFields;
+
return
- Hook {index}
+ Hook {index} {findHookTypeName(hookData)}
remove(field.name)}
style={{ marginRight: "5px", marginTop: "2px", float: "right" }}
/>
>
- } size="small" >
+ } size="small" style={{ marginBottom: "5px" }}>
{
style={{ width: "60%" }}
placement="bottom"
>
- }>
+ } style={{ width: "100%" }}>
Add Hook
@@ -116,6 +120,8 @@ export const HooksFormList = () => {
const hookTypes: {
name: string,
template: HookFields,
+ oneofKey: string,
+ component: ({ field }: { field: FormListFieldData }) => React.ReactNode
}[] = [
{
name: "Command", template: {
@@ -124,6 +130,17 @@ const hookTypes: {
},
conditions: [],
},
+ oneofKey: "actionCommand",
+ component: ({ field }: { field: FormListFieldData }) => {
+ return <>
+
+ Script:
+
+
+
+
+ >
+ }
},
{
name: "Discord", template: {
@@ -132,6 +149,18 @@ const hookTypes: {
template: "{{ .Summary }}",
},
conditions: [],
+ },
+ oneofKey: "actionDiscord",
+ component: ({ field }: { field: FormListFieldData }) => {
+ return <>
+
+ Discord Webhook} />
+
+ Text Template:
+
+
+
+ >
}
},
{
@@ -143,6 +172,24 @@ const hookTypes: {
titleTemplate: "Backrest {{ .EventName .Event }} in plan {{ .Plan.Id }}",
},
conditions: [],
+ },
+ oneofKey: "actionGotify",
+ component: ({ field }: { field: FormListFieldData }) => {
+ return <>
+
+ Gotify Base URL} />
+
+
+ Gotify Token} />
+
+
+ Title Template} />
+
+ Text Template:
+
+
+
+ >
}
},
{
@@ -152,62 +199,49 @@ const hookTypes: {
template: "{{ .Summary }}",
},
conditions: [],
+ },
+ oneofKey: "actionSlack",
+ component: ({ field }: { field: FormListFieldData }) => {
+ return <>
+
+ Slack Webhook} />
+
+ Text Template:
+
+
+
+ >
}
}
];
+const findHookTypeName = (field: HookFields): string => {
+ if (!field) {
+ return "Unknown";
+ }
+ for (const hookType of hookTypes) {
+ if (hookType.oneofKey in field) {
+ return hookType.name;
+ }
+ }
+ return "Unknown";
+}
+
const HookBuilder = ({ field }: { field: FormListFieldData }) => {
const form = Form.useFormInstance();
const hookData = form.getFieldValue(["hooks", field.name]) as HookFields;
- if (hookData.actionDiscord) {
- return <>
-
- Discord Webhook} />
-
- Text Template:
-
-
-
- >
- } else if (hookData.actionCommand) {
- return <>
-
- Script:
-
-
-
-
- >
- } else if (hookData.actionGotify) {
- return <>
-
- Gotify Base URL} />
-
-
- Gotify Token} />
-
-
- Title Template} />
-
- Text Template:
-
-
-
- >
- } else if (hookData.actionSlack) {
- return <>
-
- Slack Webhook} />
-
- Text Template:
-
-
-
- >
- } else {
- return Unknown hook
+ if (!hookData) {
+ return Unknown hook type
;
}
+
+ for (const hookType of hookTypes) {
+ if (hookType.oneofKey in hookData) {
+ return hookType.component({ field });
+ }
+ }
+
+ return Unknown hook type
;
}
const requiredField = (message: string, extra?: Rule) => ({ required: true, message: message });
\ No newline at end of file
diff --git a/webui/src/views/AddPlanModal.tsx b/webui/src/views/AddPlanModal.tsx
index de91fc07..7321d8d7 100644
--- a/webui/src/views/AddPlanModal.tsx
+++ b/webui/src/views/AddPlanModal.tsx
@@ -416,7 +416,7 @@ export const AddPlanModal = ({
]}
noStyle
>
-
+
add()}
- style={{ width: "60%" }}
+ style={{ width: "90%" }}
icon={ }
>
Set Flag
diff --git a/webui/src/views/AddRepoModal.tsx b/webui/src/views/AddRepoModal.tsx
index d99f8908..736088a8 100644
--- a/webui/src/views/AddRepoModal.tsx
+++ b/webui/src/views/AddRepoModal.tsx
@@ -350,7 +350,7 @@ export const AddRepoModal = ({
]}
noStyle
>
-
+
add()}
- style={{ width: "60%" }}
+ style={{ width: "90%" }}
icon={ }
>
Set Flag