forked from opensearch-project/dashboards-observability
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(timechart) use date range based on buckets for query assist
- Loading branch information
1 parent
407f059
commit 55a4cb1
Showing
17 changed files
with
331 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...onents/event_analytics/explorer/timechart/__tests__/__snapshots__/timechart.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Timechart /> spec should match snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--alignItemsCenter euiFlexGroup--justifyContentCenter euiFlexGroup--directionRow dscResultCount" | ||
> | ||
<div | ||
class="euiFlexItem euiFlexItem--flexGrowZero" | ||
> | ||
<div | ||
class="euiText euiText--medium" | ||
> | ||
<strong | ||
data-test-subj="discoverQueryHits" | ||
> | ||
194 | ||
</strong> | ||
hits | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--alignItemsCenter euiFlexGroup--justifyContentCenter euiFlexGroup--directionRow euiFlexGroup--responsive" | ||
> | ||
<div | ||
class="euiFlexItem euiFlexItem--flexGrowZero" | ||
> | ||
<span | ||
class="euiToolTipAnchor" | ||
> | ||
<div | ||
class="euiText euiText--small" | ||
data-test-subj="discoverIntervalDateRange" | ||
> | ||
Jan 1, 2024 @ 00:00:00.000 - Jan 1, 2024 @ 00:00:00.000 | ||
</div> | ||
</span> | ||
</div> | ||
<div | ||
class="euiFlexItem euiFlexItem--flexGrowZero" | ||
> | ||
<div | ||
class="euiFormControlLayout euiFormControlLayout--compressed" | ||
> | ||
<div | ||
class="euiFormControlLayout__childrenWrapper" | ||
> | ||
<select | ||
aria-label="Time interval" | ||
class="euiSelect euiSelect--compressed" | ||
data-test-subj="eventAnalytics__EventIntervalSelect" | ||
id="dscResultsIntervalSelector" | ||
> | ||
<option | ||
value="m" | ||
> | ||
Minute | ||
</option> | ||
<option | ||
value="h" | ||
> | ||
Hour | ||
</option> | ||
<option | ||
value="d" | ||
> | ||
Day | ||
</option> | ||
<option | ||
value="w" | ||
> | ||
Week | ||
</option> | ||
<option | ||
value="M" | ||
> | ||
Month | ||
</option> | ||
<option | ||
value="y" | ||
> | ||
Year | ||
</option> | ||
</select> | ||
<div | ||
class="euiFormControlLayoutIcons euiFormControlLayoutIcons--right" | ||
> | ||
<span | ||
class="euiFormControlLayoutCustomIcon" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="euiIcon euiIcon--small euiFormControlLayoutCustomIcon__icon" | ||
focusable="false" | ||
height="16" | ||
role="img" | ||
viewBox="0 0 16 16" | ||
width="16" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M13.069 5.157 8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0Z" | ||
fill-rule="non-zero" | ||
/> | ||
</svg> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="euiSpacer euiSpacer--s" | ||
/> | ||
<div | ||
id="explorerPlotComponent" | ||
style="width: 100%; height: 100%;" | ||
/> | ||
</div> | ||
`; |
61 changes: 61 additions & 0 deletions
61
public/components/event_analytics/explorer/timechart/__tests__/timechart.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { fireEvent, render } from '@testing-library/react'; | ||
import React, { ComponentProps } from 'react'; | ||
import { Timechart } from '../timechart'; | ||
|
||
const renderTimechart = (overrideProps: Partial<ComponentProps<typeof Timechart>> = {}) => { | ||
const props: jest.Mocked<ComponentProps<typeof Timechart>> = Object.assign< | ||
ComponentProps<typeof Timechart>, | ||
Partial<ComponentProps<typeof Timechart>> | ||
>( | ||
{ | ||
countDistribution: { | ||
selectedInterval: 'y', | ||
data: { 'count()': [194], 'span(timestamp,1y)': ['2024-01-01 00:00:00'] }, | ||
metadata: { | ||
fields: [ | ||
{ name: 'count()', type: 'integer' }, | ||
{ name: 'span(timestamp,1y)', type: 'timestamp' }, | ||
], | ||
}, | ||
size: 1, | ||
status: 200, | ||
jsonData: [{ 'count()': 194, 'span(timestamp,1y)': '2024-01-01 00:00:00' }], | ||
}, | ||
timeIntervalOptions: [ | ||
{ text: 'Minute', value: 'm' }, | ||
{ text: 'Hour', value: 'h' }, | ||
{ text: 'Day', value: 'd' }, | ||
{ text: 'Week', value: 'w' }, | ||
{ text: 'Month', value: 'M' }, | ||
{ text: 'Year', value: 'y' }, | ||
], | ||
onChangeInterval: jest.fn(), | ||
selectedInterval: 'y', | ||
startTime: '2024-01-01 00:00:00', | ||
endTime: '2024-01-01 00:00:00', | ||
}, | ||
overrideProps | ||
); | ||
const component = render(<Timechart {...props} />); | ||
return { component, props }; | ||
}; | ||
|
||
describe('<Timechart /> spec', () => { | ||
it('should change to week', () => { | ||
const { component, props } = renderTimechart(); | ||
fireEvent.change(component.getByTestId('eventAnalytics__EventIntervalSelect'), { | ||
target: { value: 'w' }, | ||
}); | ||
expect(props.onChangeInterval).toBeCalledWith('w'); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
const { component } = renderTimechart(); | ||
expect(component.container).toMatchSnapshot(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
public/components/event_analytics/explorer/timechart/__tests__/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { getTimeRangeFromCountDistribution } from '../utils'; | ||
|
||
describe('getTimeRangeFromCountDistribution', () => { | ||
it('gets from first and last element of span', () => { | ||
const results = getTimeRangeFromCountDistribution({ | ||
data: { | ||
'count()': [194], | ||
'span(timestamp,1d)': ['2024-01-01 00:00:00', '2024-01-02 00:00:00', '2024-01-03 00:00:00'], | ||
}, | ||
metadata: { | ||
fields: [ | ||
{ name: 'count()', type: 'integer' }, | ||
{ name: 'span(timestamp,1d)', type: 'timestamp' }, | ||
], | ||
}, | ||
}); | ||
|
||
expect(results).toMatchInlineSnapshot(` | ||
Object { | ||
"endTime": "2024-01-03 00:00:00", | ||
"startTime": "2024-01-01 00:00:00", | ||
} | ||
`); | ||
}); | ||
|
||
it('handles empty inputs and returns undefined', () => { | ||
const results = getTimeRangeFromCountDistribution({ | ||
data: { | ||
'count()': [194], | ||
'span(timestamp,1d)': [], | ||
}, | ||
metadata: { | ||
fields: [ | ||
{ name: 'count()', type: 'integer' }, | ||
{ name: 'span(timestamp,1d)', type: 'timestamp' }, | ||
], | ||
}, | ||
}); | ||
|
||
expect(results).toMatchInlineSnapshot(` | ||
Object { | ||
"endTime": undefined, | ||
"startTime": undefined, | ||
} | ||
`); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
public/components/event_analytics/explorer/timechart/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { HitsCounter } from './hits_counter/hits_counter'; | ||
export { Timechart } from './timechart'; | ||
export { getTimeRangeFromCountDistribution } from './utils'; |
Oops, something went wrong.