Skip to content

Commit 3b87780

Browse files
refactor: Applies formatting
1 parent c3dbe33 commit 3b87780

9 files changed

Lines changed: 105 additions & 80 deletions

File tree

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore artifacts:
2+
.config
3+
package.json
4+
package-lock.json
5+
tsconfig.json
6+
yarn.lock

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## 1.0.0 (Unreleased)
44

5-
Initial release.
5+
Initial release.

DEVELOPMENT_GUIDE.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Development Guide
22

33
## Environment
4+
45
To get a development environment up and running, first ensure the following are installed:
56

67
1. go
@@ -32,7 +33,7 @@ mage -v && docker-compose up
3233
## Usage
3334

3435
Create a new data source, select "Haystack", and provide it the details for the Haxall server
35-
that was started. In order to reference your host machine's network, use the url
36+
that was started. In order to reference your host machine's network, use the url
3637
`http://host.docker.internal:8080/api/`. Click "Save and Test" and make sure that it is
3738
reported as working.
3839

@@ -47,7 +48,7 @@ Alternatively, nearly every Axon query can be visualized using the table view.
4748

4849
# Release
4950

50-
To trigger a new release of the plugin, we need to push a version tag to github. This can be
51+
To trigger a new release of the plugin, we need to push a version tag to github. This can be
5152
achieved with the following steps:
5253

5354
1. Run `npm version <major|minor|patch>`
@@ -87,6 +88,7 @@ Grafana supports a wide range of data sources, including Prometheus, MySQL, and
8788
```bash
8889
mage -l
8990
```
91+
9092
### Frontend
9193

9294
1. Install dependencies
@@ -112,7 +114,7 @@ Grafana supports a wide range of data sources, including Prometheus, MySQL, and
112114
```bash
113115
# Runs the tests and watches for changes, requires git init first
114116
yarn test
115-
117+
116118
# Exists after running all the tests
117119
yarn test:ci
118120
```
@@ -126,9 +128,9 @@ Grafana supports a wide range of data sources, including Prometheus, MySQL, and
126128
6. Run the E2E tests (using Cypress)
127129

128130
```bash
129-
# Spin up a Grafana instance first that we tests against
131+
# Spin up a Grafana instance first that we tests against
130132
yarn server
131-
133+
132134
# Start the tests
133135
yarn e2e
134136
```
@@ -137,13 +139,12 @@ Grafana supports a wide range of data sources, including Prometheus, MySQL, and
137139

138140
```bash
139141
yarn lint
140-
142+
141143
# or
142144

143145
yarn lint:fix
144146
```
145147

146-
147148
# Distributing your plugin
148149

149150
When distributing a Grafana plugin either within the community or privately the plugin must be signed so the Grafana application can verify its authenticity. This can be done with the `@grafana/sign-plugin` package.
@@ -183,7 +184,6 @@ To trigger the workflow we need to push a version tag to github. This can be ach
183184
1. Run `npm version <major|minor|patch>`
184185
2. Run `git push origin main --follow-tags`
185186

186-
187187
## Learn more
188188

189189
Below you can find source code for existing app plugins and other related documentation.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Contributions are very welcome! For details on how to develop this plugin, see t
2424

2525
## Continuing Work
2626

27-
* [ ] Add alert support
28-
* [ ] Publish plugin
29-
* [ ] Consider enabling multi-point hisRead (through filters)
27+
- [ ] Add alert support
28+
- [ ] Publish plugin
29+
- [ ] Consider enabling multi-point hisRead (through filters)

src/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ one by selecting `+ New Dashboard` from the Dashboard menu in the left panel.
2424
Once within the panel editor, select your Haystack data source in the Data Sources menu. Next, select the type of
2525
Haystack query that should be performed. The supported queries are:
2626

27-
- Eval: Evaluate a free-form Axon expression. *Note: Not all Haystack servers support this functionality*
27+
- Eval: Evaluate a free-form Axon expression. _Note: Not all Haystack servers support this functionality_
2828
- HisRead: Display the history of a single point over the selected time range.
2929
- Read: Display the records matching a filter. Since this is not timeseries data, it can only be viewed in Grafana's
30-
"Table" view.
30+
"Table" view.
3131

3232
#### Variable Usage
3333

@@ -38,8 +38,8 @@ We also support injecting a few special variables from the time-range selector i
3838
- `$__timeRange_start`: DateTime start of the selected Grafana time range
3939
- `$__timeRange_end`: DateTime end of the selected Grafana time range
4040
- `$__maxDataPoints`: Number representing the pixel width of Grafana's display panel.
41-
- `$__interval`: Number representing Grafana's recommended data interval. This is the duration of the time range,
42-
divided by the number of pixels, delivered in units of minutes.
41+
- `$__interval`: Number representing Grafana's recommended data interval. This is the duration of the time range,
42+
divided by the number of pixels, delivered in units of minutes.
4343

