From 017afaa1b77936ad5e961a7ebcf71ac897948351 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 13 Mar 2024 14:54:38 +0200 Subject: [PATCH] Pass additional_settings from the integration form to backend (#4047) # What this PR does - Pass additional_settings from the integration form to backend --------- Co-authored-by: Dominik --- .../IntegrationForm.helpers.ts | 4 + .../IntegrationForm/IntegrationForm.tsx | 158 +++++++++--------- .../alert_receive_channel.ts | 14 +- .../oncall-api/autogenerated-api.types.d.ts | 36 +++- 4 files changed, 124 insertions(+), 88 deletions(-) diff --git a/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.helpers.ts b/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.helpers.ts index 20ae6d81..28a161f1 100644 --- a/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.helpers.ts +++ b/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.helpers.ts @@ -7,5 +7,9 @@ export function prepareForEdit(item: ApiSchemas['AlertReceiveChannel']): Partial team: item.team, labels: item.labels, integration: item.integration, + + additional_settings: { + ...item.additional_settings, + }, }; } diff --git a/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx b/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx index 9f1d8b82..4782bed9 100644 --- a/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx +++ b/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx @@ -35,39 +35,26 @@ import { AppFeature } from 'state/features'; import { useStore } from 'state/useStore'; import { UserActions } from 'utils/authorization/authorization'; import { PLUGIN_ROOT, URL_REGEX, generateAssignToTeamInputDescription } from 'utils/consts'; +import { OmitReadonlyMembers } from 'utils/types'; import { prepareForEdit } from './IntegrationForm.helpers'; import { getIntegrationFormStyles } from './IntegrationForm.styles'; -enum FormFieldKeys { - Name = 'verbal_name', - Description = 'description_short', - Team = 'team', - AlertManager = 'alert_manager', - ContactPoint = 'contact_point', - IsExisting = 'is_existing', - Alerting = 'alerting', - Integration = 'integration', - - ServiceNowUrl = 'servicenow_url', - AuthUsername = 'auth_username', - AuthPassword = 'auth_password', - DefaultWebhooks = 'default_webhooks', -} - interface FormFields { - [FormFieldKeys.Name]: string; - [FormFieldKeys.Description]: string; - [FormFieldKeys.Team]: string; - [FormFieldKeys.IsExisting]: boolean; - [FormFieldKeys.AlertManager]: string; - [FormFieldKeys.ContactPoint]: string; - [FormFieldKeys.Alerting]: string; - [FormFieldKeys.ServiceNowUrl]: string; - [FormFieldKeys.AuthUsername]: string; - [FormFieldKeys.AuthPassword]: string; - [FormFieldKeys.Integration]: string; - [FormFieldKeys.DefaultWebhooks]: boolean; + verbal_name?: string; + description_short?: string; + team?: string; + is_existing?: boolean; + alert_manager?: string; + contact_point?: string; + integration: ApiSchemas['AlertReceiveChannel']['integration']; + + additional_settings: { + instance_url: string; + username: string; + password: string; + default_webhooks: boolean; + }; } interface IntegrationFormProps { @@ -107,8 +94,17 @@ export const IntegrationForm = observer( const isNew = id === 'new'; const { userStore, grafanaTeamStore, alertReceiveChannelStore } = store; - const data = isNew - ? { integration: selectedIntegration?.value, team: userStore.currentUser?.current_team, labels: [] } + const data: Partial = isNew + ? { + integration: selectedIntegration?.value as ApiSchemas['AlertReceiveChannel']['integration'], + team: userStore.currentUser?.current_team, + labels: [], + additional_settings: { + instance_url: undefined, + password: undefined, + username: undefined, + }, + } : prepareForEdit(alertReceiveChannelStore.items[id]); const { integration } = data; @@ -117,8 +113,10 @@ export const IntegrationForm = observer( defaultValues: isNew ? { // these are the default values for creating an integration - [FormFieldKeys.Integration]: integration, - [FormFieldKeys.DefaultWebhooks]: true, + integration, + additional_settings: { + default_webhooks: true, + }, } : { // existing values from existing integration (edit-mode) @@ -126,6 +124,7 @@ export const IntegrationForm = observer( }, mode: 'onChange', }); + const { control, handleSubmit, @@ -175,15 +174,15 @@ export const IntegrationForm = observer(
( @@ -191,15 +190,15 @@ export const IntegrationForm = observer( /> (