Skip to content

Commit

Permalink
Dedup DocProps and remove referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Aug 29, 2023
1 parent 48341b4 commit 47b67f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
25 changes: 2 additions & 23 deletions src/plugins/discover/public/application/doc/components/doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,18 @@
import React, { useEffect } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiCallOut, EuiLink, EuiLoadingSpinner, EuiPage, EuiPageBody } from '@elastic/eui';
import type { DataView } from '@kbn/data-views-plugin/public';
import { i18n } from '@kbn/i18n';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import { ElasticRequestState } from '@kbn/unified-doc-viewer';
import { UnifiedDocViewer, useEsDocSearch } from '@kbn/unified-doc-viewer-plugin/public';
import type { EsDocSearchProps } from '@kbn/unified-doc-viewer-plugin/public/types';
import { setBreadcrumbs } from '../../../utils/breadcrumbs';
import { useDiscoverServices } from '../../../hooks/use_discover_services';

export interface DocProps {
/**
* Id of the doc in ES
*/
id: string;
/**
* Index in ES to query
*/
index: string;
/**
* DataView entity
*/
dataView: DataView;
/**
* If set, will always request source, regardless of the global `fieldsFromSource` setting
*/
requestSource?: boolean;
export interface DocProps extends EsDocSearchProps {
/**
* Discover main view url
*/
referrer?: string;
/**
* Records fetched from text based query
*/
textBasedHits?: DataTableRecord[];
}

export function Doc(props: DocProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { renderHook, act } from '@testing-library/react-hooks';
import { type DocProps, buildSearchBody, useEsDocSearch } from './use_es_doc_search';
import { type EsDocSearchProps, buildSearchBody, useEsDocSearch } from './use_es_doc_search';
import { Subject } from 'rxjs';
import type { DataView } from '@kbn/data-views-plugin/public';
import { ElasticRequestState } from '@kbn/unified-doc-viewer';
Expand Down Expand Up @@ -226,9 +226,9 @@ describe('Test of <Doc /> helper / hook', () => {
id: '1',
index: 'index1',
dataView,
} as unknown as DocProps;
} as unknown as EsDocSearchProps;

const hook = renderHook((p: DocProps) => useEsDocSearch(p), {
const hook = renderHook((p: EsDocSearchProps) => useEsDocSearch(p), {
initialProps: props,
wrapper: ({ children }) => (
<KibanaContextProvider services={services}>{children}</KibanaContextProvider>
Expand All @@ -250,9 +250,9 @@ describe('Test of <Doc /> helper / hook', () => {
id: '1',
index: 'index1',
dataView,
} as unknown as DocProps;
} as unknown as EsDocSearchProps;

const hook = renderHook((p: DocProps) => useEsDocSearch(p), {
const hook = renderHook((p: EsDocSearchProps) => useEsDocSearch(p), {
initialProps: props,
wrapper: ({ children }) => (
<KibanaContextProvider services={services}>{children}</KibanaContextProvider>
Expand Down Expand Up @@ -304,9 +304,9 @@ describe('Test of <Doc /> helper / hook', () => {
flattened: { field1: 1, field2: 2 },
},
],
} as unknown as DocProps;
} as unknown as EsDocSearchProps;

const hook = renderHook((p: DocProps) => useEsDocSearch(p), {
const hook = renderHook((p: EsDocSearchProps) => useEsDocSearch(p), {
initialProps: props,
wrapper: ({ children }) => (
<KibanaContextProvider services={services}>{children}</KibanaContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useUnifiedDocViewerServices } from './use_doc_viewer_services';

type RequestBody = Pick<estypes.SearchRequest, 'body'>;

export interface DocProps {
export interface EsDocSearchProps {
/**
* Id of the doc in ES
*/
Expand All @@ -35,10 +35,6 @@ export interface DocProps {
* If set, will always request source, regardless of the global `fieldsFromSource` setting
*/
requestSource?: boolean;
/**
* Discover main view url
*/
referrer?: string;
/**
* Records fetched from text based query
*/
Expand All @@ -54,7 +50,7 @@ export function useEsDocSearch({
dataView,
requestSource,
textBasedHits,
}: DocProps): [ElasticRequestState, DataTableRecord | null, () => void] {
}: EsDocSearchProps): [ElasticRequestState, DataTableRecord | null, () => void] {
const [status, setStatus] = useState(ElasticRequestState.Loading);
const [hit, setHit] = useState<DataTableRecord | null>(null);
const { data, uiSettings, analytics } = useUnifiedDocViewerServices();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/unified_doc_viewer/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*/

export type { JsonCodeEditorProps } from './components';
export type { UnifiedDocViewerServices } from './hooks';
export type { EsDocSearchProps, UnifiedDocViewerServices } from './hooks';
export type { UnifiedDocViewerSetup, UnifiedDocViewerStart } from './plugin';

0 comments on commit 47b67f7

Please sign in to comment.