4444
To use them, simply enter the value in the input string. Below is an example of using the variables in an Eval query:
4545

@@ -56,4 +56,4 @@ column is specified, the first one is used.
5656
The value injected by the variable exactly matches the displayed value, with the exception of Ref types, where the
5757
injected value is only the ID portion (i.e. the dis name is not included in the interpolation). Multiple-select values
5858
are combined with commas, (`red,blue`), but this may be customized using the
59-
[advanced variable format options](https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#advanced-variable-format-options).
59+
[advanced variable format options](https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#advanced-variable-format-options).

src/components/QueryEditor.tsx

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,72 +24,90 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
2424
const queryTypes = [
2525
{ label: 'Eval', value: 0, description: 'Evaluate an Axon expression' },
2626
{ label: 'HisRead', value: 1, description: 'Read the history of a point' },
27-
{ label: 'Read', value: 2, description: 'Read the records matched by a filter' }
27+
{ label: 'Read', value: 2, description: 'Read the records matched by a filter' },
2828
];
2929
const queryTypeDefault = queryTypes[0];
3030
function queryTypeFromLabel(label: string) {
31-
return queryTypes.find(queryType => queryType.label === label) ?? queryTypeDefault
31+
return queryTypes.find((queryType) => queryType.label === label) ?? queryTypeDefault;
3232
}
3333

3434
const SelectComponent = () => {
3535
return (
36-
<Field>
37-
<Select
38-
options={queryTypes}
39-
value={queryTypeFromLabel(query.type)}
40-
defaultValue={queryTypeDefault}
41-
width={30}
42-
onChange={ queryType => {
43-
onTypeChange(queryType);
44-
}}
45-
/>
46-
</Field>
36+
<Field>
37+
<Select
38+
options={queryTypes}
39+
value={queryTypeFromLabel(query.type)}
40+
defaultValue={queryTypeDefault}
41+
width={30}
42+
onChange={(queryType) => {
43+
onTypeChange(queryType);
44+
}}
45+
/>
46+
</Field>
4747
);
4848
};
4949

5050
function renderQuery(): ReactNode {
5151
let queryType = queryTypeFromLabel(query.type);
52-
switch(queryType.value) {
52+
switch (queryType.value) {
5353
case 0: // Eval
5454
return (
55-
<Field>
56-
<Input width={100} prefix={<Icon name="angle-right" />} onChange={onEvalChange} value={query.eval} placeholder={DEFAULT_QUERY.eval} />
57-
</Field>
55+
<Field>
56+
<Input
57+
width={100}
58+
prefix={<Icon name="angle-right" />}
59+
onChange={onEvalChange}
60+
value={query.eval}
61+
placeholder={DEFAULT_QUERY.eval}
62+
/>
63+
</Field>
5864
);
5965
case 1: // HisRead
6066
return (
61-
<Field>
62-
<Input width={30} prefix={"@"} onChange={onHisReadChange} value={query.hisRead} placeholder={DEFAULT_QUERY.hisRead} />
63-
</Field>
67+
<Field>
68+
<Input
69+
width={30}
70+
prefix={'@'}
71+
onChange={onHisReadChange}
72+
value={query.hisRead}
73+
placeholder={DEFAULT_QUERY.hisRead}
74+
/>
75+
</Field>
6476
);
6577
case 2: // Read
6678
return (
67-
<Field>
68-
<Input width={75} prefix={<Icon name="filter" />} onChange={onReadChange} value={query.read} placeholder={DEFAULT_QUERY.read} />
69-
</Field>
79+
<Field>
80+
<Input
81+
width={75}
82+
prefix={<Icon name="filter" />}
83+
onChange={onReadChange}
84+
value={query.read}
85+
placeholder={DEFAULT_QUERY.read}
86+
/>
87+
</Field>
7088
);
7189
}
72-
return <p>Select a query type</p>
90+
return <p>Select a query type</p>;
7391
}
7492

7593
function onSubmit(newQuery: Partial<HaystackQuery>) {
76-
query = { ...query, ...newQuery }
94+
query = { ...query, ...newQuery };
7795
onRunQuery();
7896
}
7997

8098
return (
8199
<div className="gf-form">
82-
<Form
83-
onSubmit={onSubmit}
84-
>{({register, errors}) => {
85-
return (
86-
<div>
87-
<SelectComponent/>
88-
{renderQuery()}
89-
<Button type="submit">Run</Button>
90-
</div>
91-
)
92-
}}</Form>
100+
<Form onSubmit={onSubmit}>
101+
{({ register, errors }) => {
102+
return (
103+
<div>
104+
<SelectComponent />
105+
{renderQuery()}
106+
<Button type="submit">Run</Button>
107+
</div>
108+
);
109+
}}
110+
</Form>
93111
</div>
94112
);
95113
}

src/components/VariableQueryEditor.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ export const VariableQueryEditor: React.FC<VariableQueryProps> = ({ onChange, qu
2323
<>
2424
<div className="gf-form">
2525
<span className="gf-form-label width-10">Eval</span>
26-
<input
27-
name="eval"
28-
className="gf-form-input"
29-
onBlur={saveQuery}
30-
onChange={handleChange}
31-
value={state.eval}
32-
/>
26+
<input name="eval" className="gf-form-input" onBlur={saveQuery} onChange={handleChange} value={state.eval} />
3327
</div>
3428
<div className="gf-form">
3529
<span className="gf-form-label width-10">Column</span>

src/datasource.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { DataSourceInstanceSettings, CoreApp, ScopedVars, DataQueryRequest, DataFrame, Field, MetricFindValue } from '@grafana/data';
1+
import {
2+
DataSourceInstanceSettings,
3+
CoreApp,
4+
ScopedVars,
5+
DataQueryRequest,
6+
DataFrame,
7+
Field,
8+
MetricFindValue,
9+
} from '@grafana/data';
210
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
311

412
import { HaystackQuery, HaystackDataSourceOptions, DEFAULT_QUERY, HaystackVariableQuery } from './types';
@@ -11,51 +19,50 @@ export class DataSource extends DataSourceWithBackend<HaystackQuery, HaystackDat
1119
applyTemplateVariables(query: HaystackQuery, scopedVars: ScopedVars): Record<string, any> {
1220
return {
1321
...query,
14-
eval: getTemplateSrv().replace(query.eval, scopedVars, "csv"),
15-
hisRead: getTemplateSrv().replace(query.hisRead, scopedVars, "csv"),
16-
read: getTemplateSrv().replace(query.read, scopedVars, "csv"),
22+
eval: getTemplateSrv().replace(query.eval, scopedVars, 'csv'),
23+
hisRead: getTemplateSrv().replace(query.hisRead, scopedVars, 'csv'),
24+
read: getTemplateSrv().replace(query.read, scopedVars, 'csv'),
1725
};
1826
}
1927

2028
// This is called when the user is selecting a variable value
2129
async metricFindQuery(query: HaystackVariableQuery, options?: any) {
2230
let request: HaystackQuery = {
23-
refId: "VariableQuery",
24-
type: "Eval",
31+
refId: 'VariableQuery',
32+
type: 'Eval',
2533
eval: query.eval,
26-
hisRead: "",
27-
read: ""
34+
hisRead: '',
35+
read: '',
2836
};
29-
let response = await this.query({ targets: [request] } as DataQueryRequest<HaystackQuery>).toPromise()
37+
let response = await this.query({ targets: [request] } as DataQueryRequest<HaystackQuery>).toPromise();
3038

3139
if (response === undefined || response.data === undefined) {
3240
return [];
3341
}
3442

3543
return response.data.reduce((acc: MetricFindValue[], frame: DataFrame) => {
3644
let field = frame.fields[0];
37-
if (query.column !== undefined && query.column !== "") {
45+
if (query.column !== undefined && query.column !== '') {
3846
// If a column was input, match the column name
3947
field = frame.fields.find((field: Field) => field.name === query.column) ?? field;
4048
}
4149

4250
let fieldVals = field.values.toArray().map((value) => {
43-
if (value.startsWith("@")) {
51+
if (value.startsWith('@')) {
4452
// Detect ref using @ prefix, and adjust value to just the Ref
45-
let spaceIndex = value.indexOf(" ");
53+
let spaceIndex = value.indexOf(' ');
4654
let id = value.substring(0, spaceIndex);
47-
return {text: value, value: id};
55+
return { text: value, value: id };
4856
} else {
4957
// Otherwise, just use the value directly
50-
return {text: value, value: value};
58+
return { text: value, value: value };
5159
}
5260
});
5361
return acc.concat(fieldVals);
5462
}, []);
5563
}
56-
5764

5865
getDefaultQuery(_: CoreApp): Partial<HaystackQuery> {
59-
return DEFAULT_QUERY
66+
return DEFAULT_QUERY;
6067
}
6168
}

src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export interface HaystackVariableQuery {
1313
}
1414

1515
export const DEFAULT_QUERY: Partial<HaystackQuery> = {
16-
type: "Eval",
17-
eval: "[{ts: $__timeRange_start, v0: 0}, {ts: $__timeRange_end, v0: 10}].toGrid",
18-
hisRead: "abcdef-123456",
19-
read: "point and temp and air and outside"
16+
type: 'Eval',
17+
eval: '[{ts: $__timeRange_start, v0: 0}, {ts: $__timeRange_end, v0: 10}].toGrid',
18+
hisRead: 'abcdef-123456',
19+
read: 'point and temp and air and outside',
2020
};
2121

2222
/**

0 commit comments

Comments
 (0)