mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix missing instances and history when Grafana rule is stored in folder with / (#97956)
This commit is contained in:
parent
ccb2be5962
commit
d7e07d9993
27
public/app/features/alerting/unified/hooks/useFolder.test.ts
Normal file
27
public/app/features/alerting/unified/hooks/useFolder.test.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { mockFolder } from '../mocks';
|
||||
|
||||
import { stringifyFolder } from './useFolder';
|
||||
|
||||
describe('with slashes', () => {
|
||||
it('should correctly stringify a folder', () => {
|
||||
const folder = mockFolder({ title: 'my/folder' });
|
||||
expect(stringifyFolder(folder)).toEqual('my\\/folder');
|
||||
});
|
||||
|
||||
it('should correctly stringify a nested folder', () => {
|
||||
const folder = mockFolder({ title: 'my/folder', parents: [mockFolder({ title: 'parent/slash' })] });
|
||||
expect(stringifyFolder(folder)).toEqual('parent\\/slash/my\\/folder');
|
||||
});
|
||||
});
|
||||
|
||||
describe('without slashes', () => {
|
||||
it('should correctly stringify a folder', () => {
|
||||
const folder = mockFolder({ title: 'my folder' });
|
||||
expect(stringifyFolder(folder)).toEqual('my folder');
|
||||
});
|
||||
|
||||
it('should correctly stringify a nested folder', () => {
|
||||
const folder = mockFolder({ title: 'my folder', parents: [mockFolder({ title: 'my parent' })] });
|
||||
expect(stringifyFolder(folder)).toEqual('my parent/my folder');
|
||||
});
|
||||
});
|
@ -34,5 +34,11 @@ export function useFolder(uid?: string): ReturnBag {
|
||||
}
|
||||
|
||||
export function stringifyFolder({ title, parents }: FolderDTO) {
|
||||
return parents && parents?.length ? [...parents.map((p) => p.title), title].join('/') : title;
|
||||
return parents && parents?.length
|
||||
? [...parents.map((p) => p.title), title].map(encodeTitle).join('/')
|
||||
: encodeTitle(title);
|
||||
}
|
||||
|
||||
export function encodeTitle(title: string): string {
|
||||
return title.replaceAll('/', '\\/');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user