mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
import { notifyApp } from '../../core/actions';
|
|
import { createErrorNotification, createSuccessNotification } from '../../core/copy/appNotification';
|
|
import { dispatch } from '../../store/store';
|
|
|
|
import { Playlist, PlaylistDTO } from './types';
|
|
|
|
export async function createPlaylist(playlist: Playlist) {
|
|
await withErrorHandling(() => getBackendSrv().post('/api/playlists', playlist));
|
|
}
|
|
|
|
export async function updatePlaylist(id: number, playlist: Playlist) {
|
|
await withErrorHandling(() => getBackendSrv().put(`/api/playlists/${id}`, playlist));
|
|
}
|
|
|
|
export async function deletePlaylist(id: number) {
|
|
await withErrorHandling(() => getBackendSrv().delete(`/api/playlists/${id}`), 'Playlist deleted');
|
|
}
|
|
|
|
export async function getPlaylist(id: number): Promise<Playlist> {
|
|
const result: Playlist = await getBackendSrv().get(`/api/playlists/${id}`);
|
|
return result;
|
|
}
|
|
|
|
export async function getAllPlaylist(query: string): Promise<PlaylistDTO[]> {
|
|
const result: PlaylistDTO[] = await getBackendSrv().get('/api/playlists/', { query });
|
|
return result;
|
|
}
|
|
|
|
async function withErrorHandling(apiCall: () => Promise<void>, message = 'Playlist saved') {
|
|
try {
|
|
await apiCall();
|
|
dispatch(notifyApp(createSuccessNotification(message)));
|
|
} catch (e) {
|
|
dispatch(notifyApp(createErrorNotification('Unable to save playlist', e)));
|
|
}
|
|
}
|