Use existingc thunk
This commit is contained in:
@@ -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}>
|
||||
|
||||
@@ -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}`, {
|
||||
|
||||
Reference in New Issue
Block a user