Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for stream existence when displaying replay link #3387

Merged
merged 1 commit into from Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion graylog2-web-interface/src/components/widgets/Widget.jsx
Expand Up @@ -19,6 +19,7 @@ const Widget = React.createClass({
dashboardId: PropTypes.string.isRequired,
shouldUpdate: PropTypes.bool.isRequired,
locked: PropTypes.bool.isRequired,
streamIds: PropTypes.object,
},
getInitialState() {
this.widgetPlugin = this._getWidgetPlugin(this.props.widget.type);
Expand Down Expand Up @@ -202,6 +203,11 @@ const Widget = React.createClass({
onUpdate={this.updateWidget}/>
);

let disabledTooltip = null;
if (this.props.streamIds != null && this.props.widget.config.stream_id &&
!this.props.streamIds[this.props.widget.config.stream_id]) {
disabledTooltip = "The stream is not available, cannot replay search.";
}
return (
<div ref="widget" className="widget" data-widget-id={this.props.widget.id}>
<WidgetHeader ref="widgetHeader"
Expand All @@ -217,7 +223,8 @@ const Widget = React.createClass({
onShowConfig={this._showConfig}
onEditConfig={this._showEditConfig}
onDelete={this.deleteWidget}
replayHref={this.replayUrl()}/>
replayHref={this.replayUrl()}
replayToolTip={disabledTooltip}/>
{this.props.locked ? showConfigModal : editConfigModal}
</div>
);
Expand Down
22 changes: 18 additions & 4 deletions graylog2-web-interface/src/components/widgets/WidgetFooter.jsx
@@ -1,5 +1,5 @@
import React from 'react';
import { Button } from 'react-bootstrap';
import { Button, OverlayTrigger, Tooltip } from 'react-bootstrap';

const WidgetFooter = React.createClass({
propTypes: {
Expand All @@ -8,6 +8,7 @@ const WidgetFooter = React.createClass({
onEditConfig: React.PropTypes.func.isRequired,
onShowConfig: React.PropTypes.func.isRequired,
replayHref: React.PropTypes.string.isRequired,
replayToolTip: React.PropTypes.string,
},
_showConfig(e) {
e.preventDefault();
Expand All @@ -22,12 +23,25 @@ const WidgetFooter = React.createClass({
this.props.onDelete();
},
render() {
// if we have a tooltip, we disable the button link and instead show a tooltip on hover
const title = this.props.replayToolTip ? null : "Replay search";
const href = this.props.replayToolTip ? null : this.props.replayHref;
let replay = (
<Button bsStyle="link" className="btn-text" title={title} href={href}>
<i className="fa fa-play"/>
</Button>
);
if (this.props.replayToolTip) {
replay = (
<OverlayTrigger placement="bottom" overlay={<Tooltip id="tooltip">{this.props.replayToolTip}</Tooltip>}>
{replay}
</OverlayTrigger>
);
}
const lockedActions = (
<div className="actions">
<div className="widget-replay">
<Button bsStyle="link" className="btn-text" title="Replay search" href={this.props.replayHref}>
<i className="fa fa-play"/>
</Button>
{replay}
</div>
<div className="widget-info">
<Button bsStyle="link" className="btn-text" title="Show widget configuration" onClick={this._showConfig}>
Expand Down
12 changes: 11 additions & 1 deletion graylog2-web-interface/src/pages/ShowDashboardPage.jsx
Expand Up @@ -5,6 +5,7 @@ import { PluginStore } from 'graylog-web-plugin/plugin';
import deepEqual from 'deep-equal';

import StoreProvider from 'injection/StoreProvider';
const StreamsStore = StoreProvider.getStore('Streams');
const CurrentUserStore = StoreProvider.getStore('CurrentUser');
const DashboardsStore = StoreProvider.getStore('Dashboards');
const FocusStore = StoreProvider.getStore('Focus');
Expand All @@ -31,11 +32,20 @@ const ShowDashboardPage = React.createClass({
return {
locked: true,
forceUpdateInBackground: false,
streamIds: null,
};
},
componentDidMount() {
this.loadData();
this.listenTo(WidgetsStore, this.removeWidget);
// we use the stream ids to potentially disable search replay buttons for deleted streams
StreamsStore.load((streams) => {
let streamIds2 = streams.reduce((streamIds, stream) => {
streamIds[stream.id] = stream.id;
return streamIds;
}, {});
this.setState({ streamIds: streamIds2 });
});
this.loadInterval = setInterval(this.loadData, 2000);
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({ forceUpdateInBackground: this.state.currentUser.preferences.updateUnfocussed });
Expand Down Expand Up @@ -134,7 +144,7 @@ const ShowDashboardPage = React.createClass({
}).map((widget) => {
return (
<Widget id={widget.id} key={`widget-${widget.id}`} widget={widget} dashboardId={dashboard.id}
locked={this.state.locked} shouldUpdate={this.shouldUpdate()}/>
locked={this.state.locked} shouldUpdate={this.shouldUpdate()} streamIds={this.state.streamIds}/>
);
});

Expand Down