mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[canvas] Create Nav Link service; remove legacy service (#107346)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
3bd9ff361d
commit
2d17071c9f
11 changed files with 59 additions and 52 deletions
|
@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
|
|||
import { History } from 'history';
|
||||
// @ts-expect-error
|
||||
import createHashStateHistory from 'history-extra/dist/createHashStateHistory';
|
||||
import { useServices } from '../../services';
|
||||
import { useNavLinkService } from '../../services';
|
||||
// @ts-expect-error
|
||||
import { shortcutManager } from '../../lib/shortcut_manager';
|
||||
import { CanvasRouter } from '../../routes';
|
||||
|
@ -31,11 +31,11 @@ class ShortcutManagerContextWrapper extends React.Component {
|
|||
|
||||
export const App: FC = () => {
|
||||
const historyRef = useRef<History>(createHashStateHistory() as History);
|
||||
const services = useServices();
|
||||
const { updatePath } = useNavLinkService();
|
||||
|
||||
useEffect(() => {
|
||||
return historyRef.current.listen(({ pathname }) => {
|
||||
services.navLink.updatePath(pathname);
|
||||
updatePath(pathname);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ export * from './legacy';
|
|||
|
||||
import { PluginServices } from '../../../../../src/plugins/presentation_util/public';
|
||||
import { CanvasWorkpadService } from './workpad';
|
||||
import { CanvasNavLinkService } from './nav_link';
|
||||
import { CanvasNotifyService } from './notify';
|
||||
import { CanvasPlatformService } from './platform';
|
||||
|
||||
|
@ -16,10 +17,12 @@ export interface CanvasPluginServices {
|
|||
workpad: CanvasWorkpadService;
|
||||
notify: CanvasNotifyService;
|
||||
platform: CanvasPlatformService;
|
||||
navLink: CanvasNavLinkService;
|
||||
}
|
||||
|
||||
export const pluginServices = new PluginServices<CanvasPluginServices>();
|
||||
|
||||
export const useWorkpadService = () => (() => pluginServices.getHooks().workpad.useService())();
|
||||
export const useNavLinkService = () => (() => pluginServices.getHooks().navLink.useService())();
|
||||
export const useNotifyService = () => (() => pluginServices.getHooks().notify.useService())();
|
||||
export const usePlatformService = () => (() => pluginServices.getHooks().platform.useService())();
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
} from '../../../../../../src/plugins/presentation_util/public';
|
||||
|
||||
import { workpadServiceFactory } from './workpad';
|
||||
import { navLinkServiceFactory } from './nav_link';
|
||||
import { notifyServiceFactory } from './notify';
|
||||
import { platformServiceFactory } from './platform';
|
||||
import { CanvasPluginServices } from '..';
|
||||
|
@ -27,6 +28,7 @@ export const pluginServiceProviders: PluginServiceProviders<
|
|||
KibanaPluginServiceParams<CanvasStartDeps>
|
||||
> = {
|
||||
workpad: new PluginServiceProvider(workpadServiceFactory),
|
||||
navLink: new PluginServiceProvider(navLinkServiceFactory),
|
||||
notify: new PluginServiceProvider(notifyServiceFactory),
|
||||
platform: new PluginServiceProvider(platformServiceFactory),
|
||||
};
|
||||
|
|
28
x-pack/plugins/canvas/public/services/kibana/nav_link.ts
Normal file
28
x-pack/plugins/canvas/public/services/kibana/nav_link.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { KibanaPluginServiceFactory } from '../../../../../../src/plugins/presentation_util/public';
|
||||
|
||||
import { SESSIONSTORAGE_LASTPATH } from '../../../common/lib/constants';
|
||||
import { getSessionStorage } from '../../lib/storage';
|
||||
import { CanvasStartDeps } from '../../plugin';
|
||||
import { CanvasNavLinkService } from '../nav_link';
|
||||
|
||||
export type CanvasNavLinkServiceFactory = KibanaPluginServiceFactory<
|
||||
CanvasNavLinkService,
|
||||
CanvasStartDeps
|
||||
>;
|
||||
|
||||
export const navLinkServiceFactory: CanvasNavLinkServiceFactory = ({ coreStart, appUpdater }) => ({
|
||||
updatePath: (path: string) => {
|
||||
appUpdater?.next(() => ({
|
||||
defaultPath: `#${path}`,
|
||||
}));
|
||||
|
||||
getSessionStorage().set(`${SESSIONSTORAGE_LASTPATH}:${coreStart.http.basePath.get()}`, path);
|
||||
},
|
||||
});
|
|
@ -22,7 +22,6 @@ export interface WithServicesProps {
|
|||
const defaultContextValue = {
|
||||
embeddables: {},
|
||||
expressions: {},
|
||||
navLink: {},
|
||||
search: {},
|
||||
};
|
||||
|
||||
|
@ -31,7 +30,6 @@ export const ServicesContext = createContext<CanvasServices>(defaultContextValue
|
|||
export const useServices = () => useContext(ServicesContext);
|
||||
export const useEmbeddablesService = () => useServices().embeddables;
|
||||
export const useExpressionsService = () => useServices().expressions;
|
||||
export const useNavLinkService = () => useServices().navLink;
|
||||
export const useLabsService = () => useServices().labs;
|
||||
export const useReportingService = () => useServices().reporting;
|
||||
|
||||
|
@ -49,7 +47,6 @@ export const LegacyServicesProvider: FC<{
|
|||
const value = {
|
||||
embeddables: specifiedProviders.embeddables.getService(),
|
||||
expressions: specifiedProviders.expressions.getService(),
|
||||
navLink: specifiedProviders.navLink.getService(),
|
||||
search: specifiedProviders.search.getService(),
|
||||
reporting: specifiedProviders.reporting.getService(),
|
||||
labs: specifiedProviders.labs.getService(),
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import { BehaviorSubject } from 'rxjs';
|
||||
import { CoreSetup, CoreStart, AppUpdater } from '../../../../../../src/core/public';
|
||||
import { CanvasSetupDeps, CanvasStartDeps } from '../../plugin';
|
||||
import { navLinkServiceFactory } from './nav_link';
|
||||
import { embeddablesServiceFactory } from './embeddables';
|
||||
import { expressionsServiceFactory } from './expressions';
|
||||
import { searchServiceFactory } from './search';
|
||||
|
@ -16,7 +15,6 @@ import { labsServiceFactory } from './labs';
|
|||
import { reportingServiceFactory } from './reporting';
|
||||
|
||||
export { SearchService } from './search';
|
||||
export { NavLinkService } from './nav_link';
|
||||
export { EmbeddablesService } from './embeddables';
|
||||
export { ExpressionsService } from '../../../../../../src/plugins/expressions/common';
|
||||
export * from './context';
|
||||
|
@ -75,7 +73,6 @@ export type ServiceFromProvider<P> = P extends CanvasServiceProvider<infer T> ?
|
|||
export const services = {
|
||||
embeddables: new CanvasServiceProvider(embeddablesServiceFactory),
|
||||
expressions: new CanvasServiceProvider(expressionsServiceFactory),
|
||||
navLink: new CanvasServiceProvider(navLinkServiceFactory),
|
||||
search: new CanvasServiceProvider(searchServiceFactory),
|
||||
reporting: new CanvasServiceProvider(reportingServiceFactory),
|
||||
labs: new CanvasServiceProvider(labsServiceFactory),
|
||||
|
@ -86,7 +83,6 @@ export type CanvasServiceProviders = typeof services;
|
|||
export interface CanvasServices {
|
||||
embeddables: ServiceFromProvider<typeof services.embeddables>;
|
||||
expressions: ServiceFromProvider<typeof services.expressions>;
|
||||
navLink: ServiceFromProvider<typeof services.navLink>;
|
||||
search: ServiceFromProvider<typeof services.search>;
|
||||
reporting: ServiceFromProvider<typeof services.reporting>;
|
||||
labs: ServiceFromProvider<typeof services.labs>;
|
||||
|
@ -112,7 +108,6 @@ export const stopServices = () => {
|
|||
|
||||
export const {
|
||||
embeddables: embeddableService,
|
||||
navLink: navLinkService,
|
||||
expressions: expressionsService,
|
||||
search: searchService,
|
||||
reporting: reportingService,
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { CanvasServiceFactory } from '.';
|
||||
import { SESSIONSTORAGE_LASTPATH } from '../../../common/lib/constants';
|
||||
import { getSessionStorage } from '../../lib/storage';
|
||||
|
||||
export interface NavLinkService {
|
||||
updatePath: (path: string) => void;
|
||||
}
|
||||
|
||||
export const navLinkServiceFactory: CanvasServiceFactory<NavLinkService> = (
|
||||
coreSetup,
|
||||
_coreStart,
|
||||
_setupPlugins,
|
||||
_startPlugins,
|
||||
appUpdater
|
||||
) => {
|
||||
return {
|
||||
updatePath: (path: string) => {
|
||||
appUpdater.next(() => ({
|
||||
defaultPath: `#${path}`,
|
||||
}));
|
||||
|
||||
getSessionStorage().set(`${SESSIONSTORAGE_LASTPATH}:${coreSetup.http.basePath.get()}`, path);
|
||||
},
|
||||
};
|
||||
};
|
|
@ -9,7 +9,6 @@ import { CanvasServices, services } from '../';
|
|||
import { embeddablesService } from './embeddables';
|
||||
import { expressionsService } from './expressions';
|
||||
import { reportingService } from './reporting';
|
||||
import { navLinkService } from './nav_link';
|
||||
import { labsService } from './labs';
|
||||
import { searchService } from './search';
|
||||
|
||||
|
@ -17,7 +16,6 @@ export const stubs: CanvasServices = {
|
|||
embeddables: embeddablesService,
|
||||
expressions: expressionsService,
|
||||
reporting: reportingService,
|
||||
navLink: navLinkService,
|
||||
search: searchService,
|
||||
labs: labsService,
|
||||
};
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { NavLinkService } from '../nav_link';
|
||||
|
||||
const noop = (..._args: any[]): any => {};
|
||||
|
||||
export const navLinkService: NavLinkService = {
|
||||
updatePath: noop,
|
||||
};
|
||||
export interface CanvasNavLinkService {
|
||||
updatePath: (path: string) => void;
|
||||
}
|
|
@ -15,15 +15,18 @@ import {
|
|||
|
||||
import { CanvasPluginServices } from '..';
|
||||
import { workpadServiceFactory } from './workpad';
|
||||
import { navLinkServiceFactory } from './nav_link';
|
||||
import { notifyServiceFactory } from './notify';
|
||||
import { platformServiceFactory } from './platform';
|
||||
|
||||
export { workpadServiceFactory } from './workpad';
|
||||
export { navLinkServiceFactory } from './nav_link';
|
||||
export { notifyServiceFactory } from './notify';
|
||||
export { platformServiceFactory } from './platform';
|
||||
|
||||
export const pluginServiceProviders: PluginServiceProviders<CanvasPluginServices> = {
|
||||
workpad: new PluginServiceProvider(workpadServiceFactory),
|
||||
navLink: new PluginServiceProvider(navLinkServiceFactory),
|
||||
notify: new PluginServiceProvider(notifyServiceFactory),
|
||||
platform: new PluginServiceProvider(platformServiceFactory),
|
||||
};
|
||||
|
|
17
x-pack/plugins/canvas/public/services/stubs/nav_link.ts
Normal file
17
x-pack/plugins/canvas/public/services/stubs/nav_link.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { PluginServiceFactory } from '../../../../../../src/plugins/presentation_util/public';
|
||||
import { CanvasNavLinkService } from '../nav_link';
|
||||
|
||||
type CanvasNavLinkServiceFactory = PluginServiceFactory<CanvasNavLinkService>;
|
||||
|
||||
const noop = (..._args: any[]): any => {};
|
||||
|
||||
export const navLinkServiceFactory: CanvasNavLinkServiceFactory = () => ({
|
||||
updatePath: noop,
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue