mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Discover] DiscoverContainer
cleanup (#163015)
## Summary Just some small cleanups related to the `DiscoverContainer` implementation as a followup to #160036.
This commit is contained in:
parent
73d53dc6d6
commit
a2916714d5
5 changed files with 40 additions and 35 deletions
|
@ -18,8 +18,8 @@ import { getDiscoverStateMock } from '../../../../__mocks__/discover_state.mock'
|
|||
import { DiscoverMainProvider } from '../../services/discover_state_provider';
|
||||
import type { SearchBarCustomization, TopNavCustomization } from '../../../../customizations';
|
||||
import type { DiscoverCustomizationId } from '../../../../customizations/customization_service';
|
||||
|
||||
import { useDiscoverCustomization } from '../../../../customizations';
|
||||
|
||||
setHeaderActionMenuMounter(jest.fn());
|
||||
|
||||
jest.mock('@kbn/kibana-react-plugin/public', () => ({
|
||||
|
@ -76,22 +76,20 @@ describe('Discover topnav component', () => {
|
|||
mockUseCustomizations = false;
|
||||
jest.clearAllMocks();
|
||||
|
||||
(useDiscoverCustomization as jest.Mock).mockImplementation(
|
||||
jest.fn((id: DiscoverCustomizationId) => {
|
||||
if (!mockUseCustomizations) {
|
||||
return undefined;
|
||||
}
|
||||
(useDiscoverCustomization as jest.Mock).mockImplementation((id: DiscoverCustomizationId) => {
|
||||
if (!mockUseCustomizations) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case 'top_nav':
|
||||
return mockTopNavCustomization;
|
||||
case 'search_bar':
|
||||
return mockSearchBarCustomization;
|
||||
default:
|
||||
throw new Error(`Unknown customization id: ${id}`);
|
||||
}
|
||||
})
|
||||
);
|
||||
switch (id) {
|
||||
case 'top_nav':
|
||||
return mockTopNavCustomization;
|
||||
case 'search_bar':
|
||||
return mockSearchBarCustomization;
|
||||
default:
|
||||
throw new Error(`Unknown customization id: ${id}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('generated config of TopNavMenu config is correct when discover save permissions are assigned', () => {
|
||||
|
|
|
@ -8,9 +8,12 @@
|
|||
|
||||
import React from 'react';
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
import { DiscoverServices } from '../../build_services';
|
||||
import DiscoverContainerInternal, { DiscoverContainerInternalProps } from './discover_container';
|
||||
import { ScopedHistory } from '@kbn/core-application-browser';
|
||||
import type { DiscoverServices } from '../../build_services';
|
||||
import {
|
||||
DiscoverContainerInternal,
|
||||
type DiscoverContainerInternalProps,
|
||||
} from './discover_container';
|
||||
import type { ScopedHistory } from '@kbn/core-application-browser';
|
||||
import { discoverServiceMock } from '../../__mocks__/services';
|
||||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
|
||||
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
|
||||
|
@ -45,7 +48,7 @@ const TestComponent = (props: Partial<DiscoverContainerInternalProps>) => {
|
|||
};
|
||||
|
||||
const TEST_IDS = {
|
||||
DISCOVER_CONTAINER_INTERNAL: 'data-container-internal-wrapper',
|
||||
DISCOVER_CONTAINER_INTERNAL: 'discover-container-internal-wrapper',
|
||||
};
|
||||
|
||||
describe('DiscoverContainerInternal should render properly', () => {
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
|
||||
import type { ScopedHistory } from '@kbn/core/public';
|
||||
import { euiStyled } from '@kbn/kibana-react-plugin/common';
|
||||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { css } from '@emotion/react';
|
||||
import { DiscoverMainRoute } from '../../application/main';
|
||||
import type { DiscoverServices } from '../../build_services';
|
||||
import type { CustomizationCallback } from '../../customizations';
|
||||
|
@ -31,15 +31,15 @@ export interface DiscoverContainerInternalProps {
|
|||
isDev: boolean;
|
||||
}
|
||||
|
||||
const DiscoverContainerWrapper = euiStyled(EuiFlexGroup)`
|
||||
const discoverContainerWrapperCss = css`
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
// override the embedded discover page height
|
||||
// to fit in the container
|
||||
.dscPage {
|
||||
height: 100%
|
||||
}
|
||||
height: 100%;
|
||||
}
|
||||
`;
|
||||
|
||||
export const DiscoverContainerInternal = ({
|
||||
|
@ -70,14 +70,17 @@ export const DiscoverContainerInternal = ({
|
|||
|
||||
if (!initialized || !services) {
|
||||
return (
|
||||
<DiscoverContainerWrapper>
|
||||
<EuiFlexGroup css={discoverContainerWrapperCss}>
|
||||
<LoadingIndicator type="spinner" />
|
||||
</DiscoverContainerWrapper>
|
||||
</EuiFlexGroup>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DiscoverContainerWrapper data-test-subj="data-container-internal-wrapper">
|
||||
<EuiFlexGroup
|
||||
css={discoverContainerWrapperCss}
|
||||
data-test-subj="discover-container-internal-wrapper"
|
||||
>
|
||||
<EuiFlexItem>
|
||||
<KibanaContextProvider services={services}>
|
||||
<DiscoverMainRoute
|
||||
|
@ -87,7 +90,7 @@ export const DiscoverContainerInternal = ({
|
|||
/>
|
||||
</KibanaContextProvider>
|
||||
</EuiFlexItem>
|
||||
</DiscoverContainerWrapper>
|
||||
</EuiFlexGroup>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
|
||||
import type { AggregateQuery } from '@kbn/es-query';
|
||||
import type { TopNavMenuProps } from '@kbn/navigation-plugin/public';
|
||||
import type { ComponentType, ReactElement } from 'react';
|
||||
import type { ComponentType } from 'react';
|
||||
|
||||
export interface SearchBarCustomization {
|
||||
id: 'search_bar';
|
||||
CustomDataViewPicker?: ComponentType;
|
||||
PrependFilterBar?: ComponentType;
|
||||
CustomSearchBar?: (props: TopNavMenuProps<AggregateQuery>) => ReactElement;
|
||||
CustomSearchBar?: ComponentType<TopNavMenuProps<AggregateQuery>>;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,10 @@ import {
|
|||
createProfileRegistry,
|
||||
} from './customizations/profile_registry';
|
||||
import { SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER } from './embeddable/constants';
|
||||
import { DiscoverContainerInternal, DiscoverContainerProps } from './components/discover_container';
|
||||
import {
|
||||
DiscoverContainerInternal,
|
||||
type DiscoverContainerProps,
|
||||
} from './components/discover_container';
|
||||
|
||||
const DocViewerLegacyTable = React.lazy(
|
||||
() => import('./services/doc_views/components/doc_viewer_table/legacy')
|
||||
|
@ -430,20 +433,18 @@ export class DiscoverPlugin
|
|||
injectTruncateStyles(core.uiSettings.get(TRUNCATE_MAX_HEIGHT));
|
||||
|
||||
const isDev = this.initializerContext.env.mode.dev;
|
||||
|
||||
const getDiscoverServicesInternal = () => {
|
||||
return this.getDiscoverServices(core, plugins);
|
||||
};
|
||||
|
||||
return {
|
||||
locator: this.locator,
|
||||
DiscoverContainer: ({ overrideServices, ...restProps }: DiscoverContainerProps) => {
|
||||
DiscoverContainer: (props: DiscoverContainerProps) => {
|
||||
return (
|
||||
<DiscoverContainerInternal
|
||||
overrideServices={overrideServices}
|
||||
getDiscoverServices={getDiscoverServicesInternal}
|
||||
isDev={isDev}
|
||||
{...restProps}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue