diff --git a/frontend/src/components/resources/resource-sync/config.tsx b/frontend/src/components/resources/resource-sync/config.tsx index d430fd903..c11e2f9aa 100644 --- a/frontend/src/components/resources/resource-sync/config.tsx +++ b/frontend/src/components/resources/resource-sync/config.tsx @@ -192,11 +192,6 @@ export const ResourceSyncConfig = ({ description: "Enabled managed mode / the 'Commit' button. Commit is the 'reverse' of Execute, and will update the sync file with your configs updated in the UI.", }, - pending_alert: { - label: "Pending Alerts", - description: - "Send a message to your Alerters when the Sync has Pending Changes", - }, }, }; @@ -234,6 +229,17 @@ export const ResourceSyncConfig = ({ }, }; + const pending_alerts: ConfigComponent = { + label: "Alerts", + components: { + pending_alert: { + label: "Pending Alerts", + description: + "Send a message to your Alerters when the Sync has Pending Changes", + }, + }, + }; + if (mode === undefined) { components = { "": [choose_mode], @@ -259,80 +265,250 @@ export const ResourceSyncConfig = ({ ...general_common.components, }, }, - include_toggles, match_tags, + include_toggles, + pending_alerts, ], }; } else if (mode === "Git Repo") { const repo_linked = !!(update.linked_repo ?? config.linked_repo); + const source_config: ConfigComponent = { + label: "Source", + contentHidden: !show.git, + actions: ( + setShow({ ...show, git })} + /> + ), + components: { + linked_repo: (linked_repo, set) => ( + + ), + ...(!repo_linked + ? { + git_provider: (provider: string | undefined, set) => { + const https = update.git_https ?? config.git_https; + return ( + set({ git_provider })} + https={https} + onHttpsSwitch={() => set({ git_https: !https })} + /> + ); + }, + git_account: (value: string | undefined, set) => { + return ( + set({ git_account })} + disabled={disabled} + placeholder="None" + /> + ); + }, + repo: { + placeholder: "Enter repo", + description: + "The repo path on the provider. {namespace}/{repo_name}", + }, + branch: { + placeholder: "Enter branch", + description: "Select a custom branch, or default to 'main'.", + }, + commit: { + label: "Commit Hash", + placeholder: "Input commit hash", + description: + "Optional. Switch to a specific commit hash after cloning the branch.", + }, + } + : {}), + }, + }; + const webhooks_config: ConfigComponent = { + label: "Git Webhooks", + description: `Copy the webhook given here, and configure your ${webhook_integration}-style repo provider to send webhooks to Komodo`, + contentHidden: !show.webhooks, + actions: ( + setShow({ ...show, webhooks })} + /> + ), + components: { + ["Guard" as any]: () => { + if (update.branch ?? config.branch) { + return null; + } + return ( + +
Must configure Branch before webhooks will work.
+
+ ); + }, + ["Builder" as any]: () => ( + + ), + ["Refresh" as any]: () => ( + + + + ), + ["Sync" as any]: () => ( + + + + ), + webhook_enabled: webhooks !== undefined && !webhooks.managed, + webhook_secret: { + description: + "Provide a custom webhook secret for this resource, or use the global default.", + placeholder: "Input custom secret", + }, + ["managed" as any]: () => { + const inv = useInvalidate(); + const { toast } = useToast(); + const { mutate: createWebhook, isPending: createPending } = useWrite( + "CreateSyncWebhook", + { + onSuccess: () => { + toast({ title: "Webhook Created" }); + inv(["GetSyncWebhooksEnabled", { sync: id }]); + }, + } + ); + const { mutate: deleteWebhook, isPending: deletePending } = useWrite( + "DeleteSyncWebhook", + { + onSuccess: () => { + toast({ title: "Webhook Deleted" }); + inv(["GetSyncWebhooksEnabled", { sync: id }]); + }, + } + ); + if (!webhooks || !webhooks.managed) return; + return ( + + {webhooks.sync_enabled && ( +
+
+ Incoming webhook is{" "} +
+ ENABLED +
+ and will trigger +
+ SYNC EXECUTION +
+
+ } + variant="destructive" + onClick={() => + deleteWebhook({ + sync: id, + action: Types.SyncWebhookAction.Sync, + }) + } + loading={deletePending} + disabled={disabled || deletePending} + /> +
+ )} + {!webhooks.sync_enabled && webhooks.refresh_enabled && ( +
+
+ Incoming webhook is{" "} +
+ ENABLED +
+ and will trigger +
+ PENDING REFRESH +
+
+ } + variant="destructive" + onClick={() => + deleteWebhook({ + sync: id, + action: Types.SyncWebhookAction.Refresh, + }) + } + loading={deletePending} + disabled={disabled || deletePending} + /> +
+ )} + {!webhooks.sync_enabled && !webhooks.refresh_enabled && ( +
+
+ Incoming webhook is{" "} +
+ DISABLED +
+
+ } + onClick={() => + createWebhook({ + sync: id, + action: Types.SyncWebhookAction.Refresh, + }) + } + loading={createPending} + disabled={disabled || createPending} + /> + } + onClick={() => + createWebhook({ + sync: id, + action: Types.SyncWebhookAction.Sync, + }) + } + loading={createPending} + disabled={disabled || createPending} + /> +
+ )} +
+ ); + }, + }, + }; components = { "": [ - { - label: "Source", - contentHidden: !show.git, - actions: ( - setShow({ ...show, git })} - /> - ), - components: { - linked_repo: (linked_repo, set) => ( - - ), - ...(!repo_linked - ? { - git_provider: (provider: string | undefined, set) => { - const https = update.git_https ?? config.git_https; - return ( - set({ git_provider })} - https={https} - onHttpsSwitch={() => set({ git_https: !https })} - /> - ); - }, - git_account: (value: string | undefined, set) => { - return ( - set({ git_account })} - disabled={disabled} - placeholder="None" - /> - ); - }, - repo: { - placeholder: "Enter repo", - description: - "The repo path on the provider. {namespace}/{repo_name}", - }, - branch: { - placeholder: "Enter branch", - description: - "Select a custom branch, or default to 'main'.", - }, - commit: { - label: "Commit Hash", - placeholder: "Input commit hash", - description: - "Optional. Switch to a specific commit hash after cloning the branch.", - }, - } - : {}), - }, - }, + source_config, { label: "General", components: { @@ -351,179 +527,10 @@ export const ResourceSyncConfig = ({ ...general_common.components, }, }, - include_toggles, match_tags, - { - label: "Git Webhooks", - description: `Copy the webhook given here, and configure your ${webhook_integration}-style repo provider to send webhooks to Komodo`, - contentHidden: !show.webhooks, - actions: ( - setShow({ ...show, webhooks })} - /> - ), - components: { - ["Guard" as any]: () => { - if (update.branch ?? config.branch) { - return null; - } - return ( - -
Must configure Branch before webhooks will work.
-
- ); - }, - ["Builder" as any]: () => ( - - ), - ["Refresh" as any]: () => ( - - - - ), - ["Sync" as any]: () => ( - - - - ), - webhook_enabled: webhooks !== undefined && !webhooks.managed, - webhook_secret: { - description: - "Provide a custom webhook secret for this resource, or use the global default.", - placeholder: "Input custom secret", - }, - ["managed" as any]: () => { - const inv = useInvalidate(); - const { toast } = useToast(); - const { mutate: createWebhook, isPending: createPending } = - useWrite("CreateSyncWebhook", { - onSuccess: () => { - toast({ title: "Webhook Created" }); - inv(["GetSyncWebhooksEnabled", { sync: id }]); - }, - }); - const { mutate: deleteWebhook, isPending: deletePending } = - useWrite("DeleteSyncWebhook", { - onSuccess: () => { - toast({ title: "Webhook Deleted" }); - inv(["GetSyncWebhooksEnabled", { sync: id }]); - }, - }); - if (!webhooks || !webhooks.managed) return; - return ( - - {webhooks.sync_enabled && ( -
-
- Incoming webhook is{" "} -
- ENABLED -
- and will trigger -
- SYNC EXECUTION -
-
- } - variant="destructive" - onClick={() => - deleteWebhook({ - sync: id, - action: Types.SyncWebhookAction.Sync, - }) - } - loading={deletePending} - disabled={disabled || deletePending} - /> -
- )} - {!webhooks.sync_enabled && webhooks.refresh_enabled && ( -
-
- Incoming webhook is{" "} -
- ENABLED -
- and will trigger -
- PENDING REFRESH -
-
- } - variant="destructive" - onClick={() => - deleteWebhook({ - sync: id, - action: Types.SyncWebhookAction.Refresh, - }) - } - loading={deletePending} - disabled={disabled || deletePending} - /> -
- )} - {!webhooks.sync_enabled && !webhooks.refresh_enabled && ( -
-
- Incoming webhook is{" "} -
- DISABLED -
-
- } - onClick={() => - createWebhook({ - sync: id, - action: Types.SyncWebhookAction.Refresh, - }) - } - loading={createPending} - disabled={disabled || createPending} - /> - } - onClick={() => - createWebhook({ - sync: id, - action: Types.SyncWebhookAction.Sync, - }) - } - loading={createPending} - disabled={disabled || createPending} - /> -
- )} -
- ); - }, - }, - }, + include_toggles, + pending_alerts, + webhooks_config, ], }; } else if (mode === "UI Defined") { @@ -557,8 +564,9 @@ export const ResourceSyncConfig = ({ }, }, general_common, - include_toggles, match_tags, + include_toggles, + pending_alerts, ], }; }