Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Feb 10, 2021
1 parent 279c622 commit a473946
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 450 deletions.
8 changes: 8 additions & 0 deletions src/plugins/deprecations/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
/*
* 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.
*/

export const PLUGIN_ID = 'deprecations';
export const PLUGIN_NAME = 'deprecations';
4 changes: 2 additions & 2 deletions src/plugins/deprecations/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["navigation"],
"ui": false,
"requiredPlugins": [],
"optionalPlugins": []
}
31 changes: 0 additions & 31 deletions src/plugins/deprecations/public/application.tsx

This file was deleted.

124 changes: 0 additions & 124 deletions src/plugins/deprecations/public/components/app.tsx

This file was deleted.

Empty file.
10 changes: 0 additions & 10 deletions src/plugins/deprecations/public/index.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/plugins/deprecations/public/plugin.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/plugins/deprecations/public/types.ts

This file was deleted.

20 changes: 5 additions & 15 deletions src/plugins/deprecations/server/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,24 @@
* Side Public License, v 1.
*/

interface DeprecationInfo {
message: string;
documentationUrl: string;
level: 'critical' | 'warning';
correctiveAction?: () => void;
}

interface PluginDeprecation {
pluginId: string;
getDeprecations: () => Promise<DeprecationInfo>;
}
import { DeprecationInfo, DeprecationContext } from './types';

export class Deprecations {
private readonly deprecations: { [key: string]: PluginDeprecation } = {};
private readonly deprecations: { [key: string]: DeprecationContext } = {};

public registerDeprecations = (deprecation: PluginDeprecation) => {
public registerDeprecations = (deprecation: DeprecationContext) => {
if (this.deprecations[deprecation.pluginId]) {
throw new Error(`Plugin "${deprecation.pluginId}" is duplicated.`);
}

this.deprecations[deprecation.pluginId] = deprecation;
};

public getDeprecationsByPluginId = (pluginId: string) => {
public getDeprecationInfoByPluginId = (pluginId: string) => {
return this.deprecations[pluginId];
};

public getDeprecations = () => {
public getDeprecationInfo = () => {
return this.deprecations;
};
}
2 changes: 2 additions & 0 deletions src/plugins/deprecations/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
import { PluginInitializerContext } from 'src/core/server';
import { DeprecationsPlugin } from './plugin';

export { DeprecationDependencies, DeprecationInfo, DeprecationContext } from './types';

export const plugin = (initializerContext: PluginInitializerContext) =>
new DeprecationsPlugin(initializerContext);
35 changes: 25 additions & 10 deletions src/plugins/deprecations/server/routes/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { IRouter } from 'src/core/server';
import { DeprecationDependencies, DeprecationInfo, DeprecationContext } from '../types';

export function registerDeprecationRoutes(router: IRouter, deprecations: any) {
router.get(
Expand All @@ -15,24 +16,38 @@ export function registerDeprecationRoutes(router: IRouter, deprecations: any) {
validate: false,
},
async (context, request, response) => {
const deps = deprecations.getDeprecations();
const deprecationInfo: DeprecationContext = deprecations.getDeprecationInfo();

const esClient = context.core.elasticsearch.client;
const dependencies: DeprecationDependencies = {
esClient: context.core.elasticsearch.client,
savedObjectsClient: context.core.savedObjects.client,
};

const allDeps = await Promise.all(
Object.entries(deps).map(async ([key, value]) => {
const pluginDeprecations = await value.getDeprecations(esClient);
const pluginDeprecationsWithId = pluginDeprecations.map((deps) => ({
...deps,
pluginId: key,
const pluginDeprecationsList = await Promise.all(
Object.entries(deprecationInfo).map(async ([pluginId, deprecationInfoContext]) => {
const pluginDeprecations: DeprecationInfo[] = await deprecationInfoContext.getDeprecations(
dependencies
);
const pluginDeprecationsWithId = pluginDeprecations.map((pluginDeprecation) => ({
...pluginDeprecation,
pluginId,
}));
return pluginDeprecationsWithId;
})
);
).catch((error) => {
// TODO handle error
// eslint-disable-next-line no-console
console.log('error', error);
});

const flattenedPluginDeprecationsList =
pluginDeprecationsList && pluginDeprecationsList.length
? pluginDeprecationsList.flat()
: [];

return response.ok({
body: {
deprecations: allDeps.flat(),
deprecations: flattenedPluginDeprecationsList,
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/deprecations/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import { IRouter } from 'src/core/server';
import { registerDeprecationRoutes } from './deprecations';

export { DeprecationDependencies } from './deprecations';

export function setupRoutes({ router, deprecations }: { router: IRouter; deprecations: any }) {
registerDeprecationRoutes(router, deprecations);
}
27 changes: 27 additions & 0 deletions src/plugins/deprecations/server/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
/*
* 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 { IScopedClusterClient, SavedObjectsClientContract } from 'src/core/server';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DeprecationsPluginSetup {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DeprecationsPluginStart {}

export interface DeprecationDependencies {
esClient: IScopedClusterClient;
savedObjectsClient: SavedObjectsClientContract;
}

export interface DeprecationInfo {
message: string;
level: 'warning' | 'critical';
documentationUrl?: string;
correctionAction?: () => void;
}
export interface DeprecationContext {
pluginId: string;
getDeprecations: Promise<DeprecationInfo>;
}
Loading

0 comments on commit a473946

Please sign in to comment.