-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Synthetics] Summary doc viewer in pings list (#163926)
Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Abdul Zahid <[email protected]>
- Loading branch information
1 parent
6b6dcdb
commit addb5b7
Showing
8 changed files
with
183 additions
and
31 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
93 changes: 93 additions & 0 deletions
93
.../plugins/synthetics/public/apps/synthetics/components/common/components/view_document.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,93 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiButtonIcon, EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, EuiTitle } from '@elastic/eui'; | ||
import React, { useState } from 'react'; | ||
import { useUnifiedDocViewerServices } from '@kbn/unified-doc-viewer-plugin/public'; | ||
import { buildDataTableRecord } from '@kbn/discover-utils'; | ||
import { UnifiedDocViewer } from '@kbn/unified-doc-viewer-plugin/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useFetcher } from '@kbn/observability-shared-plugin/public'; | ||
import { DataTableRecord } from '@kbn/discover-utils/src/types'; | ||
import { useDateFormat } from '../../../../../hooks/use_date_format'; | ||
import { LoadingState } from '../../monitors_page/overview/overview/monitor_detail_flyout'; | ||
import { useSyntheticsDataView } from '../../../contexts/synthetics_data_view_context'; | ||
import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants'; | ||
import { Ping } from '../../../../../../common/runtime_types'; | ||
|
||
export const ViewDocument = ({ ping }: { ping: Ping }) => { | ||
const { data } = useUnifiedDocViewerServices(); | ||
const [isFlyoutVisible, setIsFlyoutVisible] = useState<boolean>(false); | ||
|
||
const dataView = useSyntheticsDataView(); | ||
const formatter = useDateFormat(); | ||
|
||
const { data: hit } = useFetcher<Promise<DataTableRecord | undefined>>(async () => { | ||
if (!dataView?.id || !isFlyoutVisible) return; | ||
const response = await data.search | ||
.search({ | ||
params: { | ||
index: SYNTHETICS_INDEX_PATTERN, | ||
body: { | ||
query: { | ||
ids: { | ||
values: [ping.docId], | ||
}, | ||
}, | ||
fields: ['*'], | ||
_source: false, | ||
}, | ||
}, | ||
}) | ||
.toPromise(); | ||
const docs = response?.rawResponse?.hits?.hits ?? []; | ||
if (docs.length > 0) { | ||
return buildDataTableRecord(docs[0], dataView); | ||
} | ||
}, [data, dataView, ping.docId, isFlyoutVisible]); | ||
|
||
return ( | ||
<> | ||
<EuiButtonIcon | ||
iconType="inspect" | ||
title={INSPECT_DOCUMENT} | ||
onClick={() => { | ||
setIsFlyoutVisible(true); | ||
}} | ||
/> | ||
{isFlyoutVisible && ( | ||
<EuiFlyout onClose={() => setIsFlyoutVisible(false)} ownFocus={true}> | ||
<EuiFlyoutHeader> | ||
<EuiTitle size="m"> | ||
<h4> | ||
{INDEXED_AT} {formatter(ping.timestamp)} | ||
</h4> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody> | ||
{dataView?.id && hit ? ( | ||
<UnifiedDocViewer hit={hit} dataView={dataView} /> | ||
) : ( | ||
<LoadingState /> | ||
)} | ||
</EuiFlyoutBody> | ||
</EuiFlyout> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const INDEXED_AT = i18n.translate('xpack.synthetics.monitorDetails.summary.indexedAt', { | ||
defaultMessage: 'Indexed at', | ||
}); | ||
|
||
export const INSPECT_DOCUMENT = i18n.translate( | ||
'xpack.synthetics.monitorDetails.action.inspectDocument', | ||
{ | ||
defaultMessage: 'Inspect document', | ||
} | ||
); |
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
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/synthetics/public/apps/synthetics/contexts/synthetics_data_view_context.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,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { createContext, useContext } from 'react'; | ||
import { useFetcher } from '@kbn/observability-shared-plugin/public'; | ||
import { DataViewsPublicPluginStart, DataView } from '@kbn/data-views-plugin/public'; | ||
import { SYNTHETICS_INDEX_PATTERN } from '../../../../common/constants'; | ||
|
||
export const SyntheticsDataViewContext = createContext({} as DataView); | ||
|
||
export const SyntheticsDataViewContextProvider: React.FC<{ | ||
dataViews: DataViewsPublicPluginStart; | ||
}> = ({ children, dataViews }) => { | ||
const { data } = useFetcher<Promise<DataView | undefined>>(async () => { | ||
return dataViews.create({ title: SYNTHETICS_INDEX_PATTERN }); | ||
}, []); | ||
|
||
return <SyntheticsDataViewContext.Provider value={data!} children={children} />; | ||
}; | ||
|
||
export const useSyntheticsDataView = () => useContext(SyntheticsDataViewContext); |
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