From c509284b423b89673f2a164413c7d502d4f4d3e8 Mon Sep 17 00:00:00 2001 From: logonoff Date: Thu, 16 Jan 2025 01:23:44 -0500 Subject: [PATCH] OCPBUGS-45847: Prune unused code removed references to files that are exposed by a static plugin but is not used by it, and remove files entirely if not referenced elsewhere --- frontend/packages/console-app/package.json | 1 - .../multi-network-policy/multiNetworkFlag.ts | 22 -- .../console-telemetry-plugin/package.json | 1 - .../src/listeners/usage.ts | 49 ----- .../dev-console/console-extensions.json | 31 --- .../dev-console/locales/en/devconsole.json | 4 +- frontend/packages/dev-console/package.json | 1 - .../CatalogCategoriesConfiguration.tsx | 135 ------------- frontend/packages/helm-plugin/package.json | 1 - .../package.json | 5 +- .../NetworkAttachmentDefinitionCreateYaml.tsx | 59 ------ .../src/models/templates.ts | 16 -- .../locales/en/olm.json | 6 +- .../operator-lifecycle-manager/package.json | 1 - .../src/utils/useClusterServiceVersions.tsx | 188 ------------------ 15 files changed, 3 insertions(+), 517 deletions(-) delete mode 100644 frontend/packages/console-app/src/components/network-policies/multi-network-policy/multiNetworkFlag.ts delete mode 100644 frontend/packages/console-telemetry-plugin/src/listeners/usage.ts delete mode 100644 frontend/packages/dev-console/src/components/catalog/CatalogCategoriesConfiguration.tsx delete mode 100644 frontend/packages/network-attachment-definition-plugin/src/components/network-attachment-definitions/NetworkAttachmentDefinitionCreateYaml.tsx delete mode 100644 frontend/packages/network-attachment-definition-plugin/src/models/templates.ts delete mode 100644 frontend/packages/operator-lifecycle-manager/src/utils/useClusterServiceVersions.tsx diff --git a/frontend/packages/console-app/package.json b/frontend/packages/console-app/package.json index 13119e56c6e..fbd96a4f5ef 100644 --- a/frontend/packages/console-app/package.json +++ b/frontend/packages/console-app/package.json @@ -62,7 +62,6 @@ "CSRStatus": "src/components/nodes/status/CSRStatus.tsx", "nodeActions": "src/components/nodes/menu-actions.tsx", "oauthConfigDetailsPage": "src/components/oauth-config/OAuthConfigDetailsPage.tsx", - "multiNetworkFlag": "src/components/network-policies/multi-network-policy/multiNetworkFlag.ts", "consolePluginDescriptionDetail": "src/components/console-operator/ConsolePluginDescriptionDetail.tsx", "consolePluginVersionDetail": "src/components/console-operator/ConsolePluginVersionDetail.tsx", "consolePluginStatusDetail": "src/components/console-operator/ConsolePluginStatusDetail.tsx", diff --git a/frontend/packages/console-app/src/components/network-policies/multi-network-policy/multiNetworkFlag.ts b/frontend/packages/console-app/src/components/network-policies/multi-network-policy/multiNetworkFlag.ts deleted file mode 100644 index 0e6e2894f62..00000000000 --- a/frontend/packages/console-app/src/components/network-policies/multi-network-policy/multiNetworkFlag.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { SetFeatureFlag, K8sResourceCommon } from '@console/dynamic-plugin-sdk'; -import { k8sGetResource } from '@console/dynamic-plugin-sdk/src/utils/k8s'; -import { FLAG_MULTI_NETWORK_POLICY, NetworkConfigModel } from './constants'; - -export const enableMultiNetworkPolicy = (setFeatureFlag: SetFeatureFlag) => { - k8sGetResource({ model: NetworkConfigModel, name: 'cluster' }) - .then((networkClusterConfig: K8sResourceCommon & { spec: any }) => { - if (networkClusterConfig?.spec?.disableMultiNetwork) { - setFeatureFlag(FLAG_MULTI_NETWORK_POLICY, !networkClusterConfig.spec.disableMultiNetwork); - return; - } - - if (networkClusterConfig?.spec?.useMultiNetworkPolicy) { - setFeatureFlag(FLAG_MULTI_NETWORK_POLICY, networkClusterConfig?.spec?.disableMultiNetwork); - return; - } - - setFeatureFlag(FLAG_MULTI_NETWORK_POLICY, false); - }) - // eslint-disable-next-line no-console - .catch(console.error); -}; diff --git a/frontend/packages/console-telemetry-plugin/package.json b/frontend/packages/console-telemetry-plugin/package.json index 2036e164e8b..bf67586e9e0 100644 --- a/frontend/packages/console-telemetry-plugin/package.json +++ b/frontend/packages/console-telemetry-plugin/package.json @@ -10,7 +10,6 @@ "description": "An OpenShift Console plugin for capturing events in segment.", "exposedModules": { "telemetryDebugListener": "src/listeners/debug.ts", - "telemetryUsageListener": "src/listeners/usage.ts", "telemetrySegmentListener": "src/listeners/segment.ts", "detectTelemetry": "src/flags/detect-telemetry.ts", "telemetryConfiguration": "src/components/TelemetryConfiguration.tsx", diff --git a/frontend/packages/console-telemetry-plugin/src/listeners/usage.ts b/frontend/packages/console-telemetry-plugin/src/listeners/usage.ts deleted file mode 100644 index ef9fddf8334..00000000000 --- a/frontend/packages/console-telemetry-plugin/src/listeners/usage.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { TelemetryEventListener } from '@console/dynamic-plugin-sdk/src'; - -/** - * Fire and forget implementation to send usage data to the backend. - * See pkg/usage/ for more information. - */ -const trackUsage = (data: { event: string; perspective: string }) => { - return fetch('/metrics/usage', { - method: 'POST', - body: JSON.stringify(data), - }) - .then((response) => { - if (!response.ok) { - // eslint-disable-next-line no-console - console.error('console-telemetry-plugin: unable to track usage:', response.statusText); - } - }) - .catch((error) => { - // eslint-disable-next-line no-console - console.error('console-telemetry-plugin: unable to track usage:', error); - }); -}; - -export const eventListener: TelemetryEventListener = async ( - eventType: string, - properties?: any, -) => { - switch (eventType) { - case 'identify': { - // identify is triggered once per "browser load" ~= page_view - const perspective = properties?.perspective || 'unknown'; - trackUsage({ event: 'page_view', perspective }); - break; - } - case 'page': { - // page URL changed, incl. history.push / react-router.push/replace ~= page_impression - const perspective = properties?.perspective || 'unknown'; - trackUsage({ event: 'page_impression', perspective }); - break; - } - case 'Perspective Changed': { - const perspective = properties?.perspective || 'unknown'; - trackUsage({ event: 'perspective_changed', perspective }); - break; - } - default: - // ignore all other events - } -}; diff --git a/frontend/packages/dev-console/console-extensions.json b/frontend/packages/dev-console/console-extensions.json index 5bce0d8ae2e..4ac58f66e9b 100644 --- a/frontend/packages/dev-console/console-extensions.json +++ b/frontend/packages/dev-console/console-extensions.json @@ -126,37 +126,6 @@ ] } }, - /* - { - "type": "console.cluster-configuration/item", - "properties": { - "id": "dev-console.CatalogCategoriesConfiguration", - "groupId": "developer", - "label": "%devconsole~Developer Catalog Types%", - "description": "%devconsole~Categories which are shown in the developer catalog.%", - "field": { - "type": "custom", - "component": { "$codeRef": "CatalogCategoriesConfiguration.default" } - }, - "readAccessReview": [ - { - "group": "operator.openshift.io/v1", - "resource": "consoles", - "verb": "get", - "name": "cluster" - } - ], - "writeAccessReview": [ - { - "group": "operator.openshift.io/v1", - "resource": "consoles", - "verb": "patch", - "name": "cluster" - } - ] - } - }, - */ { "type": "console.cluster-configuration/item", "properties": { diff --git a/frontend/packages/dev-console/locales/en/devconsole.json b/frontend/packages/dev-console/locales/en/devconsole.json index ef17c0fe9df..dc75fa50814 100644 --- a/frontend/packages/dev-console/locales/en/devconsole.json +++ b/frontend/packages/dev-console/locales/en/devconsole.json @@ -181,11 +181,9 @@ "Shipwright Build": "Shipwright Build", "Shipwright Builds": "Shipwright Builds", "Select a Project to view the list of builds<1>.": "Select a Project to view the list of builds<1>.", - "Developer catalog": "Developer catalog", - "Enabled categories": "Enabled categories", - "Disabled categories": "Disabled categories", "Add shared applications, services, event sources, or source-to-image builders to your Project from the developer catalog. Cluster administrators can customize the content made available in the catalog.": "Add shared applications, services, event sources, or source-to-image builders to your Project from the developer catalog. Cluster administrators can customize the content made available in the catalog.", "Select a Project to view the developer catalog<1>.": "Select a Project to view the developer catalog<1>.", + "Developer catalog": "Developer catalog", "Another option to customize and standardize your development process. As an admin, you can disable the complete Developer Catalog, or individual sub-catalogs (available as Types in the Developer Catalog). Also here the \"Search\" and \"Topology\" will still show such resources.": "Another option to customize and standardize your development process. As an admin, you can disable the complete Developer Catalog, or individual sub-catalogs (available as Types in the Developer Catalog). Also here the \"Search\" and \"Topology\" will still show such resources.", "Enabled types": "Enabled types", "Disabled types": "Disabled types", diff --git a/frontend/packages/dev-console/package.json b/frontend/packages/dev-console/package.json index 919c7323257..c9b49d7eacc 100644 --- a/frontend/packages/dev-console/package.json +++ b/frontend/packages/dev-console/package.json @@ -31,7 +31,6 @@ "BuildsTabListPage": "src/components/builds/BuildsTabListPage.tsx", "BuildConfigFormPage": "src/components/buildconfig/BuildConfigFormPage.tsx", "icons": "src/utils/icons.tsx", - "CatalogCategoriesConfiguration": "src/components/catalog/CatalogCategoriesConfiguration.tsx", "CatalogTypesConfiguration": "src/components/catalog/CatalogTypesConfiguration.tsx", "PinnedResourcesConfiguration": "src/components/catalog/PinnedResourcesConfiguration.tsx", "CatalogPage": "src/components/catalog/CatalogPage.tsx", diff --git a/frontend/packages/dev-console/src/components/catalog/CatalogCategoriesConfiguration.tsx b/frontend/packages/dev-console/src/components/catalog/CatalogCategoriesConfiguration.tsx deleted file mode 100644 index 23f4cb86b23..00000000000 --- a/frontend/packages/dev-console/src/components/catalog/CatalogCategoriesConfiguration.tsx +++ /dev/null @@ -1,135 +0,0 @@ -import * as React from 'react'; -import { - DualListSelector, - DualListSelectorTreeItemData, - FormSection, -} from '@patternfly/react-core'; -import * as fuzzy from 'fuzzysearch'; -import { useTranslation } from 'react-i18next'; -import { K8sResourceKind } from '@console/internal/module/k8s'; -import { useTelemetry } from '@console/shared/src'; -import { CatalogCategory } from '@console/shared/src/components/catalog/utils/types'; -import { - useDebounceCallback, - useConsoleOperatorConfig, - patchConsoleOperatorConfig, - LoadError, - SaveStatus, - SaveStatusProps, -} from '@console/shared/src/components/cluster-configuration'; -import { defaultCatalogCategories } from '@console/shared/src/utils/default-categories'; - -type DeveloperCatalogTypesConsoleConfig = K8sResourceKind & { - spec: { - customization?: { - developerCatalog?: { - categories?: CatalogCategory[]; - }; - }; - }; -}; - -const CatalogCategoriesConfiguration: React.FC<{ readonly: boolean }> = ({ readonly }) => { - const { t } = useTranslation(); - const fireTelemetryEvent = useTelemetry(); - - // Current configuration - const [consoleConfig, consoleConfigLoaded, consoleConfigError] = useConsoleOperatorConfig< - DeveloperCatalogTypesConsoleConfig - >(); - const [currentCategories, setCurrentCategories] = React.useState(); - React.useEffect(() => { - if (consoleConfig && consoleConfigLoaded && !currentCategories) { - setCurrentCategories( - consoleConfig?.spec?.customization?.developerCatalog?.categories || - defaultCatalogCategories, - ); - } - }, [consoleConfig, consoleConfigLoaded, currentCategories]); - - // Calculate options - const [enabledOptions, disabledOptions] = React.useMemo< - [DualListSelectorTreeItemData[], DualListSelectorTreeItemData[]] - >(() => { - if (!consoleConfigLoaded) { - return [[], []]; - } - - const catalogCategoryToTreeItemData = ( - catalogCategory: CatalogCategory, - ): DualListSelectorTreeItemData => ({ - id: catalogCategory.id, - text: catalogCategory.label, - isChecked: false, - children: catalogCategory.subcategories?.map(catalogCategoryToTreeItemData), - defaultExpanded: true, - }); - - const x = defaultCatalogCategories.map(catalogCategoryToTreeItemData); - - return [x, []]; - }, [consoleConfigLoaded]); - - // Save the latest value (types) - const [saveStatus, setSaveStatus] = React.useState(); - const save = useDebounceCallback(() => { - fireTelemetryEvent('Console cluster configuration changed', { - customize: 'Developer Catalog categories', - }); - setSaveStatus({ status: 'in-progress' }); - - const patch: DeveloperCatalogTypesConsoleConfig = { - spec: { - customization: { - developerCatalog: { - categories: currentCategories, - // types: types.length > 0 ? types : null - }, - }, - }, - }; - patchConsoleOperatorConfig(patch) - .then(() => setSaveStatus({ status: 'successful' })) - .catch((error) => setSaveStatus({ status: 'error', error })); - }, 2000); - - // Extract types from Items - const onListChange = ( - _event, - newEnabledOptions: DualListSelectorTreeItemData[], - newDisabledOptions: DualListSelectorTreeItemData[], - ) => { - // eslint-disable-next-line no-console - console.log('xxx categories onListChange', newEnabledOptions, newDisabledOptions); - setSaveStatus({ status: 'pending' }); - save(); - }; - - const filterOption = (option: DualListSelectorTreeItemData, input: string): boolean => { - return fuzzy(input.toLocaleLowerCase(), option.text.toLocaleLowerCase()); - }; - - return ( - - - - - - - ); -}; - -export default CatalogCategoriesConfiguration; diff --git a/frontend/packages/helm-plugin/package.json b/frontend/packages/helm-plugin/package.json index ea61ad236e5..e6744655e47 100644 --- a/frontend/packages/helm-plugin/package.json +++ b/frontend/packages/helm-plugin/package.json @@ -17,7 +17,6 @@ "HelmInstallUpgradePage": "src/components/forms/install-upgrade/HelmInstallUpgradePage.tsx", "HelmReleaseRollbackPage": "src/components/forms/rollback/HelmReleaseRollbackPage.tsx", "HelmReleaseDetailsPage": "src/components/details-page/HelmReleaseDetailsPage.tsx", - "HelmReleaseListPage": "src/components/list-page/HelmReleaseListPage.tsx", "HelmChartRepositoryForm": "src/components/forms/HelmChartRepository/CreateHelmChartRepositoryPage.tsx", "ProjectHelmChartRepositoryListPage": "src/components/list-page/ProjectHelmChartRepositoryListPage.tsx", "HelmChartRepositoryListPage": "src/components/list-page/HelmChartRepositoryListPage.tsx", diff --git a/frontend/packages/network-attachment-definition-plugin/package.json b/frontend/packages/network-attachment-definition-plugin/package.json index 2ac2e125214..28646ad74a9 100644 --- a/frontend/packages/network-attachment-definition-plugin/package.json +++ b/frontend/packages/network-attachment-definition-plugin/package.json @@ -14,9 +14,6 @@ "unique-names-generator": "4.3.1" }, "consolePlugin": { - "entry": "src/plugin.ts", - "exposedModules": { - "yamlTemplates": "src/models/templates.ts" - } + "entry": "src/plugin.ts" } } diff --git a/frontend/packages/network-attachment-definition-plugin/src/components/network-attachment-definitions/NetworkAttachmentDefinitionCreateYaml.tsx b/frontend/packages/network-attachment-definition-plugin/src/components/network-attachment-definitions/NetworkAttachmentDefinitionCreateYaml.tsx deleted file mode 100644 index e1ee0443905..00000000000 --- a/frontend/packages/network-attachment-definition-plugin/src/components/network-attachment-definitions/NetworkAttachmentDefinitionCreateYaml.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import * as React from 'react'; -import { safeLoad } from 'js-yaml'; -import { useParams } from 'react-router-dom-v5-compat'; -import { CreateYAMLProps } from '@console/internal/components/create-yaml'; -import { ErrorPage404 } from '@console/internal/components/error'; -import { - LoadingBox, - AsyncComponent, - resourcePathFromModel, -} from '@console/internal/components/utils'; -import { connectToPlural } from '@console/internal/kinds'; -import { K8sResourceKind } from '@console/internal/module/k8s'; -import { getNamespace, getName } from '@console/shared'; -import { NET_ATTACH_DEF_HEADER_LABEL } from '../../constants/constants'; -import { NetworkAttachmentDefinitionModel } from '../../models'; -import { NetworkAttachmentDefinitionsYAMLTemplates } from '../../models/templates'; - -const CreateNetAttachDefYAMLConnected = connectToPlural( - ({ kindsInFlight, kindObj }: CreateYAMLProps) => { - if (!kindObj) { - if (kindsInFlight) { - return ; - } - return ; - } - const params = useParams(); - - const template = NetworkAttachmentDefinitionsYAMLTemplates.getIn(['default']); - const obj = safeLoad(template); - obj.kind = kindObj.kind; - obj.metadata = obj.metadata || {}; - obj.metadata.namespace = params.ns || 'default'; - - const netAttachDefTemplatePath = (o: K8sResourceKind) => - resourcePathFromModel(NetworkAttachmentDefinitionModel, getName(o), getNamespace(o)); - const DroppableEditYAML = () => - import('@console/internal/components/droppable-edit-yaml').then((c) => c.DroppableEditYAML); - - return ( - - ); - }, -); - -const NetworkAttachmentDefinitionCreateYaml = (props: any) => ( - -); - -export default NetworkAttachmentDefinitionCreateYaml; diff --git a/frontend/packages/network-attachment-definition-plugin/src/models/templates.ts b/frontend/packages/network-attachment-definition-plugin/src/models/templates.ts deleted file mode 100644 index 1e4a8ccf6f1..00000000000 --- a/frontend/packages/network-attachment-definition-plugin/src/models/templates.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Map as ImmutableMap } from 'immutable'; -import { NetworkAttachmentDefinitionModel } from '.'; - -export const NetworkAttachmentDefinitionsYAMLTemplates = ImmutableMap().setIn( - ['default'], - ` -apiVersion: ${NetworkAttachmentDefinitionModel.apiGroup}/${NetworkAttachmentDefinitionModel.apiVersion} -kind: ${NetworkAttachmentDefinitionModel.kind} -metadata: - name: example -spec: - config: '{}' -`, -); - -export const defaultYamlTemplate = NetworkAttachmentDefinitionsYAMLTemplates.getIn(['default']); diff --git a/frontend/packages/operator-lifecycle-manager/locales/en/olm.json b/frontend/packages/operator-lifecycle-manager/locales/en/olm.json index cdaf28a58fd..fb325435e2b 100644 --- a/frontend/packages/operator-lifecycle-manager/locales/en/olm.json +++ b/frontend/packages/operator-lifecycle-manager/locales/en/olm.json @@ -425,9 +425,5 @@ "Pending": "Pending", "OK": "OK", "Failed": "Failed", - "This operator includes a console plugin which provides a custom interface that can be included in the console. The console plugin will prompt for the console to be refreshed once it has been enabled. Make sure you trust this console plugin before enabling.": "This operator includes a console plugin which provides a custom interface that can be included in the console. The console plugin will prompt for the console to be refreshed once it has been enabled. Make sure you trust this console plugin before enabling.", - "Hide operator description": "Hide operator description", - "Show operator description": "Show operator description", - "Operator description": "Operator description", - "This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.": "This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager." + "This operator includes a console plugin which provides a custom interface that can be included in the console. The console plugin will prompt for the console to be refreshed once it has been enabled. Make sure you trust this console plugin before enabling.": "This operator includes a console plugin which provides a custom interface that can be included in the console. The console plugin will prompt for the console to be refreshed once it has been enabled. Make sure you trust this console plugin before enabling." } \ No newline at end of file diff --git a/frontend/packages/operator-lifecycle-manager/package.json b/frontend/packages/operator-lifecycle-manager/package.json index 934d50e32f1..d6eedbf498d 100644 --- a/frontend/packages/operator-lifecycle-manager/package.json +++ b/frontend/packages/operator-lifecycle-manager/package.json @@ -10,7 +10,6 @@ "consolePlugin": { "entry": "src/plugin.tsx", "exposedModules": { - "useClusterServiceVersions": "src/utils/useClusterServiceVersions.tsx", "operatorLinkTabSection": "src/components/topology/operator-link-tab-section.tsx", "topologySidebarResourceLink": "src/components/topology/sidebar/resource-link.tsx", "topologySidebarDetailsSections": "src/components/topology/sidebar/details-sections.tsx", diff --git a/frontend/packages/operator-lifecycle-manager/src/utils/useClusterServiceVersions.tsx b/frontend/packages/operator-lifecycle-manager/src/utils/useClusterServiceVersions.tsx deleted file mode 100644 index 5ecc3151868..00000000000 --- a/frontend/packages/operator-lifecycle-manager/src/utils/useClusterServiceVersions.tsx +++ /dev/null @@ -1,188 +0,0 @@ -import * as React from 'react'; -import { TFunction } from 'i18next'; -import * as _ from 'lodash'; -import { useTranslation } from 'react-i18next'; -import { - ExtensionHook, - CatalogItem, - CatalogItemDetailsDescription, - CatalogItemDetailsProperty, -} from '@console/dynamic-plugin-sdk'; -import { SyncMarkdownView } from '@console/internal/components/markdown-view'; -import { ExpandCollapse } from '@console/internal/components/utils'; -import { useK8sWatchResources } from '@console/internal/components/utils/k8s-watch-hook'; -import { referenceForModel } from '@console/internal/module/k8s'; -import { getImageForCSVIcon } from '@console/shared'; -import { providedAPIsForCSV, referenceForProvidedAPI } from '../components'; -import { GLOBAL_COPIED_CSV_NAMESPACE, GLOBAL_OPERATOR_NAMESPACES } from '../const'; -import { ClusterServiceVersionModel } from '../models'; -import { ProvidedAPI, ClusterServiceVersionKind } from '../types'; - -type ExpandCollapseDescriptionProps = { - children: React.ReactNode; -}; - -export const ExpandCollapseDescription: React.FC = ({ - children, -}) => { - const { t } = useTranslation(); - const [expanded, setExpanded] = React.useState(false); - const toggle = (isExpanded) => { - setExpanded(isExpanded); - }; - return ( - - {/** used an empty Fragment here because Expandable always expects a children, using null throws react warning */} - {expanded ? children : <>} - - ); -}; - -const normalizeClusterServiceVersions = ( - clusterServiceVersions: ClusterServiceVersionKind[], - namespace: string, - t: TFunction, -): CatalogItem[] => { - const formatTileDescription = (csvDescription: string): string => - `## ${t('olm~Operator description')}\n${csvDescription}`; - - const operatorProvidedAPIs: CatalogItem[] = _.flatten< - ProvidedAPI & { csv: ClusterServiceVersionKind } - >(clusterServiceVersions.map((csv) => providedAPIsForCSV(csv).map((desc) => ({ ...desc, csv })))) - .reduce<(ProvidedAPI & { csv: ClusterServiceVersionKind })[]>( - (all, cur) => - all.find((v) => referenceForProvidedAPI(v) === referenceForProvidedAPI(cur)) - ? all - : all.concat([cur]), - [], - ) - .map((desc) => { - const { creationTimestamp } = desc.csv.metadata; - const uid = `${desc.csv.metadata.uid}-${desc.displayName}`; - const { description } = desc; - const provider = desc.csv.spec.provider?.name; - const operatorName = desc.csv.spec.displayName; - const supportUrl = - desc.csv.metadata.annotations?.['marketplace.openshift.io/support-workflow']; - const markdownDescription = formatTileDescription(desc.csv.spec.description); - const longDescription = t( - 'olm~This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.', - { operatorName }, - ); - const documentationUrl = _.get( - (desc.csv.spec.links || []).find(({ linkName }) => linkName === 'Documentation'), - 'url', - ); - const capabilityLevel = _.get(desc, ['csv', 'metadata', 'annotations', 'capabilities'], '') - .toLowerCase() - .replace(/\s/g, ''); - - const detailsProperties: CatalogItemDetailsProperty[] = [ - { - label: t('olm~Capability level'), - value: capabilityLevel, - }, - ]; - - const operatorDescription = ( - - - - ); - - const detailsDescriptions: CatalogItemDetailsDescription[] = [ - { - value:

{description}

, - }, - { - value:

{longDescription}

, - }, - { - value: operatorDescription, - }, - ]; - - return { - // NOTE: Faking a real k8s object to avoid fetching all CRDs - uid, - type: 'OperatorBackedService', - name: desc.displayName || desc.kind, - description, - provider, - tags: desc.csv.spec.keywords, - creationTimestamp, - supportUrl, - documentationUrl, - attributes: { - operatorName, - }, - icon: { - class: null, - url: getImageForCSVIcon(desc.csv.spec.icon?.[0]), - }, - cta: { - label: t('public~Create'), - href: `/k8s/ns/${namespace}/clusterserviceversions/${ - desc.csv.metadata.name - }/${referenceForProvidedAPI(desc)}/~new`, - }, - details: { - properties: detailsProperties, - descriptions: detailsDescriptions, - }, - data: desc, - }; - }); - - return operatorProvidedAPIs; -}; - -const useClusterServiceVersions: ExtensionHook = ({ - namespace, -}): [CatalogItem[], boolean, any] => { - const { t } = useTranslation(); - const resourceSelector = React.useMemo( - () => ({ - csvs: { - isList: true, - kind: referenceForModel(ClusterServiceVersionModel), - namespaced: ClusterServiceVersionModel.namespaced, - namespace, - }, - ...(window.SERVER_FLAGS.copiedCSVsDisabled && !GLOBAL_OPERATOR_NAMESPACES.includes(namespace) - ? { - globalCsvs: { - isList: true, - kind: referenceForModel(ClusterServiceVersionModel), - namespaced: ClusterServiceVersionModel.namespaced, - namespace: GLOBAL_COPIED_CSV_NAMESPACE, - }, - } - : {}), - }), - [namespace], - ); - - const csvsResources = useK8sWatchResources<{ - csvs: ClusterServiceVersionKind[]; - globalCsvs?: ClusterServiceVersionKind[]; - }>(resourceSelector); - - const normalizedCSVs = React.useMemo( - () => - normalizeClusterServiceVersions( - [...(csvsResources.csvs?.data ?? []), ...(csvsResources.globalCsvs?.data ?? [])], - namespace, - t, - ), - [csvsResources, namespace, t], - ); - - return [normalizedCSVs, csvsResources.csvs?.loaded, csvsResources.csvs?.loadError]; -}; - -export default useClusterServiceVersions;