Use existingc thunk

This commit is contained in:
Konrad Lalik
2022-03-02 15:40:46 +01:00
parent aa3e1a4a4e
commit 6af9db2c51
2 changed files with 7 additions and 22 deletions
@@ -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 (
<Page navModel={navModel}>
+3 -18
View File
@@ -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<void> {
return async (dispatch) => {
@@ -19,19 +17,6 @@ export function getFolderByUid(uid: string): ThunkResult<void> {
};
}
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<void> {
return async (dispatch) => {
const res = await backendSrv.put(`/api/folders/${folder.uid}`, {