Skip to content

Commit

Permalink
lint and build dist
Browse files Browse the repository at this point in the history
  • Loading branch information
retzkek committed May 18, 2020
1 parent d82f15a commit 34b602c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
15 changes: 8 additions & 7 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ as a row in the data frame, otherwise the result object will be the only row.
format that can be parsed by `moment()` (e.g. ISO8601).
* Nested types will be flattened into dot-delimited fields.
* Grafana variables should be substituted directly in the query (instead of
using GraphQL variables). The dashboard time ranges are available in `$timeFrom`
and `$timeTo` variables as millisecond epoch.
using GraphQL variables). The dashboard time ranges are available in the
[global variables](https://grafana.com/docs/grafana/latest/variables/global-variables/)
`$__from` and `$__to` as millisecond epoch.
* Group by can be used to group elements into multiple data points.
* Alias by is used to alter the name of the field displayed in the legend. `$field_<field.name>` is substituted with the
values of the field and `$fieldName` is substituted with the name of the field.
Expand All @@ -29,22 +30,22 @@ examples and tutorials.

```graphql
query {
submissions(user:"$user", from:"$timeFrom", to:"$timeTo"){
submissions(user:"$user", from:"$__from", to:"$__to"){
Time:submitTime
idle running completed
}
}
```
* Data path: `submissions`

Note the use of the special `$timeFrom` and `$timeTo` variables to insert the
Note the use of the global `$__from` and `$__to` variables to insert the
dashboard time range into the query, alongside a dashboard variable `$user`.

## Alias and group by

```graphql
query {
data:queryAll(from:"$timeFrom", to:"$timeTo", sourceId:"default") {
data:queryAll(from:"$__from", to:"$__to", sourceId:"default") {
batteryVoltage {
Time:dateMillis
packet {
Expand Down Expand Up @@ -74,15 +75,15 @@ querying multiple numeric fields that you want displayed in your graph.

```graphql
query {
server1:queryEvents(from: "$timeFrom", to:"$timeTo", server:"server1") {
server1:queryEvents(from: "$__from", to:"$__to", server:"server1") {
birthdayEvent {
Time:dateMillis
person {
fullName
}
}
}
server2:queryEvents(from: "$timeFrom", to:"$timeTo", server:"server2") {
server2:queryEvents(from: "$__from", to:"$__to", server:"server2") {
birthdayEvent {
Time:dateMillis
person {
Expand Down
3 changes: 2 additions & 1 deletion dist/module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"screenshots": [],
"version": "1.1.0",
"updated": "2020-04-25"
"updated": "2020-05-18"
},

"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is needed because it is used by vscode and other tools that
// call `jest` directly. However, unless you are doing anything special
// do not edit this file

const standard = require('@grafana/toolkit/src/config/jest.plugin.config');

// This process will use the same config that `yarn test` is using
module.exports = standard.jestConfig();
65 changes: 32 additions & 33 deletions src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import {flatten} from './util.ts'
import { flatten } from './util.ts';

test('flatten function test', () => {

let obj = {
"string":"hello",
"number":123,
"float":123.4,
"null":null,
"undefined":undefined,
"array":[1,2,3],
"nested": {
"string":"hello",
"number":123,
"float":123.4,
"null":null,
"undefined":undefined,
}
}
let obj = {
string: 'hello',
number: 123,
float: 123.4,
null: null,
undefined: undefined,
array: [1, 2, 3],
nested: {
string: 'hello',
number: 123,
float: 123.4,
null: null,
undefined: undefined,
},
};

let flattenObj = {
"string":"hello",
"number":123,
"float":123.4,
"null":null,
"undefined":undefined,
"array.0":1,
"array.1":2,
"array.2":3,
"nested.string":"hello",
"nested.number":123,
"nested.float":123.4,
"nested.null":null,
"nested.undefined":undefined,
}
let flattenObj = {
string: 'hello',
number: 123,
float: 123.4,
null: null,
undefined: undefined,
'array.0': 1,
'array.1': 2,
'array.2': 3,
'nested.string': 'hello',
'nested.number': 123,
'nested.float': 123.4,
'nested.null': null,
'nested.undefined': undefined,
};

expect(flatten(obj)).toEqual(flattenObj);
expect(flatten(obj)).toEqual(flattenObj);
});
4 changes: 1 addition & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@


export function flatten<T extends Record<string, any>>(object: T, path: string | null = null, separator = '.'): T {
return Object.keys(object).reduce((acc: T, key: string): T => {
const isObject = typeof(object[key]) === 'object' && object[key] != null;
const isObject = typeof object[key] === 'object' && object[key] != null;
const newPath = [path, key].filter(Boolean).join(separator);
return isObject ? { ...acc, ...flatten(object[key], newPath, separator) } : { ...acc, [newPath]: object[key] };
}, {} as T);
Expand Down

0 comments on commit 34b602c

Please sign in to comment.