From 1d762685938b9942323951b02d53b05aa39a1978 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 25 Jun 2024 15:56:24 -0700 Subject: [PATCH] Simplify data views getCurrentUser --- src/plugins/data_views/public/index.ts | 1 - src/plugins/data_views/public/plugin.ts | 15 ++++----------- src/plugins/data_views/public/types.ts | 2 -- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/plugins/data_views/public/index.ts b/src/plugins/data_views/public/index.ts index 96380665548dd..f690552b5a147 100644 --- a/src/plugins/data_views/public/index.ts +++ b/src/plugins/data_views/public/index.ts @@ -67,7 +67,6 @@ export type { DataViewsContract, HasDataViewsResponse, IndicesViaSearchResponse, - UserIdGetter, } from './types'; // Export plugin after all other imports diff --git a/src/plugins/data_views/public/plugin.ts b/src/plugins/data_views/public/plugin.ts index 954643d9372df..3a847ce939981 100644 --- a/src/plugins/data_views/public/plugin.ts +++ b/src/plugins/data_views/public/plugin.ts @@ -15,7 +15,6 @@ import { DataViewsPublicPluginStart, DataViewsPublicSetupDependencies, DataViewsPublicStartDependencies, - UserIdGetter, } from './types'; import { DataViewsApiClient } from '.'; @@ -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) {} @@ -62,14 +60,6 @@ export class DataViewsPublicPlugin }), }); - core.getStartServices().then(([coreStart]) => { - const getUserId = async function getUserId(): Promise { - const currentUser = await coreStart.security.authc.getCurrentUser(); - return currentUser?.profile_uid; - }; - this.userIdGetter = getUserId; - }); - return { enableRollups: () => (this.rollupsEnabled = true), }; @@ -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) => { diff --git a/src/plugins/data_views/public/types.ts b/src/plugins/data_views/public/types.ts index 98db0382f641f..7d6cbbc6cf533 100644 --- a/src/plugins/data_views/public/types.ts +++ b/src/plugins/data_views/public/types.ts @@ -106,8 +106,6 @@ export interface DataViewsPublicStartDependencies { contentManagement: ContentManagementPublicStart; } -export type UserIdGetter = () => Promise; - /** * Data plugin public Setup contract */