-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cluster in url - Newest cleaned up code #7
base: multi-cluster
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
ALL_NAMESPACES_KEY, | ||
LAST_NAMESPACE_NAME_LOCAL_STORAGE_KEY, | ||
} from '@console/shared/src/constants'; | ||
// import { multiClusterRoutePrefixes } from '@console/app/src/components/detect-cluster/cluster' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the import caused most of the tests to fail. Unsure of cause, so the prefixes are duplicated in the code below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this again. When you import the multiClusterRoutePrefixes it causes this test suite to fail: Each test fails with this message:
Seems kind of crazy pants to me, but I tested it numerous times and it fails without fail (hahaha) when using the import. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stack trace for failed test:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is most likely an issue with a jest.mock in the user settings hook unit test. |
||
import { K8sResourceKind, PodKind, NodeKind } from '../module/k8s'; | ||
import { allModels } from '../module/k8s/k8s-models'; | ||
import { detectFeatures, clearSSARFlags } from './features'; | ||
|
@@ -152,10 +153,23 @@ export const formatNamespaceRoute = ( | |
originalPath, | ||
location?, | ||
forceList?: boolean, | ||
activeCluster?: string, | ||
) => { | ||
let path = originalPath.substr(window.SERVER_FLAGS.basePath.length); | ||
|
||
let parts = path.split('/').filter((p) => p); | ||
|
||
if (parts[0] === 'cluster') { | ||
// The url pattern that includes the cluster name starts with /cluster/:clusterName | ||
parts.splice(0, 2); | ||
} | ||
|
||
const multiClusterRoutePrefixes = ['/k8s/all-namespaces', '/k8s/cluster', '/k8s/ns']; | ||
const clusterPathPart = | ||
activeCluster && multiClusterRoutePrefixes.includes(`/${parts[0]}/${parts[1]}`) | ||
? `/cluster/${activeCluster}` | ||
: ''; | ||
|
||
const prefix = parts.shift(); | ||
|
||
let previousNS; | ||
|
@@ -168,7 +182,7 @@ export const formatNamespaceRoute = ( | |
} | ||
|
||
if (!previousNS) { | ||
return originalPath; | ||
return `${clusterPathPart}${originalPath}`; | ||
} | ||
|
||
if ( | ||
|
@@ -193,7 +207,7 @@ export const formatNamespaceRoute = ( | |
path += `${location.search}${location.hash}`; | ||
} | ||
|
||
return path; | ||
return `${clusterPathPart}${path}`; | ||
}; | ||
|
||
export const setCurrentLocation = (location: string) => | ||
|
@@ -211,6 +225,7 @@ export const setActiveNamespace = (namespace: string = '') => { | |
// make it noop when new active namespace is the same | ||
// otherwise users will get page refresh and cry about | ||
// broken direct links and bookmarks | ||
|
||
if (namespace !== getActiveNamespace()) { | ||
const oldPath = window.location.pathname; | ||
const newPath = formatNamespaceRoute(namespace, oldPath, window.location); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting
window.location.pathname
seems a little weird, but it works.