mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
400aafa3b3
* implement edit page * connectWithCleanup * remove angular related code * use loadingindicator * use the correct loading component * handle secureFields * fixed implementation of secure fields * Keep secureFields after rerendering the form * CollapsableSection and Page refactor * use checkbox instead of switch * fix comment * add cursor to section * Fixed issues after PR review * Fix issue with some settings being undefined * new reducer and start with test * algorithm to migrate secure fields * UX: Minor UI Tweaks * Added field around checkboxes, and missing required field * fixed test * tests for util * minor tweaks and changes * define as records * fix typ error * forward invalid to textarea and inputcontrol * merge formdata and redux data in test * fix issue with creating channel * do not figure out securefields in migration Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import memoizeOne from 'memoize-one';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { config } from '@grafana/runtime';
|
|
import { NotificationChannelDTO, NotificationChannelType } from 'app/types';
|
|
|
|
export const defaultValues: NotificationChannelDTO = {
|
|
id: -1,
|
|
name: '',
|
|
type: { value: 'email', label: 'Email' },
|
|
sendReminder: false,
|
|
disableResolveMessage: false,
|
|
frequency: '15m',
|
|
settings: {
|
|
uploadImage: config.rendererAvailable,
|
|
autoResolve: true,
|
|
httpMethod: 'POST',
|
|
severity: 'critical',
|
|
},
|
|
secureSettings: {},
|
|
secureFields: {},
|
|
isDefault: false,
|
|
};
|
|
|
|
export const mapChannelsToSelectableValue = memoizeOne(
|
|
(notificationChannels: NotificationChannelType[]): Array<SelectableValue<string>> => {
|
|
return notificationChannels.map(channel => ({
|
|
value: channel.value,
|
|
label: channel.label,
|
|
description: channel.description,
|
|
}));
|
|
}
|
|
);
|
|
|
|
export const transformSubmitData = (formData: NotificationChannelDTO) => {
|
|
/*
|
|
Some settings can be options in a select, in order to not save a SelectableValue<T>
|
|
we need to use check if it is a SelectableValue and use its value.
|
|
*/
|
|
const settings = Object.fromEntries(
|
|
Object.entries(formData.settings).map(([key, value]) => {
|
|
return [key, value && value.hasOwnProperty('value') ? value.value : value];
|
|
})
|
|
);
|
|
|
|
return {
|
|
...defaultValues,
|
|
...formData,
|
|
frequency: formData.frequency === '' ? defaultValues.frequency : formData.frequency,
|
|
type: formData.type.value,
|
|
settings: { ...defaultValues.settings, ...settings },
|
|
secureSettings: { ...formData.secureSettings },
|
|
};
|
|
};
|
|
|
|
export const transformTestData = (formData: NotificationChannelDTO) => {
|
|
return {
|
|
name: formData.name,
|
|
type: formData.type.value,
|
|
frequency: formData.frequency ?? defaultValues.frequency,
|
|
settings: { ...Object.assign(defaultValues.settings, formData.settings) },
|
|
secureSettings: { ...formData.secureSettings },
|
|
};
|
|
};
|