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] Fix bugs in date_histogram and filter ratio #42046

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ describe('date_histogram', () => {
},
],
},
2: {
id: '2',
title: 'Mock Indexpattern 2',
fields: [
{
name: 'other_timestamp',
type: 'date',
esTypes: ['date'],
aggregatable: true,
searchable: true,
},
],
},
},
layers: {
first: {
Expand All @@ -53,6 +66,26 @@ describe('date_histogram', () => {
},
},
},
second: {
indexPatternId: '2',
columnOrder: ['col2'],
columns: {
col2: {
operationId: 'op2',
label: 'Value of timestamp',
dataType: 'date',
isBucketed: true,

// Private
operationType: 'date_histogram',
params: {
interval: 'd',
},
sourceField: 'other_timestamp',
indexPatternId: '2',
},
},
},
},
};
});
Expand Down Expand Up @@ -130,6 +163,15 @@ describe('date_histogram', () => {
expect(instance.find(EuiRange).prop('value')).toEqual(1);
});

it('should render current value for other index pattern', () => {
const setStateSpy = jest.fn();
const instance = shallow(
<InlineOptions state={state} setState={setStateSpy} columnId="col2" layerId="second" />
);

expect(instance.find(EuiRange).prop('value')).toEqual(2);
});

it('should update state with the interval value', () => {
const setStateSpy = jest.fn();
const instance = shallow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const dateHistogramOperation: OperationDefinition<DateHistogramIndexPatte

const field =
column &&
state.indexPatterns[state.currentIndexPatternId].fields.find(
state.indexPatterns[state.layers[layerId].indexPatternId].fields.find(
currentField => currentField.name === column.sourceField
);
const intervalIsRestricted =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('filter_ratio', () => {
);

expect(wrapper.find(MockQueryBarInput)).toHaveLength(1);
expect(wrapper.find(MockQueryBarInput).prop('indexPatterns')).toEqual(['1']);
expect(wrapper.find(MockQueryBarInput).prop('indexPatterns')).toEqual(['Mock Indexpattern']);
});

it('should update the state when typing into the query bar', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const filterRatioOperation: OperationDefinition<FilterRatioIndexPatternCo
>
<QueryBarInput
appName={'lens'}
indexPatterns={[state.currentIndexPatternId]}
indexPatterns={[state.indexPatterns[state.layers[layerId].indexPatternId].title]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't realized that I needed to match by title, thanks for changing this

query={
(state.layers[layerId].columns[currentColumnId] as FilterRatioIndexPatternColumn)
.params.numerator
Expand Down Expand Up @@ -98,7 +98,7 @@ export const filterRatioOperation: OperationDefinition<FilterRatioIndexPatternCo
{hasDenominator ? (
<QueryBarInput
appName={'lens'}
indexPatterns={[state.currentIndexPatternId]}
indexPatterns={[state.indexPatterns[state.layers[layerId].indexPatternId].title]}
query={
(state.layers[layerId].columns[currentColumnId] as FilterRatioIndexPatternColumn)
.params.denominator
Expand Down