-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Add xy split series support #39726
Changes from 6 commits
0f1dd47
c163eee
11bdd61
85d44cb
2bf7aff
a262255
f1ca4a2
3c72069
70df631
76519f0
dd1524a
b8e700f
44831d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { generateId } from './id_generator'; | ||
|
||
describe('XYConfigPanel', () => { | ||
it('generates different ids', () => { | ||
expect(generateId()).not.toEqual(generateId()); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import uuid from 'uuid/v4'; | ||
|
||
export function generateId() { | ||
return uuid(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './id_generator'; |
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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export function mockGeneratedIds(generator: { generateId: () => string }, ...ids: string[]) { | ||
const mock = jest.spyOn(generator, 'generateId'); | ||
ids.forEach(id => mock.mockReturnValueOnce(id)); | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { | |
import { State, SeriesType } from './types'; | ||
import { VisualizationProps, Operation } from '../types'; | ||
import { NativeRenderer } from '../native_renderer'; | ||
import { generateId } from '../id_generator'; | ||
|
||
const chartTypeIcons: Array<{ id: SeriesType; label: string; iconType: IconType }> = [ | ||
{ | ||
|
@@ -161,6 +162,37 @@ export function XYConfigPanel(props: VisualizationProps<State>) { | |
</EuiFormRow> | ||
)} | ||
|
||
<EuiFormRow | ||
label={i18n.translate('xpack.lens.xyChart.splitSeries', { | ||
defaultMessage: 'Split series', | ||
})} | ||
> | ||
<> | ||
{state.splitSeriesAccessors.map(columnId => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a way to remove existing split column like for y columns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chrisdavies That just deletes the column in the data source, not the accessor in the visualization. If you press the plus button ten times, you have ten columns "to configure" and now way to remove those placeholders. y axis has separate remove buttons but they are not styled nicely |
||
<NativeRenderer | ||
data-test-subj="lnsXY_splitDimensionPanel" | ||
render={datasource.renderDimensionPanel} | ||
nativeProps={{ | ||
columnId, | ||
dragDropContext: props.dragDropContext, | ||
filterOperations: (op: Operation) => op.isBucketed === true, | ||
suggestedPriority: 0, | ||
}} | ||
/> | ||
))} | ||
<EuiButton | ||
data-test-subj="lnsXY_splitSeriesDimensionPanel_add" | ||
onClick={() => | ||
setState({ | ||
...state, | ||
splitSeriesAccessors: [...state.splitSeriesAccessors, generateId()], | ||
}) | ||
} | ||
iconType="plusInCircle" | ||
/> | ||
</> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label={i18n.translate('xpack.lens.xyChart.xAxisLabel', { | ||
defaultMessage: 'X Axis', | ||
|
@@ -287,7 +319,7 @@ export function XYConfigPanel(props: VisualizationProps<State>) { | |
...state, | ||
y: { | ||
...state.y, | ||
accessors: [...state.y.accessors, datasource.generateColumnId()], | ||
accessors: [...state.y.accessors, generateId()], | ||
}, | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you take advantage of jest's ability to replace modules with manual mocks? https://jestjs.io/docs/en/manual-mocks
Here's what I was thinking:
In
id_generator/__mocks__/index.ts
:In your test code:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks much nicer. I'll give it a shot.