Skip to content

Commit 3db901c

Browse files
committed
ds - fix sort order
1 parent 5c57d36 commit 3db901c

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@ Or docker installation:
5252
2. Paste access token to `Token` config field
5353

5454
![Rightech IoT Token Config](https://raw.githubusercontent.com/Rightech/ric-datasource/master/docs/img/config.png)
55+
56+
57+
## Development
58+
59+
```
60+
> npm start
61+
> docker run -it -p 3000:3000 \
62+
-e GF_APP_MODE=development \
63+
-e GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=rightech-ric-datasource \
64+
-v "$(pwd)"/dist:/var/lib/grafana/plugins/rightech-ric-datasource \
65+
--name=grafana grafana/grafana:8.3.1
66+
```

src/datasource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ export class DataSource extends DataSourceApi<RicQuery, RicDataSourceOptions> {
4747

4848
const id = object._id;
4949
const name = object.name;
50-
const only = ['_ts', 'time', ...params.map(({ id }) => id)];
50+
const only = ['_ts', 'time', 'online', ...params.map(({ id }) => id)];
5151

5252
const packetsUrl = this.proxyApiUrl(
5353
`objects/${id}/packets?${qs({ from, to, only, nolimit: true, streamed: true })}`
5454
);
5555

5656
let packets: Packet[] = await getBackendSrv().get(packetsUrl);
57-
packets.sort((a, b) => b.time! - a.time!);
57+
packets.sort((a, b) => a.time! - b.time!);
5858

5959
const slice = new MutableDataFrame({
6060
refId: target.refId,

src/util/store.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ export function isArgumentNode(node: ModelNode): node is ArgumentNode {
6161
return node.type === 'argument';
6262
}
6363

64+
function getOnlineNode(): ArgumentNode {
65+
return {
66+
active: true,
67+
dataType: 'boolean',
68+
type: 'argument',
69+
id: 'online',
70+
name: 'online',
71+
};
72+
}
73+
6474
export function getArgumentsOf(ids: string[]): ArgumentNode[] {
6575
return ids.flatMap((objectId) => {
6676
const object = objects.getById(objectId);
@@ -71,7 +81,12 @@ export function getArgumentsOf(ids: string[]): ArgumentNode[] {
7181
if (!model) {
7282
return [];
7383
}
74-
const xs = filterNodes<ArgumentNode>(model.data as any, (x) => isArgumentNode(x));
84+
let xs = filterNodes<ArgumentNode>(model.data as any, (x) => isArgumentNode(x));
85+
86+
if (!xs.find((x) => x.id === 'online')) {
87+
xs = [getOnlineNode(), ...xs];
88+
}
89+
7590
return xs;
7691
});
7792
}

0 commit comments

Comments
 (0)