Skip to content

Commit

Permalink
more specific dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Jun 8, 2020
1 parent ba4d131 commit 30bf1e0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IndexPatternsContract } from './index_patterns';
export type EnsureDefaultIndexPattern = () => Promise<unknown> | undefined;

export const createEnsureDefaultIndexPattern = (
core: CoreStart,
uiSettings: CoreStart['uiSettings'],
onRedirectNoIndexPattern: () => Promise<unknown> | void
) => {
/**
Expand All @@ -33,12 +33,12 @@ export const createEnsureDefaultIndexPattern = (
*/
return async function ensureDefaultIndexPattern(this: IndexPatternsContract) {
const patterns = await this.getIds();
let defaultId = core.uiSettings.get('defaultIndex');
let defaultId = uiSettings.get('defaultIndex');
let defined = !!defaultId;
const exists = contains(patterns, defaultId);

if (defined && !exists) {
core.uiSettings.remove('defaultIndex');
uiSettings.remove('defaultIndex');
defaultId = defined = false;
}

Expand All @@ -49,7 +49,7 @@ export const createEnsureDefaultIndexPattern = (
// If there is any index pattern created, set the first as default
if (patterns.length >= 1) {
defaultId = patterns[0];
core.uiSettings.set('defaultIndex', defaultId);
uiSettings.set('defaultIndex', defaultId);
} else {
return onRedirectNoIndexPattern();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('IndexPatterns', () => {
);

indexPatterns = new IndexPatternsService(
core,
core.uiSettings,
savedObjectsClient,
http,
fieldFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class IndexPatternsService {
) => Field;

constructor(
core: CoreStart,
uiSettings: CoreStart['uiSettings'],
savedObjectsClient: SavedObjectsClientContract,
http: HttpStart,
fieldFormats: FieldFormatsStartCommon,
Expand All @@ -75,13 +75,13 @@ export class IndexPatternsService {
onRedirectNoIndexPattern: () => void
) {
this.apiClient = new IndexPatternsApiClient(http);
this.config = core.uiSettings;
this.config = uiSettings;
this.savedObjectsClient = savedObjectsClient;
this.fieldFormats = fieldFormats;
this.onNotification = onNotification;
this.onError = onError;
this.ensureDefaultIndexPattern = createEnsureDefaultIndexPattern(
core,
uiSettings,
onRedirectNoIndexPattern
);
this.createFieldList = getIndexPatternFieldListCreator({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ import { toMountPoint } from '../../../../kibana_react/public';

let bannerId: string;

export const onRedirectNoIndexPattern = (core: CoreStart) => () => {
const canManageIndexPatterns = core.application.capabilities.management.kibana.index_patterns;
export const onRedirectNoIndexPattern = (
capabilities: CoreStart['application']['capabilities'],
navigateToApp: CoreStart['application']['navigateToApp'],
overlays: CoreStart['overlays']
) => () => {
const canManageIndexPatterns = capabilities.management.kibana.index_patterns;
const redirectTarget = canManageIndexPatterns ? '/management/kibana/indexPatterns' : '/home';
let timeoutId: NodeJS.Timeout | undefined;

Expand All @@ -41,21 +45,21 @@ export const onRedirectNoIndexPattern = (core: CoreStart) => () => {

// Avoid being hostile to new users who don't have an index pattern setup yet
// give them a friendly info message instead of a terse error message
bannerId = core.overlays.banners.replace(
bannerId = overlays.banners.replace(
bannerId,
toMountPoint(<EuiCallOut color="warning" iconType="iInCircle" title={bannerMessage} />)
);

// hide the message after the user has had a chance to acknowledge it -- so it doesn't permanently stick around
timeoutId = setTimeout(() => {
core.overlays.banners.remove(bannerId);
overlays.banners.remove(bannerId);
timeoutId = undefined;
}, 15000);

if (redirectTarget === '/home') {
core.application.navigateToApp('home');
navigateToApp('home');
} else {
core.application.navigateToApp('management', {
navigateToApp('management', {
path: `/kibana/indexPatterns?bannerMessage=${bannerMessage}`,
});
}
Expand Down
10 changes: 4 additions & 6 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
}

public start(core: CoreStart, { uiActions }: DataStartDependencies): DataPublicPluginStart {
const { uiSettings, http, notifications, savedObjects, overlays } = core;
const { uiSettings, http, notifications, savedObjects, overlays, application } = core;
setHttp(http);
setNotifications(notifications);
setOverlays(overlays);
Expand All @@ -165,15 +165,13 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
setFieldFormats(fieldFormats);

const indexPatterns = new IndexPatternsService(
core,
uiSettings,
savedObjects.client,
http,
fieldFormats,
(toastInputFields) => {
notifications.toasts.add(toastInputFields);
},
notifications.toasts.add,
notifications.toasts.addError,
onRedirectNoIndexPattern(core)
onRedirectNoIndexPattern(application.capabilities, application.navigateToApp, overlays)
);
setIndexPatterns(indexPatterns);

Expand Down

0 comments on commit 30bf1e0

Please sign in to comment.