Skip to content

Commit

Permalink
initial commit (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
iadamjee authored Jul 13, 2023
1 parent edf5601 commit d1ed4a5
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ yarn-error.log*

node_modules/

#OS
.DS_Store

# Runtime data
pids
*.pid
Expand All @@ -32,4 +35,4 @@ e2e-results/
# Editor
.idea

.eslintcache
.eslintcache
6 changes: 6 additions & 0 deletions src/datasources/tag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Systemlink Tag data source

<!--
TODO: Write a short description of your plugin and document any extra
configuration that is required for development.
-->
46 changes: 46 additions & 0 deletions src/datasources/tag/TagDataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
DataQueryRequest,
DataQueryResponse,
DataSourceApi,
DataSourceInstanceSettings,
MutableDataFrame,
FieldType,
} from '@grafana/data';

import { TestingStatus, getBackendSrv } from '@grafana/runtime';

import { TagQuery } from './types';

export class TagDataSource extends DataSourceApi<TagQuery> {
baseUrl: string;
constructor(private instanceSettings: DataSourceInstanceSettings) {
super(instanceSettings);
// TODO: set base path of the service
this.baseUrl = this.instanceSettings.url + '/nifoo/v2';
}

async query(options: DataQueryRequest<TagQuery>): Promise<DataQueryResponse> {
const { range } = options;
const from = range!.from.valueOf();
const to = range!.to.valueOf();

// Return a constant for each query.
const data = options.targets.map((target) => {
return new MutableDataFrame({
refId: target.refId,
fields: [
{ name: 'Time', values: [from, to], type: FieldType.time },
{ name: 'Value', values: [target.constant, target.constant], type: FieldType.number },
],
});
});

return { data };
}

async testDatasource(): Promise<TestingStatus> {
// TODO: Implement a health and authentication check
await getBackendSrv().get(this.baseUrl + '/bar');
return { status: 'success', message: 'Data source connected and authentication successful!' };
}
}
32 changes: 32 additions & 0 deletions src/datasources/tag/components/TagQueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { ChangeEvent } from 'react';
import { InlineField, Input } from '@grafana/ui';
import { QueryEditorProps } from '@grafana/data';
import { TagDataSource } from '../TagDataSource';
import { TagQuery } from '../types';

type Props = QueryEditorProps<TagDataSource, TagQuery>;

export function TagQueryEditor({ query, onChange, onRunQuery }: Props) {
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...query, queryText: event.target.value });
};

const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...query, constant: parseFloat(event.target.value) });
// executes the query
onRunQuery();
};

const { queryText, constant } = query;

return (
<div className="gf-form">
<InlineField label="Constant">
<Input onChange={onConstantChange} value={constant} width={8} type="number" step="0.1" />
</InlineField>
<InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
<Input onChange={onQueryTextChange} value={queryText || ''} />
</InlineField>
</div>
);
}
11 changes: 11 additions & 0 deletions src/datasources/tag/img/logo-ni.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/datasources/tag/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DataSourcePlugin } from '@grafana/data';
import { TagDataSource } from './TagDataSource';
import { TagQueryEditor } from './components/TagQueryEditor';
import { HttpConfigEditor } from 'core/HttpConfigEditor';

export const plugin = new DataSourcePlugin(TagDataSource)
.setConfigEditor(HttpConfigEditor)
.setQueryEditor(TagQueryEditor);
15 changes: 15 additions & 0 deletions src/datasources/tag/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "datasource",
"name": "SystemLink Tags",
"id": "ni-sltag-datasource",
"metrics": true,
"info": {
"author": {
"name": "NI"
},
"logos": {
"small": "img/logo-ni.svg",
"large": "img/logo-ni.svg"
}
}
}
6 changes: 6 additions & 0 deletions src/datasources/tag/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DataQuery } from '@grafana/schema'

export interface TagQuery extends DataQuery {
queryText?: string;
constant: number;
}

0 comments on commit d1ed4a5

Please sign in to comment.