The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.tsx

82 lines
2.7 KiB

import React, { useEffect, useRef } from 'react';
import { SIGV4ConnectionConfig } from '@grafana/aws-sdk';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { Alert, DataSourceHttpSettings, SecureSocksProxySettings } from '@grafana/ui';
import { config } from 'app/core/config';
import { ElasticsearchOptions } from '../types';
import { DataLinks } from './DataLinks';
import { ElasticDetails } from './ElasticDetails';
import { LogsConfig } from './LogsConfig';
import { coerceOptions, isValidOptions } from './utils';
export type Props = DataSourcePluginOptionsEditorProps<ElasticsearchOptions>;
export const ConfigEditor = (props: Props) => {
// we decide on whether to show access options or not at the point when the config page opens.
// whatever happens while the page is open, this decision does not change.
// (we do this to avoid situations where you switch access-mode and suddenly
// the access-mode-select-box vanishes)
const showAccessOptions = useRef(props.options.access === 'direct');
const { options: originalOptions, onOptionsChange } = props;
const options = coerceOptions(originalOptions);
useEffect(() => {
if (!isValidOptions(originalOptions)) {
onOptionsChange(coerceOptions(originalOptions));
}
// We can't enforce the eslint rule here because we only want to run this once.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<>
{options.access === 'direct' && (
<Alert title="Error" severity="error">
Browser access mode in the Elasticsearch datasource is no longer available. Switch to server access mode.
</Alert>
)}
<DataSourceHttpSettings
defaultUrl="http://localhost:9200"
dataSourceConfig={options}
showAccessOptions={showAccessOptions.current}
onChange={onOptionsChange}
sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}
/>
{config.featureToggles.secureSocksDatasourceProxy && (
<SecureSocksProxySettings options={options} onOptionsChange={onOptionsChange} />
)}
<ElasticDetails value={options} onChange={onOptionsChange} />
<LogsConfig
value={options.jsonData}
onChange={(newValue) =>
onOptionsChange({
...options,
jsonData: newValue,
})
}
/>
<DataLinks
value={options.jsonData.dataLinks}
onChange={(newValue) => {
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
dataLinks: newValue,
},
});
}}
/>
</>
);
};