Skip to content

Commit

Permalink
[Vis: Default editor] EUIficate other bucket control (elastic#34945) (e…
Browse files Browse the repository at this point in the history
…lastic#35781)

* EUIficate other_bucket control

* Filter invalid string params

* Fix functional tests

* Fix browser tests
  • Loading branch information
sulemanof authored Apr 30, 2019
1 parent e5925ca commit d7be854
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { AggConfig } from 'ui/vis/agg_config';

export function isStringType(type: AggConfig): boolean;
38 changes: 26 additions & 12 deletions src/legacy/ui/public/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import { Schemas } from '../../vis/editors/default/schemas';
import { createFilterTerms } from './create_filter/terms';
import orderAggTemplate from '../controls/order_agg.html';
import orderAndSizeTemplate from '../controls/order_and_size.html';
import otherBucketTemplate from '../controls/other_bucket.html';
import { i18n } from '@kbn/i18n';

import { getRequestInspectorStats, getResponseInspectorStats } from '../../courier/utils/courier_inspector_utils';
import { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } from './_terms_other_bucket_helper';
import { MissingBucketParamEditor } from '../controls/missing_bucket';
import { OtherBucketParamEditor } from '../controls/other_bucket';
import { isStringType, migrateIncludeExcludeFormat } from './migrate_include_exclude_format';

const aggFilter = [
Expand Down Expand Up @@ -266,27 +267,40 @@ export const termsBucketAgg = new BucketAggType({
{
name: 'otherBucket',
default: false,
editor: otherBucketTemplate,
write: _.noop
}, {
editorComponent: OtherBucketParamEditor,
write: _.noop,
},
{
name: 'otherBucketLabel',
type: 'string',
default: i18n.translate('common.ui.aggTypes.buckets.terms.otherBucketLabel', {
defaultMessage: 'Other',
}),
write: _.noop
}, {
displayName: i18n.translate('common.ui.aggTypes.otherBucket.labelForOtherBucketLabel', {
defaultMessage: 'Label for other bucket',
}),
shouldShow: agg => agg.params.otherBucket,
write: _.noop,
},
{
name: 'missingBucket',
default: false,
write: _.noop
}, {
editorComponent: MissingBucketParamEditor,
write: _.noop,
},
{
name: 'missingBucketLabel',
default: i18n.translate('common.ui.aggTypes.buckets.terms.missingBucketLabel', {
defaultMessage: 'Missing',
description: `Default label used inside of charts for documents missing a specific field.
Can be seen when creating a chart with a terms aggregation and select the "Show missing values"
checkbox.`
description: `Default label used in charts when documents are missing a field.
Visible when you create a chart with a terms aggregation and enable "Show missing values"`,
}),
type: 'string',
displayName: i18n.translate('common.ui.aggTypes.otherBucket.labelForMissingValuesLabel', {
defaultMessage: 'Label for missing values',
}),
write: _.noop
shouldShow: agg => agg.params.missingBucket,
write: _.noop,
},
{
name: 'exclude',
Expand Down
46 changes: 46 additions & 0 deletions src/legacy/ui/public/agg_types/controls/missing_bucket.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 React from 'react';
import { i18n } from '@kbn/i18n';
import { AggParamEditorProps } from 'ui/vis/editors/default';
import { SwitchParamEditor } from './switch';
import { isStringType } from '../buckets/migrate_include_exclude_format';

function MissingBucketParamEditor(props: AggParamEditorProps<boolean>) {
return (
<SwitchParamEditor
dataTestSubj="missingBucketSwitch"
displayLabel={i18n.translate('common.ui.aggTypes.otherBucket.showMissingValuesLabel', {
defaultMessage: 'Show missing values',
})}
displayToolTip={i18n.translate('common.ui.aggTypes.otherBucket.showMissingValuesTooltip', {
defaultMessage:
'Only works for fields of type "string". When enabled, include documents with missing ' +
'values in the search. If this bucket is in the top N, it appears in the chart. ' +
'If not in the top N, and you enable "Group other values in separate bucket", ' +
'Elasticsearch adds the missing values to the "other" bucket.',
})}
disabled={!isStringType(props.agg)}
{...props}
/>
);
}

export { MissingBucketParamEditor };
74 changes: 0 additions & 74 deletions src/legacy/ui/public/agg_types/controls/other_bucket.html

This file was deleted.

42 changes: 42 additions & 0 deletions src/legacy/ui/public/agg_types/controls/other_bucket.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 React from 'react';
import { i18n } from '@kbn/i18n';
import { AggParamEditorProps } from 'ui/vis/editors/default';
import { SwitchParamEditor } from './switch';

function OtherBucketParamEditor(props: AggParamEditorProps<boolean>) {
return (
<SwitchParamEditor
dataTestSubj="otherBucketSwitch"
displayLabel={i18n.translate('common.ui.aggTypes.otherBucket.groupValuesLabel', {
defaultMessage: 'Group other values in separate bucket',
})}
displayToolTip={i18n.translate('common.ui.aggTypes.otherBucket.groupValuesTooltip', {
defaultMessage:
'Values not in the top N are grouped in this bucket. ' +
"To include documents with missing values, enable 'Show missing values'.",
})}
{...props}
/>
);
}

export { OtherBucketParamEditor };
56 changes: 56 additions & 0 deletions src/legacy/ui/public/agg_types/controls/switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 React from 'react';

import { EuiSwitch, EuiToolTip, EuiSpacer } from '@elastic/eui';
import { AggParamEditorProps } from 'ui/vis/editors/default';

interface SwitchParamEditorProps extends AggParamEditorProps<boolean> {
dataTestSubj?: string;
displayLabel?: string;
displayToolTip?: string;
disabled?: boolean;
}

function SwitchParamEditor({
value,
setValue,
dataTestSubj,
displayToolTip,
displayLabel,
disabled,
}: SwitchParamEditorProps) {
return (
<div className="visEditorSidebar__aggParamFormRow">
<EuiToolTip content={displayToolTip} delay="long" position="right">
<EuiSwitch
label={displayLabel}
checked={value}
disabled={disabled}
data-test-subj={dataTestSubj}
onChange={ev => setValue(ev.target.checked)}
/>
</EuiToolTip>
<EuiSpacer size="s" />
</div>
);
}

export { SwitchParamEditor };
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.selectAggregation('Terms');
await PageObjects.visualize.selectField('machine.os.raw');
await PageObjects.visualize.setSize(2);
await PageObjects.visualize.toggleOtherBucket();
await PageObjects.visualize.toggleOtherBucket(3);
await PageObjects.visualize.clickGo();
});

Expand Down
8 changes: 4 additions & 4 deletions test/functional/apps/visualize/_pie_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.selectAggregation('Terms');
log.debug('Click field machine.os.raw');
await PageObjects.visualize.selectField('machine.os.raw');
await PageObjects.visualize.toggleOtherBucket();
await PageObjects.visualize.toggleMissingBucket();
await PageObjects.visualize.toggleOtherBucket(2);
await PageObjects.visualize.toggleMissingBucket(2);
log.debug('clickGo');
await PageObjects.visualize.clickGo();
await pieChart.expectPieChartLabels(expectedTableData);
Expand Down Expand Up @@ -131,8 +131,8 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.selectAggregation('Terms');
log.debug('Click field geo.src');
await PageObjects.visualize.selectField('geo.src');
await PageObjects.visualize.toggleOtherBucket();
await PageObjects.visualize.toggleMissingBucket();
await PageObjects.visualize.toggleOtherBucket(3);
await PageObjects.visualize.toggleMissingBucket(3);
log.debug('clickGo');
await PageObjects.visualize.clickGo();
await pieChart.expectPieChartLabels(expectedTableData);
Expand Down
8 changes: 4 additions & 4 deletions test/functional/page_objects/visualize_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,12 @@ export function VisualizePageProvider({ getService, getPageObjects, updateBaseli
await PageObjects.header.waitUntilLoadingHasFinished();
}

async toggleOtherBucket() {
return await find.clickByCssSelector('vis-editor-agg-params:not(.ng-hide) input[name="showOther"]');
async toggleOtherBucket(agg = 2) {
return await testSubjects.click(`aggregationEditor${agg} otherBucketSwitch`);
}

async toggleMissingBucket() {
return await find.clickByCssSelector('vis-editor-agg-params:not(.ng-hide) input[name="showMissing"]');
async toggleMissingBucket(agg = 2) {
return await testSubjects.click(`aggregationEditor${agg} missingBucketSwitch`);
}

async isApplyEnabled() {
Expand Down

0 comments on commit d7be854

Please sign in to comment.