-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Sync logs timestamps with wider Kibana Co-authored-by: Felix Stürmer <[email protected]>
- Loading branch information
1 parent
cd01025
commit 5469edf
Showing
7 changed files
with
105 additions
and
6 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
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
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/infra/public/hooks/use_kibana_timefilter_time.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,43 @@ | ||
/* | ||
* 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 { useCallback } from 'react'; | ||
import { useUpdateEffect, useMount } from 'react-use'; | ||
import { useKibanaContextForPlugin } from './use_kibana'; | ||
import { TimeRange, TimefilterContract } from '../../../../../src/plugins/data/public'; | ||
|
||
export const useKibanaTimefilterTime = ({ | ||
from: fromDefault, | ||
to: toDefault, | ||
}: TimeRange): [typeof getTime, TimefilterContract['setTime']] => { | ||
const { services } = useKibanaContextForPlugin(); | ||
|
||
const getTime = useCallback(() => { | ||
const timefilterService = services.data.query.timefilter.timefilter; | ||
return timefilterService.isTimeTouched() | ||
? timefilterService.getTime() | ||
: { from: fromDefault, to: toDefault }; | ||
}, [services.data.query.timefilter.timefilter, fromDefault, toDefault]); | ||
|
||
return [getTime, services.data.query.timefilter.timefilter.setTime]; | ||
}; | ||
|
||
export const useSyncKibanaTimeFilterTime = (defaults: TimeRange, currentTimeRange: TimeRange) => { | ||
const [, setTime] = useKibanaTimefilterTime(defaults); | ||
|
||
// On first mount we only want to sync time with Kibana if the derived currentTimeRange (e.g. from URL params) | ||
// differs from our defaults. | ||
useMount(() => { | ||
if (defaults.from !== currentTimeRange.from || defaults.to !== currentTimeRange.to) { | ||
setTime({ from: currentTimeRange.from, to: currentTimeRange.to }); | ||
} | ||
}); | ||
|
||
// Sync explicit changes *after* mount back to Kibana | ||
useUpdateEffect(() => { | ||
setTime({ from: currentTimeRange.from, to: currentTimeRange.to }); | ||
}, [currentTimeRange.from, currentTimeRange.to, setTime]); | ||
}; |
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