UNPKG

@openshift-console/dynamic-plugin-sdk

Version:

Provides core APIs, types and utilities used by dynamic plugins at runtime.

138 lines (137 loc) 6.23 kB
import * as React from 'react'; import { ExtensionHook } from '../api/common-types'; import { Extension, ExtensionDeclaration, CodeRef } from '../types'; /** This extension allows plugins to contribute a new type of catalog item. For example, a Helm plugin can define a new catalog item type as HelmCharts that it wants to contribute to the Software Catalog. */ export type CatalogItemType = ExtensionDeclaration<'console.catalog/item-type', { /** Type for the catalog item. */ type: string; /** Title for the catalog item. */ title: string; /** Description for the type specific catalog. */ catalogDescription?: string | CodeRef<React.ReactNode>; /** Description for the catalog item type. */ typeDescription?: string; /** Custom filters specific to the catalog item. */ filters?: CatalogItemAttribute[]; /** Custom groupings specific to the catalog item. */ groupings?: CatalogItemAttribute[]; }>; /** This extension allows plugins to contribute extra metadata like custom filters or groupings for any catalog item type. For example, a plugin can attach a custom filter for HelmCharts that can filter based on chart provider. */ export type CatalogItemTypeMetadata = ExtensionDeclaration<'console.catalog/item-type-metadata', { /** Type for the catalog item. */ type: string; /** Custom filters specific to the catalog item. */ filters?: CatalogItemAttribute[]; /** Custom groupings specific to the catalog item. */ groupings?: CatalogItemAttribute[]; }>; /** This extension allows plugins to contribute a provider for a catalog item type. For example, a Helm Plugin can add a provider that fetches all the Helm Charts. This extension can also be used by other plugins to add more items to a specific catalog item type. */ export type CatalogItemProvider = ExtensionDeclaration<'console.catalog/item-provider', { /** The unique identifier for the catalog this provider contributes to. */ catalogId: string | string[]; /** Type ID for the catalog item type. */ type: string; /** Title for the catalog item provider */ title: string; /** Fetch items and normalize it for the catalog. Value is a react effect hook. */ provider: CodeRef<ExtensionHook<CatalogItem[], CatalogExtensionHookOptions>>; /** Priority for this provider. Defaults to 0. Higher priority providers may override catalog items provided by other providers. */ priority?: number; }>; /** This extension can be used for plugins to contribute a handler that can filter specific catalog items. For example, the plugin can contribute a filter that filters helm charts from specific provider. */ export type CatalogItemFilter = ExtensionDeclaration<'console.catalog/item-filter', { /** The unique identifier for the catalog this provider contributes to. */ catalogId: string | string[]; /** Type ID for the catalog item type. */ type: string; /** Filters items of a specific type. Value is a function that takes CatalogItem[] and returns a subset based on the filter criteria. */ filter: CodeRef<(item: CatalogItem) => boolean>; }>; /** This extension can be used to contribute a provider that adds extra metadata to specific catalog items. */ export type CatalogItemMetadataProvider = ExtensionDeclaration<'console.catalog/item-metadata', { /** The unique identifier for the catalog this provider contributes to. */ catalogId: string | string[]; /** Type ID for the catalog item type. */ type: string; /** A hook which returns a function that will be used to provide metadata to catalog items of a specific type. */ provider: CodeRef<ExtensionHook<CatalogItemMetadataProviderFunction, CatalogExtensionHookOptions>>; }>; export type SupportedCatalogExtensions = CatalogItemType | CatalogItemTypeMetadata | CatalogItemProvider | CatalogItemFilter | CatalogItemMetadataProvider; export declare const isCatalogItemType: (e: Extension) => e is CatalogItemType; export declare const isCatalogItemTypeMetadata: (e: Extension) => e is CatalogItemTypeMetadata; export declare const isCatalogItemProvider: (e: Extension) => e is CatalogItemProvider; export declare const isCatalogItemFilter: (e: Extension) => e is CatalogItemFilter; export declare const isCatalogItemMetadataProvider: (e: Extension) => e is CatalogItemMetadataProvider; export type CatalogExtensionHookOptions = { namespace: string; }; export type CatalogItem<T extends any = any> = { uid: string; type: string; typeLabel?: string | React.ReactNode; name: string; /** Optional title to render a custom title using ReactNode. * Rendered in catalog tile and side panel * */ title?: React.ReactNode; secondaryLabel?: React.ReactNode; provider?: string; description?: string | React.ReactNode; tags?: string[]; creationTimestamp?: string; supportUrl?: string; documentationUrl?: string; attributes?: { [key: string]: any; }; cta?: { label: string; href?: string; callback?: (props?: any) => void; }; icon?: { url?: string; class?: string; node?: React.ReactNode; }; details?: CatalogItemDetails; badges?: CatalogItemBadge[]; data?: T; }; export type CatalogItemDetails = { properties?: CatalogItemDetailsProperty[]; descriptions?: CatalogItemDetailsDescription[]; }; export type CatalogItemDetailsProperty = { label: string; value: string | React.ReactNode; isHidden?: boolean; }; export type CatalogItemDetailsDescription = { label?: string; value: string | React.ReactNode; }; export type CatalogItemAttribute = { label: string; attribute: string; description?: string; comparator?: CodeRef<(a: string, b: string) => number>; }; export type CatalogItemBadge = { text: string; color?: 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'grey'; icon?: React.ReactNode; variant?: 'outline' | 'filled'; }; export type CatalogItemMetadataProviderFunction = (item: CatalogItem) => { tags?: string[]; badges?: CatalogItemBadge[]; attributes?: { [key: string]: any; }; } | undefined;