Skip to content

Commit

Permalink
fixes for #80 #81
Browse files Browse the repository at this point in the history
(cherry picked from commit aa761b4)

(cherry picked from commit 71d6486)

(cherry picked from commit e7b7cf6)

(cherry picked from commit aecf125)
  • Loading branch information
Pierre Padovani committed Jul 29, 2018
1 parent 2284320 commit b69b3ca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
14 changes: 10 additions & 4 deletions public/nested_support/agg_types/buckets/filters.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="form-group">
<div ng-repeat="filter in agg.params.filters">
<div class="vis-editor-agg-header">
<label>
<label for="visEditorFilterInput{{agg.id}}">
Filter {{$index + 1}}
<span ng-if="filter.label">- {{ filter.label }}</span>
</label>
Expand All @@ -10,11 +10,15 @@
<button
ng-click="showConfig = !showConfig"
type="button"
aria-label="Toggle filter label"
aria-expanded="{{!!showConfig}}"
aria-controls="visEditorFilterLabel{{agg.id}}"
class="kuiButton kuiButton--basic kuiButton--small">
<i class="fa fa-tag"></i>
</button>
<button
type="button"
aria-label="Remove this filter"
ng-click="agg.params.filters.splice($index, 1)"
class="kuiButton kuiButton--danger kuiButton--small">
<i class="fa fa-times"></i>
Expand All @@ -24,17 +28,19 @@

<div class="form-group">
<input
parse-query
id="visEditorFilterInput{{agg.id}}"
knql-parse-query
ng-model="filter.input.query"
type="text"
class="form-control"
name="filter{{$index}}">
<div ng-show="parseError !== undefined" class="form-group"><pre>{{parseError}}</pre></div>
</div>

<div class="form-group" ng-show="showConfig">
<label>Filter {{$index + 1}} label</label>
<div class="form-group" ng-show="showConfig" id="visEditorFilterLabel{{agg.id}}">
<label for="visEditorFilterLabelInput{{agg.id}}">Filter {{$index + 1}} label</label>
<input
id="visEditorFilterLabelInput{{agg.id}}"
ng-model="filter.label"
placeholder="Label"
type="text"
Expand Down
2 changes: 1 addition & 1 deletion public/nested_support/agg_types/buckets/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Filters.AggTypesBucketsFiltersProvider = function(Private, Notifier) {
decorateQuery(query);

const matchAllLabel = (filter.input.query === '' && _.has(query, 'match_all')) ? '*' : '';
const label = filter.label || matchAllLabel || _.get(query, 'query_string.query') || angular.toJson(query);
const label = filter.label || matchAllLabel || _.get(query, 'query_string.query') || filter.base_query || angular.toJson(query);
filters[label] = input;
}, {});

Expand Down
29 changes: 22 additions & 7 deletions public/nested_support/parse_query/lib/from_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import {parser} from './knql';
let ngModel;
parser.yy = require('./knql_adapter');

function getQueryBar($scope) {
let queryBar = undefined;
let curScope = $scope;
while (queryBar === undefined && curScope) {
curScope = curScope.$parent;
if (curScope) {
queryBar = curScope.queryBarForm;
}
}
return queryBar;
}

/**
* Take text from the user and make it into a query object
* @param {text} user's query input
Expand All @@ -15,13 +27,14 @@ export function fromUser(text, model) {
return DecorateQueryProvider({query_string: {query: text}});
}

parser.yy.possibleFields = {};
parser.yy.possibleFields = [];
let matchAll = getQueryStringQuery('*');
if (model !== undefined) {
ngModel = model;
}

ngModel.parseError = undefined;
const queryBar = getQueryBar(ngModel);
// If we get an empty object, treat it as a *
if (_.isObject(text)) {
if (Object.keys(text).length) {
Expand All @@ -42,18 +55,20 @@ export function fromUser(text, model) {
return getQueryStringQuery(text);
}
} else {
const cursorPos = ngModel.$parent.queryBarForm.$$element[0][0].selectionEnd;
const fieldPart = text.substr(text.substr(0, cursorPos).lastIndexOf(' ') + 1)
const cursorPos = queryBar ? queryBar.$$element[0][0].selectionEnd : 0;
const fieldPart = queryBar ? text.substr(text.substr(0, cursorPos).lastIndexOf(' ') + 1) : undefined;
try {
const parsed = parser.parse(text).toJson();
ngModel.$parent.parseError = undefined;
ngModel.$parent.possibleFields = fieldPart ? parser.yy.possibleFields[fieldPart] : [];
if (ngModel.filter) {
ngModel.filter.base_query = text;
}
let parsed = parser.parse(text).toJson();
ngModel.$parent.possibleFields = parser.yy.possibleFields[fieldPart];
ngModel.$parent.parseError = undefined;
return JSON.parse(parsed);
} catch (e) {
ngModel.$parent.possibleFields = parser.yy.possibleFields[fieldPart];
if (queryBar) {
ngModel.$parent.possibleFields = parser.yy.possibleFields[fieldPart];
}
ngModel.$parent.parseError = e.message;
return undefined;
}
Expand Down
19 changes: 18 additions & 1 deletion public/nested_support/parse_query/parse_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ import {toUser, toUserIndexPattern} from './lib/to_user';
import {fromUser, fromUserIndexPattern} from './lib/from_user';
import {uiModules} from 'ui/modules';

function getIndexPattern($scope) {
let indexPattern = undefined;
let curScope = $scope;
while (indexPattern === undefined && curScope) {
curScope = curScope.$parent;
if (curScope) {
indexPattern = curScope.indexPattern;
}
}
// Check specifically for the $parent.agg
if (!indexPattern && $scope.$parent.agg) {
indexPattern = $scope.$parent.agg.vis.indexPattern;
}
return indexPattern;
}


uiModules
.get('kibana')
.directive('knqlParseQuery', function (Private) {
Expand All @@ -17,7 +34,7 @@ uiModules
$scope.ngModel = fromUser($scope.ngModel, ($scope ? $scope.$parent : undefined));
};

$scope.indexPattern = $scope.$parent.$parent.$parent.$parent.indexPattern;
$scope.indexPattern = getIndexPattern($scope);

let fieldMap;

Expand Down

0 comments on commit b69b3ca

Please sign in to comment.