mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 13:09:22 -06:00
51e7b87f39
* WIP: initial commit * Playlist: Migrates New/Edit to React * Tests: adds tests for PlaylistForm * Tests: adds more tests * Chore: moved some styles * Chore: updates after PR review
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
import { Playlist } from './types';
|
|
import { dispatch } from '../../store/store';
|
|
import { notifyApp } from '../../core/actions';
|
|
import { createErrorNotification, createSuccessNotification } from '../../core/copy/appNotification';
|
|
|
|
export async function createPlaylist(playlist: Playlist) {
|
|
await withErrorHandling(async () => await getBackendSrv().post('/api/playlists', playlist));
|
|
}
|
|
|
|
export async function updatePlaylist(id: number, playlist: Playlist) {
|
|
await withErrorHandling(async () => await getBackendSrv().put(`/api/playlists/${id}`, playlist));
|
|
}
|
|
|
|
export async function getPlaylist(id: number): Promise<Playlist> {
|
|
const result: Playlist = await getBackendSrv().get(`/api/playlists/${id}`);
|
|
return result;
|
|
}
|
|
|
|
async function withErrorHandling(apiCall: () => Promise<void>) {
|
|
try {
|
|
await apiCall();
|
|
dispatch(notifyApp(createSuccessNotification('Playlist saved')));
|
|
} catch (e) {
|
|
dispatch(notifyApp(createErrorNotification('Unable to save playlist', e)));
|
|
}
|
|
}
|