From d2eb10554a398182be50b59b6dc371f39a625cb4 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Wed, 17 Jan 2024 12:05:15 -0500 Subject: [PATCH] Review feedback, fix i18n --- .../_dashboard_actions_strings.ts | 1 + .../dashboard_actions/export_csv_action.tsx | 7 +++++-- .../unlink_from_library_action.test.tsx | 2 +- .../unlink_from_library_action.tsx | 6 +++--- .../compatibility/edit_legacy_embeddable.tsx | 17 ++--------------- .../public/lib/embeddables/embeddable.tsx | 10 ++-------- .../public/adapters/has_inspector_adapters.ts | 10 +--------- src/plugins/inspector/public/index.ts | 12 +++++++++--- 8 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/plugins/dashboard/public/dashboard_actions/_dashboard_actions_strings.ts b/src/plugins/dashboard/public/dashboard_actions/_dashboard_actions_strings.ts index dcc4997bbd5c4..3490ed4b06238 100644 --- a/src/plugins/dashboard/public/dashboard_actions/_dashboard_actions_strings.ts +++ b/src/plugins/dashboard/public/dashboard_actions/_dashboard_actions_strings.ts @@ -98,6 +98,7 @@ export const dashboardUnlinkFromLibraryActionStrings = { getFailureMessage: (panelTitle: string) => i18n.translate('dashboard.panel.unlinkFromLibrary.failureMessage', { defaultMessage: `An error occured while unlinking {panelTitle} from the library.`, + values: { panelTitle }, }), }; diff --git a/src/plugins/dashboard/public/dashboard_actions/export_csv_action.tsx b/src/plugins/dashboard/public/dashboard_actions/export_csv_action.tsx index 3dfc3a16f988b..22be8fd853cd5 100644 --- a/src/plugins/dashboard/public/dashboard_actions/export_csv_action.tsx +++ b/src/plugins/dashboard/public/dashboard_actions/export_csv_action.tsx @@ -7,13 +7,16 @@ */ import { exporters } from '@kbn/data-plugin/public'; -import type { Adapters } from '@kbn/embeddable-plugin/public'; import { Datatable } from '@kbn/expressions-plugin/public'; import { FormatFactory } from '@kbn/field-formats-plugin/common'; import { downloadMultipleAs } from '@kbn/share-plugin/public'; import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; -import { apiHasInspectorAdapters, HasInspectorAdapters } from '@kbn/inspector-plugin/public'; +import { + apiHasInspectorAdapters, + HasInspectorAdapters, + type Adapters, +} from '@kbn/inspector-plugin/public'; import { EmbeddableApiContext, PublishesPanelTitle } from '@kbn/presentation-publishing'; import { pluginServices } from '../services/plugin_services'; import { dashboardExportCsvActionStrings } from './_dashboard_actions_strings'; diff --git a/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.test.tsx b/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.test.tsx index 010ae0a37cd39..d400e41646d14 100644 --- a/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.test.tsx +++ b/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.test.tsx @@ -70,7 +70,7 @@ describe('Unlink from library action', () => { await action.execute(context); expect(pluginServices.getServices().notifications.toasts.addDanger).toHaveBeenCalledWith({ 'data-test-subj': 'unlinkPanelFailure', - title: 'An error occured while unlinking a panel from the library.', + title: "An error occured while unlinking 'A very compatible API' from the library.", }); }); }); diff --git a/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.tsx b/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.tsx index 38ef010d09c5b..250524c74cfc6 100644 --- a/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.tsx +++ b/src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.tsx @@ -59,16 +59,16 @@ export class UnlinkFromLibraryAction implements Action { public async execute({ embeddable }: EmbeddableApiContext) { if (!unlinkActionIsCompatible(embeddable)) throw new IncompatibleActionError(); - const panelTitle = embeddable.panelTitle?.value ?? embeddable.defaultPanelTitle?.value ?? ''; + const title = embeddable.panelTitle?.value ?? embeddable.defaultPanelTitle?.value; try { await embeddable.unlinkFromLibrary(); this.toastsService.addSuccess({ - title: dashboardUnlinkFromLibraryActionStrings.getSuccessMessage(panelTitle), + title: dashboardUnlinkFromLibraryActionStrings.getSuccessMessage(title ? `'${title}'` : ''), 'data-test-subj': 'unlinkPanelSuccess', }); } catch (e) { this.toastsService.addDanger({ - title: dashboardUnlinkFromLibraryActionStrings.getFailureMessage(panelTitle), + title: dashboardUnlinkFromLibraryActionStrings.getFailureMessage(title ? `'${title}'` : ''), 'data-test-subj': 'unlinkPanelFailure', }); } diff --git a/src/plugins/embeddable/public/lib/embeddables/compatibility/edit_legacy_embeddable.tsx b/src/plugins/embeddable/public/lib/embeddables/compatibility/edit_legacy_embeddable.tsx index a0b11c50411d4..aba1a256b8028 100644 --- a/src/plugins/embeddable/public/lib/embeddables/compatibility/edit_legacy_embeddable.tsx +++ b/src/plugins/embeddable/public/lib/embeddables/compatibility/edit_legacy_embeddable.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { Subscription } from 'rxjs'; +import { firstValueFrom } from 'rxjs'; import { LegacyCompatibleEmbeddable } from '../../../embeddable_panel/types'; import { core, embeddableStart } from '../../../kibana_services'; import { Container } from '../../containers'; @@ -15,19 +15,6 @@ import { EmbeddableEditorState } from '../../state_transfer'; import { isExplicitInputWithAttributes } from '../embeddable_factory'; import { EmbeddableInput } from '../i_embeddable'; -const getLatestAppId = async (): Promise => { - const subscription: Subscription = new Subscription(); - const appId = new Promise((resolve) => { - subscription.add( - core.application.currentAppId$.subscribe((currentAppId) => { - resolve(currentAppId); - }) - ); - }); - subscription?.unsubscribe(); - return appId; -}; - const getExplicitInput = (embeddable: LegacyCompatibleEmbeddable) => (embeddable.getRoot() as Container)?.getInput()?.panels?.[embeddable.id]?.explicitInput ?? embeddable.getInput(); @@ -37,7 +24,7 @@ const getAppTarget = async (embeddable: LegacyCompatibleEmbeddable) => { const path = embeddable ? embeddable.getOutput().editPath : undefined; if (!app || !path) return; - const currentAppId = await getLatestAppId(); + const currentAppId = await firstValueFrom(core.application.currentAppId$); if (!currentAppId) return { app, path }; const state: EmbeddableEditorState = { diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx b/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx index cb0f94b46cc58..44f41ac519a46 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx @@ -9,7 +9,7 @@ import fastIsEqual from 'fast-deep-equal'; import { cloneDeep } from 'lodash'; import * as Rx from 'rxjs'; -import { merge } from 'rxjs'; +import { lastValueFrom, merge } from 'rxjs'; import { debounceTime, distinctUntilChanged, map, skip } from 'rxjs/operators'; import { RenderCompleteDispatcher } from '@kbn/kibana-utils-plugin/public'; import { Adapters } from '../types'; @@ -346,13 +346,7 @@ export abstract class Embeddable< } public async untilInitializationFinished(): Promise { - return new Promise((resolve) => { - this.initializationFinished.subscribe({ - complete: () => { - resolve(); - }, - }); - }); + return lastValueFrom(this.initializationFinished); } /** diff --git a/src/plugins/inspector/public/adapters/has_inspector_adapters.ts b/src/plugins/inspector/public/adapters/has_inspector_adapters.ts index 686cb15d99c5c..2d3337a18ee6d 100644 --- a/src/plugins/inspector/public/adapters/has_inspector_adapters.ts +++ b/src/plugins/inspector/public/adapters/has_inspector_adapters.ts @@ -6,15 +6,7 @@ * Side Public License, v 1. */ -import { RequestAdapter } from '../../common'; - -/** - * The interface that the adapters used to open an inspector have to fullfill. - */ -export interface Adapters { - requests?: RequestAdapter; - [key: string]: any; -} +import { Adapters } from '../../common'; export interface HasInspectorAdapters { getInspectorAdapters: () => Adapters | undefined; diff --git a/src/plugins/inspector/public/index.ts b/src/plugins/inspector/public/index.ts index 50fb0944a9556..906b918632395 100644 --- a/src/plugins/inspector/public/index.ts +++ b/src/plugins/inspector/public/index.ts @@ -17,11 +17,17 @@ import { InspectorPublicPlugin } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { return new InspectorPublicPlugin(initializerContext); } - -export * from '../common/adapters'; export { - apiHasInspectorAdapters, type Adapters, + type Request, + type RequestStatistic, + type RequestStatistics, + RequestAdapter, + RequestStatus, + RequestResponder, +} from '../common'; +export { + apiHasInspectorAdapters, type HasInspectorAdapters, } from './adapters/has_inspector_adapters'; export { InspectorPublicPlugin as Plugin } from './plugin';