mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
a3b396854a
stylings tweaks to command palette
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
import { useSelector } from 'app/types';
|
|
|
|
import { CommandPaletteAction } from '../types';
|
|
|
|
import { getRecentDashboardActions } from './dashboardActions';
|
|
import getStaticActions from './staticActions';
|
|
|
|
export default function useActions(searchQuery: string) {
|
|
const [navTreeActions, setNavTreeActions] = useState<CommandPaletteAction[]>([]);
|
|
const [recentDashboardActions, setRecentDashboardActions] = useState<CommandPaletteAction[]>([]);
|
|
|
|
const { navBarTree } = useSelector((state) => {
|
|
return {
|
|
navBarTree: state.navBarTree,
|
|
};
|
|
});
|
|
// Load standard static actions
|
|
useEffect(() => {
|
|
const staticActionsResp = getStaticActions(navBarTree);
|
|
setNavTreeActions(staticActionsResp);
|
|
}, [navBarTree]);
|
|
|
|
// Load recent dashboards - we don't want them to reload when the nav tree changes
|
|
useEffect(() => {
|
|
if (!searchQuery) {
|
|
getRecentDashboardActions()
|
|
.then((recentDashboardActions) => setRecentDashboardActions(recentDashboardActions))
|
|
.catch((err) => {
|
|
console.error('Error loading recent dashboard actions', err);
|
|
});
|
|
} else {
|
|
setRecentDashboardActions([]);
|
|
}
|
|
}, [searchQuery]);
|
|
|
|
return [...recentDashboardActions, ...navTreeActions];
|
|
}
|