Skip to content

Commit

Permalink
Review feedback, fix i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Jan 17, 2024
1 parent b341128 commit d2eb105
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ export class UnlinkFromLibraryAction implements Action<EmbeddableApiContext> {

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',
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,19 +15,6 @@ import { EmbeddableEditorState } from '../../state_transfer';
import { isExplicitInputWithAttributes } from '../embeddable_factory';
import { EmbeddableInput } from '../i_embeddable';

const getLatestAppId = async (): Promise<string | undefined> => {
const subscription: Subscription = new Subscription();
const appId = new Promise<string | undefined>((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();
Expand All @@ -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 = {
Expand Down
10 changes: 2 additions & 8 deletions src/plugins/embeddable/public/lib/embeddables/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -346,13 +346,7 @@ export abstract class Embeddable<
}

public async untilInitializationFinished(): Promise<void> {
return new Promise((resolve) => {
this.initializationFinished.subscribe({
complete: () => {
resolve();
},
});
});
return lastValueFrom(this.initializationFinished);
}

/**
Expand Down
10 changes: 1 addition & 9 deletions src/plugins/inspector/public/adapters/has_inspector_adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/inspector/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d2eb105

Please sign in to comment.