|
|
|
@ -1,12 +1,12 @@ |
|
|
|
|
import React, { PureComponent } from 'react'; |
|
|
|
|
import { connect, ConnectedProps } from 'react-redux'; |
|
|
|
|
import { css } from '@emotion/css'; |
|
|
|
|
import React, { useEffect } from 'react'; |
|
|
|
|
|
|
|
|
|
import { AppEvents } from '@grafana/data'; |
|
|
|
|
import { VerticalGroup } from '@grafana/ui'; |
|
|
|
|
import { AppEvents, GrafanaTheme2 } from '@grafana/data'; |
|
|
|
|
import { useStyles2, VerticalGroup } from '@grafana/ui'; |
|
|
|
|
import { notifyApp, hideAppNotification } from 'app/core/actions'; |
|
|
|
|
import appEvents from 'app/core/app_events'; |
|
|
|
|
import { selectVisible } from 'app/core/reducers/appNotification'; |
|
|
|
|
import { StoreState } from 'app/types'; |
|
|
|
|
import { useSelector, useDispatch } from 'app/types'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
createErrorNotification, |
|
|
|
@ -16,53 +16,48 @@ import { |
|
|
|
|
|
|
|
|
|
import AppNotificationItem from './AppNotificationItem'; |
|
|
|
|
|
|
|
|
|
export interface OwnProps {} |
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: StoreState, props: OwnProps) => ({ |
|
|
|
|
appNotifications: selectVisible(state.appNotifications), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
|
notifyApp, |
|
|
|
|
hideAppNotification, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps); |
|
|
|
|
|
|
|
|
|
export type Props = OwnProps & ConnectedProps<typeof connector>; |
|
|
|
|
|
|
|
|
|
export class AppNotificationListUnConnected extends PureComponent<Props> { |
|
|
|
|
componentDidMount() { |
|
|
|
|
const { notifyApp } = this.props; |
|
|
|
|
export function AppNotificationList() { |
|
|
|
|
const appNotifications = useSelector((state) => selectVisible(state.appNotifications)); |
|
|
|
|
const dispatch = useDispatch(); |
|
|
|
|
const styles = useStyles2(getStyles); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
appEvents.on(AppEvents.alertWarning, (payload) => notifyApp(createWarningNotification(...payload))); |
|
|
|
|
appEvents.on(AppEvents.alertSuccess, (payload) => notifyApp(createSuccessNotification(...payload))); |
|
|
|
|
appEvents.on(AppEvents.alertError, (payload) => notifyApp(createErrorNotification(...payload))); |
|
|
|
|
} |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
onClearAppNotification = (id: string) => { |
|
|
|
|
this.props.hideAppNotification(id); |
|
|
|
|
const onClearAppNotification = (id: string) => { |
|
|
|
|
dispatch(hideAppNotification(id)); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const { appNotifications } = this.props; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div className="page-alert-list"> |
|
|
|
|
<VerticalGroup> |
|
|
|
|
{appNotifications.map((appNotification, index) => { |
|
|
|
|
return ( |
|
|
|
|
<AppNotificationItem |
|
|
|
|
key={`${appNotification.id}-${index}`} |
|
|
|
|
appNotification={appNotification} |
|
|
|
|
onClearNotification={(id) => this.onClearAppNotification(id)} |
|
|
|
|
/> |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
|
</VerticalGroup> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
return ( |
|
|
|
|
<div className={styles.wrapper}> |
|
|
|
|
<VerticalGroup> |
|
|
|
|
{appNotifications.map((appNotification, index) => { |
|
|
|
|
return ( |
|
|
|
|
<AppNotificationItem |
|
|
|
|
key={`${appNotification.id}-${index}`} |
|
|
|
|
appNotification={appNotification} |
|
|
|
|
onClearNotification={onClearAppNotification} |
|
|
|
|
/> |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
|
</VerticalGroup> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const AppNotificationList = connector(AppNotificationListUnConnected); |
|
|
|
|
function getStyles(theme: GrafanaTheme2) { |
|
|
|
|
return { |
|
|
|
|
wrapper: css({ |
|
|
|
|
label: 'app-notifications-list', |
|
|
|
|
zIndex: theme.zIndex.portal, |
|
|
|
|
minWidth: 400, |
|
|
|
|
maxWidth: 600, |
|
|
|
|
position: 'fixed', |
|
|
|
|
right: 6, |
|
|
|
|
top: 88, |
|
|
|
|
}), |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|