mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Query History: Implement star, comment and delete methods (#49330)
* Implement star, comment and delete methods * Remove redundant await
This commit is contained in:
parent
0a509b97ef
commit
8f4c3e94b0
@ -18,10 +18,16 @@ dsMock.init(
|
||||
);
|
||||
|
||||
const fetchMock = jest.fn();
|
||||
const postMock = jest.fn();
|
||||
const deleteMock = jest.fn();
|
||||
const patchMock = jest.fn();
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
getBackendSrv: () => ({
|
||||
fetch: fetchMock,
|
||||
post: postMock,
|
||||
delete: deleteMock,
|
||||
patch: patchMock,
|
||||
}),
|
||||
getDataSourceSrv: () => dsMock,
|
||||
}));
|
||||
@ -41,6 +47,9 @@ describe('RichHistoryRemoteStorage', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset();
|
||||
postMock.mockReset();
|
||||
deleteMock.mockReset();
|
||||
patchMock.mockReset();
|
||||
storage = new RichHistoryRemoteStorage();
|
||||
});
|
||||
|
||||
@ -173,4 +182,41 @@ describe('RichHistoryRemoteStorage', () => {
|
||||
showSuccessAlert: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('stars query history items', async () => {
|
||||
const { richHistoryQuery, dto } = setup();
|
||||
postMock.mockResolvedValue({
|
||||
result: dto,
|
||||
});
|
||||
const query = await storage.updateStarred('test', true);
|
||||
expect(postMock).toBeCalledWith('/api/query-history/star/test');
|
||||
expect(query).toMatchObject(richHistoryQuery);
|
||||
});
|
||||
|
||||
it('unstars query history items', async () => {
|
||||
const { richHistoryQuery, dto } = setup();
|
||||
deleteMock.mockResolvedValue({
|
||||
result: dto,
|
||||
});
|
||||
const query = await storage.updateStarred('test', false);
|
||||
expect(deleteMock).toBeCalledWith('/api/query-history/star/test');
|
||||
expect(query).toMatchObject(richHistoryQuery);
|
||||
});
|
||||
|
||||
it('updates query history comments', async () => {
|
||||
const { richHistoryQuery, dto } = setup();
|
||||
patchMock.mockResolvedValue({
|
||||
result: dto,
|
||||
});
|
||||
const query = await storage.updateComment('test', 'just a comment');
|
||||
expect(patchMock).toBeCalledWith('/api/query-history/test', {
|
||||
comment: 'just a comment',
|
||||
});
|
||||
expect(query).toMatchObject(richHistoryQuery);
|
||||
});
|
||||
|
||||
it('deletes query history items', async () => {
|
||||
await storage.deleteRichHistory('test');
|
||||
expect(deleteMock).toBeCalledWith('/api/query-history/test');
|
||||
});
|
||||
});
|
||||
|
@ -38,6 +38,10 @@ type RichHistoryRemoteStorageResultsPayloadDTO = {
|
||||
};
|
||||
};
|
||||
|
||||
type RichHistoryRemoteStorageUpdatePayloadDTO = {
|
||||
result: RichHistoryRemoteStorageDTO;
|
||||
};
|
||||
|
||||
export default class RichHistoryRemoteStorage implements RichHistoryStorage {
|
||||
private readonly preferenceService: PreferencesService;
|
||||
|
||||
@ -62,7 +66,7 @@ export default class RichHistoryRemoteStorage implements RichHistoryStorage {
|
||||
}
|
||||
|
||||
async deleteRichHistory(id: string): Promise<void> {
|
||||
throw new Error('not supported yet');
|
||||
getBackendSrv().delete(`/api/query-history/${id}`);
|
||||
}
|
||||
|
||||
async getRichHistory(filters: RichHistorySearchFilters) {
|
||||
@ -95,7 +99,10 @@ export default class RichHistoryRemoteStorage implements RichHistoryStorage {
|
||||
}
|
||||
|
||||
async updateComment(id: string, comment: string | undefined): Promise<RichHistoryQuery> {
|
||||
throw new Error('not supported yet');
|
||||
const dto: RichHistoryRemoteStorageUpdatePayloadDTO = await getBackendSrv().patch(`/api/query-history/${id}`, {
|
||||
comment: comment,
|
||||
});
|
||||
return fromDTO(dto.result);
|
||||
}
|
||||
|
||||
updateSettings(settings: RichHistorySettings): Promise<void> {
|
||||
@ -107,7 +114,13 @@ export default class RichHistoryRemoteStorage implements RichHistoryStorage {
|
||||
}
|
||||
|
||||
async updateStarred(id: string, starred: boolean): Promise<RichHistoryQuery> {
|
||||
throw new Error('not supported yet');
|
||||
let dto: RichHistoryRemoteStorageUpdatePayloadDTO;
|
||||
if (starred) {
|
||||
dto = await getBackendSrv().post(`/api/query-history/star/${id}`);
|
||||
} else {
|
||||
dto = await getBackendSrv().delete(`/api/query-history/star/${id}`);
|
||||
}
|
||||
return fromDTO(dto.result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user