Update time range in proper format when either window or time are changed
Co-authored-by: Alex Paxton <thealexpaxton@gmail.com> Co-authored-by: Daniel Campbell <metalwhirlwind@gmail.com>pull/10616/head
parent
934b39fe37
commit
19b0cba263
|
@ -52,12 +52,16 @@ class LogViewerHeader extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private get optionsComponents(): JSX.Element {
|
private get optionsComponents(): JSX.Element {
|
||||||
const {
|
const {onShowOptionsOverlay, onChangeTimeWindow, onChooseTime} = this.props
|
||||||
onShowOptionsOverlay,
|
|
||||||
timeWindow,
|
// Todo: Replace w/ getDeep
|
||||||
onChangeTimeWindow,
|
const timeWindow = _.get(this.props, 'timeWindow', {
|
||||||
onChooseTime,
|
upper: null,
|
||||||
} = this.props
|
lower: 'now() - 1m',
|
||||||
|
seconds: 60,
|
||||||
|
windowOption: '1m',
|
||||||
|
timeOption: 'now',
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -394,37 +394,49 @@ class LogsPage extends Component<Props, State> {
|
||||||
this.props.executeQueriesAsync()
|
this.props.executeQueriesAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
// private handleChooseTimerange = (timeRange: TimeRange) => {
|
private handleChooseTimerange = (timeWindow: TimeWindow) => {
|
||||||
// console.log('TIME RANGE', timeRange)
|
const {seconds, windowOption, timeOption} = timeWindow
|
||||||
// this.props.setTimeRangeAsync(timeRange)
|
|
||||||
// this.fetchNewDataset()
|
|
||||||
// }
|
|
||||||
|
|
||||||
private transformTimeToRange = (timeOption: string) => {
|
|
||||||
const {seconds, windowOption} = this.props.timeWindow
|
|
||||||
let lower = `now() - ${windowOption}`
|
let lower = `now() - ${windowOption}`
|
||||||
let upper = null
|
let upper = null
|
||||||
|
|
||||||
if (timeOption !== 'now') {
|
if (timeOption !== 'now') {
|
||||||
const numberTimeOption = moment(timeOption).valueOf()
|
const numberTimeOption = moment(timeOption).valueOf()
|
||||||
const milliseconds = seconds * 10 / 2
|
const milliseconds = seconds * 10 / 2
|
||||||
|
console.log('MS', milliseconds)
|
||||||
lower = moment(numberTimeOption - milliseconds).format()
|
lower =
|
||||||
upper = moment(numberTimeOption + milliseconds).format()
|
moment
|
||||||
|
.utc(numberTimeOption - milliseconds)
|
||||||
|
.format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z'
|
||||||
|
upper =
|
||||||
|
moment
|
||||||
|
.utc(numberTimeOption + milliseconds)
|
||||||
|
.format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z'
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeWindow = {
|
const timeRange = {
|
||||||
...this.props.timeWindow,
|
|
||||||
lower,
|
lower,
|
||||||
upper,
|
upper,
|
||||||
|
seconds,
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('TIME RANGE', timeRange)
|
||||||
|
this.props.setTimeRangeAsync(timeRange)
|
||||||
|
this.fetchNewDataset()
|
||||||
|
}
|
||||||
|
|
||||||
|
private transformTimeToRange = (timeOption: string) => {
|
||||||
|
const timeWindow = {
|
||||||
|
...this.props.timeWindow,
|
||||||
timeOption,
|
timeOption,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.setTimeWindowAsync(timeWindow)
|
this.props.setTimeWindowAsync(timeWindow)
|
||||||
|
this.handleChooseTimerange(timeWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
private transformWindowToRange = (timeWindowOption: TimeWindowOption) => {
|
private transformWindowToRange = (timeWindowOption: TimeWindowOption) => {
|
||||||
const {text, seconds} = timeWindowOption
|
const {text, seconds} = timeWindowOption
|
||||||
|
|
||||||
const timeWindow = {
|
const timeWindow = {
|
||||||
...this.props.timeWindow,
|
...this.props.timeWindow,
|
||||||
seconds,
|
seconds,
|
||||||
|
@ -432,6 +444,7 @@ class LogsPage extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.setTimeWindowAsync(timeWindow)
|
this.props.setTimeWindowAsync(timeWindow)
|
||||||
|
this.handleChooseTimerange(timeWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleChooseSource = (sourceID: string) => {
|
private handleChooseSource = (sourceID: string) => {
|
||||||
|
|
|
@ -3,7 +3,14 @@ import {setTimeWindow} from 'src/logs/actions'
|
||||||
|
|
||||||
describe('Logs.Reducers', () => {
|
describe('Logs.Reducers', () => {
|
||||||
it('can set a time window', () => {
|
it('can set a time window', () => {
|
||||||
const expected = '1h'
|
const expected = {
|
||||||
|
timeOption: 'now',
|
||||||
|
windowOption: '1h',
|
||||||
|
upper: null,
|
||||||
|
lower: 'now() - 1h',
|
||||||
|
seconds: 3600,
|
||||||
|
}
|
||||||
|
|
||||||
const actual = reducer(defaultState, setTimeWindow(expected))
|
const actual = reducer(defaultState, setTimeWindow(expected))
|
||||||
expect(actual.timeWindow).toBe(expected)
|
expect(actual.timeWindow).toBe(expected)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue