Skip to content

Commit 5811e0d

Browse files
authored
refactor: update json data for datalayers (#3)
1 parent b134297 commit 5811e0d

File tree

4 files changed

+22
-83
lines changed

4 files changed

+22
-83
lines changed

provisioning/datasources/datalayers.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ datasources:
66
uid: 'datalayersio-datasource'
77
jsonData:
88
host: 'your_host_ip:8360'
9-
selectedAuthType: 'username/password'
109
username: 'admin'
11-
metadata:
12-
- database: 'demo'
1310
secureJsonData:
1411
password: 'public'
1512
version: 1

src/components/ConfigEditor.tsx

Lines changed: 20 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import React, {useEffect, useState} from 'react'
2-
import {InlineSwitch, FieldSet, InlineField, SecretInput, Input, InlineFieldRow, InlineLabel, TextArea} from '@grafana/ui'
3-
import {DataSourcePluginOptionsEditorProps, SelectableValue} from '@grafana/data'
1+
import React from 'react'
2+
import {InlineSwitch, FieldSet, InlineField, SecretInput, Input, TextArea} from '@grafana/ui'
3+
import {DataSourcePluginOptionsEditorProps} from '@grafana/data'
44
import {FlightSQLDataSourceOptions, SecureJsonData} from '../types'
55
import {
66
onHostChange,
77
onSecureChange,
88
onUsernameChange,
99
onPasswordChange,
10-
onAuthTypeChange,
11-
onKeyChange,
12-
onValueChange,
13-
addMetaData,
14-
removeMetaData,
1510
onResetPassword,
1611
} from './utils'
1712

@@ -20,31 +15,9 @@ export function ConfigEditor(props: DataSourcePluginOptionsEditorProps<FlightSQL
2015
const {jsonData} = options
2116
const {secureJsonData, secureJsonFields} = options
2217

23-
const [selectedAuthType] = useState<SelectableValue<string>>({
24-
value: jsonData?.selectedAuthType,
25-
label: jsonData?.selectedAuthType,
26-
})
27-
const existingMetastate = jsonData?.metadata?.length && jsonData?.metadata?.map((m: any) => ({key: Object.keys(m)[0], value: Object.values(m)[0]}))
28-
const [metaDataArr, setMetaData] = useState(existingMetastate || [{key: '', value: ''}])
29-
useEffect(() => {
30-
onAuthTypeChange(selectedAuthType, options, onOptionsChange)
31-
// eslint-disable-next-line react-hooks/exhaustive-deps
32-
}, [selectedAuthType])
33-
34-
useEffect(() => {
35-
const {onOptionsChange, options} = props
36-
const mapData = metaDataArr?.map((m: any) => ({[m.key]: m.value}))
37-
const jsonData = {
38-
...options.jsonData,
39-
metadata: mapData,
40-
}
41-
onOptionsChange({...options, jsonData})
42-
// eslint-disable-next-line react-hooks/exhaustive-deps
43-
}, [metaDataArr])
44-
4518
return (
4619
<div>
47-
<FieldSet label="FlightSQL Connection" width={400}>
20+
<FieldSet label="Datalayers Connection" width={400}>
4821
<InlineField labelWidth={20} label="Host:Port">
4922
<Input
5023
width={40}
@@ -78,7 +51,22 @@ export function ConfigEditor(props: DataSourcePluginOptionsEditorProps<FlightSQL
7851
isConfigured={secureJsonFields?.password}
7952
></SecretInput>
8053
</InlineField>
81-
54+
<InlineField labelWidth={20} label="Database">
55+
<Input
56+
width={40}
57+
name="database"
58+
type="text"
59+
placeholder="database name"
60+
onChange={(e) => {
61+
const jsonData = {
62+
...options.jsonData,
63+
database: e.currentTarget.value,
64+
}
65+
onOptionsChange({ ...options, jsonData })
66+
}}
67+
value={jsonData.database || ''}
68+
></Input>
69+
</InlineField>
8270
<InlineField labelWidth={20} label="Require TLS / SSL">
8371
<InlineSwitch
8472
label=""
@@ -98,49 +86,6 @@ export function ConfigEditor(props: DataSourcePluginOptionsEditorProps<FlightSQL
9886
}
9987

10088
</FieldSet>
101-
<FieldSet label="MetaData" width={400}>
102-
{metaDataArr?.map((_: any, i: any) => (
103-
<InlineFieldRow key={i} style={{flexFlow: 'row'}}>
104-
<InlineField labelWidth={20} label="Key">
105-
<Input
106-
key={i}
107-
width={40}
108-
name="key"
109-
type="text"
110-
value={metaDataArr[i]?.key || ''}
111-
placeholder="key"
112-
onChange={(e) => onKeyChange(e, metaDataArr, i, setMetaData)}
113-
></Input>
114-
</InlineField>
115-
<InlineField labelWidth={20} label="Value">
116-
<Input
117-
key={i}
118-
width={40}
119-
name="value"
120-
type="text"
121-
value={metaDataArr[i]?.value || ''}
122-
placeholder="value"
123-
onChange={(e) => onValueChange(e, metaDataArr, i, setMetaData)}
124-
></Input>
125-
</InlineField>
126-
{i + 1 >= metaDataArr.length && (
127-
<InlineLabel as="button" className="" onClick={() => addMetaData(setMetaData, metaDataArr)} width="auto">
128-
+
129-
</InlineLabel>
130-
)}
131-
{i > 0 && (
132-
<InlineLabel
133-
as="button"
134-
className=""
135-
width="auto"
136-
onClick={() => removeMetaData(i, setMetaData, metaDataArr)}
137-
>
138-
-
139-
</InlineLabel>
140-
)}
141-
</InlineFieldRow>
142-
))}
143-
</FieldSet>
14489
</div>
14590
)
14691
}

src/mock-datasource.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export const mockDatasourceOptions: DataSourcePluginOptionsEditorProps<FlightSQL
5555
host: '',
5656
secure: true,
5757
username: '',
58-
selectedAuthType: '',
59-
metadata: [],
6058
},
6159
secureJsonFields: {
6260
token: false,

src/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ export const DEFAULT_QUERY: Partial<SQLQuery> = {}
2020
*/
2121
export interface FlightSQLDataSourceOptions extends DataSourceJsonData {
2222
host?: string
23-
token?: string
2423
secure?: boolean
2524
username?: string
2625
password?: string
27-
selectedAuthType?: string
28-
metadata?: any
26+
database?: string
27+
token?: string
2928
}
3029

3130
export interface SecureJsonData {

0 commit comments

Comments
 (0)