From 32d1cd67d4968f6d809ac60f05a527f99ad56bf6 Mon Sep 17 00:00:00 2001 From: Robb Hamilton Date: Mon, 16 Mar 2026 15:30:33 -0400 Subject: [PATCH] OCPBUGS-76787: Fix 404 error when viewing CRs with "All Projects" selected When navigating to resource lists with "All Projects" selected (e.g., /k8s/all-namespaces/certificates), the page was showing a 404 error. The issue was that ResourceListPage and ResourceDetailsPage components were not handling the namespace correctly for routes without an explicit :ns parameter. For routes like /k8s/all-namespaces/:plural, there is no :ns param in the URL, so these components need to get the namespace from the active namespace selector. The fix uses useActiveNamespace() hook as a fallback when the namespace isn't in the URL params. The components now: - Use namespace from URL params if present (e.g., /k8s/ns/default/:plural) - Fall back to active namespace from the selector for all-namespaces routes - Convert ALL_NAMESPACES_KEY ('#ALL_NS#') to undefined so that underlying components fetch resources from all namespaces This matches the pattern used in SearchPage and ensures resource lists display correctly in all scenarios. Co-Authored-By: Claude Sonnet 4.5 --- frontend/public/components/resource-list.tsx | 7 +++++-- .../public/components/useNamespaceFromURL.ts | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 frontend/public/components/useNamespaceFromURL.ts diff --git a/frontend/public/components/resource-list.tsx b/frontend/public/components/resource-list.tsx index 4b3774dc4ed..2fa336039bd 100644 --- a/frontend/public/components/resource-list.tsx +++ b/frontend/public/components/resource-list.tsx @@ -27,6 +27,7 @@ import { ResourceListPage as ResourceListPageExt, isResourceListPage, } from '@console/dynamic-plugin-sdk/src/extensions/pages'; +import { useNamespaceFromURL } from './useNamespaceFromURL'; // Parameters can be in pros.params (in URL) or in props.route (attribute of Route tag) const allParams = (props) => Object.assign({}, _.get(props, 'params'), props); @@ -72,7 +73,8 @@ const ResourceListPage_ = connectToPlural( export const ResourceListPage = (props) => { const params = useParams(); - return ; + const ns = useNamespaceFromURL(); + return ; }; const ResourceDetailsPage_ = connectToPlural((props: ResourceDetailsPageProps) => { @@ -125,7 +127,8 @@ const ResourceDetailsPage_ = connectToPlural((props: ResourceDetailsPageProps) = export const ResourceDetailsPage = (props) => { const params = useParams(); - return ; + const ns = useNamespaceFromURL(); + return ; }; export type ResourceListPageProps = { diff --git a/frontend/public/components/useNamespaceFromURL.ts b/frontend/public/components/useNamespaceFromURL.ts new file mode 100644 index 00000000000..4dd3ab7dbb1 --- /dev/null +++ b/frontend/public/components/useNamespaceFromURL.ts @@ -0,0 +1,21 @@ +import { useParams } from 'react-router'; +import { useActiveNamespace } from '@console/dynamic-plugin-sdk/src/lib-core'; +import { ALL_NAMESPACES_KEY } from '@console/shared/src/constants'; + +/** + * Hook to get the namespace from URL params or active namespace selector. + * + * For routes with explicit namespace (/k8s/ns/:ns/:plural), returns the URL param. + * For routes without namespace (/k8s/all-namespaces/:plural), returns the active + * namespace from the selector, converting ALL_NAMESPACES_KEY to undefined. + * + * @returns The namespace string or undefined for all-namespaces view + */ +export const useNamespaceFromURL = (): string | undefined => { + const params = useParams<{ ns?: string }>(); + const [activeNamespace] = useActiveNamespace(); + + // Use namespace from URL params if available, otherwise use active namespace + // Convert ALL_NAMESPACES_KEY to undefined for the all-namespaces routes + return params.ns || (activeNamespace === ALL_NAMESPACES_KEY ? undefined : activeNamespace); +};