Skip to content

Commit

Permalink
Update variable names, use of I18nContext (use NP) and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Dec 9, 2019
1 parent 991cee2 commit 0ed3d4b
Show file tree
Hide file tree
Showing 28 changed files with 99 additions and 104 deletions.
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/watcher/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { i18n } from '@kbn/i18n';
/* Legacy UI imports */
import { npSetup, npStart } from 'ui/new_platform';
import routes from 'ui/routes';
import { I18nContext } from 'ui/i18n';
import { management, MANAGEMENT_BREADCRUMB } from 'ui/management';
// @ts-ignore
import { TimeBuckets } from 'ui/time_buckets';
Expand Down Expand Up @@ -63,7 +62,6 @@ routes.when('/management/elasticsearch/watcher/:param1?/:param2?/:param3?/:param
...(npSetup.plugins as typeof npSetup.plugins & { eui_utils: any }),
__LEGACY: {
MANAGEMENT_BREADCRUMB,
I18nContext,
TimeBuckets,
licenseStatus,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import { SavedObjectsClientContract } from 'src/core/public';

import { App, AppDeps } from './app';
import { setHttpClient, setSavedObjectsClient } from './lib/api';
import { BootLegacyDependencies } from '../types';
import { LegacyDependencies } from '../types';

interface BootDeps extends AppDeps {
element: HTMLElement;
savedObjects: SavedObjectsClientContract;
legacy: BootLegacyDependencies;
I18nContext: any;
legacy: LegacyDependencies;
}

export const boot = (bootDeps: BootDeps) => {
const { element, legacy, savedObjects, ...appDeps } = bootDeps;
const { I18nContext, ...appLegacyDeps } = legacy;
const { I18nContext, element, legacy, savedObjects, ...appDeps } = bootDeps;

setHttpClient(appDeps.http);
setSavedObjectsClient(savedObjects);

render(
<I18nContext>
<App {...{ ...appDeps, legacy: appLegacyDeps }} />
<App {...{ ...appDeps, legacy }} />
</I18nContext>,
element
);
Expand Down
10 changes: 6 additions & 4 deletions x-pack/legacy/plugins/watcher/public/np_ready/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import { Plugin, CoreSetup, CoreStart } from 'src/core/public';

import { BootLegacyDependencies } from './types';
import { LegacyDependencies } from './types';

interface LegacyPlugins {
__LEGACY: BootLegacyDependencies;
__LEGACY: LegacyDependencies;
}

export class WatcherUIPlugin implements Plugin<void, void, LegacyPlugins, any> {
Expand All @@ -25,9 +25,10 @@ export class WatcherUIPlugin implements Plugin<void, void, LegacyPlugins, any> {
core: {
docLinks,
chrome,
// Will be passed through in future, remove @ts-ignore when shim is removed or types are updated
// Waiting for types to be updated.
// @ts-ignore
savedObjects,
i18n: { Context: I18nContext },
},
},
{ element }
Expand All @@ -42,7 +43,8 @@ export class WatcherUIPlugin implements Plugin<void, void, LegacyPlugins, any> {
docLinks,
chrome,
euiUtils,
savedObjects,
savedObjects: savedObjects.client,
I18nContext,
legacy: {
...__LEGACY,
},
Expand Down
4 changes: 0 additions & 4 deletions x-pack/legacy/plugins/watcher/public/np_ready/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ export interface LegacyDependencies {
TimeBuckets: any;
licenseStatus: any;
}

export interface BootLegacyDependencies extends LegacyDependencies {
I18nContext: any;
}
19 changes: 9 additions & 10 deletions x-pack/legacy/plugins/watcher/server/np_ready/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Plugin, CoreSetup } from 'src/core/server';
import { i18n } from '@kbn/i18n';
import { PLUGIN } from '../../common/constants';
import { ServerShim, NPServer } from './types';
import { ServerShim, RouteDependencies } from './types';

import { registerLicenseChecker } from '../../../../server/lib/register_license_checker';
import { registerSettingsRoutes } from './routes/api/settings';
Expand All @@ -21,7 +20,7 @@ import { registerLoadHistoryRoute } from './routes/api/register_load_history_rou
export class WatcherServerPlugin implements Plugin<void, void, any, any> {
async setup({ http }: CoreSetup, { __LEGACY: serverShim }: { __LEGACY: ServerShim }) {
const router = http.createRouter();
const npServer: NPServer = {
const routeDependencies: RouteDependencies = {
router,
};
// Register license checker
Expand All @@ -32,13 +31,13 @@ export class WatcherServerPlugin implements Plugin<void, void, any, any> {
PLUGIN.MINIMUM_LICENSE_REQUIRED
);

registerListFieldsRoute(npServer, serverShim);
registerLoadHistoryRoute(npServer, serverShim);
registerIndicesRoutes(npServer, serverShim);
registerLicenseRoutes(npServer, serverShim);
registerSettingsRoutes(npServer, serverShim);
registerWatchesRoutes(npServer, serverShim);
registerWatchRoutes(npServer, serverShim);
registerListFieldsRoute(routeDependencies, serverShim);
registerLoadHistoryRoute(routeDependencies, serverShim);
registerIndicesRoutes(routeDependencies, serverShim);
registerLicenseRoutes(routeDependencies, serverShim);
registerSettingsRoutes(routeDependencies, serverShim);
registerWatchesRoutes(routeDependencies, serverShim);
registerWatchRoutes(routeDependencies, serverShim);
}
start() {}
stop() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { reduce, size } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';

function getIndexNamesFromAliasesResponse(json: Record<string, any>) {
return reduce(
Expand Down Expand Up @@ -60,7 +60,7 @@ function getIndices(callWithRequest: any, pattern: string, limit = 10) {
});
}

export function registerGetRoute(server: NPServer, legacy: ServerShim) {
export function registerGetRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(legacy, request);
Expand All @@ -80,7 +80,7 @@ export function registerGetRoute(server: NPServer, legacy: ServerShim) {
}
};

server.router.post(
deps.router.post(
{
path: '/api/watcher/indices',
validate: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { registerGetRoute } from './register_get_route';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';

export function registerIndicesRoutes(server: NPServer, legacy: ServerShim) {
registerGetRoute(server, legacy);
export function registerIndicesRoutes(deps: RouteDependencies, legacy: ServerShim) {
registerGetRoute(deps, legacy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { registerRefreshRoute } from './register_refresh_route';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';

export function registerLicenseRoutes(server: NPServer, legacy: ServerShim) {
registerRefreshRoute(server, legacy);
export function registerLicenseRoutes(deps: RouteDependencies, legacy: ServerShim) {
registerRefreshRoute(deps, legacy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

import { RequestHandler } from 'src/core/server';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';

/*
In order for the client to have the most up-to-date snapshot of the current license,
it needs to make a round-trip to the kibana server. This refresh endpoint is provided
for when the client needs to check the license, but doesn't need to pull data from the
server for any reason, i.e., when adding a new watch.
*/
export function registerRefreshRoute(server: NPServer, legacy: ServerShim) {
export function registerRefreshRoute(deps: RouteDependencies, legacy: ServerShim) {
const handler: RequestHandler<any, any, any> = (ctx, request, response) => {
return response.ok({ body: { success: true } });
};

server.router.get(
deps.router.get(
{
path: '/api/watcher/license/refresh',
validate: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isEsErrorFactory } from '../../lib/is_es_error_factory';
import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory';
// @ts-ignore
import { Fields } from '../../models/fields';
import { NPServer, ServerShim } from '../../types';
import { RouteDependencies, ServerShim } from '../../types';

function fetchFields(callWithRequest: any, indexes: string[]) {
const params = {
Expand All @@ -24,7 +24,7 @@ function fetchFields(callWithRequest: any, indexes: string[]) {
return callWithRequest('fieldCaps', params);
}

export function registerListFieldsRoute(server: NPServer, legacy: ServerShim) {
export function registerListFieldsRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);

const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
Expand Down Expand Up @@ -52,7 +52,7 @@ export function registerListFieldsRoute(server: NPServer, legacy: ServerShim) {
}
};

server.router.post(
deps.router.post(
{
path: '/api/watcher/fields',
validate: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { callWithRequestFactory } from '../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../lib/is_es_error_factory';
import { INDEX_NAMES } from '../../../../common/constants';
import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory';
import { NPServer, ServerShim } from '../../types';
import { RouteDependencies, ServerShim } from '../../types';
// @ts-ignore
import { WatchHistoryItem } from '../../models/watch_history_item';

Expand All @@ -28,7 +28,7 @@ function fetchHistoryItem(callWithRequest: any, watchHistoryItemId: string) {
});
}

export function registerLoadHistoryRoute(server: NPServer, legacy: ServerShim) {
export function registerLoadHistoryRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(legacy, request);
Expand Down Expand Up @@ -64,7 +64,7 @@ export function registerLoadHistoryRoute(server: NPServer, legacy: ServerShim) {
}
};

server.router.get(
deps.router.get(
{
path: '/api/watcher/history/{id}',
validate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
// @ts-ignore
import { Settings } from '../../../models/settings';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';

function fetchClusterSettings(callWithInternalUser: any) {
return callWithInternalUser('cluster.getSettings', {
Expand All @@ -19,7 +19,7 @@ function fetchClusterSettings(callWithInternalUser: any) {
});
}

export function registerLoadRoute(server: NPServer, legacy: ServerShim) {
export function registerLoadRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
try {
Expand All @@ -37,7 +37,7 @@ export function registerLoadRoute(server: NPServer, legacy: ServerShim) {
};
const callWithInternalUser = callWithInternalUserFactory(legacy);

server.router.get(
deps.router.get(
{
path: '/api/watcher/settings',
validate: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { registerLoadRoute } from './register_load_route';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';

export function registerSettingsRoutes(server: NPServer, legacy: ServerShim) {
registerLoadRoute(server, legacy);
export function registerSettingsRoutes(deps: RouteDependencies, legacy: ServerShim) {
registerLoadRoute(deps, legacy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import { schema } from '@kbn/config-schema';
import { get } from 'lodash';
import { RequestHandler } from 'kibana/server';
import { RequestHandler } from 'src/core/server';
import { callWithRequestFactory } from '../../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../../lib/is_es_error_factory';
import { licensePreRoutingFactory } from '../../../../lib/license_pre_routing_factory';
// @ts-ignore
import { WatchStatus } from '../../../../models/watch_status';
import { NPServer, ServerShim } from '../../../../types';
import { RouteDependencies, ServerShim } from '../../../../types';

function acknowledgeAction(callWithRequest: any, watchId: string, actionId: string) {
return callWithRequest('watcher.ackWatch', {
Expand All @@ -21,7 +21,7 @@ function acknowledgeAction(callWithRequest: any, watchId: string, actionId: stri
});
}

export function registerAcknowledgeRoute(server: NPServer, legacy: ServerShim) {
export function registerAcknowledgeRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(legacy, request);
Expand Down Expand Up @@ -51,7 +51,7 @@ export function registerAcknowledgeRoute(server: NPServer, legacy: ServerShim) {
}
};

server.router.put(
deps.router.put(
{
path: '/api/watcher/watch/{watchId}/action/{actionId}/acknowledge',
validate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { registerAcknowledgeRoute } from './register_acknowledge_route';
import { NPServer, ServerShim } from '../../../../types';
import { RouteDependencies, ServerShim } from '../../../../types';

export function registerActionRoutes(server: NPServer, legacy: ServerShim) {
export function registerActionRoutes(server: RouteDependencies, legacy: ServerShim) {
registerAcknowledgeRoute(server, legacy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { get } from 'lodash';
import { callWithRequestFactory } from '../../../lib/call_with_request_factory';
import { isEsErrorFactory } from '../../../lib/is_es_error_factory';
import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory';
import { NPServer, ServerShim } from '../../../types';
import { RouteDependencies, ServerShim } from '../../../types';
// @ts-ignore
import { WatchStatus } from '../../../models/watch_status';

Expand All @@ -20,7 +20,7 @@ function activateWatch(callWithRequest: any, watchId: string) {
});
}

export function registerActivateRoute(server: NPServer, legacy: ServerShim) {
export function registerActivateRoute(deps: RouteDependencies, legacy: ServerShim) {
const isEsError = isEsErrorFactory(legacy);
const handler: RequestHandler<any, any, any> = async (ctx, request, response) => {
const callWithRequest = callWithRequestFactory(legacy, request);
Expand Down Expand Up @@ -53,7 +53,7 @@ export function registerActivateRoute(server: NPServer, legacy: ServerShim) {
}
};

server.router.put(
deps.router.put(
{
path: '/api/watcher/watch/{watchId}/activate',
validate: {
Expand Down
Loading

0 comments on commit 0ed3d4b

Please sign in to comment.