elastic: config: hide access-mode selector when not needed (#49246)

This commit is contained in:
Gábor Farkas 2022-05-20 17:42:12 +02:00 committed by GitHub
parent 34fa7b493c
commit c980655f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import React, { useEffect } from 'react'; import React, { useEffect, useRef } from 'react';
import { SIGV4ConnectionConfig } from '@grafana/aws-sdk'; import { SIGV4ConnectionConfig } from '@grafana/aws-sdk';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
@ -16,6 +16,12 @@ import { coerceOptions, isValidOptions } from './utils';
export type Props = DataSourcePluginOptionsEditorProps<ElasticsearchOptions>; export type Props = DataSourcePluginOptionsEditorProps<ElasticsearchOptions>;
export const ConfigEditor = (props: Props) => { 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: originalOptions, onOptionsChange } = props;
const options = coerceOptions(originalOptions); const options = coerceOptions(originalOptions);
@ -45,7 +51,7 @@ export const ConfigEditor = (props: Props) => {
<DataSourceHttpSettings <DataSourceHttpSettings
defaultUrl="http://localhost:9200" defaultUrl="http://localhost:9200"
dataSourceConfig={options} dataSourceConfig={options}
showAccessOptions showAccessOptions={showAccessOptions.current}
onChange={onOptionsChange} onChange={onOptionsChange}
sigV4AuthToggleEnabled={config.sigV4AuthEnabled} sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>} renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}