-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Click to filter values in Discover doc table #5344
Changes from all commits
2db1f9f
7a2d69e
1082a99
ebf8c50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import noWhiteSpace from 'ui/utils/no_white_space'; | |
import openRowHtml from 'ui/doc_table/components/table_row/open.html'; | ||
import detailsHtml from 'ui/doc_table/components/table_row/details.html'; | ||
import uiModules from 'ui/modules'; | ||
import FilterManagerProvider from 'ui/filter_manager'; | ||
const module = uiModules.get('app/discover'); | ||
|
||
|
||
|
@@ -24,9 +25,10 @@ const MIN_LINE_LENGTH = 20; | |
* <tr ng-repeat="row in rows" kbn-table-row="row"></tr> | ||
* ``` | ||
*/ | ||
module.directive('kbnTableRow', function ($compile) { | ||
module.directive('kbnTableRow', ['$compile', 'Private', function ($compile, Private) { | ||
const cellTemplate = _.template(noWhiteSpace(require('ui/doc_table/components/table_row/cell.html'))); | ||
const truncateByHeightTemplate = _.template(noWhiteSpace(require('ui/partials/truncate_by_height.html'))); | ||
const filterManager = Private(FilterManagerProvider); | ||
|
||
return { | ||
restrict: 'A', | ||
|
@@ -83,27 +85,46 @@ module.directive('kbnTableRow', function ($compile) { | |
createSummaryRow($scope.row, $scope.row._id); | ||
}); | ||
|
||
$scope.inlineFilter = function inlineFilter($event, type) { | ||
const column = $($event.target).data().column; | ||
const field = $scope.indexPattern.fields.byName[column]; | ||
$scope.indexPattern.popularizeField(field, 1); | ||
filterManager.add(field, $scope.flattenedRow[column], type, $scope.indexPattern.id); | ||
}; | ||
|
||
// create a tr element that lists the value for each *column* | ||
function createSummaryRow(row) { | ||
const indexPattern = $scope.indexPattern; | ||
$scope.flattenedRow = indexPattern.flattenHit(row); | ||
|
||
// We just create a string here because its faster. | ||
const newHtmls = [ | ||
openRowHtml | ||
]; | ||
|
||
const mapping = indexPattern.fields.byName; | ||
if (indexPattern.timeFieldName) { | ||
newHtmls.push(cellTemplate({ | ||
timefield: true, | ||
formatted: _displayField(row, indexPattern.timeFieldName) | ||
formatted: _displayField(row, indexPattern.timeFieldName), | ||
filterable: mapping[indexPattern.timeFieldName].filterable, | ||
column: indexPattern.timeFieldName | ||
})); | ||
} | ||
|
||
$scope.columns.forEach(function (column) { | ||
const isFilterable = | ||
$scope.flattenedRow[column] === undefined | ||
? false | ||
: !mapping[column] | ||
? false | ||
: mapping[column].filterable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a difficult time parsing this. Personally I think the following would be more readable:
Thoughts @cjcenizal ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a few issues with this:
I think the reason I like the ternary is because it has the same pattern as a function with early exits, which makes it really easy for me to map input to output. Maybe the best route is to actually create a function that does just that? function isFilterable(row, mapping, column) {
if (row[column] === undefined) {
return false;
}
if (!mapping[column]) {
return false;
}
return mapping[column].filterable;
} What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally dislike custom functions where a general one will do. Now I have to find and understand
First of all, that's not true: http://codepen.io/anon/pen/EZKNNN?editors=0011
I'd be ok with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having let it percolate overnight, I think we should just leave the ternary. It was sort of a silly thing to worry about in the first place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it turns out we have an eslint rule against nested ternaries:
@jimmyjones2 would you mind implementing the function @cjcenizal suggested above to replace the ternary? Sorry for the back and forth, this should be the last change assuming tests pass. |
||
newHtmls.push(cellTemplate({ | ||
timefield: false, | ||
sourcefield: (column === '_source'), | ||
formatted: _displayField(row, column, true) | ||
formatted: _displayField(row, column, true), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's pass a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Bargs I was worried the raw field value could contain special characters such as quotes - would this be safe to pass into an HTML element attribute and back into inlineFilter unscathed? Just tried a field value containing single and double quotes and it broke. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jimmyjones2 That's a great point. Ignore both my comments about passing literal values into If you could do me just one other favor, I think this'll be good to merge. Could you add a |
||
filterable: isFilterable, | ||
column: column | ||
})); | ||
}); | ||
|
||
|
@@ -128,7 +149,7 @@ module.directive('kbnTableRow', function ($compile) { | |
// rebuild cells since we modified the children | ||
$cells = $el.children(); | ||
|
||
if (i === 0 && !reuse) { | ||
if (!reuse) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why this was changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Bargs Can't exactly remember now, but without that change it doesn't work! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I looked back in the history, and I guess index 0 is the toggle control which previously was the only element that needed compiled. Now we need to compile the individual cells, so this makes sense. |
||
$toggleScope = $scope.$new(); | ||
$compile($target)($toggleScope); | ||
} | ||
|
@@ -160,4 +181,4 @@ module.directive('kbnTableRow', function ($compile) { | |
} | ||
} | ||
}; | ||
}); | ||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,23 @@ | |
%> | ||
<td <%= attributes %>> | ||
<%= formatted %> | ||
<span class="table-cell-filter"> | ||
<% if (filterable) { %> | ||
<span | ||
ng-click="inlineFilter($event, '+')" | ||
class="fa fa-search-plus docTableRowFilterIcon" | ||
data-column="<%- column %>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned in my other comment, ignore this. |
||
tooltip="Filter for value" | ||
tooltip-append-to-body="1" | ||
></span> | ||
|
||
<span | ||
ng-click="inlineFilter($event, '-')" | ||
class="fa fa-search-minus docTableRowFilterIcon" | ||
data-column="<%- column %>" | ||
tooltip="Filter out value" | ||
tooltip-append-to-body="1" | ||
></span> | ||
<% } %> | ||
</span> | ||
</td> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,7 +253,6 @@ kbn-table, .kbn-table { | |
visibility: visible; | ||
} | ||
} | ||
|
||
} | ||
|
||
//== Generic Table | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this improvement! :D