Skip to content

Commit

Permalink
Merge with master and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed May 31, 2021
2 parents b2982f4 + 055ade5 commit 6fec9f0
Show file tree
Hide file tree
Showing 49 changed files with 1,430 additions and 251 deletions.
7 changes: 0 additions & 7 deletions src/plugins/dashboard/public/application/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,6 @@ export function DashboardApp({
};
}, [dashboardStateManager, dashboardContainer, onAppLeave, embeddable]);

// clear search session when leaving dashboard route
useEffect(() => {
return () => {
data.search.session.clear();
};
}, [data.search.session]);

return (
<>
{savedDashboard && dashboardStateManager && dashboardContainer && viewMode && (
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/dashboard/public/application/dashboard_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,14 @@ export async function mountApp({
return <DashboardNoMatch history={routeProps.history} />;
};

// make sure the index pattern list is up to date
await dataStart.indexPatterns.clearCache();
const hasEmbeddableIncoming = Boolean(
dashboardServices.embeddable
.getStateTransfer()
.getIncomingEmbeddablePackage(DashboardConstants.DASHBOARDS_ID, false)
);
if (!hasEmbeddableIncoming) {
dataStart.indexPatterns.clearCache();
}

// dispatch synthetic hash change event to update hash history objects
// this is necessary because hash updates triggered by using popState won't trigger this event naturally.
Expand Down Expand Up @@ -242,7 +248,6 @@ export async function mountApp({
}
render(app, element);
return () => {
dataStart.search.session.clear();
unlistenParentHistory();
unmountComponentAtNode(element);
appUnMounted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ export const useDashboardContainer = ({
let canceled = false;
let pendingContainer: DashboardContainer | ErrorEmbeddable | null | undefined;
(async function createContainer() {
const existingSession = searchSession.getSessionId();
pendingContainer = await dashboardFactory.create(
getDashboardContainerInput({
isEmbeddedExternally: Boolean(isEmbeddedExternally),
dashboardCapabilities,
dashboardStateManager,
incomingEmbeddable,
query,
searchSessionId: searchSessionIdFromURL ?? searchSession.start(),
searchSessionId:
searchSessionIdFromURL ??
(existingSession && incomingEmbeddable ? existingSession : searchSession.start()),
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export const DashboardListing = ({
};
}, [title, savedObjectsClient, redirectTo, data.query, kbnUrlStateStorage]);

// clear dangling session because they are not required here
useEffect(() => {
data.search.session.clear();
}, [data.search.session]);

const hideWriteControls = dashboardCapabilities.hideWriteControls;
const listingLimit = savedObjects.settings.getListingLimit();
const defaultFilter = title ? `"${title}"` : '';
Expand Down
86 changes: 74 additions & 12 deletions src/plugins/data/common/es_query/es_query/build_es_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ describe('build query', () => {
{ query: 'extension:jpg', language: 'kuery' },
{ query: 'bar:baz', language: 'lucene' },
] as Query[];
const filters = [
{
match_all: {},
meta: { type: 'match_all' },
} as MatchAllFilter,
];
const filters = {
match: {
a: 'b',
},
meta: {
alias: '',
disabled: false,
negate: false,
},
};
const config = {
allowLeadingWildcards: true,
queryStringOptions: {},
Expand All @@ -56,7 +60,11 @@ describe('build query', () => {
must: [decorateQuery(luceneStringToDsl('bar:baz'), config.queryStringOptions)],
filter: [
toElasticsearchQuery(fromKueryExpression('extension:jpg'), indexPattern),
{ match_all: {} },
{
match: {
a: 'b',
},
},
],
should: [],
must_not: [],
Expand All @@ -71,9 +79,15 @@ describe('build query', () => {
it('should accept queries and filters as either single objects or arrays', () => {
const queries = { query: 'extension:jpg', language: 'lucene' } as Query;
const filters = {
match_all: {},
meta: { type: 'match_all' },
} as MatchAllFilter;
match: {
a: 'b',
},
meta: {
alias: '',
disabled: false,
negate: false,
},
};
const config = {
allowLeadingWildcards: true,
queryStringOptions: {},
Expand All @@ -83,7 +97,13 @@ describe('build query', () => {
const expectedResult = {
bool: {
must: [decorateQuery(luceneStringToDsl('extension:jpg'), config.queryStringOptions)],
filter: [{ match_all: {} }],
filter: [
{
match: {
a: 'b',
},
},
],
should: [],
must_not: [],
},
Expand All @@ -94,6 +114,49 @@ describe('build query', () => {
expect(result).toEqual(expectedResult);
});

it('should remove match_all clauses', () => {
const filters = [
{
match_all: {},
meta: { type: 'match_all' },
} as MatchAllFilter,
{
match: {
a: 'b',
},
meta: {
alias: '',
disabled: false,
negate: false,
},
},
];
const config = {
allowLeadingWildcards: true,
queryStringOptions: {},
ignoreFilterIfFieldNotInIndex: false,
};

const expectedResult = {
bool: {
must: [],
filter: [
{
match: {
a: 'b',
},
},
],
should: [],
must_not: [],
},
};

const result = buildEsQuery(indexPattern, [], filters, config);

expect(result).toEqual(expectedResult);
});

it('should use the default time zone set in the Advanced Settings in queries and filters', () => {
const queries = [
{ query: '@timestamp:"2019-03-23T13:18:00"', language: 'kuery' },
Expand Down Expand Up @@ -122,7 +185,6 @@ describe('build query', () => {
indexPattern,
config
),
{ match_all: {} },
],
should: [],
must_not: [],
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/data/common/es_query/es_query/build_es_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { groupBy, has } from 'lodash';
import { groupBy, has, isEqual } from 'lodash';
import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
Expand All @@ -21,6 +21,12 @@ export interface EsQueryConfig {
dateFormatTZ?: string;
}

function removeMatchAll<T>(filters: T[]) {
return filters.filter(
(filter) => !filter || typeof filter !== 'object' || !isEqual(filter, { match_all: {} })
);
}

/**
* @param indexPattern
* @param queries - a query object or array of query objects. Each query has a language property and a query property.
Expand Down Expand Up @@ -63,9 +69,9 @@ export function buildEsQuery(

return {
bool: {
must: [...kueryQuery.must, ...luceneQuery.must, ...filterQuery.must],
filter: [...kueryQuery.filter, ...luceneQuery.filter, ...filterQuery.filter],
should: [...kueryQuery.should, ...luceneQuery.should, ...filterQuery.should],
must: removeMatchAll([...kueryQuery.must, ...luceneQuery.must, ...filterQuery.must]),
filter: removeMatchAll([...kueryQuery.filter, ...luceneQuery.filter, ...filterQuery.filter]),
should: removeMatchAll([...kueryQuery.should, ...luceneQuery.should, ...filterQuery.should]),
must_not: [...kueryQuery.must_not, ...luceneQuery.must_not, ...filterQuery.must_not],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ describe('Session service', () => {
expect(nowProvider.reset).toHaveBeenCalled();
});

it("Can't clear other apps' session", async () => {
sessionService.start();
expect(sessionService.getSessionId()).not.toBeUndefined();
currentAppId$.next('change');
sessionService.clear();
expect(sessionService.getSessionId()).not.toBeUndefined();
});

it("Can start a new session in case there is other apps' stale session", async () => {
const s1 = sessionService.start();
expect(sessionService.getSessionId()).not.toBeUndefined();
Expand Down
27 changes: 0 additions & 27 deletions src/plugins/data/public/search/session/session_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,6 @@ export class SessionService {
this.subscription.add(
coreStart.application.currentAppId$.subscribe((newAppName) => {
this.currentApp = newAppName;
if (!this.getSessionId()) return;

// Apps required to clean up their sessions before unmounting
// Make sure that apps don't leave sessions open by throwing an error in DEV mode
const message = `Application '${
this.state.get().appName
}' had an open session while navigating`;
if (initializerContext.env.mode.dev) {
coreStart.fatalErrors.add(message);
} else {
// this should never happen in prod because should be caught in dev mode
// in case this happen we don't want to throw fatal error, as most likely possible bugs are not that critical
// eslint-disable-next-line no-console
console.warn(message);
}
})
);
});
Expand Down Expand Up @@ -230,18 +215,6 @@ export class SessionService {
* Cleans up current state
*/
public clear() {
// make sure apps can't clear other apps' sessions
const currentSessionApp = this.state.get().appName;
if (currentSessionApp && currentSessionApp !== this.currentApp) {
// eslint-disable-next-line no-console
console.warn(
`Skip clearing session "${this.getSessionId()}" because it belongs to a different app. current: "${
this.currentApp
}", owner: "${currentSessionApp}"`
);
return;
}

this.state.transitions.clear();
this.searchSessionInfoProvider = undefined;
this.searchSessionIndicatorUiConfig = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ export function createInfiniteScrollDirective() {
const isMobileView = document.getElementsByClassName('dscSidebar__mobile').length > 0;
const usedScrollDiv = isMobileView ? scrollDivMobile : scrollDiv;
const scrollTop = usedScrollDiv.scrollTop();
const scrollOffset = usedScrollDiv.prop('offsetTop') || 0;

const winHeight = Number(usedScrollDiv.height());
const winBottom = Number(winHeight) + Number(scrollTop);
const elTop = $element.get(0).offsetTop || 0;
const remaining = elTop - winBottom;
const remaining = elTop - scrollOffset - winBottom;

if (remaining <= winHeight) {
$scope[$scope.$$phase ? '$eval' : '$apply'](function () {
Expand Down
40 changes: 0 additions & 40 deletions src/plugins/vis_type_timeseries/common/get_last_value.test.js

This file was deleted.

Loading

0 comments on commit 6fec9f0

Please sign in to comment.