reducer.ts 972 B

12345678910111213141516171819202122232425262728293031323334
  1. import { createAction } from '@reduxjs/toolkit';
  2. import { AnyAction } from 'redux';
  3. import { LoadingState } from '@grafana/data';
  4. import { DashboardSearchHit } from 'app/features/search/types';
  5. export interface DeleteLibraryPanelModalState {
  6. loadingState: LoadingState;
  7. dashboardTitles: string[];
  8. }
  9. export const initialDeleteLibraryPanelModalState: DeleteLibraryPanelModalState = {
  10. loadingState: LoadingState.Loading,
  11. dashboardTitles: [],
  12. };
  13. export const searchCompleted = createAction<{ dashboards: DashboardSearchHit[] }>(
  14. 'libraryPanels/delete/searchCompleted'
  15. );
  16. export const deleteLibraryPanelModalReducer = (
  17. state: DeleteLibraryPanelModalState = initialDeleteLibraryPanelModalState,
  18. action: AnyAction
  19. ): DeleteLibraryPanelModalState => {
  20. if (searchCompleted.match(action)) {
  21. return {
  22. ...state,
  23. dashboardTitles: action.payload.dashboards.map((d) => d.title),
  24. loadingState: LoadingState.Done,
  25. };
  26. }
  27. return state;
  28. };