Update tab counters on filter change (#34246)
This commit is contained in:
parent
c618751bb8
commit
b7b584c2af
|
@ -113,8 +113,13 @@
|
|||
data-test-subj="tab-count-{{ editSection.index }}"
|
||||
aria-label="{{:: editSection.count + ' ' + editSection.title}}"
|
||||
>
|
||||
<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>
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -20,39 +20,59 @@
|
|||
import _ from 'lodash';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
export function IndicesEditSectionsProvider() {
|
||||
function filterBy(items, key, filter) {
|
||||
const lowercaseFilter = (filter || '').toLowerCase();
|
||||
return items.filter(item => item[key].toLowerCase().includes(lowercaseFilter));
|
||||
}
|
||||
|
||||
return function (indexPattern, indexPatternListProvider) {
|
||||
const fieldCount = _.countBy(indexPattern.fields, function (field) {
|
||||
return (field.scripted) ? 'scripted' : 'indexed';
|
||||
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: indexPattern.sourceFilters ? indexPattern.sourceFilters.length : 0,
|
||||
sourceFilters: sourceFilters ? filterBy(sourceFilters, 'value', fieldFilter).length : 0,
|
||||
});
|
||||
|
||||
return fieldCount;
|
||||
}
|
||||
|
||||
export function IndicesEditSectionsProvider() {
|
||||
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)) {
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue