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

Fix field analyzers loading when search changes #2997

Merged
merged 2 commits into from Oct 28, 2016
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
Expand Up @@ -15,6 +15,10 @@ const RefreshStore = StoreProvider.getStore('Refresh');
const FieldQuickValues = React.createClass({
propTypes: {
permissions: PropTypes.arrayOf(PropTypes.string).isRequired,
query: React.PropTypes.string.isRequired,
rangeType: React.PropTypes.string.isRequired,
rangeParams: React.PropTypes.object.isRequired,
stream: PropTypes.object,
},
mixins: [Reflux.listenTo(RefreshStore, '_setupTimer', '_setupTimer')],
getInitialState() {
Expand All @@ -27,6 +31,15 @@ const FieldQuickValues = React.createClass({
componentDidMount() {
this._loadQuickValuesData();
},
componentWillReceiveProps(nextProps) {
// Reload values when executed search changes
if (this.props.query !== nextProps.query ||
this.props.rangeType !== nextProps.rangeType ||
JSON.stringify(this.props.rangeParams) !== JSON.stringify(nextProps.rangeParams) ||
this.props.stream !== nextProps.stream) {
this._loadQuickValuesData();
}
},
componentDidUpdate(oldProps, oldState) {
if (this.state.field !== oldState.field) {
const element = ReactDOM.findDOMNode(this);
Expand Down
Expand Up @@ -15,6 +15,10 @@ import UserNotification from 'util/UserNotification';
const FieldStatistics = React.createClass({
propTypes: {
permissions: PropTypes.arrayOf(PropTypes.string).isRequired,
query: React.PropTypes.string.isRequired,
rangeType: React.PropTypes.string.isRequired,
rangeParams: React.PropTypes.object.isRequired,
stream: PropTypes.object,
},
mixins: [Reflux.listenTo(RefreshStore, '_setupTimer', '_setupTimer')],

Expand All @@ -27,6 +31,16 @@ const FieldStatistics = React.createClass({
};
},

componentWillReceiveProps(nextProps) {
// Reload values when executed search changes
if (this.props.query !== nextProps.query ||
this.props.rangeType !== nextProps.rangeType ||
JSON.stringify(this.props.rangeParams) !== JSON.stringify(nextProps.rangeParams) ||
this.props.stream !== nextProps.stream) {
this._reloadAllStatistics();
}
},

WIDGET_TYPE: 'STATS_COUNT',

_setupTimer(refresh) {
Expand Down
17 changes: 13 additions & 4 deletions graylog2-web-interface/src/components/search/SearchResult.jsx
Expand Up @@ -104,16 +104,25 @@ const SearchResult = React.createClass({
},

_fieldAnalyzerComponents(filter) {
// Get params used in the last executed search.
const searchParams = SearchStore.getOriginalSearchURLParams().toJS();
const rangeParams = {};
['relative', 'from', 'to', 'keyword'].forEach(param => {
if (searchParams[param]) {
rangeParams[param] = searchParams[param];
}
});

return this._fieldAnalyzers(filter)
.map((analyzer, idx) => {
return React.createElement(analyzer.component, {
key: idx,
ref: analyzer.refId,
permissions: this.props.permissions,
query: SearchStore.query,
page: SearchStore.page,
rangeType: SearchStore.rangeType,
rangeParams: SearchStore.rangeParams.toJS(),
query: searchParams.q,
page: searchParams.page,
rangeType: searchParams.rangetype,
rangeParams: rangeParams,
stream: this.props.searchInStream,
resolution: this.props.histogram.interval,
from: this.props.histogram.histogram_boundaries.from,
Expand Down