DataSourceSettings: Fix recent changes to HttpDataSourceSettings (#67436)

This commit is contained in:
Torkel Ödegaard 2023-04-28 07:17:18 +02:00 committed by GitHub
parent f5d97c677b
commit ea536411f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 28 deletions

View File

@ -73,11 +73,13 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
azureAuthSettings,
renderSigV4Editor,
secureSocksDSProxyEnabled,
connectionElements,
urlLabel,
urlDocs,
} = props;
let urlTooltip;
const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false);
const theme = useTheme2();
let urlTooltip;
const onSettingsChange = useCallback(
(change: Partial<DataSourceSettings<any, any>>) => {
@ -94,7 +96,7 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
urlTooltip = (
<>
Your access method is <em>Browser</em>, this means the URL needs to be accessible from the browser.
{connectionElements?.tooltip}
{urlDocs}
</>
);
break;
@ -103,12 +105,12 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
<>
Your access method is <em>Server</em>, this means the URL needs to be accessible from the grafana
backend/server.
{connectionElements?.tooltip}
{urlDocs}
</>
);
break;
default:
urlTooltip = <>Specify a complete HTTP URL (for example http://your_server:8080) {connectionElements?.tooltip}</>;
urlTooltip = <>Specify a complete HTTP URL (for example http://your_server:8080) {urlDocs}</>;
}
const accessSelect = (
@ -146,24 +148,20 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
const azureAuthEnabled: boolean =
(azureAuthSettings?.azureAuthSupported && azureAuthSettings.getAzureAuthEnabled(dataSourceConfig)) || false;
const connectionLabel = connectionElements?.label ? connectionElements?.label : 'URL';
return (
<div className="gf-form-group">
<>
<h3 className="page-heading">HTTP</h3>
<div className="gf-form-group">
{defaultUrl && (
<div className="gf-form">
<FormField
interactive={connectionElements?.tooltip ? true : false}
label={connectionLabel}
labelWidth={13}
tooltip={urlTooltip}
inputEl={urlInput}
/>
</div>
)}
<div className="gf-form">
<FormField
interactive={urlDocs ? true : false}
label={urlLabel ?? 'URL'}
labelWidth={13}
tooltip={urlTooltip}
inputEl={urlInput}
/>
</div>
{showAccessOptions && (
<>

View File

@ -30,7 +30,11 @@ export interface HttpSettingsBaseProps<JSONData extends DataSourceJsonData = any
export interface HttpSettingsProps extends HttpSettingsBaseProps {
/** The default url for the data source */
defaultUrl?: string;
defaultUrl: string;
/** Set label for url option */
urlLabel?: string;
/** Added to default url tooltip */
urlDocs?: React.ReactNode;
/** Show the http access help box */
showAccessOptions?: boolean;
/** Show the SigV4 auth toggle option */
@ -41,9 +45,4 @@ export interface HttpSettingsProps extends HttpSettingsBaseProps {
renderSigV4Editor?: React.ReactNode;
/** Show the Secure Socks Datasource Proxy toggle option */
secureSocksDSProxyEnabled?: boolean;
/** connection URL label and tooltip */
connectionElements?: {
label?: string;
tooltip?: React.ReactNode;
};
}

View File

@ -49,10 +49,8 @@ export const ConfigEditor = (props: Props) => {
azureAuthSettings={azureAuthSettings}
renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}
secureSocksDSProxyEnabled={config.secureSocksDSProxyEnabled}
connectionElements={{
label: 'Prometheus server URL',
tooltip: docsTip(),
}}
urlLabel="Prometheus server URL"
urlDocs={docsTip()}
/>
<>
<hr className={styles.hrTopSpace} />