-
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
Factor out column manipulation in the doc table #10681
Factor out column manipulation in the doc table #10681
Conversation
d577e31
to
aa68edb
Compare
7eeabcd
to
d9131a3
Compare
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.
This looks awesome Felix! Much improved.
}, | ||
controller: function ($scope) { | ||
$scope.mapping = $scope.indexPattern.fields.byName; | ||
$scope.flattened = $scope.indexPattern.flattenHit($scope.hit); | ||
$scope.formatted = $scope.indexPattern.formatHit($scope.hit); | ||
$scope.fields = _.keys($scope.flattened).sort(); | ||
|
||
$scope.toggleColumn = function (fieldName) { | ||
_.toggleInOut($scope.columns, fieldName); | ||
$scope.canToggleColumn = function canToggleColumn() { |
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.
This is called per row so could maybe pull out the calculation so it doesn't run every time?
const canToggleColumns = _.isFunction($scope.onAddColumn) && _.isFunction($scope.onRemoveColumn);
$scope.canToggleColumns = () => canToggleColumns;
Though it's probably like a nanosecond extra for those _.isFunction calculations and negligible in the long run, so feel free to ignore. :)
Though I do think I'd call it canToggleColumns which makes it clearer it's either on or off for all.
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.
Good point about the plural, thanks!
To get the precomputed value correct I would have to set up a watch (because $scope.onAddColumn
and $scope.onRemoveColumn
could change over time), which would probably already negate some of the benefit. I'll take a look at the profiler to see if it's worth it 😉
}; | ||
|
||
$scope.removeColumn = function removeColumn(columnName) { | ||
$scope.savedObj.searchSource.get('index').popularizeField(columnName, 1); |
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.
Interesting. Is this new? A quick test seems to indicate that previously adjusting the columns via dashboard didn't affect popularity score. Makes sense to add it here, though.
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.
You're right, this was previously not consistently triggered for the different ways to add columns. I actually didn't notice, but I guess we could keep it.
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.
I would think it would make sense to add it here as well.
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.
I left a few tiny nitpicks below, but really this LGTM. Thanks for taking this on!
link: function ($scope, $elem) { | ||
let detailsElem; | ||
let detailScope = $scope.$new(); | ||
let detailScope = null; |
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.
Any reason to initialize this to null
rather than just leaving uninitialized?
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.
no, just habit from languages where this could blow up 😉 thanks for pointing it out
@@ -155,7 +152,7 @@ app.directive('discFieldChooser', function ($location, globalState, config, $rou | |||
$scope.indexPattern.popularizeField(fieldName, 1); | |||
}; | |||
|
|||
$scope.vizLocation = function (field) { | |||
function getVizualizeUrl(field) { |
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.
Nit: Misspelling of "visualize"
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.
zZzZz, thanks - that's the downside of auto-completion
ng-if="canMoveColumnRight(name)" | ||
tooltip-append-to-body="1" | ||
tooltip="Move column to the right" | ||
></i> |
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.
Soooo much more readable. Thanks 👍
d9131a3
to
68a50ee
Compare
jenkins, test this (and stop failing arbitrarily) |
f57d78d
to
1850e2c
Compare
This refactoring effort turns the implicit manipulation of the set of columns that was scattered throughout the doc table and the field chooser into explicit function calls. This brings with it the following improvements: * The column manipulation code is not duplicated (DRY) * The controller stays in control (IOC) * If the required functions are not provided by the controller, manipulation of the columns is disabled. Additionally, the `discover_field` now uses a properly isolated scope instead of accessing inherited properties of the scope.
1850e2c
to
7f2bda8
Compare
* Factor out column manipulation in the doc table This refactoring effort turns the implicit manipulation of the set of columns that was scattered throughout the doc table and the field chooser into explicit function calls. This brings with it the following improvements: * The column manipulation code is not duplicated (DRY) * The controller stays in control (IOC) * If the required functions are not provided by the controller, manipulation of the columns is disabled. Additionally, the `discover_field` now uses a properly isolated scope instead of accessing inherited properties of the scope. * Make filter addition and removal in tests more reliable * Change function name to plural, move up ng-if * Remove inconsistent variable initialization * Fix function name typo * Save the state in the action instead of a $watch
Backports PR #10681 * Factor out column manipulation in the doc table This refactoring effort turns the implicit manipulation of the set of columns that was scattered throughout the doc table and the field chooser into explicit function calls. This brings with it the following improvements: * The column manipulation code is not duplicated (DRY) * The controller stays in control (IOC) * If the required functions are not provided by the controller, manipulation of the columns is disabled. Additionally, the `discover_field` now uses a properly isolated scope instead of accessing inherited properties of the scope. * Make filter addition and removal in tests more reliable * Change function name to plural, move up ng-if * Remove inconsistent variable initialization * Fix function name typo * Save the state in the action instead of a $watch
This refactoring effort turns the implicit manipulation of the set of
columns that was scattered throughout the doc table and the field
chooser into explicit function calls. This brings with it the following
improvements:
manipulation of the columns is disabled.
Additionally, the
discover_field
now uses a properly isolated scopeinstead of accessing inherited properties of the scope.
As a side benefit, this enables us to restrict the ability of the user to change the columns in saved search panels on dashboards. See #9523 for a (currently unresolved) discussion on that topic.