mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 11:42:36 +08:00

* Prometheus package: Replace deprecated @grafana/experimental with @grafana/plugin-ui and @grafana/llm * Fix @grafana/llm mock in test * Keep version exact * Keep version exact * Update lock
97 lines
3.2 KiB
TypeScript
97 lines
3.2 KiB
TypeScript
// Core Grafana history https://github.com/grafana/grafana/blob/v11.0.0-preview/public/app/plugins/datasource/prometheus/configuration/DataSourceHttpSettingsOverhaul.tsx
|
|
import { DataSourceSettings } from '@grafana/data';
|
|
import { Auth, AuthMethod, ConnectionSettings, convertLegacyAuthProps } from '@grafana/plugin-ui';
|
|
import { SecureSocksProxySettings, useTheme2 } from '@grafana/ui';
|
|
|
|
import { PromOptions } from '../types';
|
|
|
|
import { docsTip, overhaulStyles } from './ConfigEditor';
|
|
|
|
export type DataSourceHttpSettingsProps = {
|
|
options: DataSourceSettings<PromOptions, {}>;
|
|
onOptionsChange: (options: DataSourceSettings<PromOptions, {}>) => void;
|
|
secureSocksDSProxyEnabled: boolean;
|
|
};
|
|
|
|
export const DataSourceHttpSettingsOverhaul = (props: DataSourceHttpSettingsProps) => {
|
|
const { options, onOptionsChange, secureSocksDSProxyEnabled } = props;
|
|
|
|
const newAuthProps = convertLegacyAuthProps({
|
|
config: options,
|
|
onChange: onOptionsChange,
|
|
});
|
|
|
|
const theme = useTheme2();
|
|
const styles = overhaulStyles(theme);
|
|
|
|
function returnSelectedMethod() {
|
|
return newAuthProps.selectedMethod;
|
|
}
|
|
|
|
// Do we need this switch anymore? Update the language.
|
|
let urlTooltip;
|
|
switch (options.access) {
|
|
case 'direct':
|
|
urlTooltip = (
|
|
<>
|
|
Your access method is <em>Browser</em>, this means the URL needs to be accessible from the browser.
|
|
{docsTip()}
|
|
</>
|
|
);
|
|
break;
|
|
case 'proxy':
|
|
urlTooltip = (
|
|
<>
|
|
Your access method is <em>Server</em>, this means the URL needs to be accessible from the grafana
|
|
backend/server.
|
|
{docsTip()}
|
|
</>
|
|
);
|
|
break;
|
|
default:
|
|
urlTooltip = <>Specify a complete HTTP URL (for example http://your_server:8080) {docsTip()}</>;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<ConnectionSettings
|
|
urlPlaceholder="http://localhost:9090"
|
|
config={options}
|
|
onChange={onOptionsChange}
|
|
urlLabel="Prometheus server URL"
|
|
urlTooltip={urlTooltip}
|
|
/>
|
|
<hr className={`${styles.hrTopSpace} ${styles.hrBottomSpace}`} />
|
|
<Auth
|
|
// Reshaped legacy props
|
|
{...newAuthProps}
|
|
// Still need to call `onAuthMethodSelect` function from
|
|
// `newAuthProps` to store the legacy data correctly.
|
|
// Also make sure to store the data about your component
|
|
// being selected/unselected.
|
|
onAuthMethodSelect={(method) => {
|
|
onOptionsChange({
|
|
...options,
|
|
basicAuth: method === AuthMethod.BasicAuth,
|
|
withCredentials: method === AuthMethod.CrossSiteCredentials,
|
|
jsonData: {
|
|
...options.jsonData,
|
|
oauthPassThru: method === AuthMethod.OAuthForward,
|
|
},
|
|
});
|
|
}}
|
|
// If your method is selected pass its id to `selectedMethod`,
|
|
// otherwise pass the id from converted legacy data
|
|
selectedMethod={returnSelectedMethod()}
|
|
/>
|
|
<div className={styles.sectionBottomPadding} />
|
|
{secureSocksDSProxyEnabled && (
|
|
<>
|
|
<SecureSocksProxySettings options={options} onOptionsChange={onOptionsChange} />
|
|
<div className={styles.sectionBottomPadding} />
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
};
|