Skip to content

Commit

Permalink
Update tab counters on filter change (elastic#34246) (elastic#34864)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Apr 11, 2019
1 parent b48ac3c commit 679fa71
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
_.defaults(fieldCount, {
indexed: 0,
scripted: 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)) {
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;
Expand Down

0 comments on commit 679fa71

Please sign in to comment.