Skip to content

Commit e9af417

Browse files
committed
added timestamp column input in config
1 parent 19ad370 commit e9af417

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed
Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,67 @@
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';
33
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
44
import { MyDataSourceOptions } from '../../types';
5+
import { css } from '@emotion/css';
56

67
interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions> {}
78

89
export function ConfigEditor(props: Props) {
910
const { onOptionsChange, options } = props;
1011

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+
1137
return (
1238
<div>
1339
<DataSourceHttpSettings
1440
defaultUrl="http://localhost:9200"
1541
dataSourceConfig={options}
1642
showAccessOptions={false}
1743
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>
1965
</div>
2066
);
2167
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const DEFAULT_QUERY: Partial<MyQuery> = {
2424
export interface MyDataSourceOptions extends DataSourceJsonData {
2525
path?: string;
2626
url: string;
27+
timestamp_column: string;
2728
}
2829

2930
/**

0 commit comments

Comments
 (0)