From 95067c39fa006a110105bf5fadc232605ed500cd Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Wed, 29 Apr 2026 22:05:10 +0200 Subject: [PATCH] refactor: simplify hooks ceremonies --- app/client/api-client/types.gen.ts | 140 +- .../create-schedule-form/advanced-section.tsx | 180 +- .../components/create-schedule-form/index.tsx | 32 +- .../components/create-schedule-form/types.ts | 29 +- .../components/create-schedule-form/utils.ts | 39 +- .../routes/__tests__/backup-details.test.tsx | 3 +- .../routes/__tests__/edit-backup.test.tsx | 14 +- .../modules/backups/routes/backup-details.tsx | 3 +- .../modules/backups/routes/create-backup.tsx | 3 +- .../migration.sql | 2 - .../snapshot.json | 2482 ----------------- .../20260429194428_short_mentor/migration.sql | 1 + .../20260429194428_short_mentor/snapshot.json | 2341 ++++++++++++++++ app/server/db/schema.ts | 5 +- .../backups.service.execution.test.ts | 27 +- .../backups/__tests__/backups.service.test.ts | 47 +- app/server/modules/backups/backup-executor.ts | 39 +- app/server/modules/backups/backups.dto.ts | 11 +- app/server/modules/backups/backups.service.ts | 6 +- apps/agent/src/commands/backup-run.test.ts | 37 +- apps/agent/src/commands/backup-run.ts | 65 +- .../src/backup-hooks/__tests__/hooks.test.ts | 287 +- packages/core/src/backup-hooks/index.ts | 324 +-- 23 files changed, 2954 insertions(+), 3163 deletions(-) delete mode 100644 app/drizzle/20260423190302_cute_pete_wisdom/migration.sql delete mode 100644 app/drizzle/20260423190302_cute_pete_wisdom/snapshot.json create mode 100644 app/drizzle/20260429194428_short_mentor/migration.sql create mode 100644 app/drizzle/20260429194428_short_mentor/snapshot.json diff --git a/app/client/api-client/types.gen.ts b/app/client/api-client/types.gen.ts index 4ada52f3..e6e5f670 100644 --- a/app/client/api-client/types.gen.ts +++ b/app/client/api-client/types.gen.ts @@ -2434,15 +2434,17 @@ export type ListBackupSchedulesResponses = { includePatterns: Array | null; oneFileSystem: boolean; customResticParams: Array | null; - preBackupWebhook: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook: { - url: string; - headers?: Array; - body?: string; + backupWebhooks: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries: number; retryDelay: number; @@ -2722,15 +2724,17 @@ export type CreateBackupScheduleData = { oneFileSystem?: boolean; tags?: Array; customResticParams?: Array; - preBackupWebhook?: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook?: { - url: string; - headers?: Array; - body?: string; + backupWebhooks?: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries?: number; retryDelay?: number; @@ -2767,15 +2771,17 @@ export type CreateBackupScheduleResponses = { includePatterns: Array | null; oneFileSystem: boolean; customResticParams: Array | null; - preBackupWebhook: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook: { - url: string; - headers?: Array; - body?: string; + backupWebhooks: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries: number; retryDelay: number; @@ -2846,15 +2852,17 @@ export type GetBackupScheduleResponses = { includePatterns: Array | null; oneFileSystem: boolean; customResticParams: Array | null; - preBackupWebhook: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook: { - url: string; - headers?: Array; - body?: string; + backupWebhooks: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries: number; retryDelay: number; @@ -3133,15 +3141,17 @@ export type UpdateBackupScheduleData = { oneFileSystem?: boolean; tags?: Array; customResticParams?: Array; - preBackupWebhook?: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook?: { - url: string; - headers?: Array; - body?: string; + backupWebhooks?: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries?: number; retryDelay?: number; @@ -3180,15 +3190,17 @@ export type UpdateBackupScheduleResponses = { includePatterns: Array | null; oneFileSystem: boolean; customResticParams: Array | null; - preBackupWebhook: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook: { - url: string; - headers?: Array; - body?: string; + backupWebhooks: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries: number; retryDelay: number; @@ -3239,15 +3251,17 @@ export type GetBackupScheduleForVolumeResponses = { includePatterns: Array | null; oneFileSystem: boolean; customResticParams: Array | null; - preBackupWebhook: { - url: string; - headers?: Array; - body?: string; - } | null; - postBackupWebhook: { - url: string; - headers?: Array; - body?: string; + backupWebhooks: { + pre: { + url: string; + headers?: Array; + body?: string; + } | null; + post: { + url: string; + headers?: Array; + body?: string; + } | null; } | null; maxRetries: number; retryDelay: number; diff --git a/app/client/modules/backups/components/create-schedule-form/advanced-section.tsx b/app/client/modules/backups/components/create-schedule-form/advanced-section.tsx index 87ca541e..0b6c3d33 100644 --- a/app/client/modules/backups/components/create-schedule-form/advanced-section.tsx +++ b/app/client/modules/backups/components/create-schedule-form/advanced-section.tsx @@ -8,6 +8,72 @@ type AdvancedSectionProps = { form: UseFormReturn; }; +type WebhookFieldsProps = { + form: UseFormReturn; + phase: "pre" | "post"; + urlPlaceholder: string; + bodyPlaceholder: string; + description: string; +}; + +const WebhookFields = ({ form, phase, urlPlaceholder, bodyPlaceholder, description }: WebhookFieldsProps) => { + const labelPrefix = phase === "pre" ? "Pre-backup" : "Post-backup"; + const fieldPrefix = phase === "pre" ? "preBackupWebhook" : "postBackupWebhook"; + + return ( + <> + ( + + {labelPrefix} webhook + + + + {description} + + + )} + /> + ( + + {labelPrefix} webhook headers + +