Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions frontend/packages/console-dynamic-plugin-sdk/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

| API kind | Exposed APIs |
| -------- | ------------ |
| Variable (82) | [ActionServiceProvider](#actionserviceprovider), [BlueInfoCircleIcon](#blueinfocircleicon), [CamelCaseWrap](#camelcasewrap), [checkAccess](#checkaccess), [CodeEditor](#codeeditor), [consoleFetch](#consolefetch), [consoleFetchJSON](#consolefetchjson), [consoleFetchText](#consolefetchtext), [DocumentTitle](#documenttitle), [ErrorBoundaryFallbackPage](#errorboundaryfallbackpage), [ErrorStatus](#errorstatus), [GenericStatus](#genericstatus), [getAPIVersionForModel](#getapiversionformodel), [getGroupVersionKindForModel](#getgroupversionkindformodel), [getGroupVersionKindForResource](#getgroupversionkindforresource), [GreenCheckCircleIcon](#greencheckcircleicon), [HorizontalNav](#horizontalnav), [InfoStatus](#infostatus), [InventoryItem](#inventoryitem), [InventoryItemBody](#inventoryitembody), [InventoryItemLoading](#inventoryitemloading), [InventoryItemStatus](#inventoryitemstatus), [InventoryItemTitle](#inventoryitemtitle), [isAllNamespacesKey](#isallnamespaceskey), [k8sCreate](#k8screate), [k8sDelete](#k8sdelete), [k8sGet](#k8sget), [k8sList](#k8slist), [k8sListItems](#k8slistitems), [k8sPatch](#k8spatch), [k8sUpdate](#k8supdate), [ListPageBody](#listpagebody), [ListPageCreate](#listpagecreate), [ListPageCreateButton](#listpagecreatebutton), [ListPageCreateDropdown](#listpagecreatedropdown), [ListPageCreateLink](#listpagecreatelink), [ListPageHeader](#listpageheader), [NamespaceBar](#namespacebar), [Overview](#overview), [OverviewGrid](#overviewgrid), [PopoverStatus](#popoverstatus), [ProgressStatus](#progressstatus), [QueryBrowser](#querybrowser), [RedExclamationCircleIcon](#redexclamationcircleicon), [ResourceEventStream](#resourceeventstream), [ResourceIcon](#resourceicon), [ResourceLink](#resourcelink), [ResourceStatus](#resourcestatus), [ResourceYAMLEditor](#resourceyamleditor), [StatusComponent](#statuscomponent), [StatusIconAndText](#statusiconandtext), [StatusPopupItem](#statuspopupitem), [StatusPopupSection](#statuspopupsection), [SuccessStatus](#successstatus), [TableData](#tabledata), [Timestamp](#timestamp), [useAccessReview](#useaccessreview), [useActiveColumns](#useactivecolumns), [useActiveNamespace](#useactivenamespace), [useActivePerspective](#useactiveperspective), [useAnnotationsModal](#useannotationsmodal), [useDeleteModal](#usedeletemodal), [useFlag](#useflag), [useK8sModel](#usek8smodel), [useK8sModels](#usek8smodels), [useK8sWatchResource](#usek8swatchresource), [useK8sWatchResources](#usek8swatchresources), [useLabelsModal](#uselabelsmodal), [useOverlay](#useoverlay), [usePrometheusPoll](#useprometheuspoll), [useQuickStartContext](#usequickstartcontext), [useResolvedExtensions](#useresolvedextensions), [useUserSettings](#useusersettings), [YellowExclamationTriangleIcon](#yellowexclamationtriangleicon), [ListPageFilter](#listpagefilter), [PerspectiveContext](#perspectivecontext), [useAccessReviewAllowed](#useaccessreviewallowed), [useListPageFilter](#uselistpagefilter), [useModal](#usemodal), [useSafetyFirst](#usesafetyfirst), [VirtualizedTable](#virtualizedtable), [YAMLEditor](#yamleditor) |
| TypeAlias (28) | [Alert](#alert), [Alerts](#alerts), [AlwaysOnExtension](#alwaysonextension), [ColoredIconProps](#colorediconprops), [DiscoveryResources](#discoveryresources), [ExtensionHook](#extensionhook), [ExtensionHookResult](#extensionhookresult), [ExtensionK8sGroupKindModel](#extensionk8sgroupkindmodel), [ExtensionK8sGroupModel](#extensionk8sgroupmodel), [ExtensionK8sKindVersionModel](#extensionk8skindversionmodel), [ExtensionK8sModel](#extensionk8smodel), [K8sModel](#k8smodel), [K8sVerb](#k8sverb), [MatchExpression](#matchexpression), [MatchLabels](#matchlabels), [ModalComponent](#modalcomponent), [OverlayComponent](#overlaycomponent), [PerspectiveContextType](#perspectivecontexttype), [PrometheusAlert](#prometheusalert), [PrometheusLabels](#prometheuslabels), [PrometheusRule](#prometheusrule), [PrometheusRulesResponse](#prometheusrulesresponse), [PrometheusValue](#prometheusvalue), [ResolvedExtension](#resolvedextension), [Rule](#rule), [Selector](#selector), [Silence](#silence), [K8sKind](#k8skind) |
| Variable (83) | [ActionServiceProvider](#actionserviceprovider), [BlueInfoCircleIcon](#blueinfocircleicon), [CamelCaseWrap](#camelcasewrap), [checkAccess](#checkaccess), [CodeEditor](#codeeditor), [consoleFetch](#consolefetch), [consoleFetchJSON](#consolefetchjson), [consoleFetchText](#consolefetchtext), [DocumentTitle](#documenttitle), [ErrorBoundaryFallbackPage](#errorboundaryfallbackpage), [ErrorStatus](#errorstatus), [GenericStatus](#genericstatus), [getAPIVersionForModel](#getapiversionformodel), [getGroupVersionKindForModel](#getgroupversionkindformodel), [getGroupVersionKindForResource](#getgroupversionkindforresource), [getSwaggerPropertyDescription](#getswaggerpropertydescription), [GreenCheckCircleIcon](#greencheckcircleicon), [HorizontalNav](#horizontalnav), [InfoStatus](#infostatus), [InventoryItem](#inventoryitem), [InventoryItemBody](#inventoryitembody), [InventoryItemLoading](#inventoryitemloading), [InventoryItemStatus](#inventoryitemstatus), [InventoryItemTitle](#inventoryitemtitle), [isAllNamespacesKey](#isallnamespaceskey), [k8sCreate](#k8screate), [k8sDelete](#k8sdelete), [k8sGet](#k8sget), [k8sList](#k8slist), [k8sListItems](#k8slistitems), [k8sPatch](#k8spatch), [k8sUpdate](#k8supdate), [ListPageBody](#listpagebody), [ListPageCreate](#listpagecreate), [ListPageCreateButton](#listpagecreatebutton), [ListPageCreateDropdown](#listpagecreatedropdown), [ListPageCreateLink](#listpagecreatelink), [ListPageHeader](#listpageheader), [NamespaceBar](#namespacebar), [Overview](#overview), [OverviewGrid](#overviewgrid), [PopoverStatus](#popoverstatus), [ProgressStatus](#progressstatus), [QueryBrowser](#querybrowser), [RedExclamationCircleIcon](#redexclamationcircleicon), [ResourceEventStream](#resourceeventstream), [ResourceIcon](#resourceicon), [ResourceLink](#resourcelink), [ResourceStatus](#resourcestatus), [ResourceYAMLEditor](#resourceyamleditor), [StatusComponent](#statuscomponent), [StatusIconAndText](#statusiconandtext), [StatusPopupItem](#statuspopupitem), [StatusPopupSection](#statuspopupsection), [SuccessStatus](#successstatus), [TableData](#tabledata), [Timestamp](#timestamp), [useAccessReview](#useaccessreview), [useActiveColumns](#useactivecolumns), [useActiveNamespace](#useactivenamespace), [useActivePerspective](#useactiveperspective), [useAnnotationsModal](#useannotationsmodal), [useDeleteModal](#usedeletemodal), [useFlag](#useflag), [useK8sModel](#usek8smodel), [useK8sModels](#usek8smodels), [useK8sWatchResource](#usek8swatchresource), [useK8sWatchResources](#usek8swatchresources), [useLabelsModal](#uselabelsmodal), [useOverlay](#useoverlay), [usePrometheusPoll](#useprometheuspoll), [useQuickStartContext](#usequickstartcontext), [useResolvedExtensions](#useresolvedextensions), [useUserSettings](#useusersettings), [YellowExclamationTriangleIcon](#yellowexclamationtriangleicon), [ListPageFilter](#listpagefilter), [PerspectiveContext](#perspectivecontext), [useAccessReviewAllowed](#useaccessreviewallowed), [useListPageFilter](#uselistpagefilter), [useModal](#usemodal), [useSafetyFirst](#usesafetyfirst), [VirtualizedTable](#virtualizedtable), [YAMLEditor](#yamleditor) |
| TypeAlias (29) | [Alert](#alert), [Alerts](#alerts), [AlwaysOnExtension](#alwaysonextension), [ColoredIconProps](#colorediconprops), [DiscoveryResources](#discoveryresources), [ExtensionHook](#extensionhook), [ExtensionHookResult](#extensionhookresult), [ExtensionK8sGroupKindModel](#extensionk8sgroupkindmodel), [ExtensionK8sGroupModel](#extensionk8sgroupmodel), [ExtensionK8sKindVersionModel](#extensionk8skindversionmodel), [ExtensionK8sModel](#extensionk8smodel), [GetSwaggerPropertyDescription](#getswaggerpropertydescription), [K8sModel](#k8smodel), [K8sVerb](#k8sverb), [MatchExpression](#matchexpression), [MatchLabels](#matchlabels), [ModalComponent](#modalcomponent), [OverlayComponent](#overlaycomponent), [PerspectiveContextType](#perspectivecontexttype), [PrometheusAlert](#prometheusalert), [PrometheusLabels](#prometheuslabels), [PrometheusRule](#prometheusrule), [PrometheusRulesResponse](#prometheusrulesresponse), [PrometheusValue](#prometheusvalue), [ResolvedExtension](#resolvedextension), [Rule](#rule), [Selector](#selector), [Silence](#silence), [K8sKind](#k8skind) |
| Interface (1) | [ModelDefinition](#modeldefinition) |
| Enum (6) | [AlertSeverity](#alertseverity), [AlertStates](#alertstates), [Operator](#operator), [PrometheusEndpoint](#prometheusendpoint), [RuleStates](#rulestates), [SilenceStates](#silencestates) |

Expand Down Expand Up @@ -723,6 +723,53 @@ The group, version, kind for the provided resource.<br/>If the resource does not

---

## `getSwaggerPropertyDescription`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove "swagger" from the name. OpenAPI would be better.


### Summary

Function that returns a description of a K8s property described by a given K8sModel and path.<br/>Dynamic plugins can use this function to generate popover help content for standard K8s properties like Name, Namespace, Labels, etc.




### Parameters

| Parameter Name | Description |
| -------------- | ----------- |
| `kindObj` | K8sModel whose properties will be used |
| `propertyPath` | path to the property in a given K8sModel, e.g. "metadata.name" |



### Returns

Description of a given property.


### Source

[`frontend/packages/console-dynamic-plugin-sdk/src/api/dynamic-core-api.ts`](https://github.com/openshift/console/tree/main/frontend/packages/console-dynamic-plugin-sdk/src/api/dynamic-core-api.ts)

---

## `GetSwaggerPropertyDescription`

### Summary

Documentation is not available, please refer to the implementation.







### Source

[`frontend/packages/console-dynamic-plugin-sdk/src/api/common-types.ts`](https://github.com/openshift/console/tree/main/frontend/packages/console-dynamic-plugin-sdk/src/api/common-types.ts)

---

## `GreenCheckCircleIcon`

### Summary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ export enum PrometheusEndpoint {
RULES = 'api/v1/rules',
TARGETS = 'api/v1/targets',
}

export type GetSwaggerPropertyDescription = (
kindObj: K8sModel,
propertyPath: string | string[],
) => string;
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
VirtualizedTableFC,
} from '../extensions/console-types';
import { StatusPopupSectionProps, StatusPopupItemProps } from '../extensions/dashboard-types';
import { GetSwaggerPropertyDescription } from './common-types';

export * from '../app/components';
export * from './common-types';
Expand Down Expand Up @@ -946,3 +947,13 @@ export const useUserSettings: UseUserSettings = require('@console/shared/src/hoo
*/
export const useQuickStartContext: UseQuickStartContext = require('@console/shared/src/hooks/useQuickStartContext')
.useQuickStartContext;

/**
* Function that returns a description of a K8s property described by a given K8sModel and path.
* Dynamic plugins can use this function to generate popover help content for standard K8s properties like Name, Namespace, Labels, etc.
* @param kindObj - K8sModel whose properties will be used
* @param propertyPath - path to the property in a given K8sModel, e.g. "metadata.name"
* @returns Description of a given property.
*/
export const getSwaggerPropertyDescription: GetSwaggerPropertyDescription = require('@console/internal/module/k8s/swagger')
.getSwaggerPropertyDescription;
4 changes: 2 additions & 2 deletions frontend/public/components/utils/details-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';

import { getPropertyDescription, K8sResourceKind, referenceFor } from '../../module/k8s';
import { getSwaggerPropertyDescription, K8sResourceKind, referenceFor } from '../../module/k8s';
import { LinkifyExternal } from './link';
import { useK8sModel } from '@console/shared/src/hooks/useK8sModel';

Expand Down Expand Up @@ -79,7 +79,7 @@ export const DetailsItem: React.FC<DetailsItemProps> = ({
const { t } = useTranslation();
const [model] = useK8sModel(obj ? referenceFor(obj) : '');
const hide = hideEmpty && _.isEmpty(_.get(obj, path));
const popoverContent: string = description ?? getPropertyDescription(model, path);
const popoverContent: string = description ?? getSwaggerPropertyDescription(model, path);
const value: React.ReactNode = children || _.get(obj, path, defaultValue);
const editable = onEdit && canEdit;
return hide ? null : (
Expand Down
13 changes: 8 additions & 5 deletions frontend/public/module/k8s/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as _ from 'lodash-es';

import { STORAGE_PREFIX } from '@console/shared/src/constants';
import { coFetchJSON } from '../../co-fetch';
import { K8sKind } from '@console/dynamic-plugin-sdk/src/api/common-types';
import {
GetSwaggerPropertyDescription,
K8sKind,
} from '@console/dynamic-plugin-sdk/src/api/common-types';
import { referenceForModel } from '@console/internal/module/k8s/k8s';

const SWAGGER_LOCAL_STORAGE_KEY = `${STORAGE_PREFIX}/swagger-definitions`;
Expand Down Expand Up @@ -107,10 +110,10 @@ const findDefinition = (kindObj: K8sKind, propertyPath: string[]): SwaggerDefini
return path ? (_.get(swaggerDefinitions, path) as SwaggerDefinition) : null;
};

export const getPropertyDescription = (
kindObj: K8sKind,
propertyPath: string | string[],
): string => {
export const getSwaggerPropertyDescription: GetSwaggerPropertyDescription = (
kindObj,
propertyPath,
) => {
const path: string[] = _.toPath(propertyPath);
const definition = findDefinition(kindObj, path);
return definition ? definition.description : null;
Expand Down