RuleSettingsEditor.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. import { CodeEditor, Select } from '@grafana/ui';
  3. import { RuleType, RuleSetting, PipeLineEntitiesInfo } from './types';
  4. interface Props {
  5. ruleType: RuleType;
  6. onChange: (value: RuleSetting) => void;
  7. value: RuleSetting;
  8. entitiesInfo: PipeLineEntitiesInfo;
  9. }
  10. export const RuleSettingsEditor: React.FC<Props> = ({ onChange, value, ruleType, entitiesInfo }) => {
  11. return (
  12. <>
  13. <Select
  14. key={ruleType}
  15. options={entitiesInfo[ruleType]}
  16. placeholder="Select an option"
  17. value={value?.type ?? ''}
  18. onChange={(value) => {
  19. // set the body with example
  20. const type = value.value;
  21. onChange({
  22. type,
  23. [type]: entitiesInfo.getExample(ruleType, type),
  24. });
  25. }}
  26. />
  27. <CodeEditor
  28. height={'50vh'}
  29. value={value ? JSON.stringify(value[value.type], null, '\t') : ''}
  30. showLineNumbers={true}
  31. readOnly={false}
  32. language="json"
  33. showMiniMap={false}
  34. onBlur={(text: string) => {
  35. const body = JSON.parse(text);
  36. onChange({
  37. type: value.type,
  38. [value.type]: body,
  39. });
  40. }}
  41. />
  42. </>
  43. );
  44. };