Update tab counters on filter change (#34246)

This commit is contained in:
Joe Reuter 2019-04-10 15:41:39 +02:00 committed by GitHub
parent c618751bb8
commit b7b584c2af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 21 deletions

View file

@ -113,7 +113,12 @@
data-test-subj="tab-count-{{ editSection.index }}"
aria-label="{{:: editSection.count + ' ' + editSection.title}}"
>
({{ editSection.count }})
<span ng-if="editSection.count != editSection.totalCount">
({{ editSection.count }} / {{ editSection.totalCount }})
</span>
<span ng-if="editSection.count == editSection.totalCount">
({{ editSection.count }})
</span>
</span>
</button>
</div>

View file

@ -58,7 +58,7 @@ function updateSourceFiltersTable($scope, $state) {
filterFilter={$scope.fieldFilter}
fieldWildcardMatcher={$scope.fieldWildcardMatcher}
onAddOrRemoveFilter={() => {
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern, $scope.indexPatternListProvider);
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern, $scope.fieldFilter, $scope.indexPatternListProvider);
$scope.refreshFilters();
$scope.$apply();
}}
@ -191,7 +191,7 @@ uiModules.get('apps/management')
});
$scope.$watch('indexPattern.fields', function () {
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern, indexPatternListProvider);
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern, $scope.fieldFilter, indexPatternListProvider);
$scope.refreshFilters();
$scope.fields = $scope.indexPattern.getNonScriptedFields();
updateIndexedFieldsTable($scope, $state);
@ -294,6 +294,7 @@ uiModules.get('apps/management')
};
$scope.$watch('fieldFilter', () => {
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern, $scope.fieldFilter, indexPatternListProvider);
if ($scope.fieldFilter === undefined) {
return;
}

View file

@ -20,39 +20,59 @@
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
function filterBy(items, key, filter) {
const lowercaseFilter = (filter || '').toLowerCase();
return items.filter(item => item[key].toLowerCase().includes(lowercaseFilter));
}
function getCounts(fields, sourceFilters, fieldFilter = '') {
const fieldCount = _.countBy(filterBy(fields, 'name', fieldFilter), function (field) {
return field.scripted ? 'scripted' : 'indexed';
});
_.defaults(fieldCount, {
indexed: 0,
scripted: 0,
sourceFilters: sourceFilters ? filterBy(sourceFilters, 'value', fieldFilter).length : 0,
});
return fieldCount;
}
export function IndicesEditSectionsProvider() {
return function (indexPattern, indexPatternListProvider) {
const fieldCount = _.countBy(indexPattern.fields, function (field) {
return (field.scripted) ? 'scripted' : 'indexed';
});
_.defaults(fieldCount, {
indexed: 0,
scripted: 0,
sourceFilters: indexPattern.sourceFilters ? indexPattern.sourceFilters.length : 0,
});
return function (indexPattern, fieldFilter, indexPatternListProvider) {
const totalCount = getCounts(indexPattern.fields, indexPattern.sourceFilters);
const filteredCount = getCounts(indexPattern.fields, indexPattern.sourceFilters, fieldFilter);
const editSections = [];
editSections.push({
title: i18n.translate('kbn.management.editIndexPattern.tabs.fieldsHeader', { defaultMessage: 'Fields' }),
title: i18n.translate('kbn.management.editIndexPattern.tabs.fieldsHeader', {
defaultMessage: 'Fields',
}),
index: 'indexedFields',
count: fieldCount.indexed
count: filteredCount.indexed,
totalCount: totalCount.indexed,
});
if(indexPatternListProvider.areScriptedFieldsEnabled(indexPattern)) {
if (indexPatternListProvider.areScriptedFieldsEnabled(indexPattern)) {
editSections.push({
title: i18n.translate('kbn.management.editIndexPattern.tabs.scriptedHeader', { defaultMessage: 'Scripted fields' }),
title: i18n.translate('kbn.management.editIndexPattern.tabs.scriptedHeader', {
defaultMessage: 'Scripted fields',
}),
index: 'scriptedFields',
count: fieldCount.scripted
count: filteredCount.scripted,
totalCount: totalCount.scripted,
});
}
editSections.push({
title: i18n.translate('kbn.management.editIndexPattern.tabs.sourceHeader', { defaultMessage: 'Source filters' }),
title: i18n.translate('kbn.management.editIndexPattern.tabs.sourceHeader', {
defaultMessage: 'Source filters',
}),
index: 'sourceFilters',
count: fieldCount.sourceFilters
count: filteredCount.sourceFilters,
totalCount: totalCount.sourceFilters,
});
return editSections;