Skip to content

Commit 4c1fb7b

Browse files
committed
mgr/dashboard: resolve the redirect url with the prop name
the prop can be passed to the redirectLink array like `::prop` and the table component will resolve the url Fixes: https://tracker.ceph.com/issues/73754 Signed-off-by: Nizamudeen A <[email protected]>
1 parent 7cc2a30 commit 4c1fb7b

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,5 +482,5 @@
482482
<ng-template #redirectTpl
483483
let-value="data.value"
484484
let-column="data.column">
485-
<a [routerLink]="column.customTemplateConfig?.redirectLink">{{value}}</a>
485+
<a [routerLink]="column.customTemplateConfig?.redirectLink | redirectLinkResolver:value">{{value}}</a>
486486
</ng-template>

src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export enum CellTemplate {
111111
// }
112112
// ...
113113
// }
114+
// you can also use '::prop' in the redirectLink array to replace it with the cell value.
115+
// e.g ['dashboard', '::prop', 'details']
114116
*/
115117
redirect = 'redirect'
116118
}

src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/pipes.module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { XmlPipe } from './xml.pipe';
4040
import { MbpersecondPipe } from './mbpersecond.pipe';
4141
import { PipeFunctionPipe } from './pipe-function.pipe';
4242
import { DimlessBinaryPerMinutePipe } from './dimless-binary-per-minute.pipe';
43+
import { RedirectLinkResolverPipe } from './redirect-link-resolver.pipe';
4344

4445
@NgModule({
4546
imports: [CommonModule],
@@ -82,7 +83,8 @@ import { DimlessBinaryPerMinutePipe } from './dimless-binary-per-minute.pipe';
8283
XmlPipe,
8384
MbpersecondPipe,
8485
PipeFunctionPipe,
85-
DimlessBinaryPerMinutePipe
86+
DimlessBinaryPerMinutePipe,
87+
RedirectLinkResolverPipe
8688
],
8789
exports: [
8890
ArrayPipe,
@@ -123,7 +125,8 @@ import { DimlessBinaryPerMinutePipe } from './dimless-binary-per-minute.pipe';
123125
XmlPipe,
124126
MbpersecondPipe,
125127
PipeFunctionPipe,
126-
DimlessBinaryPerMinutePipe
128+
DimlessBinaryPerMinutePipe,
129+
RedirectLinkResolverPipe
127130
],
128131
providers: [
129132
ArrayPipe,
@@ -155,7 +158,8 @@ import { DimlessBinaryPerMinutePipe } from './dimless-binary-per-minute.pipe';
155158
MgrSummaryPipe,
156159
OctalToHumanReadablePipe,
157160
MbpersecondPipe,
158-
DimlessBinaryPerMinutePipe
161+
DimlessBinaryPerMinutePipe,
162+
RedirectLinkResolverPipe
159163
]
160164
})
161165
export class PipesModule {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { RedirectLinkResolverPipe } from './redirect-link-resolver.pipe';
2+
3+
describe('RedirectLinkResolverPipe', () => {
4+
let pipe: RedirectLinkResolverPipe;
5+
6+
beforeEach(() => {
7+
pipe = new RedirectLinkResolverPipe();
8+
});
9+
10+
it('should create an instance', () => {
11+
expect(pipe).toBeTruthy();
12+
});
13+
14+
it('should replace "::prop" with the provided value', () => {
15+
const redirectLink = ['home', '::prop', 'details'];
16+
const value = 'route';
17+
const result = pipe.transform(redirectLink, value);
18+
expect(result).toEqual(['home', 'route', 'details']);
19+
});
20+
21+
it('should handle multiple "::prop" replacements', () => {
22+
const redirectLink = ['::prop', 'user', '::prop'];
23+
const value = 'id42';
24+
const result = pipe.transform(redirectLink, value);
25+
expect(result).toEqual(['id42', 'user', 'id42']);
26+
});
27+
28+
it('should return the same array if no "::prop" exists', () => {
29+
const redirectLink = ['home', 'about', 'contact'];
30+
const value = 'ignored';
31+
const result = pipe.transform(redirectLink, value);
32+
expect(result).toEqual(redirectLink);
33+
});
34+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'redirectLinkResolver'
5+
})
6+
export class RedirectLinkResolverPipe implements PipeTransform {
7+
transform(redirectLink: string[], value: string): string[] {
8+
return redirectLink.map((seg) => (seg === '::prop' ? value : seg));
9+
}
10+
}

0 commit comments

Comments
 (0)