Scopes: Change redirectUrl to redirectPath (#112783)

* Scopes: change redirectUrl to redirectPath

* Update e2e helpers
This commit is contained in:
Tobias Skarhed
2025-10-22 11:21:14 +02:00
committed by GitHub
parent 9b72973293
commit 2bbba880cd
8 changed files with 21 additions and 19 deletions
+2
View File
@@ -9,3 +9,5 @@ go test --tags "pro" -timeout 30s -run ^TestIntegrationOpenAPIs$ github.com/graf
```
./hack/update-codegen.sh scope
```
This should generate a diff in the Enterprise repo. Make sure to open a PR there too.
+2 -2
View File
@@ -154,8 +154,8 @@ type ScopeNodeSpec struct {
LinkID string `json:"linkId,omitempty"` // the k8s name
// ?? should this be a slice of links
// Redirect to a specific URL when this node is selected.
RedirectUrl string `json:"redirectUrl,omitempty"`
// Redirect to a specific path when this node is selected.
RedirectPath string `json:"redirectPath,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -866,9 +866,9 @@ func schema_pkg_apis_scope_v0alpha1_ScopeNodeSpec(ref common.ReferenceCallback)
Format: "",
},
},
"redirectUrl": {
"redirectPath": {
SchemaProps: spec.SchemaProps{
Description: "Redirect to a specific URL when this node is selected.",
Description: "Redirect to a specific path when this node is selected.",
Type: []string{"string"},
Format: "",
},
+3 -3
View File
@@ -19,7 +19,7 @@ export type TestScope = {
type?: string;
category?: string;
addLinks?: boolean;
redirectUrl?: string;
redirectPath?: string;
};
type ScopeDashboardBinding = Resource<ScopeDashboardBindingSpec, ScopeDashboardBindingStatus, 'ScopeDashboardBinding'>;
@@ -56,8 +56,8 @@ export async function scopeNodeChildrenRequest(
linkType: 'scope',
linkId: `scope-${scope.name}`,
}),
...(scope.redirectUrl && {
redirectUrl: scope.redirectUrl,
...(scope.redirectPath && {
redirectPath: scope.redirectPath,
}),
},
})),
+2 -2
View File
@@ -111,14 +111,14 @@ export const testScopesWithRedirect = (): TestScope[] => {
{
name: 'sn-redirect-custom',
title: 'Custom Redirect',
redirectUrl: '/d/cuj-dashboard-2', // Use existing dashboard
redirectPath: '/d/cuj-dashboard-2', // Use existing dashboard
filters: [{ key: 'namespace', operator: 'equals', value: 'custom-redirect' }],
addLinks: true,
},
{
name: 'sn-redirect-fallback',
title: 'Fallback Navigation',
// No redirectUrl - should fall back to scope navigation
// No redirectPath - should fall back to scope navigation
filters: [{ key: 'namespace', operator: 'equals', value: 'fallback-nav' }],
dashboardUid: 'cuj-dashboard-2', // Use existing dashboard
dashboardTitle: 'CUJ Dashboard 2',
+2 -2
View File
@@ -84,8 +84,8 @@ export interface ScopeNodeSpec {
// Id of the parent node.
parentName?: string;
// Redirect to a specific URL when this node is selected.
redirectUrl?: string;
// Redirect to a specific path when this node is selected.
redirectPath?: string;
}
// TODO: Use Resource from apiserver when we export the types
@@ -719,11 +719,11 @@ describe('ScopesSelectorService', () => {
parentName: '',
nodeType: 'leaf',
title: 'test-scope-node',
redirectUrl: '/custom-redirect-url',
redirectPath: '/custom-redirect-url',
},
};
// Mock fetchNodes to return the node with redirectUrl
// Mock fetchNodes to return the node with redirectPath
apiClient.fetchNodes = jest
.fn()
.mockImplementation((options: { parent?: string; query?: string; limit?: number }) => {
@@ -755,7 +755,7 @@ describe('ScopesSelectorService', () => {
parentName: '',
nodeType: 'leaf',
title: 'test-scope-node',
redirectUrl: '/priority-redirect',
redirectPath: '/priority-redirect',
},
};
@@ -767,7 +767,7 @@ describe('ScopesSelectorService', () => {
},
];
// Mock fetchNodes to return the node with redirectUrl
// Mock fetchNodes to return the node with redirectPath
apiClient.fetchNodes = jest
.fn()
.mockImplementation((options: { parent?: string; query?: string; limit?: number }) => {
@@ -790,7 +790,7 @@ describe('ScopesSelectorService', () => {
// Then apply to trigger the redirect
await service.apply();
// Should use redirectUrl, not scope navigation
// Should use redirectPath, not scope navigation
expect(locationService.push).toHaveBeenCalledWith('/priority-redirect');
expect(locationService.push).toHaveBeenCalledTimes(1);
});
@@ -389,9 +389,9 @@ export class ScopesSelectorService extends ScopesServiceBase<ScopesSelectorServi
// Redirect to the scope node's redirect URL if it exists, otherwise redirect to the first scope navigation.
private redirectAfterApply = (scopeNode: ScopeNode | undefined) => {
// Check if the selected scope has a redirect URL
if (scopeNode && scopeNode.spec.redirectUrl && typeof scopeNode.spec.redirectUrl === 'string') {
locationService.push(scopeNode.spec.redirectUrl);
// Check if the selected scope has a redirect path
if (scopeNode && scopeNode.spec.redirectPath && typeof scopeNode.spec.redirectPath === 'string') {
locationService.push(scopeNode.spec.redirectPath);
return;
}