mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 09:12:52 +08:00

* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
36 lines
877 B
TypeScript
36 lines
877 B
TypeScript
import { useEffect } from 'react';
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { FolderDTO } from 'app/types';
|
|
|
|
import { fetchFolderIfNotFetchedAction } from '../state/actions';
|
|
import { initialAsyncRequestState } from '../utils/redux';
|
|
|
|
import { useUnifiedAlertingSelector } from './useUnifiedAlertingSelector';
|
|
|
|
interface ReturnBag {
|
|
folder?: FolderDTO;
|
|
loading: boolean;
|
|
}
|
|
|
|
export function useFolder(uid?: string): ReturnBag {
|
|
const dispatch = useDispatch();
|
|
const folderRequests = useUnifiedAlertingSelector((state) => state.folders);
|
|
useEffect(() => {
|
|
if (uid) {
|
|
dispatch(fetchFolderIfNotFetchedAction(uid));
|
|
}
|
|
}, [dispatch, uid]);
|
|
|
|
if (uid) {
|
|
const request = folderRequests[uid] || initialAsyncRequestState;
|
|
return {
|
|
folder: request.result,
|
|
loading: request.loading,
|
|
};
|
|
}
|
|
return {
|
|
loading: false,
|
|
};
|
|
}
|