user.ts 868 B

12345678910111213141516171819202122232425262728
  1. import { ThunkAction } from 'redux-thunk';
  2. import { getBackendSrv } from '../services/backend_srv';
  3. import { DashboardAcl, DashboardSearchHit, StoreState } from '../../types';
  4. type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>;
  5. export type Action = LoadStarredDashboardsAction;
  6. export enum ActionTypes {
  7. LoadStarredDashboards = 'LOAD_STARRED_DASHBOARDS',
  8. }
  9. interface LoadStarredDashboardsAction {
  10. type: ActionTypes.LoadStarredDashboards;
  11. payload: DashboardSearchHit[];
  12. }
  13. const starredDashboardsLoaded = (dashboards: DashboardAcl[]) => ({
  14. type: ActionTypes.LoadStarredDashboards,
  15. payload: dashboards,
  16. });
  17. export function loadStarredDashboards(): ThunkResult<void> {
  18. return async dispatch => {
  19. const starredDashboards = await getBackendSrv().search({ starred: true });
  20. dispatch(starredDashboardsLoaded(starredDashboards));
  21. };
  22. }