-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display system status counts (#6)
Co-authored-by: Carson Moore <carson.moore@ni.com> Co-authored-by: Cameron Waterman <cameron.waterman@ni.com>
- Loading branch information
1 parent
2b21199
commit 285b8b2
Showing
6 changed files
with
78 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ module.exports = { | |
}], | ||
'@semantic-release/git' | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { enumToOptions } from "./utils"; | ||
|
||
test('enumToOptions', () => { | ||
enum fakeStringEnum { | ||
Label1 = 'Value1', | ||
Label2 = 'Value2' | ||
}; | ||
|
||
const result = enumToOptions(fakeStringEnum); | ||
|
||
expect(result).toEqual([ | ||
{ label: 'Label1', value: 'Value1' }, | ||
{ label: 'Label2', value: 'Value2' } | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SelectableValue } from "@grafana/data"; | ||
|
||
export function enumToOptions<T>(stringEnum: { [name: string]: T }): Array<SelectableValue<T>> { | ||
const RESULT = []; | ||
|
||
for (const [key, value] of Object.entries(stringEnum)) { | ||
RESULT.push({ label: key, value: value }); | ||
} | ||
|
||
return RESULT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
import React, { ChangeEvent } from 'react'; | ||
import { InlineField, Input } from '@grafana/ui'; | ||
import React from 'react'; | ||
import { InlineField, InlineFieldRow, RadioButtonGroup } from '@grafana/ui'; | ||
import { QueryEditorProps } from '@grafana/data'; | ||
import { SystemDataSource } from '../SystemDataSource'; | ||
import { SystemQuery } from '../types'; | ||
import { QueryType, SystemQuery } from '../types'; | ||
import { enumToOptions } from 'core/utils'; | ||
|
||
type Props = QueryEditorProps<SystemDataSource, SystemQuery>; | ||
|
||
export function SystemQueryEditor({ query, onChange, onRunQuery }: Props) { | ||
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, queryText: event.target.value }); | ||
}; | ||
// const QUERY_TYPES = [ | ||
// {label: "Metadata", value: QueryType.Metadata}, | ||
// {label: "Summary", value: QueryType.Summary} | ||
// ] | ||
|
||
const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, constant: parseFloat(event.target.value) }); | ||
// executes the query | ||
export function SystemQueryEditor({ query, onChange, onRunQuery }: Props) { | ||
const onQueryTypeChange = (value: QueryType) => { | ||
onChange({ ...query, queryKind: value }) | ||
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> | ||
<InlineFieldRow > | ||
<InlineField label="Query type"> | ||
<RadioButtonGroup options={enumToOptions(QueryType)} onChange={onQueryTypeChange} value={query.queryKind} /> | ||
</InlineField> | ||
</InlineFieldRow> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { DataQuery } from '@grafana/schema' | ||
|
||
export enum QueryType { | ||
Metadata = "Metadata", | ||
Summary = "Summary" | ||
} | ||
|
||
export interface SystemQuery extends DataQuery { | ||
queryText?: string; | ||
constant: number; | ||
queryKind: QueryType | ||
} | ||
|
||
export interface SystemSummary { | ||
connectedCount: number, | ||
disconnectedCount: number | ||
} |