Skip to content

Commit

Permalink
Merge pull request #29 from gapitio/Feature/add-search-displayname
Browse files Browse the repository at this point in the history
Feature/add search displayname
  • Loading branch information
flesa authored Jan 7, 2022
2 parents 48a1f3c + add7aed commit c08830e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for grafana-metric

## v1.1.1 (2022/01/07)

### Features / enhancements

- Check if field contains displayName if name fails [#29](https://github.com/gapitio/grafana-metric/pull/29)

## v1.1.0 (2021/08/03)

### Features / enhancements
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gapit/grafana-metric",
"description": "Retrieves metric value",
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
4 changes: 3 additions & 1 deletion src/utils/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ export function field({
calcs,
labels,
values = [],
displayName = null,
}: {
name: string;
type: FieldType;
calcs?: FieldCalcs;
labels?: Labels;
values?: number[];
displayName?: string | null;
}): Field {
return {
name,
Expand All @@ -61,7 +63,7 @@ export function field({
toArray: () => values,
},
state: {
displayName: null,
displayName,
scopedVars: {},
calcs,
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/getDataFieldsFromName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function getValueField(
return series.fields.find((field) =>
[
field.name,
field.state?.displayName,
...(searchLabels && field.labels ? [field.labels.name] : []),
].includes(name)
);
Expand Down
12 changes: 12 additions & 0 deletions src/utils/metricValue/getMetricValueFromName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ window.data = {
calcs: { [ReducerID.last]: 300 },
labels: { name: "label-1" },
}),
field({
name: "Value",
type: FieldType.number,
calcs: { [ReducerID.last]: 400 },
displayName: "displayName-1",
}),
],
length: 1,
},
Expand Down Expand Up @@ -107,6 +113,12 @@ describe("getMetricValueFromName", () => {
});
});

describe("display name", () => {
it("gets correct value from display name", () => {
expect(getMetricValueFromName("displayName-1")).toEqual(400);
});
});

describe("missing calcs", () => {
it("gets correct value from label name", () => {
expect(getMetricValueFromName("random-value-field")).toEqual(300);
Expand Down

0 comments on commit c08830e

Please sign in to comment.