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

GS providers improvements #75174

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app1',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
expect(applications.get('app2')).toEqual(
expect.objectContaining({
id: 'app2',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand All @@ -142,7 +142,7 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app1',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.hidden,
status: AppStatus.inaccessible,
defaultPath: 'foo/bar',
tooltip: 'App inaccessible due to reason',
Expand All @@ -152,7 +152,7 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app2',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app2',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
tooltip: 'App accessible',
})
Expand Down Expand Up @@ -523,7 +523,7 @@ describe('#start()', () => {
appRoute: '/app/app1',
id: 'app1',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand All @@ -532,7 +532,7 @@ describe('#start()', () => {
appUrl: '/my-url',
id: 'app2',
legacy: true,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand Down
39 changes: 33 additions & 6 deletions src/core/public/application/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/

import { of } from 'rxjs';
import { LegacyApp, App, AppStatus, AppNavLinkStatus } from './types';
import { App, AppNavLinkStatus, AppStatus, LegacyApp } from './types';
import { BasePath } from '../http/base_path';
import {
removeSlashes,
appendAppPath,
getAppInfo,
isLegacyApp,
relativeToAbsolute,
parseAppUrl,
getAppInfo,
relativeToAbsolute,
removeSlashes,
} from './utils';

describe('removeSlashes', () => {
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('getAppInfo', () => {
id: 'some-id',
title: 'some-title',
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
appRoute: `/app/some-id`,
legacy: false,
});
Expand All @@ -509,8 +509,35 @@ describe('getAppInfo', () => {
id: 'some-id',
title: 'some-title',
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
legacy: true,
});
});

it('computes the navLinkStatus depending on the app status', () => {
expect(
getAppInfo(
createApp({
navLinkStatus: AppNavLinkStatus.default,
status: AppStatus.inaccessible,
})
)
).toEqual(
expect.objectContaining({
navLinkStatus: AppNavLinkStatus.hidden,
})
);
expect(
getAppInfo(
createApp({
navLinkStatus: AppNavLinkStatus.default,
status: AppStatus.accessible,
})
)
).toEqual(
expect.objectContaining({
navLinkStatus: AppNavLinkStatus.visible,
})
);
});
});
20 changes: 17 additions & 3 deletions src/core/public/application/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
*/

import { IBasePath } from '../http';
import { App, LegacyApp, PublicAppInfo, PublicLegacyAppInfo, ParsedAppUrl } from './types';
import {
App,
AppNavLinkStatus,
AppStatus,
LegacyApp,
ParsedAppUrl,
PublicAppInfo,
PublicLegacyAppInfo,
} from './types';

/**
* Utility to remove trailing, leading or duplicate slashes.
Expand Down Expand Up @@ -116,20 +124,26 @@ const removeBasePath = (url: string, basePath: IBasePath, origin: string): strin
};

export function getAppInfo(app: App<unknown> | LegacyApp): PublicAppInfo | PublicLegacyAppInfo {
const navLinkStatus =
app.navLinkStatus === AppNavLinkStatus.default
? app.status === AppStatus.inaccessible
? AppNavLinkStatus.hidden
: AppNavLinkStatus.visible
: app.navLinkStatus!;
if (isLegacyApp(app)) {
Comment on lines +127 to 133
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAppInfo now computes the navlink status as it was more or less done in

hidden: useAppStatus
? app.status === AppStatus.inaccessible
: app.navLinkStatus === AppNavLinkStatus.hidden,
disabled: useAppStatus ? false : app.navLinkStatus === AppNavLinkStatus.disabled,

As AppServiceStart.applications$ is a public API that is supposed to return the computed state of the apps, I think it make sense, instead of letting the consumers manually apply this logic.

const { updater$, ...infos } = app;
return {
...infos,
status: app.status!,
navLinkStatus: app.navLinkStatus!,
navLinkStatus,
legacy: true,
};
} else {
const { updater$, mount, ...infos } = app;
return {
...infos,
status: app.status!,
navLinkStatus: app.navLinkStatus!,
navLinkStatus,
appRoute: app.appRoute!,
legacy: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { getAppResultsMock } from './application.test.mocks';

import { of, EMPTY } from 'rxjs';
import { EMPTY, of } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { ApplicationStart, AppNavLinkStatus, AppStatus, PublicAppInfo } from 'src/core/public';
import {
Expand Down Expand Up @@ -100,6 +100,20 @@ describe('applicationResultProvider', () => {
expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]);
});

it('ignores apps with non-visible navlink', async () => {
application.applications$ = of(
createAppMap([
createApp({ id: 'app1', title: 'App 1', navLinkStatus: AppNavLinkStatus.visible }),
createApp({ id: 'disabled', title: 'disabled', navLinkStatus: AppNavLinkStatus.disabled }),
createApp({ id: 'hidden', title: 'hidden', navLinkStatus: AppNavLinkStatus.hidden }),
])
);
const provider = createApplicationResultProvider(Promise.resolve(application));
await provider.find('term', defaultOption).toPromise();

expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]);
});

it('ignores chromeless apps', async () => {
application.applications$ = of(
createAppMap([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const createApplicationResultProvider = (
mergeMap((application) => application.applications$),
map((apps) =>
[...apps.values()].filter(
(app) => app.status === 0 && (app.legacy === true || app.chromeless !== true)
// only include non-chromeless enabled apps with visible navLinks
(app) => app.status === 0 && app.navLinkStatus === 1 && app.chromeless !== true
)
),
shareReplay(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('savedObjectsResultProvider', () => {
expect(context.core.savedObjects.client.find).toHaveBeenCalledWith({
page: 1,
perPage: defaultOption.maxResults,
search: 'term',
search: 'term*',
preference: 'pref',
searchFields: ['title', 'description'],
type: ['typeA', 'typeB'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const createSavedObjectsResultProvider = (): GlobalSearchResultProvider =
const responsePromise = client.find({
page: 1,
perPage: maxResults,
search: term,
search: term ? `${term}*` : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any issue with using *${term}* so we can match anywhere in the field? Maybe this reduces the quality of the search results.

Ideally, we'd be boosting results where the beginning of the field matches the search term, probably using multiple should clauses, one with the phrase_prefix match type. Definitely out of scope here though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any issue with using ${term} so we can match anywhere in the field? Maybe this reduces the quality of the search results.

Yea, I'm not really sure. Without proper boost, searching anywhere in the field can have some unexpected behavior in term of results. I feel like until we are able to construct a more precise search dsl, prefix-only may be better.

@ryankeairns WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m happy with the prefix-only change for now and collecting more feedback post-merge/release.

preference,
searchFields,
type: searchableTypes.map((type) => type.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(results.length).to.be(1);
expect(results[0].type).to.be('index-pattern');
expect(results[0].title).to.be('logstash-*');
expect(results[0].score).to.be.greaterThan(1);
expect(results[0].score).to.be.greaterThan(0.9);
});

it('can search for visualizations', async () => {
Expand Down Expand Up @@ -70,5 +70,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(results.map((r) => r.title)).to.contain('dashboard with map');
expect(results.map((r) => r.title)).to.contain('Amazing Dashboard');
});

it('can search by prefix', async () => {
const results = await findResultsWithAPI('Amaz');
expect(results.length).to.be(1);
expect(results[0].type).to.be('dashboard');
expect(results[0].title).to.be('Amazing Dashboard');
});
});
}