mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
chore: Fix typings and add Page-component to DataSourceDashboards #14762
This commit is contained in:
parent
acbcca1102
commit
e448a140f5
@ -14,6 +14,7 @@ const setup = (propOverrides?: object) => {
|
|||||||
loadDataSource: jest.fn(),
|
loadDataSource: jest.fn(),
|
||||||
loadPluginDashboards: jest.fn(),
|
loadPluginDashboards: jest.fn(),
|
||||||
removeDashboard: jest.fn(),
|
removeDashboard: jest.fn(),
|
||||||
|
isLoading: false
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(props, propOverrides);
|
Object.assign(props, propOverrides);
|
||||||
|
@ -4,7 +4,7 @@ import { hot } from 'react-hot-loader';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import PageHeader from 'app/core/components/PageHeader/PageHeader';
|
import Page from 'app/core/components/Page/Page';
|
||||||
import DashboardTable from './DashboardsTable';
|
import DashboardTable from './DashboardsTable';
|
||||||
|
|
||||||
// Actions & Selectors
|
// Actions & Selectors
|
||||||
@ -16,7 +16,7 @@ import { importDashboard, removeDashboard } from '../dashboard/state/actions';
|
|||||||
import { getDataSource } from './state/selectors';
|
import { getDataSource } from './state/selectors';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { NavModel, PluginDashboard } from 'app/types';
|
import { NavModel, PluginDashboard, StoreState } from 'app/types';
|
||||||
import { DataSourceSettings } from '@grafana/ui/src/types';
|
import { DataSourceSettings } from '@grafana/ui/src/types';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
@ -28,6 +28,7 @@ export interface Props {
|
|||||||
loadDataSource: typeof loadDataSource;
|
loadDataSource: typeof loadDataSource;
|
||||||
loadPluginDashboards: typeof loadPluginDashboards;
|
loadPluginDashboards: typeof loadPluginDashboards;
|
||||||
removeDashboard: typeof removeDashboard;
|
removeDashboard: typeof removeDashboard;
|
||||||
|
isLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DataSourceDashboards extends PureComponent<Props> {
|
export class DataSourceDashboards extends PureComponent<Props> {
|
||||||
@ -64,30 +65,30 @@ export class DataSourceDashboards extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { dashboards, navModel } = this.props;
|
const { dashboards, navModel, isLoading } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<Page navModel={navModel}>
|
||||||
<PageHeader model={navModel} />
|
<Page.Contents isLoading={isLoading}>
|
||||||
<div className="page-container page-body">
|
|
||||||
<DashboardTable
|
<DashboardTable
|
||||||
dashboards={dashboards}
|
dashboards={dashboards}
|
||||||
onImport={(dashboard, overwrite) => this.onImport(dashboard, overwrite)}
|
onImport={(dashboard, overwrite) => this.onImport(dashboard, overwrite)}
|
||||||
onRemove={dashboard => this.onRemove(dashboard)}
|
onRemove={dashboard => this.onRemove(dashboard)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</div>
|
</Page.Contents>
|
||||||
|
</Page>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state: StoreState) {
|
||||||
const pageId = getRouteParamsId(state.location);
|
const pageId = getRouteParamsId(state.location);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
navModel: getNavModel(state.navIndex, `datasource-dashboards-${pageId}`),
|
navModel: getNavModel(state.navIndex, `datasource-dashboards-${pageId}`),
|
||||||
pageId: pageId,
|
pageId: pageId,
|
||||||
dashboards: state.plugins.dashboards,
|
dashboards: state.plugins.dashboards,
|
||||||
dataSource: getDataSource(state.dataSources, pageId),
|
dataSource: getDataSource(state.dataSources, pageId),
|
||||||
|
isLoading: state.plugins.isLoadingPluginDashboards
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Render should render component 1`] = `
|
exports[`Render should render component 1`] = `
|
||||||
<div>
|
<Page
|
||||||
<PageHeader
|
navModel={Object {}}
|
||||||
model={Object {}}
|
>
|
||||||
/>
|
<PageContents
|
||||||
<div
|
isLoading={false}
|
||||||
className="page-container page-body"
|
|
||||||
>
|
>
|
||||||
<DashboardsTable
|
<DashboardsTable
|
||||||
dashboards={Array []}
|
dashboards={Array []}
|
||||||
onImport={[Function]}
|
onImport={[Function]}
|
||||||
onRemove={[Function]}
|
onRemove={[Function]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</PageContents>
|
||||||
</div>
|
</Page>
|
||||||
`;
|
`;
|
||||||
|
@ -7,6 +7,7 @@ import { PluginDashboard } from '../../../types/plugins';
|
|||||||
export enum ActionTypes {
|
export enum ActionTypes {
|
||||||
LoadPlugins = 'LOAD_PLUGINS',
|
LoadPlugins = 'LOAD_PLUGINS',
|
||||||
LoadPluginDashboards = 'LOAD_PLUGIN_DASHBOARDS',
|
LoadPluginDashboards = 'LOAD_PLUGIN_DASHBOARDS',
|
||||||
|
LoadedPluginDashboards = 'LOADED_PLUGIN_DASHBOARDS',
|
||||||
SetPluginsSearchQuery = 'SET_PLUGIN_SEARCH_QUERY',
|
SetPluginsSearchQuery = 'SET_PLUGIN_SEARCH_QUERY',
|
||||||
SetLayoutMode = 'SET_LAYOUT_MODE',
|
SetLayoutMode = 'SET_LAYOUT_MODE',
|
||||||
}
|
}
|
||||||
@ -18,6 +19,10 @@ export interface LoadPluginsAction {
|
|||||||
|
|
||||||
export interface LoadPluginDashboardsAction {
|
export interface LoadPluginDashboardsAction {
|
||||||
type: ActionTypes.LoadPluginDashboards;
|
type: ActionTypes.LoadPluginDashboards;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LoadedPluginDashboardsAction {
|
||||||
|
type: ActionTypes.LoadedPluginDashboards;
|
||||||
payload: PluginDashboard[];
|
payload: PluginDashboard[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,12 +51,20 @@ const pluginsLoaded = (plugins: Plugin[]): LoadPluginsAction => ({
|
|||||||
payload: plugins,
|
payload: plugins,
|
||||||
});
|
});
|
||||||
|
|
||||||
const pluginDashboardsLoaded = (dashboards: PluginDashboard[]): LoadPluginDashboardsAction => ({
|
const pluginDashboardsLoad = (): LoadPluginDashboardsAction => ({
|
||||||
type: ActionTypes.LoadPluginDashboards,
|
type: ActionTypes.LoadPluginDashboards,
|
||||||
|
});
|
||||||
|
|
||||||
|
const pluginDashboardsLoaded = (dashboards: PluginDashboard[]): LoadedPluginDashboardsAction => ({
|
||||||
|
type: ActionTypes.LoadedPluginDashboards,
|
||||||
payload: dashboards,
|
payload: dashboards,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Action = LoadPluginsAction | LoadPluginDashboardsAction | SetPluginsSearchQueryAction | SetLayoutModeAction;
|
export type Action = LoadPluginsAction
|
||||||
|
| LoadPluginDashboardsAction
|
||||||
|
| LoadedPluginDashboardsAction
|
||||||
|
| SetPluginsSearchQueryAction
|
||||||
|
| SetLayoutModeAction;
|
||||||
|
|
||||||
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
|
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
|
||||||
|
|
||||||
@ -64,8 +77,8 @@ export function loadPlugins(): ThunkResult<void> {
|
|||||||
|
|
||||||
export function loadPluginDashboards(): ThunkResult<void> {
|
export function loadPluginDashboards(): ThunkResult<void> {
|
||||||
return async (dispatch, getStore) => {
|
return async (dispatch, getStore) => {
|
||||||
|
dispatch(pluginDashboardsLoad());
|
||||||
const dataSourceType = getStore().dataSources.dataSource.type;
|
const dataSourceType = getStore().dataSources.dataSource.type;
|
||||||
|
|
||||||
const response = await getBackendSrv().get(`api/plugins/${dataSourceType}/dashboards`);
|
const response = await getBackendSrv().get(`api/plugins/${dataSourceType}/dashboards`);
|
||||||
dispatch(pluginDashboardsLoaded(response));
|
dispatch(pluginDashboardsLoaded(response));
|
||||||
};
|
};
|
||||||
|
@ -9,6 +9,7 @@ export const initialState: PluginsState = {
|
|||||||
layoutMode: LayoutModes.Grid,
|
layoutMode: LayoutModes.Grid,
|
||||||
hasFetched: false,
|
hasFetched: false,
|
||||||
dashboards: [] as PluginDashboard[],
|
dashboards: [] as PluginDashboard[],
|
||||||
|
isLoadingPluginDashboards: false
|
||||||
};
|
};
|
||||||
|
|
||||||
export const pluginsReducer = (state = initialState, action: Action): PluginsState => {
|
export const pluginsReducer = (state = initialState, action: Action): PluginsState => {
|
||||||
@ -23,7 +24,10 @@ export const pluginsReducer = (state = initialState, action: Action): PluginsSta
|
|||||||
return { ...state, layoutMode: action.payload };
|
return { ...state, layoutMode: action.payload };
|
||||||
|
|
||||||
case ActionTypes.LoadPluginDashboards:
|
case ActionTypes.LoadPluginDashboards:
|
||||||
return { ...state, dashboards: action.payload };
|
return { ...state, dashboards: [], isLoadingPluginDashboards: true };
|
||||||
|
|
||||||
|
case ActionTypes.LoadedPluginDashboards:
|
||||||
|
return { ...state, dashboards: action.payload, isLoadingPluginDashboards: false };
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
@ -47,6 +47,7 @@ export interface PluginsState {
|
|||||||
layoutMode: string;
|
layoutMode: string;
|
||||||
hasFetched: boolean;
|
hasFetched: boolean;
|
||||||
dashboards: PluginDashboard[];
|
dashboards: PluginDashboard[];
|
||||||
|
isLoadingPluginDashboards: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VariableQueryProps {
|
export interface VariableQueryProps {
|
||||||
|
Loading…
Reference in New Issue
Block a user