Skip to content

Commit b54ccaf

Browse files
committed
feat: better default config values
1 parent 8118160 commit b54ccaf

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

pkg/plugin/datasource.go

+5
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRe
208208
res.Message = "'Host' cannot be empty"
209209
return res, nil
210210
}
211+
if len(config.Username) == 0 {
212+
res.Status = backend.HealthStatusError
213+
res.Message = "'Username' cannot be empty"
214+
return res, nil
215+
}
211216

212217
engine := timeplus.NewEngine(logger, config.Host, config.TCPPort, config.HTTPPort, config.Username, config.Secrets.Password)
213218

pkg/timeplus/engine.go

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ type TimeplusEngine struct {
3737
}
3838

3939
func NewEngine(logger log.Logger, host string, tcpPort, httpPort int, username, password string) *TimeplusEngine {
40+
if tcpPort == 0 {
41+
tcpPort = 8463
42+
}
43+
if httpPort == 0 {
44+
httpPort = 3218
45+
}
4046
connection := protonDriver.OpenDB(&protonDriver.Options{
4147
Addr: []string{fmt.Sprintf("%s:%d", host, tcpPort)},
4248
Auth: protonDriver.Auth{

src/components/ConfigEditor.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { ChangeEvent } from 'react';
21
import { InlineField, Input, SecretInput } from '@grafana/ui';
3-
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
2+
import React, { ChangeEvent } from 'react';
43
import { TpDataSourceOptions, TpSecureJsonData } from '../types';
54

5+
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
6+
67
interface Props extends DataSourcePluginOptionsEditorProps<TpDataSourceOptions, TpSecureJsonData> {}
78

89
export function ConfigEditor(props: Props) {
@@ -75,8 +76,9 @@ export function ConfigEditor(props: Props) {
7576

7677
return (
7778
<>
78-
<InlineField label="Host" labelWidth={14} interactive tooltip={'Hostname'}>
79+
<InlineField required={true} label="Host" labelWidth={14} interactive tooltip={'Hostname'}>
7980
<Input
81+
required={true}
8082
id="config-editor-host"
8183
onChange={onHostChange}
8284
value={jsonData.host}
@@ -104,8 +106,9 @@ export function ConfigEditor(props: Props) {
104106
width={40}
105107
/>
106108
</InlineField>
107-
<InlineField label="Username" labelWidth={14} interactive tooltip={'Username'}>
109+
<InlineField required={true} label="Username" labelWidth={14} interactive tooltip={'Username'}>
108110
<Input
111+
required={true}
109112
id="config-editor-username"
110113
onChange={onUsernameChange}
111114
value={jsonData.username}

0 commit comments

Comments
 (0)