@openshift-console/dynamic-plugin-sdk
Version:
Provides core APIs, types and utilities used by dynamic plugins at runtime.
169 lines (168 loc) • 11.2 kB
TypeScript
import { K8sModel } from '../api/common-types';
import { Extension, ExtensionDeclaration, CodeRef, ResolvedExtension } from '../types';
import { K8sResourceCommon, PrometheusResponse, ResourcesObject, StatusGroupMapper, WatchK8sResources, WatchK8sResults, FirehoseResource, FirehoseResult } from './console-types';
import { CardSpan, GetOperatorsWithStatuses, K8sActivityProps, OperatorRowProps, PrometheusActivityProps, PrometheusHealthHandler, PrometheusHealthPopupProps, ResourceHealthHandler, URLHealthHandler } from './dashboard-types';
/** Adds a new dashboard tab, placed after the Overview tab. */
export type DashboardsTab = ExtensionDeclaration<'console.dashboards/tab', {
/** A unique tab identifier, used as tab link `href` and when adding cards to this tab. */
id: string;
/** NavSection to which the tab belongs to */
navSection: 'home' | 'storage';
/** The title of the tab. */
title: string;
}>;
/** Adds a new dashboard card. */
export type DashboardsCard = ExtensionDeclaration<'console.dashboards/card', {
/** The id of the dashboard tab to which the card will be added. */
tab: string;
/** The grid position of the card on the dashboard. */
position: 'LEFT' | 'RIGHT' | 'MAIN';
/** Dashboard card component. */
component: CodeRef<React.ComponentType>;
/** Card's vertical span in the column. Ignored for small screens, defaults to 12. */
span?: CardSpan;
}>;
/** Adds a health subsystem to the status card of Overview dashboard where the source of status is Prometheus. */
export type DashboardsOverviewHealthPrometheusSubsystem = ExtensionDeclaration<'console.dashboards/overview/health/prometheus', {
/** The display name of the subsystem. */
title: string;
/** The Prometheus queries */
queries: string[];
/** Resolve the subsystem's health. */
healthHandler: CodeRef<PrometheusHealthHandler>;
/** Additional resource which will be fetched and passed to `healthHandler`. */
additionalResource?: CodeRef<FirehoseResource>;
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
popupComponent?: CodeRef<React.ComponentType<PrometheusHealthPopupProps>>;
/** The title of the popover. */
popupTitle?: string;
/** Optional classname for the popup top-level component. */
popupClassname?: string;
/** If true, the popup will stay open when clicked outside of its boundary. Default: false */
popupKeepOnOutsideClick?: boolean;
/** Control plane topology for which the subsystem should be hidden. */
disallowedControlPlaneTopology?: string[];
}>;
/** Adds a health subsystem to the status card of Overview dashboard where the source of status is a K8s REST API. */
export type DashboardsOverviewHealthURLSubsystem<T = any, R extends K8sResourceCommon | K8sResourceCommon[] = K8sResourceCommon | K8sResourceCommon[]> = ExtensionDeclaration<'console.dashboards/overview/health/url', {
/** The display name of the subsystem. */
title: string;
/** The URL to fetch data from. It will be prefixed with base k8s URL. */
url: string;
/** Resolve the subsystem's health. */
healthHandler: CodeRef<URLHealthHandler<T>>;
/** Additional resource which will be fetched and passed to `healthHandler`. */
additionalResource?: CodeRef<FirehoseResource>;
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
popupComponent?: CodeRef<React.ComponentType<{
healthResult?: T;
healthResultError?: any;
k8sResult?: FirehoseResult<R>;
}>>;
/** The title of the popover. */
popupTitle?: string;
}>;
/** Adds a health subsystem to the status card of Overview dashboard where the source of status is a K8s Resource. */
export type DashboardsOverviewHealthResourceSubsystem<T extends ResourcesObject = ResourcesObject> = ExtensionDeclaration<'console.dashboards/overview/health/resource', {
/** The display name of the subsystem. */
title: string;
/** Kubernetes resources which will be fetched and passed to `healthHandler`. */
resources: CodeRef<WatchK8sResources<T>>;
/** Resolve the subsystem's health. */
healthHandler: CodeRef<ResourceHealthHandler<T>>;
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
popupComponent?: CodeRef<WatchK8sResults<T>>;
/** The title of the popover. */
popupTitle?: string;
}>;
/** Adds a health subsystem to the status card of Overview dashboard where the source of status is a K8s REST API. */
export type DashboardsOverviewHealthOperator<T extends K8sResourceCommon = K8sResourceCommon> = ExtensionDeclaration<'console.dashboards/overview/health/operator', {
/** Title of operators section in the popup. */
title: string;
/** Kubernetes resources which will be fetched and passed to `healthHandler`. */
resources: CodeRef<FirehoseResource[]>;
/** Resolves status for the operators. */
getOperatorsWithStatuses?: CodeRef<GetOperatorsWithStatuses<T>>;
/** Loader for popup row component. */
operatorRowLoader?: CodeRef<React.ComponentType<OperatorRowProps<T>>>;
/** Links to all resources page. If not provided then a list page of the first resource from resources prop is used. */
viewAllLink?: string;
}>;
/** Adds an inventory status group. */
export type DashboardsInventoryItemGroup = ExtensionDeclaration<'console.dashboards/overview/inventory/item/group', {
/** The id of the status group. */
id: string;
/** React component representing the status group icon. */
icon: CodeRef<React.ReactElement>;
}>;
/** Adds a resource tile to the overview inventory card. */
export type DashboardsOverviewInventoryItem<T extends K8sModel = K8sModel, R extends {
[key: string]: K8sResourceCommon[];
} = {
[key: string]: K8sResourceCommon[];
}> = ExtensionDeclaration<'console.dashboards/overview/inventory/item', DashboardsOverviewInventoryItemProperties<T, R> & {}>;
/** Replaces an overview inventory card. */
export type DashboardsOverviewInventoryItemReplacement<T extends K8sModel = K8sModel, R extends {
[key: string]: K8sResourceCommon[];
} = {
[key: string]: K8sResourceCommon[];
}> = ExtensionDeclaration<'console.dashboards/overview/inventory/item/replacement', DashboardsOverviewInventoryItemProperties<T, R> & {}>;
/** Adds a resource tile to the project overview inventory card. */
export type DashboardsProjectOverviewInventoryItem<T extends K8sModel = K8sModel, R extends {
[key: string]: K8sResourceCommon[];
} = {
[key: string]: K8sResourceCommon[];
}> = ExtensionDeclaration<'console.dashboards/project/overview/item', DashboardsOverviewInventoryItemProperties<T, R> & {}>;
/** Adds an activity to the Activity Card of Overview Dashboard where the triggering of activity is based on watching a K8s resource. */
export type DashboardsOverviewResourceActivity<T extends K8sResourceCommon = K8sResourceCommon> = ExtensionDeclaration<'console.dashboards/overview/activity/resource', {
/** The utilization item to be replaced. */
k8sResource: CodeRef<FirehoseResource & {
isList: true;
}>;
/** Function which determines if the given resource represents the action. If not defined, every resource represents activity. */
isActivity?: CodeRef<(resource: T) => boolean>;
/** Timestamp for the given action, which will be used for ordering. */
getTimestamp?: CodeRef<(resource: T) => Date>;
/** The action component. */
component: CodeRef<React.ComponentType<K8sActivityProps<T>>>;
}>;
/** Adds an activity to the Activity Card of Prometheus Overview Dashboard where the triggering of activity is based on watching a K8s resource. */
export type DashboardsOverviewPrometheusActivity = ExtensionDeclaration<'console.dashboards/overview/prometheus/activity/resource', {
/** Queries to watch */
queries: string[];
/** Function which determines if the given resource represents the action. If not defined, every resource represents activity. */
isActivity?: CodeRef<(results: PrometheusResponse[]) => boolean>;
/** The action component. */
component: CodeRef<React.ComponentType<PrometheusActivityProps>>;
}>;
export declare const isDashboardsTab: (e: Extension) => e is DashboardsTab;
export declare const isDashboardsCard: (e: Extension) => e is DashboardsCard;
export declare const isDashboardsOverviewHealthPrometheusSubsystem: (e: Extension) => e is DashboardsOverviewHealthPrometheusSubsystem;
export declare const isResolvedDashboardsOverviewHealthPrometheusSubsystem: (e: Extension) => e is ResolvedExtension<DashboardsOverviewHealthPrometheusSubsystem>;
export declare const isDashboardsOverviewHealthURLSubsystem: (e: Extension) => e is DashboardsOverviewHealthURLSubsystem;
export declare const isResolvedDashboardsOverviewHealthURLSubsystem: (e: Extension) => e is ResolvedExtension<DashboardsOverviewHealthURLSubsystem>;
export declare const isDashboardsOverviewHealthResourceSubsystem: (e: Extension) => e is DashboardsOverviewHealthResourceSubsystem;
export declare const isResolvedDashboardsOverviewHealthResourceSubsystem: (e: Extension) => e is ResolvedExtension<DashboardsOverviewHealthResourceSubsystem>;
export declare const isDashboardsOverviewHealthOperator: (e: Extension) => e is DashboardsOverviewHealthOperator;
export declare const isResolvedDashboardsOverviewHealthOperator: (e: Extension) => e is ResolvedExtension<DashboardsOverviewHealthOperator>;
export declare const isDashboardsInventoryItemGroup: (e: Extension) => e is DashboardsInventoryItemGroup;
export declare const isDashboardsOverviewInventoryItem: (e: Extension) => e is DashboardsOverviewInventoryItem;
export declare const isDashboardsOverviewInventoryItemReplacement: (e: Extension) => e is DashboardsOverviewInventoryItemReplacement;
export declare const isDashboardsProjectOverviewInventoryItem: (e: Extension) => e is DashboardsProjectOverviewInventoryItem;
export declare const isDashboardsOverviewResourceActivity: (e: Extension) => e is DashboardsOverviewResourceActivity;
export declare const isDashboardsOverviewPrometheusActivity: (e: Extension) => e is DashboardsOverviewPrometheusActivity;
export type DashboardsOverviewHealthSubsystem = DashboardsOverviewHealthURLSubsystem | DashboardsOverviewHealthPrometheusSubsystem | DashboardsOverviewHealthResourceSubsystem | DashboardsOverviewHealthOperator;
export declare const isDashboardsOverviewHealthSubsystem: (e: Extension) => e is DashboardsOverviewHealthSubsystem;
type DashboardsOverviewInventoryItemProperties<T extends K8sModel = K8sModel, R extends {
[key: string]: K8sResourceCommon[];
} = {
[key: string]: K8sResourceCommon[];
}> = {
/** The model for `resource` which will be fetched. Used to get the model's `label` or `abbr`. */
model: CodeRef<T>;
/** Function which maps various statuses to groups. */
mapper?: CodeRef<StatusGroupMapper<T, R>>;
/** Additional resources which will be fetched and passed to the `mapper` function. */
additionalResources?: CodeRef<WatchK8sResources<R>>;
};
export {};