Skip to content

Commit

Permalink
Merge branch '7.x' into ua/7.x/step-completion-state
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Sep 8, 2021
2 parents 6e3bbea + e1ae485 commit b5b082b
Show file tree
Hide file tree
Showing 227 changed files with 2,260 additions and 1,688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ describe('migration v2', () => {
await root.setup();
await expect(root.start()).resolves.toBeTruthy();

// After plugins start, some saved objects are deleted/recreated, so we
// wait a bit for the count to settle.
await new Promise((resolve) => setTimeout(resolve, 5000));

const esClient: ElasticsearchClient = esServer.es.getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import { retryAsync } from './retry_async';

// FLAKY: https://github.com/elastic/kibana/issues/110970
describe.skip('retry', () => {
describe('retry', () => {
it('retries throwing functions until they succeed', async () => {
let i = 0;
await expect(
Expand Down Expand Up @@ -53,6 +52,8 @@ describe.skip('retry', () => {
},
{ retryAttempts: 3, retryDelayMs: 100 }
);
expect(Date.now() - now).toBeGreaterThanOrEqual(200);
// Would expect it to take 200ms but seems like timing inaccuracies
// sometimes causes the duration to be measured as 199ms
expect(Date.now() - now).toBeGreaterThanOrEqual(199);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getProps(timefield?: string) {
}) as DataCharts$;

return {
resetQuery: jest.fn(),
resetSavedSearch: jest.fn(),
savedSearch: savedSearchMock,
savedSearchDataChart$: charts$,
savedSearchDataTotalHits$: totalHits$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DiscoverServices } from '../../../../../build_services';
const TimechartHeaderMemoized = memo(TimechartHeader);
const DiscoverHistogramMemoized = memo(DiscoverHistogram);
export function DiscoverChart({
resetQuery,
resetSavedSearch,
savedSearch,
savedSearchDataChart$,
savedSearchDataTotalHits$,
Expand All @@ -30,7 +30,7 @@ export function DiscoverChart({
stateContainer,
timefield,
}: {
resetQuery: () => void;
resetSavedSearch: () => void;
savedSearch: SavedSearch;
savedSearchDataChart$: DataCharts$;
savedSearchDataTotalHits$: DataTotalHits$;
Expand Down Expand Up @@ -88,7 +88,7 @@ export function DiscoverChart({
<HitsCounter
savedSearchData$={savedSearchDataTotalHits$}
showResetButton={!!(savedSearch && savedSearch.id)}
onResetQuery={resetQuery}
onResetQuery={resetSavedSearch}
/>
</EuiFlexItem>
{!state.hideChart && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function getProps(indexPattern: IndexPattern): DiscoverLayoutProps {
navigateTo: jest.fn(),
onChangeIndexPattern: jest.fn(),
onUpdateQuery: jest.fn(),
resetQuery: jest.fn(),
resetSavedSearch: jest.fn(),
savedSearch: savedSearchMock,
savedSearchData$,
savedSearchRefetch$: new Subject(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function DiscoverLayout({
onChangeIndexPattern,
onUpdateQuery,
savedSearchRefetch$,
resetQuery,
resetSavedSearch,
savedSearchData$,
savedSearch,
searchSource,
Expand Down Expand Up @@ -165,6 +165,7 @@ export function DiscoverLayout({
services={services}
stateContainer={stateContainer}
updateQuery={onUpdateQuery}
resetSavedSearch={resetSavedSearch}
/>
<EuiPageBody className="dscPageBody" aria-describedby="savedSearchTitle">
<h1 id="savedSearchTitle" className="euiScreenReaderOnly">
Expand Down Expand Up @@ -246,7 +247,7 @@ export function DiscoverLayout({
<EuiFlexItem grow={false}>
<DiscoverChartMemoized
state={state}
resetQuery={resetQuery}
resetSavedSearch={resetSavedSearch}
savedSearch={savedSearch}
savedSearchDataChart$={charts$}
savedSearchDataTotalHits$={totalHits$}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface DiscoverLayoutProps {
navigateTo: (url: string) => void;
onChangeIndexPattern: (id: string) => void;
onUpdateQuery: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void;
resetQuery: () => void;
resetSavedSearch: () => void;
savedSearch: SavedSearch;
savedSearchData$: SavedSearchData;
savedSearchRefetch$: DataRefetch$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function getProps(savePermissions = true): DiscoverTopNavProps {
updateQuery: jest.fn(),
onOpenInspector: jest.fn(),
searchSource: {} as ISearchSource,
resetSavedSearch: () => {},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import { DiscoverLayoutProps } from '../layout/types';
import { getTopNavLinks } from './get_top_nav_links';
import { Query, TimeRange } from '../../../../../../../data/common/query';
Expand All @@ -21,6 +22,7 @@ export type DiscoverTopNavProps = Pick<
savedQuery?: string;
updateQuery: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void;
stateContainer: GetStateReturn;
resetSavedSearch: () => void;
};

export const DiscoverTopNav = ({
Expand All @@ -34,9 +36,23 @@ export const DiscoverTopNav = ({
navigateTo,
savedSearch,
services,
resetSavedSearch,
}: DiscoverTopNavProps) => {
const history = useHistory();
const showDatePicker = useMemo(() => indexPattern.isTimeBased(), [indexPattern]);
const { TopNavMenu } = services.navigation.ui;

const onOpenSavedSearch = useCallback(
(newSavedSearchId: string) => {
if (savedSearch.id && savedSearch.id === newSavedSearchId) {
resetSavedSearch();
} else {
history.push(`/view/${encodeURIComponent(newSavedSearchId)}`);
}
},
[history, resetSavedSearch, savedSearch.id]
);

const topNavMenu = useMemo(
() =>
getTopNavLinks({
Expand All @@ -47,8 +63,18 @@ export const DiscoverTopNav = ({
state: stateContainer,
onOpenInspector,
searchSource,
onOpenSavedSearch,
}),
[indexPattern, navigateTo, onOpenInspector, searchSource, stateContainer, savedSearch, services]
[
indexPattern,
navigateTo,
savedSearch,
services,
stateContainer,
onOpenInspector,
searchSource,
onOpenSavedSearch,
]
);

const updateSavedQueryId = (newSavedQueryId: string | undefined) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test('getTopNavLinks result', () => {
services,
state,
searchSource: {} as ISearchSource,
onOpenSavedSearch: () => {},
});
expect(topNavLinks).toMatchInlineSnapshot(`
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const getTopNavLinks = ({
state,
onOpenInspector,
searchSource,
onOpenSavedSearch,
}: {
indexPattern: IndexPattern;
navigateTo: (url: string) => void;
Expand All @@ -37,6 +38,7 @@ export const getTopNavLinks = ({
state: GetStateReturn;
onOpenInspector: () => void;
searchSource: ISearchSource;
onOpenSavedSearch: (id: string) => void;
}) => {
const options = {
id: 'options',
Expand Down Expand Up @@ -89,7 +91,7 @@ export const getTopNavLinks = ({
testId: 'discoverOpenButton',
run: () =>
showOpenSearchPanel({
makeUrl: (searchId) => `#/view/${encodeURIComponent(searchId)}`,
onOpenSavedSearch,
I18nContext: services.core.i18n.Context,
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import { OpenSearchPanel } from './open_search_panel';

describe('OpenSearchPanel', () => {
test('render', () => {
const component = shallow(<OpenSearchPanel onClose={jest.fn()} makeUrl={jest.fn()} />);
const component = shallow(
<OpenSearchPanel onClose={jest.fn()} onOpenSavedSearch={jest.fn()} />
);
expect(component).toMatchSnapshot();
});

Expand All @@ -40,7 +42,9 @@ describe('OpenSearchPanel', () => {
delete: false,
},
});
const component = shallow(<OpenSearchPanel onClose={jest.fn()} makeUrl={jest.fn()} />);
const component = shallow(
<OpenSearchPanel onClose={jest.fn()} onOpenSavedSearch={jest.fn()} />
);
expect(component.find('[data-test-subj="manageSearches"]').exists()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SEARCH_OBJECT_TYPE = 'search';

interface OpenSearchPanelProps {
onClose: () => void;
makeUrl: (id: string) => string;
onOpenSavedSearch: (id: string) => void;
}

export function OpenSearchPanel(props: OpenSearchPanelProps) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export function OpenSearchPanel(props: OpenSearchPanelProps) {
},
]}
onChoose={(id) => {
window.location.assign(props.makeUrl(id));
props.onOpenSavedSearch(id);
props.onClose();
}}
uiSettings={uiSettings}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { OpenSearchPanel } from './open_search_panel';
let isOpen = false;

export function showOpenSearchPanel({
makeUrl,
I18nContext,
onOpenSavedSearch,
}: {
makeUrl: (path: string) => string;
I18nContext: I18nStart['Context'];
onOpenSavedSearch: (id: string) => void;
}) {
if (isOpen) {
return;
Expand All @@ -35,7 +35,7 @@ export function showOpenSearchPanel({
document.body.appendChild(container);
const element = (
<I18nContext>
<OpenSearchPanel onClose={onClose} makeUrl={makeUrl} />
<OpenSearchPanel onClose={onClose} onOpenSavedSearch={onOpenSavedSearch} />
</I18nContext>
);
ReactDOM.render(element, container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function DiscoverMainApp(props: DiscoverMainProps) {
addHelpMenuToAppChrome(chrome, docLinks);
}, [stateContainer, chrome, docLinks]);

const resetQuery = useCallback(() => {
const resetCurrentSavedSearch = useCallback(() => {
resetSavedSearch(savedSearch.id);
}, [resetSavedSearch, savedSearch]);

Expand All @@ -103,7 +103,7 @@ export function DiscoverMainApp(props: DiscoverMainProps) {
inspectorAdapters={inspectorAdapters}
onChangeIndexPattern={onChangeIndexPattern}
onUpdateQuery={onUpdateQuery}
resetQuery={resetQuery}
resetSavedSearch={resetCurrentSavedSearch}
navigateTo={navigateTo}
savedSearch={savedSearch}
savedSearchData$={data$}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export function useDiscoverState({
const resetSavedSearch = useCallback(
async (id?: string) => {
const newSavedSearch = await services.getSavedSearchById(id);
newSavedSearch.searchSource.setField('index', indexPattern);
const newIndexPattern = newSavedSearch.searchSource.getField('index') || indexPattern;
newSavedSearch.searchSource.setField('index', newIndexPattern);
const newAppState = getStateDefaults({
config,
data,
Expand All @@ -157,7 +158,7 @@ export function useDiscoverState({
await stateContainer.replaceUrlAppState(newAppState);
setState(newAppState);
},
[services, indexPattern, config, data, stateContainer]
[indexPattern, services, config, data, stateContainer]
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import { share } from 'rxjs/operators';
import { isEqual, isEmpty, debounce } from 'lodash';
import { EventEmitter } from 'events';
import type { IUiSettingsClient } from 'kibana/public';
import {
import type {
Vis,
PersistedState,
VisualizeEmbeddableContract,
} from '../../../../../plugins/visualizations/public';
import { KibanaContextProvider } from '../../../../../plugins/kibana_react/public';
Expand All @@ -31,8 +30,9 @@ import { TIME_RANGE_DATA_MODES, TIME_RANGE_MODE_KEY } from '../../../common/enum
import { VisPicker } from './vis_picker';
import { fetchFields, VisFields } from '../lib/fetch_fields';
import { getDataStart, getCoreStart } from '../../services';
import { TimeseriesVisParams } from '../../types';
import type { TimeseriesVisParams } from '../../types';
import { UseIndexPatternModeCallout } from './use_index_patter_mode_callout';
import type { EditorRenderProps } from '../../../../visualize/public';

const VIS_STATE_DEBOUNCE_DELAY = 200;
const APP_NAME = 'VisEditor';
Expand All @@ -42,7 +42,9 @@ export interface TimeseriesEditorProps {
embeddableHandler: VisualizeEmbeddableContract;
eventEmitter: EventEmitter;
timeRange: TimeRange;
uiState: PersistedState;
filters: EditorRenderProps['filters'];
query: EditorRenderProps['query'];
uiState: EditorRenderProps['uiState'];
vis: Vis<TimeseriesVisParams>;
}

Expand Down Expand Up @@ -189,6 +191,8 @@ export class VisEditor extends Component<TimeseriesEditorProps, TimeseriesEditor
eventEmitter={this.props.eventEmitter}
vis={this.props.vis}
timeRange={this.props.timeRange}
filters={this.props.filters}
query={this.props.query}
uiState={this.props.uiState}
onCommit={this.handleCommit}
onToggleAutoApply={this.handleAutoApplyToggle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ class VisEditorVisualizationUI extends Component {

componentDidUpdate() {
if (this._handler) {
this._handler.updateInput({
timeRange: this.props.timeRange,
filters: this.props.filters || [],
query: this.props.query,
});
const { timeRange, filters, query } = this.props;
this._handler.updateInput({ timeRange, filters, query });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class EditorController implements IEditorController {
private embeddableHandler: VisualizeEmbeddableContract
) {}

render({ timeRange, uiState }: EditorRenderProps) {
render({ timeRange, uiState, filters, query }: EditorRenderProps) {
const I18nContext = getI18n().Context;

render(
Expand All @@ -38,6 +38,8 @@ export class EditorController implements IEditorController {
embeddableHandler={this.embeddableHandler}
eventEmitter={this.eventEmitter}
uiState={uiState}
filters={filters}
query={query}
/>
</I18nContext>,
this.el
Expand Down
Loading

0 comments on commit b5b082b

Please sign in to comment.