Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into np/rollups
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Feb 3, 2020
2 parents 2c99beb + 4f4d3d7 commit 6d1a0db
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 416 deletions.
24 changes: 20 additions & 4 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ function createMockFilterManager() {
return unsubscribe;
},
}),
setFilters: (newFilters: unknown[]) => {
setFilters: jest.fn((newFilters: unknown[]) => {
filters = newFilters;
subscriber();
},
if (subscriber) subscriber();
}),
setAppFilters: jest.fn((newFilters: unknown[]) => {
filters = newFilters;
if (subscriber) subscriber();
}),
getFilters: () => filters,
getGlobalFilters: () => {
// @ts-ignore
Expand Down Expand Up @@ -189,6 +193,13 @@ describe('Lens App', () => {
`);
});

it('clears app filters on load', () => {
const defaultArgs = makeDefaultArgs();
mount(<App {...defaultArgs} />);

expect(defaultArgs.data.query.filterManager.setAppFilters).toHaveBeenCalledWith([]);
});

it('sets breadcrumbs when the document title changes', async () => {
const defaultArgs = makeDefaultArgs();
const instance = mount(<App {...defaultArgs} />);
Expand Down Expand Up @@ -226,14 +237,15 @@ describe('Lens App', () => {
expect(args.docStorage.load).not.toHaveBeenCalled();
});

it('loads a document and uses query if there is a document id', async () => {
it('loads a document and uses query and filters if there is a document id', async () => {
const args = makeDefaultArgs();
args.editorFrame = frame;
(args.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
expression: 'valid expression',
state: {
query: 'fake query',
filters: [{ query: { match_phrase: { src: 'test' } } }],
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
});
Expand All @@ -245,6 +257,9 @@ describe('Lens App', () => {

expect(args.docStorage.load).toHaveBeenCalledWith('1234');
expect(args.data.indexPatterns.get).toHaveBeenCalledWith('1');
expect(args.data.query.filterManager.setAppFilters).toHaveBeenCalledWith([
{ query: { match_phrase: { src: 'test' } } },
]);
expect(TopNavMenu).toHaveBeenCalledWith(
expect.objectContaining({
query: 'fake query',
Expand All @@ -260,6 +275,7 @@ describe('Lens App', () => {
expression: 'valid expression',
state: {
query: 'fake query',
filters: [{ query: { match_phrase: { src: 'test' } } }],
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
},
Expand Down
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export function App({
const { lastKnownDoc } = state;

useEffect(() => {
// Clear app-specific filters when navigating to Lens. Necessary because Lens
// can be loaded without a full page refresh
data.query.filterManager.setAppFilters([]);

const filterSubscription = data.query.filterManager.getUpdates$().subscribe({
next: () => {
setState(s => ({ ...s, filters: data.query.filterManager.getFilters() }));
Expand Down Expand Up @@ -123,13 +127,14 @@ export function App({
core.notifications
)
.then(indexPatterns => {
// Don't overwrite any pinned filters
data.query.filterManager.setAppFilters(doc.state.filters);
setState(s => ({
...s,
isLoading: false,
persistedDoc: doc,
lastKnownDoc: doc,
query: doc.state.query,
filters: doc.state.filters,
indexPatternsForTopNav: indexPatterns,
}));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { IndexPatternMapping } from '../types';
import { IndexPatternSavedObject } from '../../ml_popover/types';
import { IndexPatternSavedObject } from '../../../hooks/types';

export const mockIndexPatternIds: IndexPatternMapping[] = [
{ title: 'filebeat-*', id: '8c7323ac-97ad-4b53-ac0a-40f8f691a918' },
Expand Down Expand Up @@ -425,8 +425,7 @@ export const mockLayerListMixed = [
export const mockAPMIndexPattern: IndexPatternSavedObject = {
id: 'apm-*',
type: 'index-pattern',
updated_at: '',
version: 'abc',
_version: 'abc',
attributes: {
title: 'apm-*',
},
Expand All @@ -435,8 +434,7 @@ export const mockAPMIndexPattern: IndexPatternSavedObject = {
export const mockAPMRegexIndexPattern: IndexPatternSavedObject = {
id: 'apm-7.*',
type: 'index-pattern',
updated_at: '',
version: 'abc',
_version: 'abc',
attributes: {
title: 'apm-7.*',
},
Expand All @@ -445,8 +443,7 @@ export const mockAPMRegexIndexPattern: IndexPatternSavedObject = {
export const mockFilebeatIndexPattern: IndexPatternSavedObject = {
id: 'filebeat-*',
type: 'index-pattern',
updated_at: '',
version: 'abc',
_version: 'abc',
attributes: {
title: 'filebeat-*',
},
Expand All @@ -455,8 +452,7 @@ export const mockFilebeatIndexPattern: IndexPatternSavedObject = {
export const mockAuditbeatIndexPattern: IndexPatternSavedObject = {
id: 'auditbeat-*',
type: 'index-pattern',
updated_at: '',
version: 'abc',
_version: 'abc',
attributes: {
title: 'auditbeat-*',
},
Expand All @@ -465,8 +461,7 @@ export const mockAuditbeatIndexPattern: IndexPatternSavedObject = {
export const mockAPMTransactionIndexPattern: IndexPatternSavedObject = {
id: 'apm-*-transaction*',
type: 'index-pattern',
updated_at: '',
version: 'abc',
_version: 'abc',
attributes: {
title: 'apm-*-transaction*',
},
Expand All @@ -475,8 +470,7 @@ export const mockAPMTransactionIndexPattern: IndexPatternSavedObject = {
export const mockGlobIndexPattern: IndexPatternSavedObject = {
id: '*',
type: 'index-pattern',
updated_at: '',
version: 'abc',
_version: 'abc',
attributes: {
title: '*',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getLayerList } from './map_config';
import { MAP_SAVED_OBJECT_TYPE } from '../../../../maps/common/constants';
import * as i18n from './translations';
import { Query, esFilters } from '../../../../../../../src/plugins/data/public';
import { IndexPatternSavedObject } from '../ml_popover/types';
import { IndexPatternSavedObject } from '../../hooks/types';

/**
* Creates MapEmbeddable with provided initial configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';

import { npStart } from 'ui/new_platform';
import { Anomalies, InfluencerInput, CriteriaFields } from '../types';
import { throwIfNotOk } from '../../../hooks/api/api';

export interface Body {
jobIds: string[];
criteriaFields: CriteriaFields[];
Expand All @@ -22,17 +22,17 @@ export interface Body {
}

export const anomaliesTableData = async (body: Body, signal: AbortSignal): Promise<Anomalies> => {
const response = await fetch(`${chrome.getBasePath()}/api/ml/results/anomalies_table_data`, {
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify(body),
headers: {
'content-Type': 'application/json',
'kbn-system-api': 'true',
'kbn-xsrf': 'true',
},
signal,
});
await throwIfNotOk(response);
return response.json();
const response = await npStart.core.http.fetch<Anomalies>(
'/api/ml/results/anomalies_table_data',
{
method: 'POST',
body: JSON.stringify(body),
asResponse: true,
asSystemRequest: true,
signal,
}
);

await throwIfNotOk(response.response);
return response.body!;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';
import { npStart } from 'ui/new_platform';

import { InfluencerInput, MlCapabilities } from '../types';
import { throwIfNotOk } from '../../../hooks/api/api';
Expand All @@ -23,16 +23,13 @@ export interface Body {
}

export const getMlCapabilities = async (signal: AbortSignal): Promise<MlCapabilities> => {
const response = await fetch(`${chrome.getBasePath()}/api/ml/ml_capabilities`, {
const response = await npStart.core.http.fetch<MlCapabilities>('/api/ml/ml_capabilities', {
method: 'GET',
credentials: 'same-origin',
headers: {
'content-Type': 'application/json',
'kbn-system-api': 'true',
'kbn-xsrf': 'true',
},
asResponse: true,
asSystemRequest: true,
signal,
});
await throwIfNotOk(response);
return response.json();

await throwIfNotOk(response.response);
return response.body!;
};
Loading

0 comments on commit 6d1a0db

Please sign in to comment.