Skip to content

Commit

Permalink
Simplify data views getCurrentUser
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Jun 25, 2024
1 parent 548fcbe commit 1d76268
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/plugins/data_views/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export type {
DataViewsContract,
HasDataViewsResponse,
IndicesViaSearchResponse,
UserIdGetter,
} from './types';

// Export plugin after all other imports
Expand Down
15 changes: 4 additions & 11 deletions src/plugins/data_views/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
DataViewsPublicPluginStart,
DataViewsPublicSetupDependencies,
DataViewsPublicStartDependencies,
UserIdGetter,
} from './types';

import { DataViewsApiClient } from '.';
Expand All @@ -42,7 +41,6 @@ export class DataViewsPublicPlugin
{
private readonly hasData = new HasData();
private rollupsEnabled: boolean = false;
protected userIdGetter: UserIdGetter = async () => undefined;

constructor(private readonly initializerContext: PluginInitializerContext) {}

Expand All @@ -62,14 +60,6 @@ export class DataViewsPublicPlugin
}),
});

core.getStartServices().then(([coreStart]) => {
const getUserId = async function getUserId(): Promise<string | undefined> {
const currentUser = await coreStart.security.authc.getCurrentUser();
return currentUser?.profile_uid;
};
this.userIdGetter = getUserId;
});

return {
enableRollups: () => (this.rollupsEnabled = true),
};
Expand All @@ -96,7 +86,10 @@ export class DataViewsPublicPlugin
hasData: this.hasData.start(core),
uiSettings: new UiSettingsPublicToCommon(uiSettings),
savedObjectsClient: new ContentMagementWrapper(contentManagement.client),
apiClient: new DataViewsApiClient(http, () => this.userIdGetter()),
apiClient: new DataViewsApiClient(http, async () => {
const currentUser = await core.security.authc.getCurrentUser();
return currentUser?.profile_uid;
}),
fieldFormats,
http,
onNotification: (toastInputFields, key) => {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data_views/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ export interface DataViewsPublicStartDependencies {
contentManagement: ContentManagementPublicStart;
}

export type UserIdGetter = () => Promise<string | undefined>;

/**
* Data plugin public Setup contract
*/
Expand Down

0 comments on commit 1d76268

Please sign in to comment.