Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppEx-SharedUX] Remove toMountPoint parameter from TableListViewKibanaProvider #182030

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React from 'react';
import { ContentClientProvider, type ContentClient } from '@kbn/content-management-plugin/public';
import { TableListViewKibanaProvider } from '@kbn/content-management-table-list-view-table';
import type { CoreStart } from '@kbn/core/public';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { FormattedRelative, I18nProvider } from '@kbn/i18n-react';
import { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { MSearchTable } from './msearch_table';
Expand All @@ -25,7 +24,6 @@ export const MSearchApp = (props: {
<I18nProvider>
<TableListViewKibanaProvider
core={props.core}
toMountPoint={toMountPoint}
FormattedRelative={FormattedRelative}
savedObjectsTagging={props.savedObjectsTagging.getTaggingApi()}
>
Expand Down
1 change: 0 additions & 1 deletion examples/content_management_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@kbn/shared-ux-link-redirect-app",
"@kbn/content-management-table-list-view",
"@kbn/content-management-table-list-view-table",
"@kbn/kibana-react-plugin",
"@kbn/i18n-react",
"@kbn/saved-objects-tagging-oss-plugin",
"@kbn/core-saved-objects-api-browser",
Expand Down
45 changes: 21 additions & 24 deletions packages/content-management/content_editor/src/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* Side Public License, v 1.
*/

import React, { useContext, useCallback, useMemo, PropsWithChildren } from 'react';
import type { FC, ReactNode } from 'react';
import type { Observable } from 'rxjs';
import type { FC, PropsWithChildren, ReactNode } from 'react';
import React, { useCallback, useContext, useMemo } from 'react';

import type { EuiComboBoxProps } from '@elastic/eui';
import type { MountPoint, OverlayRef } from '@kbn/core-mount-utils-browser';
import type { OverlayFlyoutOpenOptions } from '@kbn/core-overlays-browser';
import type { AnalyticsServiceStart, I18nStart, ThemeServiceStart } from '@kbn/core/public';
import { toMountPoint } from '@kbn/react-kibana-mount';

type NotifyFn = (title: JSX.Element, text?: string) => void;

Expand Down Expand Up @@ -52,12 +54,21 @@ export const ContentEditorProvider: FC<PropsWithChildren<Services>> = ({
return <ContentEditorContext.Provider value={services}>{children}</ContentEditorContext.Provider>;
};

/**
* Specific services for mounting React
*/
interface ContentEditorStartServices {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
}

/**
* Kibana-specific service types.
*/
export interface ContentEditorKibanaDependencies {
/** CoreStart contract */
core: {
core: ContentEditorStartServices & {
overlays: {
openFlyout(mount: MountPoint, options?: OverlayFlyoutOpenOptions): OverlayRef;
};
Expand All @@ -66,21 +77,7 @@ export interface ContentEditorKibanaDependencies {
addDanger: (notifyArgs: { title: MountPoint; text?: string }) => void;
};
};
theme: {
theme$: Observable<Theme>;
};
};
/**
* Handler from the '@kbn/kibana-react-plugin/public' Plugin
*
* ```
* import { toMountPoint } from '@kbn/kibana-react-plugin/public';
* ```
*/
toMountPoint: (
node: React.ReactNode,
options?: { theme$: Observable<{ readonly darkMode: boolean }> }
) => MountPoint;
/**
* The public API from the savedObjectsTaggingOss plugin.
* It is returned by calling `getTaggingApi()` from the SavedObjectTaggingOssPluginStart
Expand Down Expand Up @@ -115,9 +112,9 @@ export interface ContentEditorKibanaDependencies {
export const ContentEditorKibanaProvider: FC<
PropsWithChildren<ContentEditorKibanaDependencies>
> = ({ children, ...services }) => {
const { core, toMountPoint, savedObjectsTagging } = services;
const { openFlyout: coreOpenFlyout } = core.overlays;
const { theme$ } = core.theme;
const { core, savedObjectsTagging } = services;
const { overlays, notifications, ...startServices } = core;
const { openFlyout: coreOpenFlyout } = overlays;

const TagList = useMemo(() => {
const Comp: Services['TagList'] = ({ references }) => {
Expand All @@ -133,16 +130,16 @@ export const ContentEditorKibanaProvider: FC<

const openFlyout = useCallback(
(node: ReactNode, options: OverlayFlyoutOpenOptions) => {
return coreOpenFlyout(toMountPoint(node, { theme$ }), options);
return coreOpenFlyout(toMountPoint(node, startServices), options);
},
[coreOpenFlyout, toMountPoint, theme$]
[coreOpenFlyout, startServices]
);

return (
<ContentEditorProvider
openFlyout={openFlyout}
notifyError={(title, text) => {
core.notifications.toasts.addDanger({ title: toMountPoint(title), text });
notifications.toasts.addDanger({ title: toMountPoint(title, startServices), text });
}}
TagList={TagList}
TagSelector={savedObjectsTagging?.ui.components.SavedObjectSaveModalTagSelector}
Expand Down
2 changes: 2 additions & 0 deletions packages/content-management/content_editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"@kbn/core-mount-utils-browser",
"@kbn/core-overlays-browser",
"@kbn/test-jest-helpers",
"@kbn/core",
"@kbn/react-kibana-mount",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
* Side Public License, v 1.
*/

import React, { FC, PropsWithChildren, useContext, useMemo, useCallback } from 'react';
import type { FC, PropsWithChildren } from 'react';
import React, { useCallback, useContext, useMemo } from 'react';
import type { Observable } from 'rxjs';
import type { FormattedRelative } from '@kbn/i18n-react';
import type { MountPoint, OverlayRef } from '@kbn/core-mount-utils-browser';
import type { OverlayFlyoutOpenOptions } from '@kbn/core-overlays-browser';
import { RedirectAppLinksKibanaProvider } from '@kbn/shared-ux-link-redirect-app';

import {
ContentEditorKibanaProvider,
type SavedObjectsReference,
} from '@kbn/content-management-content-editor';
import type { MountPoint, OverlayRef } from '@kbn/core-mount-utils-browser';
import type { OverlayFlyoutOpenOptions } from '@kbn/core-overlays-browser';
import type { AnalyticsServiceStart, I18nStart, ThemeServiceStart } from '@kbn/core/public';
import type { FormattedRelative } from '@kbn/i18n-react';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { RedirectAppLinksKibanaProvider } from '@kbn/shared-ux-link-redirect-app';

import { TAG_MANAGEMENT_APP_URL } from './constants';
import type { Tag } from './types';
Expand Down Expand Up @@ -72,12 +76,21 @@ export const TableListViewProvider: FC<PropsWithChildren<Services>> = ({
return <TableListViewContext.Provider value={services}>{children}</TableListViewContext.Provider>;
};

/**
* Specific services for mounting React
*/
interface TableListViewStartServices {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
}

/**
* Kibana-specific service types.
*/
export interface TableListViewKibanaDependencies {
/** CoreStart contract */
core: {
core: TableListViewStartServices & {
application: {
capabilities: {
[key: string]: Readonly<Record<string, boolean | Record<string, boolean>>>;
Expand All @@ -99,23 +112,7 @@ export interface TableListViewKibanaDependencies {
overlays: {
openFlyout(mount: MountPoint, options?: OverlayFlyoutOpenOptions): OverlayRef;
};
theme: {
theme$: Observable<{
readonly darkMode: boolean;
}>;
};
};
/**
* Handler from the '@kbn/kibana-react-plugin/public' Plugin
*
* ```
* import { toMountPoint } from '@kbn/kibana-react-plugin/public';
* ```
*/
toMountPoint: (
node: React.ReactNode,
options?: { theme$: Observable<{ readonly darkMode: boolean }> }
) => MountPoint;
/**
* The public API from the savedObjectsTaggingOss plugin.
* It is returned by calling `getTaggingApi()` from the SavedObjectTaggingOssPluginStart
Expand Down Expand Up @@ -165,7 +162,8 @@ export interface TableListViewKibanaDependencies {
export const TableListViewKibanaProvider: FC<
PropsWithChildren<TableListViewKibanaDependencies>
> = ({ children, ...services }) => {
const { core, toMountPoint, savedObjectsTagging, FormattedRelative } = services;
const { core, savedObjectsTagging, FormattedRelative } = services;
const { application, http, notifications, ...startServices } = core;

const searchQueryParser = useMemo(() => {
if (savedObjectsTagging) {
Expand Down Expand Up @@ -220,30 +218,26 @@ export const TableListViewKibanaProvider: FC<

return (
<RedirectAppLinksKibanaProvider coreStart={core}>
<ContentEditorKibanaProvider
core={core}
toMountPoint={toMountPoint}
savedObjectsTagging={savedObjectsTagging}
>
<ContentEditorKibanaProvider core={core} savedObjectsTagging={savedObjectsTagging}>
<TableListViewProvider
canEditAdvancedSettings={Boolean(core.application.capabilities.advancedSettings?.save)}
canEditAdvancedSettings={Boolean(application.capabilities.advancedSettings?.save)}
getListingLimitSettingsUrl={() =>
core.application.getUrlForApp('management', {
application.getUrlForApp('management', {
path: `/kibana/settings?query=savedObjects:listingLimit`,
})
}
notifyError={(title, text) => {
core.notifications.toasts.addDanger({ title: toMountPoint(title), text });
notifications.toasts.addDanger({ title: toMountPoint(title, startServices), text });
}}
searchQueryParser={searchQueryParser}
DateFormatterComp={(props) => <FormattedRelative {...props} />}
currentAppId$={core.application.currentAppId$}
navigateToUrl={core.application.navigateToUrl}
currentAppId$={application.currentAppId$}
navigateToUrl={application.navigateToUrl}
getTagList={getTagList}
TagList={TagList}
itemHasTags={itemHasTags}
getTagIdsFromReferences={getTagIdsFromReferences}
getTagManagementUrl={() => core.http.basePath.prepend(TAG_MANAGEMENT_APP_URL)}
getTagManagementUrl={() => http.basePath.prepend(TAG_MANAGEMENT_APP_URL)}
>
{children}
</TableListViewProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"@kbn/shared-ux-link-redirect-app",
"@kbn/test-jest-helpers",
"@kbn/content-management-table-list-view-common",
"@kbn/core",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably nit: I prefer to depend on specific packages types in packages instead of depending on the whole core

"@kbn/react-kibana-mount",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TableListViewKibanaProvider,
} from '@kbn/content-management-table-list-view-table';

import { toMountPoint, useExecutionContext } from '@kbn/kibana-react-plugin/public';
import { useExecutionContext } from '@kbn/kibana-react-plugin/public';

import { pluginServices } from '../services/plugin_services';

Expand All @@ -35,10 +35,12 @@ export const DashboardListing = ({
useSessionStorageIntegration,
}: DashboardListingProps) => {
const {
analytics,
application,
notifications,
overlays,
http,
i18n,
chrome: { theme },
savedObjectsTagging,
coreContext: { executionContext },
Expand Down Expand Up @@ -70,13 +72,14 @@ export const DashboardListing = ({
<TableListViewKibanaProvider
{...{
core: {
analytics,
application: application as TableListViewApplicationService,
notifications,
overlays,
http,
i18n,
theme,
},
toMountPoint,
savedObjectsTagging: savedObjectsTaggingFakePlugin,
FormattedRelative,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TableListViewTable,
} from '@kbn/content-management-table-list-view-table';

import { toMountPoint, useExecutionContext } from '@kbn/kibana-react-plugin/public';
import { useExecutionContext } from '@kbn/kibana-react-plugin/public';

import { pluginServices } from '../services/plugin_services';

Expand All @@ -37,10 +37,12 @@ export const DashboardListingTable = ({
showCreateDashboardButton = true,
}: DashboardListingProps) => {
const {
analytics,
application,
notifications,
overlays,
http,
i18n,
savedObjectsTagging,
coreContext: { executionContext },
chrome: { theme },
Expand Down Expand Up @@ -77,20 +79,21 @@ export const DashboardListingTable = ({

const core = useMemo(
() => ({
analytics,
application: application as TableListViewApplicationService,
notifications,
overlays,
http,
i18n,
theme,
}),
[application, notifications, overlays, http, theme]
[application, notifications, overlays, http, analytics, i18n, theme]
);

return (
<I18nProvider>
<TableListViewKibanaProvider
core={core}
toMountPoint={toMountPoint}
savedObjectsTagging={savedObjectsTaggingFakePlugin}
FormattedRelative={FormattedRelative}
>
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/dashboard/public/services/i18n/i18n.stub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { coreMock } from '@kbn/core/public/mocks';
import { PluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { DashboardI18nService } from './types';

type I18nServiceFactory = PluginServiceFactory<DashboardI18nService>;

export const i18nServiceFactory: I18nServiceFactory = () => {
const { i18n } = coreMock.createStart();

return i18n;
};
21 changes: 21 additions & 0 deletions src/plugins/dashboard/public/services/i18n/i18n_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { KibanaPluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import type { DashboardStartDependencies } from '../../plugin';
import type { DashboardI18nService } from './types';

export type I18nServiceFactory = KibanaPluginServiceFactory<
DashboardI18nService,
DashboardStartDependencies
>;
export const i18nServiceFactory: I18nServiceFactory = ({ coreStart }) => {
const { i18n } = coreStart;

return i18n;
};
11 changes: 11 additions & 0 deletions src/plugins/dashboard/public/services/i18n/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { CoreStart } from '@kbn/core/public';

export type DashboardI18nService = CoreStart['i18n'];