Skip to content

Commit

Permalink
Limit visualization editor based on rollup capabilities (#23637)
Browse files Browse the repository at this point in the history
* Limit vis editor based on rollup capabilities

* Migrate new `type` and `typeMeta` field mappings for old indices

* Disable timefield for rollup index patterns in discover so that the raw rollup docs can be viewed

* Restructure index pattern list registry

* Disable scripted fields tab for rollup index patterns

* Allow count in list of available vis aggs

* Add error when min/max aggs are not available for histograms
  • Loading branch information
jen-huang authored Oct 2, 2018
1 parent 0445ca4 commit c765ecb
Show file tree
Hide file tree
Showing 24 changed files with 347 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function discoverController(
// searchSource which applies time range
const timeRangeSearchSource = savedSearch.searchSource.create();
timeRangeSearchSource.setField('filter', () => {
return timefilter.createFilter($scope.indexPattern);
return isDefaultTypeIndexPattern($scope.indexPattern) && timefilter.createFilter($scope.indexPattern);
});

$scope.searchSource.setParent(timeRangeSearchSource);
Expand Down Expand Up @@ -391,7 +391,7 @@ function discoverController(
$scope.opts = {
// number of records to fetch, then paginate through
sampleSize: config.get('discover:sampleSize'),
timefield: $scope.indexPattern.timeFieldName,
timefield: isDefaultTypeIndexPattern($scope.indexPattern) && $scope.indexPattern.timeFieldName,
savedSearch: savedSearch,
indexPatternList: $route.current.locals.ip.list,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import template from './edit_index_pattern.html';
import { FieldWildcardProvider } from 'ui/field_wildcard';
import { IndexPatternListFactory } from 'ui/management';
import { IndexPatternListFactory } from 'ui/management/index_pattern_list';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { SourceFiltersTable } from './source_filters_table';
Expand Down Expand Up @@ -201,7 +201,7 @@ uiModules.get('apps/management')
});

$scope.$watch('indexPattern.fields', function () {
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern);
$scope.editSections = $scope.editSectionsProvider($scope.indexPattern, indexPatternListProvider);
$scope.refreshFilters();
$scope.fields = $scope.indexPattern.getNonScriptedFields();
updateIndexedFieldsTable($scope, $state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n';

export function IndicesEditSectionsProvider() {

return function (indexPattern) {
return function (indexPattern, indexPatternListProvider) {
const fieldCount = _.countBy(indexPattern.fields, function (field) {
return (field.scripted) ? 'scripted' : 'indexed';
});
Expand All @@ -33,22 +33,28 @@ export function IndicesEditSectionsProvider() {
sourceFilters: indexPattern.sourceFilters ? indexPattern.sourceFilters.length : 0,
});

return [
{
title: i18n.translate('kbn.management.editIndexPattern.tabs.fieldsHeader', { defaultMessage: 'Fields' }),
index: 'indexedFields',
count: fieldCount.indexed
},
{
const editSections = [];

editSections.push({
title: i18n.translate('kbn.management.editIndexPattern.tabs.fieldsHeader', { defaultMessage: 'Fields' }),
index: 'indexedFields',
count: fieldCount.indexed
});

if(indexPatternListProvider.areScriptedFieldsEnabled(indexPattern)) {
editSections.push({
title: i18n.translate('kbn.management.editIndexPattern.tabs.scriptedHeader', { defaultMessage: 'Scripted fields' }),
index: 'scriptedFields',
count: fieldCount.scripted
},
{
title: i18n.translate('kbn.management.editIndexPattern.tabs.sourceHeader', { defaultMessage: 'Source filters' }),
index: 'sourceFilters',
count: fieldCount.sourceFilters
}
];
});
}

editSections.push({
title: i18n.translate('kbn.management.editIndexPattern.tabs.sourceHeader', { defaultMessage: 'Source filters' }),
index: 'sourceFilters',
count: fieldCount.sourceFilters
});

return editSections;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import { management, IndexPatternListFactory } from 'ui/management';
import { management } from 'ui/management';
import { IndexPatternListFactory } from 'ui/management/index_pattern_list';
import { IndexPatternCreationFactory } from 'ui/management/index_pattern_creation';
import './create_index_pattern_wizard';
import './edit_index_pattern';
Expand Down Expand Up @@ -126,7 +127,7 @@ uiModules.get('apps/management')
return 1;
}
return 0;
});
}) || [];

updateIndexPatternList($scope, indexPatternCreationOptions, $scope.defaultIndex, $scope.indexPatternList);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ import PropTypes from 'prop-types';
import {
EuiButtonEmpty,
EuiBadge,
EuiCallOut,
} from '@elastic/eui';

export class List extends Component {
static propTypes = {
indexPatterns: PropTypes.array,
defaultIndex: PropTypes.string,
}

render() {
renderList() {
const { indexPatterns } = this.props;
return (
return indexPatterns && indexPatterns.length ? (
<div>
{
indexPatterns.map(pattern => {
Expand All @@ -51,6 +53,29 @@ export class List extends Component {
})
}
</div>
) : null;
}

renderNoDefaultMessage() {
const { defaultIndex } = this.props;
return !defaultIndex ? (
<div className="indexPatternList__headerWrapper">
<EuiCallOut
color="warning"
size="s"
iconType="alert"
title="No default index pattern. You must select or create one to continue."
/>
</div>
) : null;
}

render() {
return (
<div>
{this.renderNoDefaultMessage()}
{this.renderList()}
</div>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,20 @@
* under the License.
*/

import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import React, { Fragment } from 'react';

import { Header } from './components/header';
import { List } from './components/list';

export class IndexPatternList extends Component {
static propTypes = {
indexPatternCreationOptions: PropTypes.array.isRequired,
defaultIndex: PropTypes.string,
indexPatterns: PropTypes.array.isRequired,
}

render() {
const { indexPatterns, indexPatternCreationOptions } = this.props;

return(
<Fragment>
<div className="indexPatternList__headerWrapper">
<Header indexPatternCreationOptions={indexPatternCreationOptions} />
</div>
<List indexPatterns={indexPatterns} />
</Fragment>
);
}
}
export const IndexPatternList = ({
indexPatternCreationOptions,
defaultIndex,
indexPatterns
}) => (
<Fragment>
<div className="indexPatternList__headerWrapper">
<Header indexPatternCreationOptions={indexPatternCreationOptions} />
</div>
<List indexPatterns={indexPatterns} defaultIndex={defaultIndex} />
</Fragment>
);
7 changes: 7 additions & 0 deletions src/ui/public/agg_types/buckets/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import _ from 'lodash';

import { toastNotifications } from 'ui/notify';
import '../../validate_date_interval';
import chrome from '../../chrome';
import { BucketAggType } from './_bucket_agg_type';
Expand Down Expand Up @@ -95,6 +96,12 @@ export const histogramBucketAgg = new BucketAggType({
min: _.get(resp, 'aggregations.minAgg.value'),
max: _.get(resp, 'aggregations.maxAgg.value')
});
})
.catch(() => {
toastNotifications.addWarning(`
Unable to retrieve max and min values to auto-scale histogram buckets.
This may lead to poor visualization performance.
`);
});
},
write: function (aggConfig, output) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/controls/order_and_size.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div>
<div class="visEditorAgg__formRow--flex">
<div ng-if="agg.type.params.byName.order" class="form-group">
<div ng-if="agg.type.params.byName.order && aggParam.options" class="form-group">
<label for="visEditorOrderByOrder{{agg.id}}">Order</label>
<select
id="visEditorOrderByOrder{{agg.id}}"
Expand Down
1 change: 0 additions & 1 deletion src/ui/public/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ export {
export { registerSettingsComponent } from '../../../core_plugins/kibana/public/management/sections/settings/components/component_registry';
export { Field } from '../../../core_plugins/kibana/public/management/sections/settings/components/field/field';
export { management } from './sections_register';
export { IndexPatternListRegistry, IndexPatternListFactory } from './index_pattern_list';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

export { parseEsInterval } from './parse_es_interval';
export { ParseEsIntervalInvalidCalendarIntervalError } from './parse_es_interval_invalid_calendar_interval_error';
export { ParseEsIntervalInvalidFormatError } from './parse_es_interval_invalid_format_error';
import './register';
export { IndexPatternListFactory } from './index_pattern_list';
export { IndexPatternListConfig } from './index_pattern_list_config';
export { IndexPatternListConfigRegistry } from './index_pattern_list_config_registry';
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@
* under the License.
*/

import { uiRegistry } from 'ui/registry/_registry';

export const IndexPatternListRegistry = uiRegistry({
name: 'indexPatternList',
index: ['name'],
order: ['order'],
});
import { IndexPatternListConfigRegistry } from './index_pattern_list_config_registry';

class IndexPatternList {
constructor(registry) {
this._plugins = registry.inOrder.map(Plugin => new Plugin);
this._plugins = registry.inOrder.map(Plugin => new Plugin());
}

getIndexPatternTags = (indexPattern) => {
Expand All @@ -41,11 +35,17 @@ class IndexPatternList {
return plugin.getFieldInfo ? info.concat(plugin.getFieldInfo(indexPattern, field)) : info;
}, []);
}

areScriptedFieldsEnabled = (indexPattern) => {
return this._plugins.every((plugin) => {
return plugin.areScriptedFieldsEnabled ? plugin.areScriptedFieldsEnabled(indexPattern) : true;
});
}
}

export const IndexPatternListFactory = (Private) => {
return function () {
const indexPatternListRegistry = Private(IndexPatternListRegistry);
const indexPatternListRegistry = Private(IndexPatternListConfigRegistry);
const indexPatternListProvider = new IndexPatternList(indexPatternListRegistry);
return indexPatternListProvider;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export class IndexPatternListConfig {
static key = 'default';

getIndexPatternTags = () => {
return [];
}

getFieldInfo = () => {
return [];
}

areScriptedFieldsEnabled = () => {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { uiRegistry } from 'ui/registry/_registry';

export const IndexPatternListConfigRegistry = uiRegistry({
name: 'indexPatternList',
index: ['name'],
order: ['order'],
});
23 changes: 23 additions & 0 deletions src/ui/public/management/index_pattern_list/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { IndexPatternListConfig } from './index_pattern_list_config';
import { IndexPatternListConfigRegistry } from './index_pattern_list_config_registry';

IndexPatternListConfigRegistry.register(() => IndexPatternListConfig);
24 changes: 24 additions & 0 deletions src/ui/public/utils/parse_es_interval/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { parseEsInterval } from './parse_es_interval';
export {
ParseEsIntervalInvalidCalendarIntervalError,
} from './parse_es_interval_invalid_calendar_interval_error';
export { ParseEsIntervalInvalidFormatError } from './parse_es_interval_invalid_format_error';
Loading

0 comments on commit c765ecb

Please sign in to comment.