Skip to content

Commit

Permalink
Merge branch 'master' into ml-transform-range-filter-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Aug 17, 2021
2 parents 14c1ea1 + 94f3508 commit 7e33871
Show file tree
Hide file tree
Showing 38 changed files with 426 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('kuery functions', () => {
const node = nodeTypes.function.buildNode('geoBoundingBox', 'geo', params);
const result = geoBoundingBox.toElasticsearchQuery(node, indexPattern);

// @ts-expect-error @elastic/elasticsearch doesn't support ignore_unmapped in QueryDslGeoBoundingBoxQuery
expect(result.geo_bounding_box!.ignore_unmapped).toBe(true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function toElasticsearchQuery(
}

return {
// @ts-expect-error @elastic/elasticsearch doesn't support ignore_unmapped in QueryDslGeoBoundingBoxQuery
geo_bounding_box: {
[fieldName]: queryParams,
ignore_unmapped: true,
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-query/src/kuery/functions/geo_polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function toElasticsearchQuery(
}

return {
// @ts-expect-error @elastic/elasticsearch doesn't support ignore_unmapped in QueryDslGeoPolygonQuery
geo_polygon: {
[fieldName]: queryParams,
ignore_unmapped: true,
Expand Down
3 changes: 2 additions & 1 deletion src/dev/build/tasks/copy_source_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export const CopySource: Task = {
'!src/cli/dev.js',
'!src/functional_test_runner/**',
'!src/dev/**',
'!**/jest.config.js',
'!src/plugins/telemetry/schema/**', // Skip telemetry schemas
// this is the dev-only entry
'!src/setup_node_env/index.js',
'!**/public/**/*.{js,ts,tsx,json}',
'!**/public/**/*.{js,ts,tsx,json,scss}',
'typings/**',
'config/kibana.yml',
'config/node.options',
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/cases/public/components/case_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const CaseComponent = React.memo<CaseComponentProps>(
const [initLoadingData, setInitLoadingData] = useState(true);
const init = useRef(true);
const timelineUi = useTimelineContext()?.ui;
const alertConsumers = useTimelineContext()?.alertConsumers;

const {
caseUserActions,
Expand Down Expand Up @@ -486,7 +487,9 @@ export const CaseComponent = React.memo<CaseComponentProps>(
</EuiFlexGroup>
</ContentWrapper>
</WhitePageWrapper>
{timelineUi?.renderTimelineDetailsPanel ? timelineUi.renderTimelineDetailsPanel() : null}
{timelineUi?.renderTimelineDetailsPanel
? timelineUi.renderTimelineDetailsPanel({ alertConsumers })
: null}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, { useState } from 'react';
import { EuiMarkdownEditorUiPlugin, EuiMarkdownAstNodePosition } from '@elastic/eui';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { Plugin } from 'unified';
/**
* @description - manage the plugins, hooks, and ui components needed to enable timeline functionality within the cases plugin
Expand All @@ -28,6 +29,7 @@ interface TimelineProcessingPluginRendererProps {
}

export interface CasesTimelineIntegration {
alertConsumers?: AlertConsumers[];
editor_plugins: {
parsingPlugin: Plugin;
processingPluginRenderer: React.FC<
Expand All @@ -43,7 +45,11 @@ export interface CasesTimelineIntegration {
};
ui?: {
renderInvestigateInTimelineActionComponent?: (alertIds: string[]) => JSX.Element;
renderTimelineDetailsPanel?: () => JSX.Element;
renderTimelineDetailsPanel?: ({
alertConsumers,
}: {
alertConsumers?: AlertConsumers[];
}) => JSX.Element;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export interface HeatmapLegendConfig {
* Position of the legend relative to the chart
*/
position: Position;
/**
* Defines the number of lines per legend item
*/
maxLines?: number;
/**
* Defines if the legend items should be truncated
*/
shouldTruncate?: boolean;
}

export type HeatmapLegendConfigResult = HeatmapLegendConfig & {
Expand Down Expand Up @@ -54,6 +62,19 @@ export const heatmapLegendConfig: ExpressionFunctionDefinition<
defaultMessage: 'Specifies the legend position.',
}),
},
maxLines: {
types: ['number'],
help: i18n.translate('xpack.lens.heatmapChart.legend.maxLines.help', {
defaultMessage: 'Specifies the number of lines per legend item.',
}),
},
shouldTruncate: {
types: ['boolean'],
default: true,
help: i18n.translate('xpack.lens.heatmapChart.legend.shouldTruncate.help', {
defaultMessage: 'Specifies whether or not the legend items should be truncated.',
}),
},
},
fn(input, args) {
return {
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/lens/common/expressions/pie_chart/pie_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ export const pie: ExpressionFunctionDefinition<
types: ['boolean'],
help: '',
},
legendMaxLines: {
types: ['number'],
help: '',
},
truncateLegend: {
types: ['boolean'],
help: '',
},
legendPosition: {
types: ['string'],
options: [Position.Top, Position.Right, Position.Bottom, Position.Left],
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/common/expressions/pie_chart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface SharedPieLayerState {
legendPosition?: 'left' | 'right' | 'top' | 'bottom';
nestedLegend?: boolean;
percentDecimals?: number;
legendMaxLines?: number;
truncateLegend?: boolean;
}

export type PieLayerState = SharedPieLayerState & {
Expand Down
21 changes: 21 additions & 0 deletions x-pack/plugins/lens/common/expressions/xy_chart/legend_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export interface LegendConfig {
* Number of columns when legend is set inside chart
*/
floatingColumns?: number;
/**
* Maximum number of lines per legend item
*/
maxLines?: number;
/**
* Flag whether the legend items are truncated or not
*/
shouldTruncate?: boolean;
}

export type LegendConfigResult = LegendConfig & { type: 'lens_xy_legendConfig' };
Expand Down Expand Up @@ -100,6 +108,19 @@ export const legendConfig: ExpressionFunctionDefinition<
defaultMessage: 'Specifies the number of columns when legend is displayed inside chart.',
}),
},
maxLines: {
types: ['number'],
help: i18n.translate('xpack.lens.xyChart.maxLines.help', {
defaultMessage: 'Specifies the number of lines per legend item.',
}),
},
shouldTruncate: {
types: ['boolean'],
default: true,
help: i18n.translate('xpack.lens.xyChart.shouldTruncate.help', {
defaultMessage: 'Specifies whether the legend items will be truncated or not',
}),
},
},
fn: function fn(input: unknown, args: LegendConfig) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = ({
showLegend={args.legend.isVisible}
legendPosition={args.legend.position}
debugState={window._echDebugStateFlag ?? false}
theme={{
...chartTheme,
legend: {
labelOptions: { maxLines: args.legend.shouldTruncate ? args.legend?.maxLines ?? 1 : 0 },
},
}}
/>
<Heatmap
id={tableId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ export const HeatmapToolbar = memo(
legend: { ...state.legend, position: id as Position },
});
}}
maxLines={state?.legend.maxLines}
onMaxLinesChange={(val) => {
setState({
...state,
legend: { ...state.legend, maxLines: val },
});
}}
shouldTruncate={state?.legend.shouldTruncate ?? true}
onTruncateLegendChange={() => {
const current = state.legend.shouldTruncate ?? true;
setState({
...state,
legend: { ...state.legend, shouldTruncate: !current },
});
}}
/>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function exampleState(): HeatmapVisualizationState {
isVisible: true,
position: Position.Right,
type: LEGEND_FUNCTION,
maxLines: 1,
shouldTruncate: true,
},
gridConfig: {
type: HEATMAP_GRID_FUNCTION,
Expand Down Expand Up @@ -63,6 +65,8 @@ describe('heatmap', () => {
isVisible: true,
position: Position.Right,
type: LEGEND_FUNCTION,
maxLines: 1,
shouldTruncate: true,
},
gridConfig: {
type: HEATMAP_GRID_FUNCTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function getInitialState(): Omit<HeatmapVisualizationState, 'layerId' | 'layerTy
legend: {
isVisible: true,
position: Position.Right,
maxLines: 1,
shouldTruncate: true,
type: LEGEND_FUNCTION,
},
gridConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ describe('PieVisualization component', () => {
numberDisplay: 'hidden',
categoryDisplay: 'default',
legendDisplay: 'default',
legendMaxLines: 1,
truncateLegend: true,
nestedLegend: false,
percentDecimals: 3,
hideLabels: false,
Expand Down Expand Up @@ -106,6 +108,20 @@ describe('PieVisualization component', () => {
expect(component.find(Settings).prop('showLegend')).toEqual(false);
});

test('it sets the correct lines per legend item', () => {
const component = shallow(<PieComponent args={args} {...getDefaultArgs()} />);
expect(component.find(Settings).prop('theme')).toEqual({
background: {
color: undefined,
},
legend: {
labelOptions: {
maxLines: 1,
},
},
});
});

test('it calls the color function with the right series layers', () => {
const defaultArgs = getDefaultArgs();
const component = shallow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export function PieComponent(
legendPosition,
nestedLegend,
percentDecimals,
legendMaxLines,
truncateLegend,
hideLabels,
palette,
} = props.args;
Expand Down Expand Up @@ -297,6 +299,9 @@ export function PieComponent(
...chartTheme.background,
color: undefined, // removes background for embeddables
},
legend: {
labelOptions: { maxLines: truncateLegend ? legendMaxLines ?? 1 : 0 },
},
}}
baseTheme={chartBaseTheme}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ describe('suggestions', () => {
categoryDisplay: 'inside',
legendDisplay: 'show',
percentDecimals: 0,
legendMaxLines: 1,
truncateLegend: true,
nestedLegend: true,
},
],
Expand All @@ -516,6 +518,8 @@ describe('suggestions', () => {
categoryDisplay: 'inside',
legendDisplay: 'show',
percentDecimals: 0,
legendMaxLines: 1,
truncateLegend: true,
nestedLegend: true,
},
],
Expand Down Expand Up @@ -684,6 +688,8 @@ describe('suggestions', () => {
categoryDisplay: 'inside',
legendDisplay: 'show',
percentDecimals: 0,
legendMaxLines: 1,
truncateLegend: true,
nestedLegend: true,
},
],
Expand All @@ -705,6 +711,8 @@ describe('suggestions', () => {
categoryDisplay: 'default', // This is changed
legendDisplay: 'show',
percentDecimals: 0,
legendMaxLines: 1,
truncateLegend: true,
nestedLegend: true,
},
],
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/pie_visualization/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function expressionHelper(
legendDisplay: [layer.legendDisplay],
legendPosition: [layer.legendPosition || 'right'],
percentDecimals: [layer.percentDecimals ?? DEFAULT_PERCENT_DECIMALS],
legendMaxLines: [layer.legendMaxLines ?? 1],
truncateLegend: [layer.truncateLegend ?? true],
nestedLegend: [!!layer.nestedLegend],
...(state.palette
? {
Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/lens/public/pie_visualization/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ export function PieToolbar(props: VisualizationToolbarProps<PieVisualizationStat
layers: [{ ...layer, nestedLegend: !layer.nestedLegend }],
});
}}
shouldTruncate={layer.truncateLegend ?? true}
onTruncateLegendChange={() => {
const current = layer.truncateLegend ?? true;
setState({
...state,
layers: [{ ...layer, truncateLegend: !current }],
});
}}
maxLines={layer?.legendMaxLines}
onMaxLinesChange={(val) => {
setState({
...state,
layers: [{ ...layer, legendMaxLines: val }],
});
}}
/>
</EuiFlexGroup>
);
Expand Down
Loading

0 comments on commit 7e33871

Please sign in to comment.