Skip to content

Commit

Permalink
fix: redirect in incorrect path
Browse files Browse the repository at this point in the history
  • Loading branch information
mrCherry97 committed Feb 6, 2025
1 parent dabfa47 commit 338553b
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/components/App/IncorrectPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@ export function IncorrectPath({ to, title = '', message = '' }) {
message = message || t('components.incorrect-path.message.default');

const resourceUrl = `/apis/apiextensions.k8s.io/v1/customresourcedefinitions`;
const { namespaceResourceType = '', namespaceResourceName = '' } =
const { namespaceResourceName = '' } =
useMatch({
path:
'/cluster/:cluster/namespaces/:namespace/:namespaceResourceType/:namespaceResourceName',
end: false,
})?.params ?? {};

const { clusterResourceType = '', clusterResourceName = '' } =
const { namespaceResourceType = '' } =
useMatch({
path: '/cluster/:cluster/namespaces/:namespace/:namespaceResourceType',
end: false,
})?.params ?? {};

const { clusterResourceName = '' } =
useMatch({
path: '/cluster/:cluster/:clusterResourceType/:clusterResourceName',
end: false,
})?.params ?? {};

const { clusterResourceType = '' } =
useMatch({
path: '/cluster/:cluster/:clusterResourceType',
end: false,
})?.params ?? {};

const resourceType = namespace ? namespaceResourceType : clusterResourceType;
const resourceName = namespace ? namespaceResourceName : clusterResourceName;

Expand All @@ -51,8 +63,11 @@ export function IncorrectPath({ to, title = '', message = '' }) {
const crdGroup = data[0]?.spec?.group;

const path = `customresources/${resourceType}.${crdGroup}/${resourceName}`;

const link = namespace ? namespaceUrl(path) : clusterUrl(path);
const link = namespace
? namespace !== '-all-'
? namespaceUrl(path)
: namespaceUrl(path, { namespace: '-all-' })
: clusterUrl(path);

if (link && crdGroup) {
notificationManager.notifySuccess({
Expand Down

0 comments on commit 338553b

Please sign in to comment.