Skip to content

Commit 170a4e4

Browse files
refactor: Improve JS object naming
1 parent 04ff0d1 commit 170a4e4

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

src/components/ConfigEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { ChangeEvent } from 'react';
22
import { InlineField, Input, SecretInput } from '@grafana/ui';
33
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
4-
import { MyDataSourceOptions, MySecureJsonData } from '../types';
4+
import { HaystackDataSourceOptions, HaystackSecureJsonData } from '../types';
55

6-
interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions> {}
6+
interface Props extends DataSourcePluginOptionsEditorProps<HaystackDataSourceOptions> {}
77

88
export function ConfigEditor(props: Props) {
99
const { onOptionsChange, options } = props;
@@ -48,7 +48,7 @@ export function ConfigEditor(props: Props) {
4848
};
4949

5050
const { jsonData, secureJsonFields } = options;
51-
const secureJsonData = (options.secureJsonData || {}) as MySecureJsonData;
51+
const secureJsonData = (options.secureJsonData || {}) as HaystackSecureJsonData;
5252

5353
return (
5454
<div className="gf-form-group">

src/components/QueryEditor.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React, { ChangeEvent, ReactNode } from 'react';
22
import { Button, Field, Form, Icon, InlineField, Input, Select } from '@grafana/ui';
33
import { QueryEditorProps, SelectableValue } from '@grafana/data';
44
import { DataSource } from '../datasource';
5-
import { DEFAULT_QUERY, MyDataSourceOptions, MyQuery } from '../types';
5+
import { DEFAULT_QUERY, HaystackDataSourceOptions, HaystackQuery } from '../types';
66

7-
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
7+
type Props = QueryEditorProps<DataSource, HaystackQuery, HaystackDataSourceOptions>;
88

99
export function QueryEditor({ query, onChange, onRunQuery }: Props) {
1010
const onTypeChange = (event: SelectableValue<number>) => {
@@ -78,7 +78,7 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
7878
return <p>Select a query type</p>
7979
}
8080

81-
function onSubmit(newQuery: Partial<MyQuery>) {
81+
function onSubmit(newQuery: Partial<HaystackQuery>) {
8282
query = { ...query, ...newQuery }
8383
onRunQuery();
8484
}
@@ -88,11 +88,10 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
8888
<Form
8989
onSubmit={onSubmit}
9090
>{({register, errors}) => {
91-
let queryComponent = renderQuery();
9291
return (
9392
<div>
9493
<SelectComponent/>
95-
{queryComponent}
94+
{renderQuery()}
9695
<Button type="submit">Run</Button>
9796
</div>
9897
)

src/datasource.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { DataSourceInstanceSettings, CoreApp } from '@grafana/data';
22
import { DataSourceWithBackend } from '@grafana/runtime';
33

4-
import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
4+
import { HaystackQuery, HaystackDataSourceOptions, DEFAULT_QUERY } from './types';
55

6-
export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptions> {
7-
constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
6+
export class DataSource extends DataSourceWithBackend<HaystackQuery, HaystackDataSourceOptions> {
7+
constructor(instanceSettings: DataSourceInstanceSettings<HaystackDataSourceOptions>) {
88
super(instanceSettings);
99
}
1010

11-
getDefaultQuery(_: CoreApp): Partial<MyQuery> {
11+
getDefaultQuery(_: CoreApp): Partial<HaystackQuery> {
1212
return DEFAULT_QUERY
1313
}
1414
}

src/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { DataSourcePlugin } from '@grafana/data';
22
import { DataSource } from './datasource';
33
import { ConfigEditor } from './components/ConfigEditor';
44
import { QueryEditor } from './components/QueryEditor';
5-
import { MyQuery, MyDataSourceOptions } from './types';
5+
import { HaystackQuery, HaystackDataSourceOptions } from './types';
66

7-
export const plugin = new DataSourcePlugin<DataSource, MyQuery, MyDataSourceOptions>(DataSource)
7+
export const plugin = new DataSourcePlugin<DataSource, HaystackQuery, HaystackDataSourceOptions>(DataSource)
88
.setConfigEditor(ConfigEditor)
99
.setQueryEditor(QueryEditor);

src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { DataQuery, DataSourceJsonData } from '@grafana/data';
22

3-
export interface MyQuery extends DataQuery {
3+
export interface HaystackQuery extends DataQuery {
44
type: string; // Defines the type of query that should be executed
55
eval: string;
66
hisRead: string;
77
read: string;
88
}
99

10-
export const DEFAULT_QUERY: Partial<MyQuery> = {
10+
export const DEFAULT_QUERY: Partial<HaystackQuery> = {
1111
type: "Eval",
1212
eval: "[{ts: $__timeRange_start, v0: 0}, {ts: $__timeRange_end, v0: 10}].toGrid",
1313
hisRead: "abcdef-123456",
@@ -17,14 +17,14 @@ export const DEFAULT_QUERY: Partial<MyQuery> = {
1717
/**
1818
* These are options configured for each DataSource instance
1919
*/
20-
export interface MyDataSourceOptions extends DataSourceJsonData {
20+
export interface HaystackDataSourceOptions extends DataSourceJsonData {
2121
url: string;
2222
username: string;
2323
}
2424

2525
/**
2626
* Value that is used in the backend, but never sent over HTTP to the frontend
2727
*/
28-
export interface MySecureJsonData {
28+
export interface HaystackSecureJsonData {
2929
password: string;
3030
}

0 commit comments

Comments
 (0)