|
1 |
| -import React from 'react'; |
2 |
| -import { DataSourceHttpSettings } from '@grafana/ui'; |
| 1 | +import React, { useState, useEffect } from 'react'; |
| 2 | +import { DataSourceHttpSettings, Field, InlineLabel, Input } from '@grafana/ui'; |
3 | 3 | import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
4 | 4 | import { MyDataSourceOptions } from '../../types';
|
| 5 | +import { css } from '@emotion/css'; |
5 | 6 |
|
6 | 7 | interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions> {}
|
7 | 8 |
|
8 | 9 | export function ConfigEditor(props: Props) {
|
9 | 10 | const { onOptionsChange, options } = props;
|
10 | 11 |
|
| 12 | + const [timestampName, setTimestampName] = useState(''); |
| 13 | + |
| 14 | + useEffect(() => { |
| 15 | + const timestamp_column = options?.jsonData?.timestamp_column || '_timestamp'; |
| 16 | + if (timestamp_column) { |
| 17 | + setTimestampName(timestamp_column); |
| 18 | + } |
| 19 | + |
| 20 | + // eslint-disable-next-line react-hooks/exhaustive-deps |
| 21 | + }, []); |
| 22 | + |
| 23 | + const updateTimestampName = (name: string) => { |
| 24 | + if (name === '') { |
| 25 | + name = '_timestamp'; |
| 26 | + } |
| 27 | + setTimestampName(name); |
| 28 | + onOptionsChange({ |
| 29 | + ...options, |
| 30 | + jsonData: { |
| 31 | + ...options.jsonData, |
| 32 | + timestamp_column: name, |
| 33 | + }, |
| 34 | + }); |
| 35 | + }; |
| 36 | + |
11 | 37 | return (
|
12 | 38 | <div>
|
13 | 39 | <DataSourceHttpSettings
|
14 | 40 | defaultUrl="http://localhost:9200"
|
15 | 41 | dataSourceConfig={options}
|
16 | 42 | showAccessOptions={false}
|
17 | 43 | onChange={onOptionsChange}
|
18 |
| - /> |
| 44 | + ></DataSourceHttpSettings> |
| 45 | + <div className="page-heading">OpenObserve details</div> |
| 46 | + <div |
| 47 | + className={css` |
| 48 | + display: flex; |
| 49 | + align-items: start; |
| 50 | + padding-right: 1rem; |
| 51 | + `} |
| 52 | + > |
| 53 | + <InlineLabel className="width-10">Time field name</InlineLabel> |
| 54 | + <Field |
| 55 | + invalid={timestampName === ''} |
| 56 | + error={timestampName === '' ? 'Timestamp Field Name cannot be empty' : ''} |
| 57 | + > |
| 58 | + <Input |
| 59 | + className="width-18" |
| 60 | + value={timestampName} |
| 61 | + onChange={(e) => updateTimestampName(e.currentTarget.value)} |
| 62 | + /> |
| 63 | + </Field> |
| 64 | + </div> |
19 | 65 | </div>
|
20 | 66 | );
|
21 | 67 | }
|
0 commit comments