Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #28 from grafana/20190225_fix_dotdot_autocomplete
Browse files Browse the repository at this point in the history
20190225 fix dotdot autocomplete
  • Loading branch information
davkal authored Feb 26, 2019
2 parents 71c4337 + 4ffd782 commit a9de70b
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 370 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
verbose: true,
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.jest.json"
"tsConfig": "tsconfig.jest.json"
}
},
"moduleNameMapper": {
Expand All @@ -14,7 +14,7 @@ module.exports = {
"<rootDir>/node_modules/(?!grafana-sdk-mocks)"
],
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
".(ts|tsx)": "ts-jest"
},
"testRegex": "(\\.|/)([jt]est)\\.ts$",
"moduleFileExtensions": [
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"author": "Grafana Labs",
"license": "Apache",
"lint-staged": {
"*.{js,ts,json,css,md}": ["prettier --write", "git add"]
"*.{js,ts,json,css,md}": [
"prettier --write",
"git add"
]
},
"prettier": {
"singleQuote": true,
Expand All @@ -28,7 +31,7 @@
"immutable": "^3.8.2",
"lodash": "^4.17.4",
"moment": "^2.22.1",
"papaparse": "^4.5.0",
"papaparse": "4.6.3",
"prismjs": "^1.6.0",
"react": "^16.6.3",
"react-dom": "^16.6.3",
Expand All @@ -40,6 +43,7 @@
"@types/grafana": "github:CorpGlory/types-grafana.git",
"@types/jest": "^22.2.3",
"@types/lodash": "^4.14.74",
"@types/papaparse": "^4.5.7",
"@types/react": "^16.6.3",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.1",
Expand Down
6 changes: 3 additions & 3 deletions specs/metric_find_query.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('metric find query', () => {
const query = ' measurements(mydb) ';
const result = expandMacros(query).replace(/\s/g, '');
expect(result).toBe(
'from(bucket:"mydb")|>range($range)|>group(by:["_measurement"])|>distinct(column:"_measurement")|>group(none:true)'
'from(bucket:"mydb")|>range($range)|>group(columns:["_measurement"])|>distinct(column:"_measurement")'
);
});

Expand All @@ -29,7 +29,7 @@ describe('metric find query', () => {
const result = expandMacros(query).replace(/\s/g, '');
expect(result).toBe(
'from(bucket:"mydb")|>range($range)|>filter(fn:(r)=>r._measurement=="mymetric")' +
'|>group(by:["mytag"])|>distinct(column:"mytag")|>group(none:true)'
'|>group(columns:["mytag"])|>distinct(column:"mytag")'
);
});

Expand All @@ -38,7 +38,7 @@ describe('metric find query', () => {
const result = expandMacros(query).replace(/\s/g, '');
expect(result).toBe(
'from(bucket:"mydb")|>range($range)|>filter(fn:(r)=>r._measurement=="mymetric")' +
'|>group(by:["_field"])|>distinct(column:"_field")|>group(none:true)'
'|>group(columns:["_field"])|>distinct(column:"_field")'
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions specs/sample_response_csv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const result = `#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
const response = `#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
#partition,false,false,true,true,false,false,true,true,true,true
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,cpu,host
Expand Down Expand Up @@ -346,4 +346,4 @@ const result = `#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime
`;

export default result;
export default response;
2 changes: 1 addition & 1 deletion src/editor/FluxQueryField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function expandQuery(bucket, measurement, field) {
if (field) {
return (
`from(bucket: "${bucket}")\n` +
` |> filter(fn: (r) => r["_measurement"] == "${measurement}" AND r["_field"] == "${field}")\n |> range($range)\n |> limit(n: 1000)`
` |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> filter(fn: (r) => r["_field"] == "${field}")\n |> range($range)\n |> limit(n: 1000)`
);
}
return `from(bucket: "${bucket}")\n |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> range($range)\n |> limit(n: 1000)`;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/flux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const FUNCTIONS = [
},
{
text: 'group',
display: 'group(by: ["host"]) ',
display: 'group(columns: ["host"], mode:"by") ',
hint: 'Groups results by a specified list of columns',
},
{
Expand Down
15 changes: 6 additions & 9 deletions src/metric_find_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export default function expandMacros(query) {
const database = measurementsQuery[1];
return `from(bucket:"${database}")
|> range($range)
|> group(by:["_measurement"])
|> distinct(column:"_measurement")
|> group(none:true)`;
|> group(columns:["_measurement"])
|> distinct(column:"_measurement")`;
}

const tagsQuery = query.match(TAGS_REGEXP);
Expand All @@ -41,9 +40,8 @@ export default function expandMacros(query) {
return `from(bucket:"${database}")
|> range($range)
|> filter(fn:(r) => r._measurement == "${measurement}")
|> group(by:["${tag}"])
|> distinct(column:"${tag}")
|> group(none:true)`;
|> group(columns:["${tag}"])
|> distinct(column:"${tag}")`;
}

const fieldKeysQuery = query.match(FIELD_KEYS_REGEXP);
Expand All @@ -53,9 +51,8 @@ export default function expandMacros(query) {
return `from(bucket:"${database}")
|> range($range)
|> filter(fn:(r) => r._measurement == "${measurement}")
|> group(by:["_field"])
|> distinct(column:"_field")
|> group(none:true)`;
|> group(columns:["_field"])
|> distinct(column:"_field")`;
}

// By default return pure query
Expand Down
5 changes: 3 additions & 2 deletions src/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
<div class="gf-form-select-wrapper">
<select
class="gf-form-input gf-size-auto"
ng-init="time_series"
ng-model="ctrl.target.resultFormat"
ng-options="f.value as f.text for f in ctrl.resultFormats"
ng-change="ctrl.refresh()"
></select>
ng-change="ctrl.refresh()">
</select>
</div>
</div>
<div class="gf-form" ng-if="ctrl.panelCtrl.loading">
Expand Down
11 changes: 5 additions & 6 deletions src/response_parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Papa from 'papaparse';
import flatten from 'lodash/flatten';
import groupBy from 'lodash/groupBy';
import { parse } from 'papaparse';
import * as _ from 'lodash';

interface Annotation {
time: number;
Expand Down Expand Up @@ -55,7 +54,7 @@ const determineFieldTypes = (input: string, meta: any) => {
};

const parseCSV = (input: string) => {
const {data, meta} = Papa.parse(input, {
const {data, meta} = parse(input, {
header: true,
comments: '#',
});
Expand Down Expand Up @@ -114,7 +113,7 @@ export function getAnnotationsFromResult(result: string, options: any) {
data.forEach(record => {
// Remove empty values, then split in different tags for comma separated values
const tags = getTagsFromRecord(record);
const tagValues = flatten(
let tagValues = _.flatten(
tagSelection.filter(tag => tags[tag]).map(tag => tags[tag].split(','))
);

Expand Down Expand Up @@ -171,7 +170,7 @@ export function getTimeSeriesFromResult(result: string) {
}

// Group results by table ID (assume one table per timeseries for now)
const tables = groupBy(data, 'table');
const tables = _.groupBy(data, 'table');
const seriesList = Object.keys(tables)
.map(id => tables[id])
.map(series => {
Expand Down
Loading

0 comments on commit a9de70b

Please sign in to comment.