ConfigEditor.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import { SIGV4ConnectionConfig } from '@grafana/aws-sdk';
  3. import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
  4. import { AlertingSettings, DataSourceHttpSettings, Alert } from '@grafana/ui';
  5. import { config } from 'app/core/config';
  6. import { getAllAlertmanagerDataSources } from 'app/features/alerting/unified/utils/alertmanager';
  7. import { PromOptions } from '../types';
  8. import { AzureAuthSettings } from './AzureAuthSettings';
  9. import { hasCredentials, setDefaultCredentials, resetCredentials } from './AzureCredentialsConfig';
  10. import { PromSettings } from './PromSettings';
  11. export type Props = DataSourcePluginOptionsEditorProps<PromOptions>;
  12. export const ConfigEditor = (props: Props) => {
  13. const { options, onOptionsChange } = props;
  14. const alertmanagers = getAllAlertmanagerDataSources();
  15. const azureAuthSettings = {
  16. azureAuthSupported: !!config.featureToggles.prometheus_azure_auth,
  17. getAzureAuthEnabled: (config: DataSourceSettings<any, any>): boolean => hasCredentials(config),
  18. setAzureAuthEnabled: (config: DataSourceSettings<any, any>, enabled: boolean) =>
  19. enabled ? setDefaultCredentials(config) : resetCredentials(config),
  20. azureSettingsUI: AzureAuthSettings,
  21. };
  22. return (
  23. <>
  24. {options.access === 'direct' && (
  25. <Alert title="Deprecation Notice" severity="warning">
  26. Browser access mode in the Prometheus datasource is deprecated and will be removed in a future release.
  27. </Alert>
  28. )}
  29. <DataSourceHttpSettings
  30. defaultUrl="http://localhost:9090"
  31. dataSourceConfig={options}
  32. showAccessOptions={true}
  33. onChange={onOptionsChange}
  34. sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
  35. azureAuthSettings={azureAuthSettings}
  36. renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}
  37. />
  38. <AlertingSettings<PromOptions>
  39. alertmanagerDataSources={alertmanagers}
  40. options={options}
  41. onOptionsChange={onOptionsChange}
  42. />
  43. <PromSettings options={options} onOptionsChange={onOptionsChange} />
  44. </>
  45. );
  46. };