Skip to content

Commit 4b08d1e

Browse files
committed
Fix boolean error and add test for it
1 parent 7a3adef commit 4b08d1e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/plugins/data/public/query/timefilter/get_time.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,43 @@ describe('get_time', () => {
5151
});
5252
clock.restore();
5353
});
54+
55+
test('build range filter for non-primary field', () => {
56+
const clock = sinon.useFakeTimers(moment.utc([2000, 1, 1, 0, 0, 0, 0]).valueOf());
57+
58+
const filter = getTime(
59+
{
60+
id: 'test',
61+
title: 'test',
62+
timeFieldName: 'date',
63+
fields: [
64+
{
65+
name: 'date',
66+
type: 'date',
67+
esTypes: ['date'],
68+
aggregatable: true,
69+
searchable: true,
70+
filterable: true,
71+
},
72+
{
73+
name: 'myCustomDate',
74+
type: 'date',
75+
esTypes: ['date'],
76+
aggregatable: true,
77+
searchable: true,
78+
filterable: true,
79+
},
80+
],
81+
} as any,
82+
{ from: 'now-60y', to: 'now' },
83+
{ fieldName: 'myCustomDate' }
84+
);
85+
expect(filter!.range.myCustomDate).toEqual({
86+
gte: '1940-02-01T00:00:00.000Z',
87+
lte: '2000-02-01T00:00:00.000Z',
88+
format: 'strict_date_optional_time',
89+
});
90+
clock.restore();
91+
});
5492
});
5593
});

src/plugins/data/public/query/timefilter/get_time.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function createTimeRangeFilter(
5454
if (!indexPattern) {
5555
return;
5656
}
57-
const field = indexPattern.fields.find(f => f.name === fieldName || indexPattern.timeFieldName);
57+
const field = indexPattern.fields.find(f => f.name === (fieldName || indexPattern.timeFieldName));
5858
if (!field) {
5959
return;
6060
}

0 commit comments

Comments
 (0)