Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lens] Improve suggestions for split series #42052

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,42 @@ export function getIndexPatterns() {
type: 'date',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'start_date',
type: 'date',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'memory',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'source',
type: 'string',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'dest',
type: 'string',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
],
},
Expand All @@ -42,18 +66,21 @@ export function getIndexPatterns() {
type: 'date',
aggregatable: true,
searchable: true,
indexPatternId: '2',
},
{
name: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '2',
},
{
name: 'source',
type: 'string',
aggregatable: true,
searchable: true,
indexPatternId: '2',
},
],
typeMeta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,35 @@ const initialState: IndexPatternPrivateState = {
type: 'date',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'memory',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'unsupported',
type: 'geo',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'source',
type: 'string',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
],
},
Expand All @@ -88,6 +93,7 @@ const initialState: IndexPatternPrivateState = {
type: 'date',
aggregatable: true,
searchable: true,
indexPatternId: '2',
aggregationRestrictions: {
date_histogram: {
agg: 'date_histogram',
Expand All @@ -102,6 +108,7 @@ const initialState: IndexPatternPrivateState = {
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '2',
aggregationRestrictions: {
histogram: {
agg: 'histogram',
Expand All @@ -126,6 +133,7 @@ const initialState: IndexPatternPrivateState = {
type: 'string',
aggregatable: true,
searchable: true,
indexPatternId: '2',
aggregationRestrictions: {
terms: {
agg: 'terms',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,28 @@ const expectedIndexPatterns = {
type: 'date',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'memory',
type: 'number',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
{
name: 'source',
type: 'string',
aggregatable: true,
searchable: true,
indexPatternId: '1',
},
],
},
Expand Down Expand Up @@ -798,6 +802,7 @@ describe('IndexPatternDimensionPanel', () => {
name: 'bar',
searchable: true,
type: 'number',
indexPatternId: 'foo',
},
],
},
Expand Down Expand Up @@ -889,7 +894,7 @@ describe('IndexPatternDimensionPanel', () => {
{...defaultProps}
dragDropContext={{
...dragDropContext,
dragging: { type: 'number', name: 'bar' },
dragging: { type: 'number', name: 'bar', indexPatternId: 'foo' },
}}
state={dragDropState()}
filterOperations={op => op.dataType === 'number'}
Expand All @@ -905,6 +910,28 @@ describe('IndexPatternDimensionPanel', () => {
).toBeTruthy();
});

it('is notdroppable if the field belongs to another index pattern', () => {
wrapper = shallow(
<IndexPatternDimensionPanel
{...defaultProps}
dragDropContext={{
...dragDropContext,
dragging: { type: 'number', name: 'bar', indexPatternId: 'foo2' },
}}
state={dragDropState()}
filterOperations={op => op.dataType === 'number'}
layerId="myLayer"
/>
);

expect(
wrapper
.find('[data-test-subj="indexPattern-dropTarget"]')
.first()
.prop('droppable')
).toBeFalsy();
});

it('appends the dropped column when a field is dropped', () => {
const dragging = { type: 'number', name: 'bar' };
const testState = dragDropState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getAvailableOperationsByMetadata, buildColumn } from '../operations';
import { PopoverEditor } from './popover_editor';
import { DragContextState, ChildDragDropProvider, DragDrop } from '../../drag_drop';
import { changeColumn, deleteColumn } from '../state_helpers';
import { isIndexPatternField } from '../utils';

export type IndexPatternDimensionPanelProps = DatasourceDimensionPanelProps & {
state: IndexPatternPrivateState;
Expand Down Expand Up @@ -87,9 +88,13 @@ export const IndexPatternDimensionPanel = memo(function IndexPatternDimensionPan

function canHandleDrop() {
const { dragging } = props.dragDropContext;
const field = dragging as IndexPatternField;
const layerIndexPatternId = props.state.layers[props.layerId].indexPatternId;

return !!field && !!field.type && !!hasOperationForField(field as IndexPatternField);
return (
isIndexPatternField(dragging) &&
layerIndexPatternId === dragging.indexPatternId &&
Boolean(hasOperationForField(dragging))
);
}

return (
Expand All @@ -99,7 +104,9 @@ export const IndexPatternDimensionPanel = memo(function IndexPatternDimensionPan
data-test-subj="indexPattern-dropTarget"
droppable={canHandleDrop()}
onDrop={field => {
if (!hasOperationForField(field as IndexPatternField)) {
const column = isIndexPatternField(field) && hasOperationForField(field);

if (!column) {
// TODO: What do we do if we couldn't find a column?
return;
}
Expand Down
Loading