grafana/public/app/features/plugins/state/actions.ts

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-09-27 07:45:36 -05:00
import { Plugin, StoreState } from 'app/types';
2018-09-25 07:53:55 -05:00
import { ThunkAction } from 'redux-thunk';
import { getBackendSrv } from '../../../core/services/backend_srv';
2018-09-27 05:15:41 -05:00
import { LayoutMode } from '../../../core/components/LayoutSelector/LayoutSelector';
2018-10-17 07:36:18 -05:00
import { PluginDashboard } from '../../../types/plugins';
2018-09-25 07:53:55 -05:00
export enum ActionTypes {
LoadPlugins = 'LOAD_PLUGINS',
2018-10-17 07:36:18 -05:00
LoadPluginDashboards = 'LOAD_PLUGIN_DASHBOARDS',
2018-09-25 09:21:52 -05:00
SetPluginsSearchQuery = 'SET_PLUGIN_SEARCH_QUERY',
SetLayoutMode = 'SET_LAYOUT_MODE',
2018-09-25 07:53:55 -05:00
}
export interface LoadPluginsAction {
type: ActionTypes.LoadPlugins;
2018-09-27 07:45:36 -05:00
payload: Plugin[];
2018-09-25 07:53:55 -05:00
}
2018-10-17 07:36:18 -05:00
export interface LoadPluginDashboardsAction {
type: ActionTypes.LoadPluginDashboards;
payload: PluginDashboard[];
}
2018-09-25 09:21:52 -05:00
export interface SetPluginsSearchQueryAction {
type: ActionTypes.SetPluginsSearchQuery;
payload: string;
}
export interface SetLayoutModeAction {
type: ActionTypes.SetLayoutMode;
2018-09-27 05:15:41 -05:00
payload: LayoutMode;
2018-09-25 09:21:52 -05:00
}
2018-10-03 02:43:10 -05:00
export const setPluginsLayoutMode = (mode: LayoutMode): SetLayoutModeAction => ({
2018-09-25 09:21:52 -05:00
type: ActionTypes.SetLayoutMode,
payload: mode,
});
export const setPluginsSearchQuery = (query: string): SetPluginsSearchQueryAction => ({
type: ActionTypes.SetPluginsSearchQuery,
payload: query,
});
2018-09-27 07:45:36 -05:00
const pluginsLoaded = (plugins: Plugin[]): LoadPluginsAction => ({
2018-09-25 07:53:55 -05:00
type: ActionTypes.LoadPlugins,
payload: plugins,
});
2018-10-17 07:36:18 -05:00
const pluginDashboardsLoaded = (dashboards: PluginDashboard[]): LoadPluginDashboardsAction => ({
type: ActionTypes.LoadPluginDashboards,
payload: dashboards,
});
export type Action = LoadPluginsAction | LoadPluginDashboardsAction | SetPluginsSearchQueryAction | SetLayoutModeAction;
2018-09-25 07:53:55 -05:00
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
export function loadPlugins(): ThunkResult<void> {
return async dispatch => {
const result = await getBackendSrv().get('api/plugins', { embedded: 0 });
dispatch(pluginsLoaded(result));
};
}
2018-10-17 07:36:18 -05:00
export function loadPluginDashboards(): ThunkResult<void> {
return async (dispatch, getStore) => {
const dataSourceType = getStore().dataSources.dataSource.type;
const response = await getBackendSrv().get(`api/plugins/${dataSourceType}/dashboards`);
dispatch(pluginDashboardsLoaded(response));
};
}