Skip to content

Commit 50c22dc

Browse files
committed
plugins-pkg: Add basic types declaration files
We should allow plugin developers to use types related to plugins when then develop them. The whole external plugin development story is still being defined though, so for now we just export the types for the plugin registry, Plugin class, and the router types they depend on. Hopefully in the short term we will be able to provide a more solid and defined package for defining plugins.
1 parent 8e38d69 commit 50c22dc

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

plugins-pkg/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"files": [
2121
"bin",
22-
"config"
22+
"config",
23+
"types"
2324
],
2425
"keywords": [
2526
"headlamp",

plugins-pkg/types/lib/router.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="react" />
2+
export interface Route {
3+
path: string;
4+
exact?: boolean;
5+
name?: string;
6+
noCluster?: boolean;
7+
noAuthRequired?: boolean;
8+
sidebar: string | null;
9+
component: () => JSX.Element;
10+
}
11+
export declare const ROUTES: {
12+
[routeName: string]: Route;
13+
};
14+
export declare function getRoute(routeName: string): Route;
15+
export declare function getRoutePath(route: Route): string;
16+
export interface RouteURLProps {
17+
cluster?: string;
18+
[prop: string]: any;
19+
}
20+
export declare function createRouteURL(routeName: string, params?: RouteURLProps): string;

plugins-pkg/types/plugin/index.d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Registry from './registry';
2+
export declare abstract class Plugin {
3+
abstract initialize(register: Registry): boolean;
4+
}
5+
declare global {
6+
interface Window {
7+
pluginLib: {
8+
[libName: string]: any;
9+
};
10+
plugins: {
11+
[pluginId: string]: Plugin;
12+
};
13+
registerPlugin: (pluginId: string, pluginObj: Plugin) => void;
14+
}
15+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference types="react" />
2+
import { Route } from '../lib/router';
3+
export default class Registry {
4+
registerSidebarItem(parentName: string, itemName: string, itemLabel: string, url: string, opts?: {
5+
useClusterURL: boolean;
6+
}): void;
7+
registerRoute(routeSpec: Route): void;
8+
registerDetailsViewHeaderAction(actionName: string, actionFunc: (...args: any[]) => JSX.Element | null): void;
9+
registerAppBarAction(actionName: string, actionFunc: (...args: any[]) => JSX.Element | null): void;
10+
}

0 commit comments

Comments
 (0)