Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Close expanded document sidebar when switch data views #119736

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function DiscoverDocumentsComponent({
onAddFilter: DocViewFilterFn;
savedSearch: SavedSearch;
services: DiscoverServices;
setExpandedDoc: (doc: ElasticSearchHit | undefined) => void;
setExpandedDoc: (doc?: ElasticSearchHit) => void;
state: AppState;
stateContainer: GetStateReturn;
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function getProps(indexPattern: IndexPattern, wasSidebarClosed?: boolean): Disco
services,
state: { columns: [] },
stateContainer: {} as GetStateReturn,
setExpandedDoc: jest.fn(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { DiscoverLayoutProps } from './types';
import { SEARCH_FIELDS_FROM_SOURCE, SHOW_FIELD_STATISTICS } from '../../../../../common';
import { popularizeField } from '../../../../utils/popularize_field';
import { DiscoverTopNav } from '../top_nav/discover_topnav';
import { DocViewFilterFn, ElasticSearchHit } from '../../../../services/doc_views/doc_views_types';
import { DocViewFilterFn } from '../../../../services/doc_views/doc_views_types';
import { DiscoverChart } from '../chart';
import { getResultState } from '../../utils/get_result_state';
import { InspectorSession } from '../../../../../../inspector/public';
Expand Down Expand Up @@ -62,9 +62,11 @@ export function DiscoverLayout({
indexPattern,
indexPatternList,
inspectorAdapters,
expandedDoc,
navigateTo,
onChangeIndexPattern,
onUpdateQuery,
setExpandedDoc,
savedSearchRefetch$,
resetSavedSearch,
savedSearchData$,
Expand All @@ -86,7 +88,6 @@ export function DiscoverLayout({
spaces,
} = services;
const { main$, charts$, totalHits$ } = savedSearchData$;
const [expandedDoc, setExpandedDoc] = useState<ElasticSearchHit | undefined>(undefined);
const [inspectorSession, setInspectorSession] = useState<InspectorSession | undefined>(undefined);

const viewMode = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticSearchHit } from 'src/plugins/discover/public/services/doc_views/doc_views_types';
kertal marked this conversation as resolved.
Show resolved Hide resolved
import {
IndexPattern,
IndexPatternAttributes,
Expand All @@ -28,6 +29,8 @@ export interface DiscoverLayoutProps {
onChangeIndexPattern: (id: string) => void;
onUpdateQuery: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void;
resetSavedSearch: () => void;
expandedDoc?: ElasticSearchHit;
setExpandedDoc: (doc?: ElasticSearchHit) => void;
savedSearch: SavedSearch;
savedSearchData$: SavedSearchData;
savedSearchRefetch$: DataRefetch$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useCallback, useEffect } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { History } from 'history';
import { DiscoverLayout } from './components/layout';
import { setBreadcrumbsTitle } from '../../utils/breadcrumbs';
Expand All @@ -15,6 +15,7 @@ import { useUrl } from './utils/use_url';
import { IndexPatternAttributes, SavedObject } from '../../../../data/common';
import { DiscoverServices } from '../../build_services';
import { SavedSearch } from '../../services/saved_searches';
import { ElasticSearchHit } from '../../services/doc_views/doc_views_types';

const DiscoverLayoutMemoized = React.memo(DiscoverLayout);

Expand All @@ -40,6 +41,7 @@ export interface DiscoverMainProps {
export function DiscoverMainApp(props: DiscoverMainProps) {
const { savedSearch, services, history, indexPatternList } = props;
const { chrome, docLinks, uiSettings: config, data } = services;
const [expandedDoc, setExpandedDoc] = useState<ElasticSearchHit | undefined>(undefined);
const navigateTo = useCallback(
(path: string) => {
history.push(path);
Expand All @@ -65,6 +67,7 @@ export function DiscoverMainApp(props: DiscoverMainProps) {
services,
history,
savedSearch,
setExpandedDoc,
});

/**
Expand Down Expand Up @@ -100,9 +103,11 @@ export function DiscoverMainApp(props: DiscoverMainProps) {
indexPattern={indexPattern}
indexPatternList={indexPatternList}
inspectorAdapters={inspectorAdapters}
expandedDoc={expandedDoc}
onChangeIndexPattern={onChangeIndexPattern}
onUpdateQuery={onUpdateQuery}
resetSavedSearch={resetCurrentSavedSearch}
setExpandedDoc={setExpandedDoc}
navigateTo={navigateTo}
savedSearch={savedSearch}
savedSearchData$={data$}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('test useDiscoverState', () => {
services: discoverServiceMock,
history,
savedSearch: savedSearchMock,
setExpandedDoc: jest.fn(),
});
});
expect(result.current.state.index).toBe(indexPatternMock.id);
Expand All @@ -53,6 +54,7 @@ describe('test useDiscoverState', () => {
services: discoverServiceMock,
history,
savedSearch: savedSearchMock,
setExpandedDoc: jest.fn(),
});
});
await act(async () => {
Expand All @@ -69,6 +71,7 @@ describe('test useDiscoverState', () => {
services: discoverServiceMock,
history,
savedSearch: savedSearchMock,
setExpandedDoc: jest.fn(),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import { useSearchSession } from './use_search_session';
import { FetchStatus } from '../../types';
import { getSwitchIndexPatternAppState } from './get_switch_index_pattern_app_state';
import { SortPairArr } from '../../../components/doc_table/lib/get_sort';
import { ElasticSearchHit } from '../../../services/doc_views/doc_views_types';

export function useDiscoverState({
services,
history,
savedSearch,
setExpandedDoc,
}: {
services: DiscoverServices;
savedSearch: SavedSearch;
history: History;
setExpandedDoc: (doc?: ElasticSearchHit) => void;
}) {
const { uiSettings: config, data, filterManager, indexPatterns, storage } = services;
const useNewFieldsApi = useMemo(() => !config.get(SEARCH_FIELDS_FROM_SOURCE), [config]);
Expand Down Expand Up @@ -186,8 +189,9 @@ export function useDiscoverState({
);
stateContainer.setAppState(nextAppState);
}
setExpandedDoc(undefined);
},
[config, indexPattern, indexPatterns, state.columns, state.sort, stateContainer]
[config, indexPattern, indexPatterns, setExpandedDoc, state.columns, state.sort, stateContainer]
);
/**
* Function triggered when the user changes the query in the search bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('test useSavedSearch', () => {
services: discoverServiceMock,
history,
savedSearch: savedSearchMock,
setExpandedDoc: jest.fn(),
});
});

Expand Down Expand Up @@ -100,6 +101,7 @@ describe('test useSavedSearch', () => {
services: discoverServiceMock,
history,
savedSearch: savedSearchMock,
setExpandedDoc: jest.fn(),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export interface DiscoverGridProps {
/**
* Function to set the expanded document, which is displayed in a flyout
*/
setExpandedDoc: (doc: ElasticSearchHit | undefined) => void;
setExpandedDoc: (doc?: ElasticSearchHit) => void;
/**
* Grid display settings persisted in Elasticsearch (e.g. column width)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { IndexPattern } from 'src/plugins/data/common';
import { DocViewFilterFn, ElasticSearchHit } from '../../services/doc_views/doc_views_types';

export interface GridContext {
expanded: ElasticSearchHit | undefined;
setExpanded: (hit: ElasticSearchHit | undefined) => void;
expanded?: ElasticSearchHit;
setExpanded: (hit?: ElasticSearchHit) => void;
rows: ElasticSearchHit[];
onFilter: DocViewFilterFn;
indexPattern: IndexPattern;
Expand Down