Skip to content

Commit

Permalink
fix behavior on missing permissions and use alex suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Sep 21, 2020
1 parent b22fe71 commit 6035a8f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
14 changes: 12 additions & 2 deletions x-pack/plugins/lens/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { UiActionsStart } from '../../../../src/plugins/ui_actions/public';
import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../common';
import { EditorFrameStart } from './types';
import { getLensAliasConfig } from './vis_type_alias';
import { searchProvider } from './search_provider';
import { getSearchProvider } from './search_provider';

import './index.scss';

Expand Down Expand Up @@ -121,7 +121,17 @@ export class LensPlugin {
});

if (globalSearch) {
globalSearch.registerResultProvider(searchProvider);
globalSearch.registerResultProvider(
getSearchProvider(
core.getStartServices().then(
([
{
application: { capabilities },
},
]) => capabilities
)
)
);
}

urlForwarding.forwardApp('lens', 'lens');
Expand Down
44 changes: 28 additions & 16 deletions x-pack/plugins/lens/public/search_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*/

import levenshtein from 'js-levenshtein';
import { ApplicationStart } from 'kibana/public';
import { from, EMPTY } from 'rxjs';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/public';
import { GlobalSearchResultProvider } from '../../global_search/public';
import { getFullPath, NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../common';
import { getFullPath } from '../common';

/**
* Global search provider adding a Lens entry.
Expand All @@ -19,10 +21,12 @@ import { getFullPath, NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../common';
* TODO: This is a workaround and can be removed once there is a generic way to register sub features
* of apps. In this case, Lens should be considered a feature of Visualize.
*/
export const searchProvider: GlobalSearchResultProvider = {
export const getSearchProvider: (
uiCapabilities: Promise<ApplicationStart['capabilities']>
) => GlobalSearchResultProvider = (uiCapabilities) => ({
id: 'lens',
find: (term) => {
const title = NOT_INTERNATIONALIZED_PRODUCT_NAME;
const title = 'Visualize: Lens';
const searchableTitle = title.toLowerCase();

term = term.toLowerCase();
Expand All @@ -46,17 +50,25 @@ export const searchProvider: GlobalSearchResultProvider = {
}
}
if (score === 0) return EMPTY;
return from([
[
{
id: 'lens',
title,
type: 'application',
icon: 'logoKibana',
score,
url: getFullPath(),
},
],
]);
return from(
uiCapabilities.then(({ navLinks: { visualize: visualizeNavLink } }) =>
visualizeNavLink
? [
{
id: 'lens',
title,
type: 'application',
icon: 'logoKibana',
meta: {
categoryId: DEFAULT_APP_CATEGORIES.kibana.id,
categoryLabel: DEFAULT_APP_CATEGORIES.kibana.label,
},
score,
url: getFullPath(),
},
]
: []
)
);
},
};
});

0 comments on commit 6035a8f

Please sign in to comment.