From 6af9db2c5176c95f38b89f7b9461d991b2f72fc0 Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Wed, 2 Mar 2022 15:40:46 +0100 Subject: [PATCH] Use existingc thunk --- .../app/features/folders/FolderAlerting.tsx | 8 +++---- public/app/features/folders/state/actions.ts | 21 +++---------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/public/app/features/folders/FolderAlerting.tsx b/public/app/features/folders/FolderAlerting.tsx index 6db224bb7c0..c1ea801a3ec 100644 --- a/public/app/features/folders/FolderAlerting.tsx +++ b/public/app/features/folders/FolderAlerting.tsx @@ -3,23 +3,23 @@ import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; import { getNavModel } from 'app/core/selectors/navModel'; import { StoreState } from 'app/types'; import React from 'react'; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { useAsync } from 'react-use'; import { AlertsFolderView } from '../alerting/unified/AlertsFolderView'; -import { useGetFolderByUid } from './state/actions'; +import { getFolderByUid } from './state/actions'; import { getLoadingNav } from './state/navModel'; export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {} const FolderAlerting = ({ match }: OwnProps) => { - const getFolderByUid = useGetFolderByUid(); + const dispatch = useDispatch(); const navIndex = useSelector((state: StoreState) => state.navIndex); const folder = useSelector((state: StoreState) => state.folder); const uid = match.params.uid; const navModel = getNavModel(navIndex, `folder-alerting-${uid}`, getLoadingNav(1)); - const { loading } = useAsync(async () => await getFolderByUid(uid), [getFolderByUid, uid]); + const { loading } = useAsync(async () => dispatch(getFolderByUid(uid)), [getFolderByUid, uid]); return ( diff --git a/public/app/features/folders/state/actions.ts b/public/app/features/folders/state/actions.ts index 8a0f7659eb6..96847be6168 100644 --- a/public/app/features/folders/state/actions.ts +++ b/public/app/features/folders/state/actions.ts @@ -1,15 +1,13 @@ import { locationUtil } from '@grafana/data'; import { getBackendSrv, locationService } from '@grafana/runtime'; +import { notifyApp, updateNavIndex } from 'app/core/actions'; +import { createSuccessNotification, createWarningNotification } from 'app/core/copy/appNotification'; import { backendSrv } from 'app/core/services/backend_srv'; import { FolderState, ThunkResult } from 'app/types'; import { DashboardAcl, DashboardAclUpdateDTO, NewDashboardAclItem, PermissionLevel } from 'app/types/acl'; -import { notifyApp, updateNavIndex } from 'app/core/actions'; -import { createSuccessNotification, createWarningNotification } from 'app/core/copy/appNotification'; +import { lastValueFrom } from 'rxjs'; import { buildNavModel } from './navModel'; import { loadFolder, loadFolderPermissions, setCanViewFolderPermissions } from './reducers'; -import { lastValueFrom } from 'rxjs'; -import { useDispatch } from 'react-redux'; -import { useCallback } from 'react'; export function getFolderByUid(uid: string): ThunkResult { return async (dispatch) => { @@ -19,19 +17,6 @@ export function getFolderByUid(uid: string): ThunkResult { }; } -export function useGetFolderByUid() { - const dispatch = useDispatch(); - - return useCallback( - async (folderUid: string) => { - const folder = await backendSrv.getFolderByUid(folderUid); - dispatch(loadFolder(folder)); - dispatch(updateNavIndex(buildNavModel(folder))); - }, - [dispatch] - ); -} - export function saveFolder(folder: FolderState): ThunkResult { return async (dispatch) => { const res = await backendSrv.put(`/api/folders/${folder.uid}`, {