ConfigEditor.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
  3. import { AlertingSettings, DataSourceHttpSettings } from '@grafana/ui';
  4. import { getAllAlertmanagerDataSources } from 'app/features/alerting/unified/utils/alertmanager';
  5. import { LokiOptions } from '../types';
  6. import { DerivedFields } from './DerivedFields';
  7. import { MaxLinesField } from './MaxLinesField';
  8. export type Props = DataSourcePluginOptionsEditorProps<LokiOptions>;
  9. const makeJsonUpdater =
  10. <T extends any>(field: keyof LokiOptions) =>
  11. (options: DataSourceSettings<LokiOptions>, value: T): DataSourceSettings<LokiOptions> => {
  12. return {
  13. ...options,
  14. jsonData: {
  15. ...options.jsonData,
  16. [field]: value,
  17. },
  18. };
  19. };
  20. const setMaxLines = makeJsonUpdater('maxLines');
  21. const setDerivedFields = makeJsonUpdater('derivedFields');
  22. export const ConfigEditor = (props: Props) => {
  23. const { options, onOptionsChange } = props;
  24. const alertmanagers = getAllAlertmanagerDataSources();
  25. return (
  26. <>
  27. <DataSourceHttpSettings
  28. defaultUrl={'http://localhost:3100'}
  29. dataSourceConfig={options}
  30. showAccessOptions={false}
  31. onChange={onOptionsChange}
  32. />
  33. <AlertingSettings<LokiOptions>
  34. alertmanagerDataSources={alertmanagers}
  35. options={options}
  36. onOptionsChange={onOptionsChange}
  37. />
  38. <div className="gf-form-group">
  39. <div className="gf-form-inline">
  40. <div className="gf-form">
  41. <MaxLinesField
  42. value={options.jsonData.maxLines || ''}
  43. onChange={(value) => onOptionsChange(setMaxLines(options, value))}
  44. />
  45. </div>
  46. </div>
  47. </div>
  48. <DerivedFields
  49. value={options.jsonData.derivedFields}
  50. onChange={(value) => onOptionsChange(setDerivedFields(options, value))}
  51. />
  52. </>
  53. );
  54. };