forked from elastic/kibana
-
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.
[Uptime] Prefer Kibana core http services (elastic#53726) (elastic#54076
) * Prefer Kibana core http service to other fetch functions, refactor helper functions to hooks. * Reintroduce newline deleted in previous commit. * Clean up obsolete import. * Clean up effect code in new hook. * Clean up enum usage in new hook. * Implement PR feedback on new hook. * Fix eslint error. Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
1697f21
commit dbdd96a
Showing
15 changed files
with
156 additions
and
243 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
20 changes: 20 additions & 0 deletions
20
x-pack/legacy/plugins/uptime/public/hooks/use_index_pattern.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,20 @@ | ||
/* | ||
* 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 { useEffect, Dispatch } from 'react'; | ||
import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; | ||
|
||
export const useIndexPattern = <T>(setIndexPattern: Dispatch<T>) => { | ||
const core = useKibana(); | ||
useEffect(() => { | ||
const fetch = core.services.http?.fetch; | ||
async function getIndexPattern() { | ||
if (!fetch) throw new Error('Http core services are not defined'); | ||
setIndexPattern(await fetch('/api/uptime/index_pattern', { method: 'GET' })); | ||
} | ||
getIndexPattern(); | ||
}, [core.services.http, setIndexPattern]); | ||
}; |
41 changes: 41 additions & 0 deletions
41
x-pack/legacy/plugins/uptime/public/hooks/use_telemetry.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,41 @@ | ||
/* | ||
* 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 { useEffect } from 'react'; | ||
import { HttpHandler } from 'kibana/public'; | ||
import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; | ||
|
||
export enum UptimePage { | ||
Overview = '/api/uptime/logOverview', | ||
Monitor = '/api/uptime/logMonitor', | ||
NotFound = '__not-found__', | ||
} | ||
|
||
const getApiPath = (page?: UptimePage) => { | ||
if (!page) throw new Error('Telemetry logging for this page not yet implemented'); | ||
if (page === '__not-found__') | ||
throw new Error('Telemetry logging for 404 page not yet implemented'); | ||
return page.valueOf(); | ||
}; | ||
|
||
const logPageLoad = async (fetch: HttpHandler, page?: UptimePage) => { | ||
try { | ||
await fetch(getApiPath(page), { | ||
method: 'POST', | ||
}); | ||
} catch (e) { | ||
throw e; | ||
} | ||
}; | ||
|
||
export const useUptimeTelemetry = (page?: UptimePage) => { | ||
const kibana = useKibana(); | ||
const fetch = kibana.services.http?.fetch; | ||
useEffect(() => { | ||
if (!fetch) throw new Error('Core http services are not defined'); | ||
logPageLoad(fetch, page); | ||
}, [fetch, page]); | ||
}; |
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
50 changes: 0 additions & 50 deletions
50
...gacy/plugins/uptime/public/lib/adapters/index_pattern/__tests__/get_index_pattern.test.ts
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
x-pack/legacy/plugins/uptime/public/lib/adapters/index_pattern/get_index_pattern.ts
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
x-pack/legacy/plugins/uptime/public/lib/adapters/index_pattern/index.ts
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
x-pack/legacy/plugins/uptime/public/lib/adapters/telemetry/index.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
x-pack/legacy/plugins/uptime/public/lib/adapters/telemetry/log_monitor.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
x-pack/legacy/plugins/uptime/public/lib/adapters/telemetry/log_overview.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.