Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/utils/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const generateName = (prefix: string): string => {
};

export const createNamespacePath = (namespace: string) =>
namespace ? `ns/${namespace}` : ALL_NAMESPACES;
namespace === ALL_NAMESPACES || !namespace ? ALL_NAMESPACES : `ns/${namespace}`;

export const getValidNamespace = (activeNamespace: string) =>
activeNamespace === ALL_NAMESPACES_KEY ? DEFAULT_NAMESPACE : activeNamespace;
Expand Down
8 changes: 6 additions & 2 deletions src/views/networkpolicies/list/NetworkPolicyPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useMemo } from 'react';
import { useLocation, useNavigate } from 'react-router-dom-v5-compat';
import { useLocation, useNavigate, useParams } from 'react-router-dom-v5-compat';

import { modelToGroupVersionKind, NetworkPolicyModel } from '@kubevirt-ui/kubevirt-api/console';
import { ListPageCreateButton, ListPageHeader } from '@openshift-console/dynamic-plugin-sdk';
Expand All @@ -21,9 +21,13 @@ export type NetworkPolicyPageNavProps = {
namespace: string;
};

const NetworkPolicyPage: FC<NetworkPolicyPageNavProps> = ({ namespace }) => {
const NetworkPolicyPage: FC<NetworkPolicyPageNavProps> = ({ namespace: namespaceProp }) => {
const navigate = useNavigate();
const location = useLocation();
const { ns } = useParams<{ ns?: string }>();

// Use namespace from route params if available (for custom RoutePage), otherwise use prop
const namespace = ns || namespaceProp;

const locationTabKey = useMemo(
() => getActiveKeyFromPathname(location?.pathname),
Expand Down
4 changes: 2 additions & 2 deletions src/views/networkpolicies/list/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { modelToRef, NetworkPolicyModel } from '@kubevirt-ui/kubevirt-api/console';
import { ALL_NAMESPACES } from '@utils/constants';
import { MultiNetworkPolicyModel } from '@utils/models';
import { createNamespacePath } from '@utils/utils/helpers';

import { TAB_INDEXES } from './constants';

Expand All @@ -13,7 +13,7 @@ export const getActiveKeyFromPathname = (pathname: string) => {
};

export const getNetworkPolicyURLTab = (tabIndex: number | string, namespace: string): string => {
const namespacePath = namespace === ALL_NAMESPACES ? namespace : `ns/${namespace}`;
const namespacePath = createNamespacePath(namespace);

if (tabIndex === TAB_INDEXES.ENABLE_MULTI) {
return `/k8s/${namespacePath}/${modelToRef(NetworkPolicyModel)}/enable-multi`;
Expand Down