2021-09-13 08:00:41 -05:00
|
|
|
import { AnyAction, createSlice, PayloadAction, Reducer } from '@reduxjs/toolkit';
|
2020-10-27 07:08:08 -05:00
|
|
|
import { PluginMeta, PanelPlugin, PluginError } from '@grafana/data';
|
2019-04-29 11:14:39 -05:00
|
|
|
import { PluginsState } from 'app/types';
|
2021-09-09 05:20:35 -05:00
|
|
|
import { config } from 'app/core/config';
|
|
|
|
import { reducer as pluginCatalogReducer } from '../admin/state/reducer';
|
2018-10-17 07:36:18 -05:00
|
|
|
import { PluginDashboard } from '../../../types/plugins';
|
2018-09-25 07:53:55 -05:00
|
|
|
|
2018-09-27 07:23:46 -05:00
|
|
|
export const initialState: PluginsState = {
|
2020-01-13 01:03:22 -06:00
|
|
|
plugins: [],
|
2020-10-27 07:08:08 -05:00
|
|
|
errors: [],
|
2018-09-27 07:23:46 -05:00
|
|
|
searchQuery: '',
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: false,
|
2020-01-13 01:03:22 -06:00
|
|
|
dashboards: [],
|
2019-02-13 04:14:53 -06:00
|
|
|
isLoadingPluginDashboards: false,
|
2020-02-10 07:23:54 -06:00
|
|
|
panels: {},
|
2018-09-27 07:23:46 -05:00
|
|
|
};
|
2018-09-25 07:53:55 -05:00
|
|
|
|
2020-01-13 01:03:22 -06:00
|
|
|
const pluginsSlice = createSlice({
|
|
|
|
name: 'plugins',
|
|
|
|
initialState,
|
|
|
|
reducers: {
|
2020-02-10 07:23:54 -06:00
|
|
|
pluginsLoaded: (state, action: PayloadAction<PluginMeta[]>) => {
|
|
|
|
state.hasFetched = true;
|
|
|
|
state.plugins = action.payload;
|
2020-01-13 01:03:22 -06:00
|
|
|
},
|
2020-10-27 07:08:08 -05:00
|
|
|
pluginsErrorsLoaded: (state, action: PayloadAction<PluginError[]>) => {
|
|
|
|
state.errors = action.payload;
|
|
|
|
},
|
2020-02-10 07:23:54 -06:00
|
|
|
setPluginsSearchQuery: (state, action: PayloadAction<string>) => {
|
|
|
|
state.searchQuery = action.payload;
|
2020-01-13 01:03:22 -06:00
|
|
|
},
|
2020-02-10 07:23:54 -06:00
|
|
|
pluginDashboardsLoad: (state, action: PayloadAction<undefined>) => {
|
|
|
|
state.isLoadingPluginDashboards = true;
|
|
|
|
state.dashboards = [];
|
2020-01-13 01:03:22 -06:00
|
|
|
},
|
2020-02-10 07:23:54 -06:00
|
|
|
pluginDashboardsLoaded: (state, action: PayloadAction<PluginDashboard[]>) => {
|
|
|
|
state.isLoadingPluginDashboards = false;
|
|
|
|
state.dashboards = action.payload;
|
|
|
|
},
|
|
|
|
panelPluginLoaded: (state, action: PayloadAction<PanelPlugin>) => {
|
|
|
|
state.panels[action.payload.meta!.id] = action.payload;
|
2020-01-13 01:03:22 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const {
|
|
|
|
pluginsLoaded,
|
2020-10-27 07:08:08 -05:00
|
|
|
pluginsErrorsLoaded,
|
2020-01-13 01:03:22 -06:00
|
|
|
pluginDashboardsLoad,
|
|
|
|
pluginDashboardsLoaded,
|
|
|
|
setPluginsSearchQuery,
|
2020-02-10 07:23:54 -06:00
|
|
|
panelPluginLoaded,
|
2020-01-13 01:03:22 -06:00
|
|
|
} = pluginsSlice.actions;
|
|
|
|
|
2021-09-13 08:00:41 -05:00
|
|
|
export const pluginsReducer: Reducer<PluginsState, AnyAction> = config.pluginAdminEnabled
|
|
|
|
? ((pluginCatalogReducer as unknown) as Reducer<PluginsState, AnyAction>)
|
|
|
|
: pluginsSlice.reducer;
|
2018-09-25 07:53:55 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
plugins: pluginsReducer,
|
|
|
|
};
|