actions.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { getBackendSrv } from 'app/core/services/backend_srv';
  2. import { ThunkResult } from 'app/types';
  3. import { DataSourceCacheDTO } from '../../types';
  4. export enum ActionTypes {
  5. LoadDataSourceCache = 'LOAD_DATA_SOURCE_CACHE',
  6. }
  7. export interface LoadDataSourceCacheAction {
  8. type: ActionTypes.LoadDataSourceCache;
  9. payload: DataSourceCacheDTO;
  10. }
  11. const dataSourceCacheLoaded = (dataSourceCache: DataSourceCacheDTO): LoadDataSourceCacheAction => ({
  12. type: ActionTypes.LoadDataSourceCache,
  13. payload: dataSourceCache,
  14. });
  15. export type Action = LoadDataSourceCacheAction;
  16. export function enableDataSourceCache(uid: string): ThunkResult<void> {
  17. return async (dispatch) => {
  18. const response = await getBackendSrv().post(`/api/datasources/${uid}/cache/enable`, {});
  19. dispatch(dataSourceCacheLoaded(response));
  20. };
  21. }
  22. export function disableDataSourceCache(uid: string): ThunkResult<void> {
  23. return async (dispatch) => {
  24. const response = await getBackendSrv().post(`/api/datasources/${uid}/cache/disable`, {});
  25. dispatch(dataSourceCacheLoaded(response));
  26. };
  27. }
  28. export function updateDataSourceCache(uid: string, config: DataSourceCacheDTO): ThunkResult<void> {
  29. return async (dispatch) => {
  30. const response = await getBackendSrv().post(`/api/datasources/${uid}/cache`, config);
  31. dispatch(dataSourceCacheLoaded(response));
  32. };
  33. }
  34. export function loadDataSourceCache(uid: string): ThunkResult<void> {
  35. return async (dispatch) => {
  36. const response = await getBackendSrv().get(`/api/datasources/${uid}/cache`);
  37. dispatch(dataSourceCacheLoaded(response));
  38. };
  39. }
  40. export function cleanCache(uid: string): ThunkResult<void> {
  41. return async (dispatch) => {
  42. const response = await getBackendSrv().post(`/api/datasources/${uid}/cache/clean`, {});
  43. dispatch(dataSourceCacheLoaded(response));
  44. };
  45. }