update types (#4059)

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
This commit is contained in:
Dominik Broj 2024-03-15 13:38:09 +01:00 committed by GitHub
parent eb1228e782
commit cf07121300
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 87 additions and 63 deletions

View file

@ -51,13 +51,9 @@ interface FormFields {
alert_manager?: string;
contact_point?: string;
integration: ApiSchemas['AlertReceiveChannel']['integration'];
create_default_webhooks: boolean;
additional_settings: {
instance_url: string;
username: string;
password: string;
default_webhooks: boolean;
};
additional_settings: ApiSchemas['AlertReceiveChannel']['additional_settings'];
}
interface IntegrationFormProps {
@ -106,6 +102,13 @@ export const IntegrationForm = observer(
instance_url: undefined,
password: undefined,
username: undefined,
is_configured: false,
state_mapping: {
acknowledged: undefined,
firing: undefined,
resolved: undefined,
silenced: undefined,
},
},
}
: prepareForEdit(alertReceiveChannelStore.items[id]);
@ -117,9 +120,7 @@ export const IntegrationForm = observer(
? {
// these are the default values for creating an integration
integration,
additional_settings: {
default_webhooks: true,
},
additional_settings: {},
}
: {
// existing values from existing integration (edit-mode)
@ -338,7 +339,7 @@ export const IntegrationForm = observer(
</Button>
<Controller
name={'additional_settings.default_webhooks'}
name={'create_default_webhooks'}
control={control}
render={({ field }) => (
<div className={styles.webhookSwitch}>
@ -390,7 +391,7 @@ export const IntegrationForm = observer(
async function onFormSubmit(formData: FormFields): Promise<void> {
const labels = labelsRef.current?.getValue();
const data: OmitReadonlyMembers<ApiSchemas['AlertReceiveChannel']> = {
const data: OmitReadonlyMembers<ApiSchemas['AlertReceiveChannelCreate']> = {
labels,
...formData,
};
@ -418,7 +419,7 @@ export const IntegrationForm = observer(
await onSubmit();
onHide();
async function createNewIntegration(): Promise<void | ApiSchemas['AlertReceiveChannel']> {
async function createNewIntegration(): Promise<void | ApiSchemas['AlertReceiveChannelCreate']> {
const response = await alertReceiveChannelStore.create({ data, skipErrorHandling: true });
const pushHistory = (id: ApiSchemas['AlertReceiveChannel']['id']) =>
history.push(`${PLUGIN_ROOT}/integrations/${id}`);

View file

@ -42,18 +42,7 @@ enum OnCallAGStatus {
}
interface FormFields {
additional_settings: {
instance_url: string;
username: string;
password: string;
state_mapping?: {
firing: string;
acknowledged: string;
resolved: string;
silenced: string;
};
};
additional_settings: ApiSchemas['AlertReceiveChannel']['additional_settings'];
}
interface StatusMapping {

View file

@ -49,12 +49,12 @@ export class AlertReceiveChannelStore {
data,
skipErrorHandling,
}: {
data: OmitReadonlyMembers<ApiSchemas['AlertReceiveChannel']>;
data: OmitReadonlyMembers<ApiSchemas['AlertReceiveChannelCreate']>;
skipErrorHandling?: boolean;
}) {
const result = await onCallApi({ skipErrorHandling }).POST('/alert_receive_channels/', {
params: {},
body: data as ApiSchemas['AlertReceiveChannel'],
body: data as ApiSchemas['AlertReceiveChannelCreate'],
});
await this.rootStore.organizationStore.loadCurrentOrganization();
return result.data;

View file

@ -1190,6 +1190,7 @@ export interface components {
* @enum {string}
*/
ActionEnum: 'acknowledge' | 'resolve' | 'silence' | 'restart';
AdditionalSettingsField: components['schemas']['Settings'];
Alert: {
readonly id: string;
/** Format: uri */
@ -1445,17 +1446,7 @@ export interface components {
alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels'];
/** Format: date-time */
readonly alertmanager_v2_migrated_at: string | null;
additional_settings?: {
instance_url: string;
username: string;
password: string;
state_mapping?: {
firing: string;
acknowledged: string;
resolved: string;
silenced: string;
};
};
additional_settings?: components['schemas']['AdditionalSettingsField'] | null;
};
AlertReceiveChannelConnectContactPoint: {
datasource_uid: string;
@ -1483,6 +1474,49 @@ export interface components {
name: string;
contact_points: string[];
};
AlertReceiveChannelCreate: {
readonly id: string;
readonly description: string | null;
description_short?: string | null;
integration: components['schemas']['IntegrationEnum'];
readonly smile_code: string;
verbal_name?: string | null;
readonly author: string;
readonly organization: string;
team?: string | null;
/** Format: date-time */
readonly created_at: string;
readonly integration_url: string | null;
readonly alert_count: number;
readonly alert_groups_count: number;
allow_source_based_resolving?: boolean;
readonly instructions: string;
readonly is_able_to_autoresolve: boolean;
readonly default_channel_filter: string | null;
readonly demo_alert_enabled: boolean;
readonly maintenance_mode:
| (components['schemas']['MaintenanceModeEnum'] | components['schemas']['NullEnum'])
| null;
readonly maintenance_till: number | null;
readonly heartbeat: components['schemas']['IntegrationHeartBeat'] | null;
readonly is_available_for_integration_heartbeat: boolean;
readonly allow_delete: boolean;
readonly demo_alert_payload: {
[key: string]: unknown;
};
readonly routes_count: number;
readonly connected_escalations_chains_count: number;
readonly is_based_on_alertmanager: boolean;
readonly inbound_email: string;
readonly is_legacy: boolean;
labels?: components['schemas']['LabelPair'][];
alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels'];
/** Format: date-time */
readonly alertmanager_v2_migrated_at: string | null;
additional_settings?: components['schemas']['AdditionalSettingsField'] | null;
/** @default true */
create_default_webhooks: boolean;
};
AlertReceiveChannelCreateContactPoint: {
datasource_uid: string;
contact_point_name: string;
@ -1564,17 +1598,7 @@ export interface components {
alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels'];
/** Format: date-time */
readonly alertmanager_v2_migrated_at: string | null;
additional_settings?: {
instance_url: string;
username: string;
password: string;
state_mapping?: {
firing: string;
acknowledged: string;
resolved: string;
silenced: string;
};
};
additional_settings?: components['schemas']['AdditionalSettingsField'] | null;
};
/** @enum {integer} */
CloudConnectionStatusEnum: 0 | 1 | 2 | 3;
@ -1882,17 +1906,7 @@ export interface components {
alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels'];
/** Format: date-time */
readonly alertmanager_v2_migrated_at?: string | null;
additional_settings?: {
instance_url: 'string';
username: 'string';
password: 'string';
state_mapping?: {
firing: null;
acknowledged: null;
resolved: null;
silenced: null;
};
};
additional_settings?: components['schemas']['AdditionalSettingsField'] | null;
};
PatchedUser: {
readonly pk?: string;
@ -1960,6 +1974,20 @@ export interface components {
* @enum {integer}
*/
RoleEnum: 0 | 1 | 2 | 3;
Settings: {
instance_url: string;
username: string;
password: string;
/** @default {
* "firing": null,
* "acknowledged": null,
* "resolved": null,
* "silenced": null
* } */
state_mapping: components['schemas']['StateMapping'];
/** @default false */
is_configured: boolean;
};
ShortAlertGroup: {
readonly pk: string;
readonly render_for_web:
@ -1980,6 +2008,12 @@ export interface components {
readonly name: string;
readonly display_name: string | null;
};
StateMapping: {
firing: unknown[] | null;
acknowledged: unknown[] | null;
resolved: unknown[] | null;
silenced: unknown[] | null;
};
TelegramToUserConnector: {
telegram_nick_name?: string | null;
/** Format: int64 */
@ -2291,9 +2325,9 @@ export interface operations {
};
requestBody: {
content: {
'application/json': components['schemas']['AlertReceiveChannel'];
'application/x-www-form-urlencoded': components['schemas']['AlertReceiveChannel'];
'multipart/form-data': components['schemas']['AlertReceiveChannel'];
'application/json': components['schemas']['AlertReceiveChannelCreate'];
'application/x-www-form-urlencoded': components['schemas']['AlertReceiveChannelCreate'];
'multipart/form-data': components['schemas']['AlertReceiveChannelCreate'];
};
};
responses: {
@ -2302,7 +2336,7 @@ export interface operations {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['AlertReceiveChannel'];
'application/json': components['schemas']['AlertReceiveChannelCreate'];
};
};
};