ConfigEditor.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React, { useEffect, useRef } from 'react';
  2. import { SIGV4ConnectionConfig } from '@grafana/aws-sdk';
  3. import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
  4. import { Alert, DataSourceHttpSettings } from '@grafana/ui';
  5. import { config } from 'app/core/config';
  6. import { ElasticsearchOptions } from '../types';
  7. import { isSupportedVersion } from '../utils';
  8. import { DataLinks } from './DataLinks';
  9. import { ElasticDetails } from './ElasticDetails';
  10. import { LogsConfig } from './LogsConfig';
  11. import { coerceOptions, isValidOptions } from './utils';
  12. export type Props = DataSourcePluginOptionsEditorProps<ElasticsearchOptions>;
  13. export const ConfigEditor = (props: Props) => {
  14. // we decide on whether to show access options or not at the point when the config page opens.
  15. // whatever happens while the page is open, this decision does not change.
  16. // (we do this to avoid situations where you switch access-mode and suddenly
  17. // the access-mode-select-box vanishes)
  18. const showAccessOptions = useRef(props.options.access === 'direct');
  19. const { options: originalOptions, onOptionsChange } = props;
  20. const options = coerceOptions(originalOptions);
  21. useEffect(() => {
  22. if (!isValidOptions(originalOptions)) {
  23. onOptionsChange(coerceOptions(originalOptions));
  24. }
  25. // We can't enforce the eslint rule here because we only want to run this once.
  26. // eslint-disable-next-line react-hooks/exhaustive-deps
  27. }, []);
  28. const supportedVersion = isSupportedVersion(options.jsonData.esVersion);
  29. return (
  30. <>
  31. {options.access === 'direct' && (
  32. <Alert title="Error" severity="error">
  33. Browser access mode in the Elasticsearch datasource is no longer available. Switch to server access mode.
  34. </Alert>
  35. )}
  36. {!supportedVersion && (
  37. <Alert title="Deprecation notice" severity="error">
  38. {`Support for Elasticsearch versions after their end-of-life (currently versions < 7.10) was removed`}
  39. </Alert>
  40. )}
  41. <DataSourceHttpSettings
  42. defaultUrl="http://localhost:9200"
  43. dataSourceConfig={options}
  44. showAccessOptions={showAccessOptions.current}
  45. onChange={onOptionsChange}
  46. sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
  47. renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}
  48. />
  49. <ElasticDetails value={options} onChange={onOptionsChange} />
  50. <LogsConfig
  51. value={options.jsonData}
  52. onChange={(newValue) =>
  53. onOptionsChange({
  54. ...options,
  55. jsonData: newValue,
  56. })
  57. }
  58. />
  59. <DataLinks
  60. value={options.jsonData.dataLinks}
  61. onChange={(newValue) => {
  62. onOptionsChange({
  63. ...options,
  64. jsonData: {
  65. ...options.jsonData,
  66. dataLinks: newValue,
  67. },
  68. });
  69. }}
  70. />
  71. </>
  72. );
  73. };