Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history


Change-Id: I2f7fd9c436b528abacdcc0aad0da5a3e60b44b64
  • Loading branch information
mtlljm committed Nov 1, 2023
2 parents 43b1dfa + ce3d807 commit 2475ae5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
63 changes: 40 additions & 23 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React, {PureComponent} from 'react';
import {InlineLabel, Select} from '@grafana/ui';
import {Checkbox, InlineLabel, Select, VerticalGroup, HorizontalGroup} from '@grafana/ui';
import {DataSourcePluginOptionsEditorProps, SelectableValue} from '@grafana/data';
import { EspDataSourceOptions } from '../types';

Expand Down Expand Up @@ -67,30 +67,47 @@ export class ConfigEditor extends PureComponent<Props> {
return this.props.options.url;
}

private handleTlsSkipVerifyCheckboxChange(e: React.ChangeEvent<HTMLInputElement>) {
this.changePropOptionsJsonData({tlsSkipVerify: e.currentTarget.checked});
}

private changePropOptionsJsonData(change: Object) {
const newJsonData = {
...this.props.options.jsonData,
...change
};

this.props.onOptionsChange({
...this.props.options,
jsonData: newJsonData
});
}

render() {
return (
<div className="gf-form-group">
<div className="gf-form">
<InlineLabel width="auto">
Discovery service provider
</InlineLabel>
<Select
options={[...ConfigEditor.DISCOVERY_DEFAULT_OPTIONS, ...this.state.customOptions]}
value={this.state.selectedOption}
allowCustomValue
onCreateOption={customValue => {
const customOption: SelectableValue<string> = {value: customValue, label: customValue};
this.setState( (prevState: State) => {
return {
customOptions: [...prevState.customOptions, customOption],
};
});
this.handleDiscoveryServiceProviderChange(customOption);
}}
onChange={this.handleDiscoveryServiceProviderChange}
/>
</div>
</div>
<VerticalGroup>
<HorizontalGroup>
<InlineLabel width="auto">
Discovery service provider
</InlineLabel>
<Select
options={[...ConfigEditor.DISCOVERY_DEFAULT_OPTIONS, ...this.state.customOptions]}
value={this.state.selectedOption}
allowCustomValue
onCreateOption={customValue => {
const customOption: SelectableValue<string> = {value: customValue, label: customValue};
this.setState( (prevState: State) => {
return {
customOptions: [...prevState.customOptions, customOption],
};
});
this.handleDiscoveryServiceProviderChange(customOption);
}}
onChange={this.handleDiscoveryServiceProviderChange}
/>
</HorizontalGroup>
<Checkbox label="(Insecure) Skip TLS certificate verification" value={this.props.options.jsonData.tlsSkipVerify} onChange={this.handleTlsSkipVerifyCheckboxChange}/>
</VerticalGroup>
);
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ export function isField(espObject: EspObject | undefined): espObject is Field {
*/
export interface EspDataSourceOptions extends DataSourceJsonData {
oauthPassThru: boolean;
tlsSkipVerify: boolean;
}

0 comments on commit 2475ae5

Please sign in to comment.