monitorModel.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import FormModel from 'sentry/components/forms/model';
  2. import {MonitorConfig} from './types';
  3. type TransformedData = {
  4. config?: Partial<MonitorConfig>;
  5. };
  6. export default class MonitorModel extends FormModel {
  7. getTransformedData() {
  8. return this.fields.toJSON().reduce<TransformedData>((data, [k, v]) => {
  9. if (k.indexOf('config.') !== 0) {
  10. data[k] = v;
  11. return data;
  12. }
  13. if (!data.config) {
  14. data.config = {};
  15. }
  16. if (k === 'config.schedule.frequency' || k === 'config.schedule.interval') {
  17. if (!Array.isArray(data.config.schedule)) {
  18. data.config.schedule = [null, null];
  19. }
  20. }
  21. if (k === 'config.schedule.frequency') {
  22. data.config!.schedule![0] = parseInt(v as string, 10);
  23. } else if (k === 'config.schedule.interval') {
  24. data.config!.schedule![1] = v;
  25. } else {
  26. data.config[k.substr(7)] = v;
  27. }
  28. return data;
  29. }, {});
  30. }
  31. getTransformedValue(id: string) {
  32. return id.indexOf('config') === 0 ? this.getValue(id) : super.getTransformedValue(id);
  33. }
  34. }