Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jun 24, 2021
2 parents 25a459f + 4266957 commit 72be570
Show file tree
Hide file tree
Showing 124 changed files with 2,832 additions and 888 deletions.
3 changes: 3 additions & 0 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ of buckets to try to represent.
[[visualization-visualize-chartslibrary]]`visualization:visualize:legacyChartsLibrary`::
Enables the legacy charts library for aggregation-based area, line, and bar charts in *Visualize*.

[[visualization-visualize-pieChartslibrary]]`visualization:visualize:legacyPieChartsLibrary`::
Enables the legacy charts library for aggregation-based pie charts in *Visualize*.

[[visualization-colormapping]]`visualization:colorMapping`::
**This setting is deprecated and will not be supported as of 8.0.**
Maps values to specific colors in charts using the *Compatibility* palette.
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@npm//pegjs:index.bzl", "pegjs")
load("@npm//peggy:index.bzl", "peggy")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-interpreter"
Expand Down Expand Up @@ -37,18 +37,18 @@ TYPES_DEPS = [

DEPS = SRC_DEPS + TYPES_DEPS

pegjs(
peggy(
name = "grammar",
data = [
":grammar/grammar.pegjs"
":grammar/grammar.peggy"
],
output_dir = True,
args = [
"--allowed-start-rules",
"expression,argument",
"-o",
"$(@D)/index.js",
"./%s/grammar/grammar.pegjs" % package_name()
"./%s/grammar/grammar.peggy" % package_name()
],
)

Expand Down
7 changes: 7 additions & 0 deletions src/plugins/data/common/field_formats/converters/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
import { shortenDottedString } from '../../utils';

export const emptyLabel = i18n.translate('data.fieldFormats.string.emptyLabel', {
defaultMessage: '(empty)',
});

const TRANSFORM_OPTIONS = [
{
kind: false,
Expand Down Expand Up @@ -103,6 +107,9 @@ export class StringFormat extends FieldFormat {
}

textConvert: TextContextTypeConvert = (val) => {
if (val === '') {
return emptyLabel;
}
switch (this.param('transform')) {
case 'lower':
return String(val).toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
import React from 'react';
import { mountWithIntl } from '@kbn/test/jest';
import { findTestSubject } from '@elastic/eui/lib/test';
import { FilterInBtn, FilterOutBtn } from './discover_grid_cell_actions';
import { FilterInBtn, FilterOutBtn, buildCellActions } from './discover_grid_cell_actions';
import { DiscoverGridContext } from './discover_grid_context';

import { indexPatternMock } from '../../../__mocks__/index_pattern';
import { esHits } from '../../../__mocks__/es_hits';
import { EuiButton } from '@elastic/eui';
import { IndexPatternField } from 'src/plugins/data/common';

describe('Discover cell actions ', function () {
it('should not show cell actions for unfilterable fields', async () => {
expect(
buildCellActions({ name: 'foo', filterable: false } as IndexPatternField)
).toBeUndefined();
});

it('triggers filter function when FilterInBtn is clicked', async () => {
const contextMock = {
expanded: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const FilterOutBtn = ({
};

export function buildCellActions(field: IndexPatternField) {
if (!field.aggregatable && !field.searchable) {
if (!field.filterable) {
return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
type: 'boolean',
_meta: { description: 'Non-default value of setting.' },
},
'visualization:visualize:legacyPieChartsLibrary': {
type: 'boolean',
_meta: { description: 'Non-default value of setting.' },
},
'doc_table:legacy': {
type: 'boolean',
_meta: { description: 'Non-default value of setting.' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface UsageStats {
'autocomplete:useTimeRange': boolean;
'search:timeout': number;
'visualization:visualize:legacyChartsLibrary': boolean;
'visualization:visualize:legacyPieChartsLibrary': boolean;
'doc_table:legacy': boolean;
'discover:modifyColumnsOnSwitch': boolean;
'discover:searchFieldsFromSource': boolean;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8594,6 +8594,12 @@
"description": "Non-default value of setting."
}
},
"visualization:visualize:legacyPieChartsLibrary": {
"type": "boolean",
"_meta": {
"description": "Non-default value of setting."
}
},
"doc_table:legacy": {
"type": "boolean",
"_meta": {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_type_pie/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export const DEFAULT_PERCENT_DECIMALS = 2;
export const LEGACY_PIE_CHARTS_LIBRARY = 'visualization:visualize:legacyPieChartsLibrary';
2 changes: 2 additions & 0 deletions src/plugins/vis_type_pie/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"id": "visTypePie",
"version": "kibana",
"ui": true,
"server": true,
"requiredPlugins": ["charts", "data", "expressions", "visualizations", "usageCollection"],
"requiredBundles": ["visDefaultEditor"],
"extraPublicDirs": ["common/index"],
"owner": {
"name": "Kibana App",
"githubTeam": "kibana-app"
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/vis_type_pie/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Plugin as ExpressionsPublicPlugin } from '../../expressions/public';
import { ChartsPluginSetup } from '../../charts/public';
import { UsageCollectionSetup } from '../../usage_collection/public';
import { DataPublicPluginStart } from '../../data/public';
import { LEGACY_CHARTS_LIBRARY } from '../../visualizations/common/constants';
import { LEGACY_PIE_CHARTS_LIBRARY } from '../common';
import { pieLabels as pieLabelsExpressionFunction } from './expression_functions/pie_labels';
import { createPieVisFn } from './pie_fn';
import { getPieVisRenderer } from './pie_renderer';
Expand Down Expand Up @@ -43,7 +43,7 @@ export class VisTypePiePlugin {
core: CoreSetup<VisTypePiePluginStartDependencies>,
{ expressions, visualizations, charts, usageCollection }: VisTypePieSetupDependencies
) {
if (!core.uiSettings.get(LEGACY_CHARTS_LIBRARY, false)) {
if (!core.uiSettings.get(LEGACY_PIE_CHARTS_LIBRARY, false)) {
const getStartDeps = async () => {
const [coreStart, deps] = await core.getStartServices();
return {
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/vis_type_pie/public/utils/get_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import {
Datum,
PartitionFillLabel,
Expand Down Expand Up @@ -125,11 +124,6 @@ export const getLayers = (
},
showAccessor: (d: Datum) => d !== EMPTY_SLICE,
nodeLabel: (d: unknown) => {
if (d === '') {
return i18n.translate('visTypePie.emptyLabelValue', {
defaultMessage: '(empty)',
});
}
if (col.format) {
const formattedLabel = formatter.deserialize(col.format).convert(d) ?? '';
if (visParams.labels.truncate && formattedLabel.length <= visParams.labels.truncate) {
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/vis_type_pie/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { VisTypePieServerPlugin } from './plugin';

export const plugin = () => new VisTypePieServerPlugin();
56 changes: 56 additions & 0 deletions src/plugins/vis_type_pie/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';

import { CoreSetup, Plugin, UiSettingsParams } from 'kibana/server';

import { LEGACY_PIE_CHARTS_LIBRARY } from '../common';

export const getUiSettingsConfig: () => Record<string, UiSettingsParams<boolean>> = () => ({
// TODO: Remove this when vis_type_vislib is removed
// https://github.com/elastic/kibana/issues/56143
[LEGACY_PIE_CHARTS_LIBRARY]: {
name: i18n.translate('visTypePie.advancedSettings.visualization.legacyPieChartsLibrary.name', {
defaultMessage: 'Pie legacy charts library',
}),
requiresPageReload: true,
value: false,
description: i18n.translate(
'visTypePie.advancedSettings.visualization.legacyPieChartsLibrary.description',
{
defaultMessage: 'Enables legacy charts library for pie charts in visualize.',
}
),
deprecation: {
message: i18n.translate(
'visTypePie.advancedSettings.visualization.legacyPieChartsLibrary.deprecation',
{
defaultMessage:
'The legacy charts library for pie in visualize is deprecated and will not be supported as of 8.0.',
}
),
docLinksKey: 'visualizationSettings',
},
category: ['visualization'],
schema: schema.boolean(),
},
});

export class VisTypePieServerPlugin implements Plugin<object, object> {
public setup(core: CoreSetup) {
core.uiSettings.register(getUiSettingsConfig());

return {};
}

public start() {
return {};
}
}
24 changes: 13 additions & 11 deletions src/plugins/vis_type_vislib/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { VisualizationsSetup } from '../../visualizations/public';
import { ChartsPluginSetup } from '../../charts/public';
import { DataPublicPluginStart } from '../../data/public';
import { KibanaLegacyStart } from '../../kibana_legacy/public';
import { LEGACY_CHARTS_LIBRARY } from '../../visualizations/common/constants';
import { LEGACY_CHARTS_LIBRARY } from '../../vis_type_xy/common/index';
import { LEGACY_PIE_CHARTS_LIBRARY } from '../../vis_type_pie/common/index';

import { createVisTypeVislibVisFn } from './vis_type_vislib_vis_fn';
import { createPieVisFn } from './pie_fn';
Expand Down Expand Up @@ -50,17 +51,18 @@ export class VisTypeVislibPlugin
core: VisTypeVislibCoreSetup,
{ expressions, visualizations, charts }: VisTypeVislibPluginSetupDependencies
) {
if (!core.uiSettings.get(LEGACY_CHARTS_LIBRARY, false)) {
// Register only non-replaced vis types
convertedTypeDefinitions.forEach(visualizations.createBaseVisualization);
expressions.registerRenderer(getVislibVisRenderer(core, charts));
expressions.registerFunction(createVisTypeVislibVisFn());
} else {
// Register all vis types
visLibVisTypeDefinitions.forEach(visualizations.createBaseVisualization);
const typeDefinitions = !core.uiSettings.get(LEGACY_CHARTS_LIBRARY, false)
? convertedTypeDefinitions
: visLibVisTypeDefinitions;
// register vislib XY axis charts
typeDefinitions.forEach(visualizations.createBaseVisualization);
expressions.registerRenderer(getVislibVisRenderer(core, charts));
expressions.registerFunction(createVisTypeVislibVisFn());

if (core.uiSettings.get(LEGACY_PIE_CHARTS_LIBRARY, false)) {
// register vislib pie chart
visualizations.createBaseVisualization(pieVisTypeDefinition);
expressions.registerRenderer(getVislibVisRenderer(core, charts));
[createVisTypeVislibVisFn(), createPieVisFn()].forEach(expressions.registerFunction);
expressions.registerFunction(createPieVisFn());
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vis_type_xy/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export enum ChartType {
* Type of xy visualizations
*/
export type XyVisType = ChartType | 'horizontal_bar';

export const LEGACY_CHARTS_LIBRARY = 'visualization:visualize:legacyChartsLibrary';
2 changes: 2 additions & 0 deletions src/plugins/vis_type_xy/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"id": "visTypeXy",
"version": "kibana",
"ui": true,
"server": true,
"requiredPlugins": ["charts", "data", "expressions", "visualizations", "usageCollection"],
"requiredBundles": ["kibanaUtils", "visDefaultEditor"],
"extraPublicDirs": ["common/index"],
"owner": {
"name": "Kibana App",
"githubTeam": "kibana-app"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { Aspects } from '../types';

import './_detailed_tooltip.scss';
import { fillEmptyValue } from '../utils/get_series_name_fn';
import { COMPLEX_SPLIT_ACCESSOR, isRangeAggType } from '../utils/accessors';

interface TooltipData {
Expand Down Expand Up @@ -100,8 +99,7 @@ export const getTooltipData = (
return data;
};

const renderData = ({ label, value: rawValue }: TooltipData, index: number) => {
const value = fillEmptyValue(rawValue);
const renderData = ({ label, value }: TooltipData, index: number) => {
return label && value ? (
<tr key={label + value + index}>
<td className="detailedTooltip__label">
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/vis_type_xy/public/components/xy_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { renderEndzoneTooltip } from '../../../charts/public';

import { getThemeService, getUISettings } from '../services';
import { VisConfig } from '../types';
import { fillEmptyValue } from '../utils/get_series_name_fn';

declare global {
interface Window {
Expand Down Expand Up @@ -134,7 +133,7 @@ export const XYSettings: FC<XYSettingsProps> = ({
};

const headerValueFormatter: TickFormatter<any> | undefined = xAxis.ticks?.formatter
? (value) => fillEmptyValue(xAxis.ticks?.formatter?.(value)) ?? ''
? (value) => xAxis.ticks?.formatter?.(value) ?? ''
: undefined;
const headerFormatter =
isTimeChart && xDomain && adjustedXDomain
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/vis_type_xy/public/config/get_axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
YScaleType,
SeriesParam,
} from '../types';
import { fillEmptyValue } from '../utils/get_series_name_fn';

export function getAxis<S extends XScaleType | YScaleType>(
{ type, title: axisTitle, labels, scale: axisScale, ...axis }: CategoryAxis,
Expand Down Expand Up @@ -90,8 +89,7 @@ function getLabelFormatter(
}

return (value: any) => {
const formattedStringValue = `${formatter ? formatter(value) : value}`;
const finalValue = fillEmptyValue(formattedStringValue);
const finalValue = `${formatter ? formatter(value) : value}`;

if (finalValue.length > truncate) {
return `${finalValue.slice(0, truncate)}...`;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_xy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './services';

import { visTypesDefinitions } from './vis_types';
import { LEGACY_CHARTS_LIBRARY } from '../../visualizations/common/constants';
import { LEGACY_CHARTS_LIBRARY } from '../common/';
import { xyVisRenderer } from './vis_renderer';

import * as expressionFunctions from './expression_functions';
Expand Down
13 changes: 1 addition & 12 deletions src/plugins/vis_type_xy/public/utils/get_series_name_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@

import { memoize } from 'lodash';

import { i18n } from '@kbn/i18n';
import { XYChartSeriesIdentifier, SeriesName } from '@elastic/charts';

import { VisConfig } from '../types';

const emptyTextLabel = i18n.translate('visTypeXy.emptyTextColumnValue', {
defaultMessage: '(empty)',
});

/**
* Returns empty values
*/
export const fillEmptyValue = <T extends string | number | undefined>(value: T) =>
value === '' ? emptyTextLabel : value;

function getSplitValues(
splitAccessors: XYChartSeriesIdentifier['splitAccessors'],
seriesAspects?: VisConfig['aspects']['series']
Expand All @@ -36,7 +25,7 @@ function getSplitValues(
const split = (seriesAspects ?? []).find(({ accessor }) => accessor === key);
splitValues.push(split?.formatter ? split?.formatter(value) : value);
});
return splitValues.map(fillEmptyValue);
return splitValues;
}

export const getSeriesNameFn = (aspects: VisConfig['aspects'], multipleY = false) =>
Expand Down
Loading

0 comments on commit 72be570

Please sign in to comment.