mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
component working
This commit is contained in:
parent
5f515bb3fc
commit
b7d821b524
@ -5,7 +5,7 @@ import EmptyListCTA from './components/EmptyListCTA/EmptyListCTA';
|
|||||||
import { SearchResult } from './components/search/SearchResult';
|
import { SearchResult } from './components/search/SearchResult';
|
||||||
import { TagFilter } from './components/TagFilter/TagFilter';
|
import { TagFilter } from './components/TagFilter/TagFilter';
|
||||||
import { SideMenu } from './components/sidemenu/SideMenu';
|
import { SideMenu } from './components/sidemenu/SideMenu';
|
||||||
import { AlertList } from './components/Alerts/AlertList';
|
import AlertList from './components/Alerts/AlertList';
|
||||||
|
|
||||||
export function registerAngularDirectives() {
|
export function registerAngularDirectives() {
|
||||||
react2AngularDirective('passwordStrength', PasswordStrength, ['password']);
|
react2AngularDirective('passwordStrength', PasswordStrength, ['password']);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
alerts: any[];
|
alerts: any[];
|
||||||
@ -10,7 +11,7 @@ export class AlertList extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const alerts = [{ severity: 'success', icon: 'warning', title: 'test', text: 'test text' }];
|
const { alerts } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -34,3 +35,11 @@ export class AlertList extends PureComponent<Props> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mapStateToProps(state) {
|
||||||
|
return {
|
||||||
|
alerts: state.alerts.alerts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(AlertList);
|
||||||
|
23
public/app/core/components/Alerts/state/actions.ts
Normal file
23
public/app/core/components/Alerts/state/actions.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { Alert } from 'app/types';
|
||||||
|
|
||||||
|
export enum ActionTypes {
|
||||||
|
AddAlert = 'ADD_ALERT',
|
||||||
|
ClearAlert = 'CLEAR_ALERT',
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddAlertAction {
|
||||||
|
type: ActionTypes.AddAlert;
|
||||||
|
payload: Alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ClearAlertAction {
|
||||||
|
type: ActionTypes.ClearAlert;
|
||||||
|
payload: Alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Action = AddAlertAction | ClearAlertAction;
|
||||||
|
|
||||||
|
export const clearAlert = (alert: Alert) => ({
|
||||||
|
type: ActionTypes.ClearAlert,
|
||||||
|
payload: alert,
|
||||||
|
});
|
41
public/app/core/components/Alerts/state/reducers.test.ts
Normal file
41
public/app/core/components/Alerts/state/reducers.test.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { alertsReducer } from './reducers';
|
||||||
|
import { ActionTypes } from './actions';
|
||||||
|
|
||||||
|
describe('clear alert', () => {
|
||||||
|
it('should filter alert', () => {
|
||||||
|
const initialState = {
|
||||||
|
alerts: [
|
||||||
|
{
|
||||||
|
severity: 'success',
|
||||||
|
icon: 'success',
|
||||||
|
title: 'test',
|
||||||
|
text: 'test alert',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
severity: 'fail',
|
||||||
|
icon: 'warning',
|
||||||
|
title: 'test2',
|
||||||
|
text: 'test alert fail 2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = alertsReducer(initialState, {
|
||||||
|
type: ActionTypes.ClearAlert,
|
||||||
|
payload: initialState.alerts[1],
|
||||||
|
});
|
||||||
|
|
||||||
|
const expectedResult = {
|
||||||
|
alerts: [
|
||||||
|
{
|
||||||
|
severity: 'success',
|
||||||
|
icon: 'success',
|
||||||
|
title: 'test',
|
||||||
|
text: 'test alert',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result).toEqual(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
23
public/app/core/components/Alerts/state/reducers.ts
Normal file
23
public/app/core/components/Alerts/state/reducers.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { Alert, AlertsState } from 'app/types';
|
||||||
|
import { Action, ActionTypes } from './actions';
|
||||||
|
|
||||||
|
export const initialState: AlertsState = {
|
||||||
|
alerts: [] as Alert[],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const alertsReducer = (state = initialState, action: Action): AlertsState => {
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionTypes.AddAlert:
|
||||||
|
return { ...state, alerts: state.alerts.concat([action.payload]) };
|
||||||
|
case ActionTypes.ClearAlert:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
alerts: state.alerts.filter(alert => alert !== action.payload),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
alerts: alertsReducer,
|
||||||
|
};
|
@ -20,8 +20,6 @@ export class AlertSrv {
|
|||||||
this.$rootScope
|
this.$rootScope
|
||||||
);
|
);
|
||||||
|
|
||||||
this.list.push({ severity: 'success', icon: 'warning', title: 'test', text: 'test text' });
|
|
||||||
|
|
||||||
this.$rootScope.onAppEvent(
|
this.$rootScope.onAppEvent(
|
||||||
'alert-warning',
|
'alert-warning',
|
||||||
(e, alert) => {
|
(e, alert) => {
|
||||||
|
10
public/app/types/alerts.ts
Normal file
10
public/app/types/alerts.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export interface Alert {
|
||||||
|
severity: string;
|
||||||
|
icon: string;
|
||||||
|
title: string;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AlertsState {
|
||||||
|
alerts: Alert[];
|
||||||
|
}
|
@ -9,6 +9,7 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
|
|||||||
import { Invitee, OrgUser, User, UsersState } from './user';
|
import { Invitee, OrgUser, User, UsersState } from './user';
|
||||||
import { DataSource, DataSourcesState } from './datasources';
|
import { DataSource, DataSourcesState } from './datasources';
|
||||||
import { PluginDashboard, PluginMeta, Plugin, PluginsState } from './plugins';
|
import { PluginDashboard, PluginMeta, Plugin, PluginsState } from './plugins';
|
||||||
|
import { Alert, AlertsState } from './alerts';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Team,
|
Team,
|
||||||
@ -46,6 +47,8 @@ export {
|
|||||||
User,
|
User,
|
||||||
UsersState,
|
UsersState,
|
||||||
PluginDashboard,
|
PluginDashboard,
|
||||||
|
Alert,
|
||||||
|
AlertsState,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface StoreState {
|
export interface StoreState {
|
||||||
@ -58,4 +61,5 @@ export interface StoreState {
|
|||||||
dashboard: DashboardState;
|
dashboard: DashboardState;
|
||||||
dataSources: DataSourcesState;
|
dataSources: DataSourcesState;
|
||||||
users: UsersState;
|
users: UsersState;
|
||||||
|
alerts: AlertsState;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user