Skip to content

Commit df12ead

Browse files
authored
Merge pull request #111 from jaegertracing/issue-88-stored-search-settings
Verify stored search settings
2 parents cec107f + 21abefd commit df12ead

File tree

4 files changed

+77
-44
lines changed

4 files changed

+77
-44
lines changed

src/components/SearchTracePage/TraceSearchForm.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,19 @@ const mapStateToProps = state => {
223223
let lastSearchOperation;
224224

225225
if (lastSearch) {
226-
lastSearchService = lastSearch.service;
227-
lastSearchOperation = lastSearch.operation;
226+
// last search is only valid if the service is in the list of services
227+
const { operation: lastOp, service: lastSvc } = lastSearch;
228+
if (lastSvc && lastSvc !== '-') {
229+
if (state.services.services.includes(lastSvc)) {
230+
lastSearchService = lastSvc;
231+
if (lastOp && lastOp !== '-') {
232+
const ops = state.services.operationsForService[lastSvc];
233+
if (lastOp === 'all' || (ops && ops.includes(lastOp))) {
234+
lastSearchOperation = lastOp;
235+
}
236+
}
237+
}
238+
}
228239
}
229240

230241
const {
@@ -242,6 +253,7 @@ const mapStateToProps = state => {
242253
if (traceIDParams) {
243254
traceIDs = traceIDParams instanceof Array ? traceIDParams.join(',') : traceIDParams;
244255
}
256+
245257
return {
246258
destroyOnUnmount: false,
247259
initialValues: {

src/components/SearchTracePage/index.js

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import React, { Component } from 'react';
1516
import _values from 'lodash/values';
1617
import PropTypes from 'prop-types';
17-
import React, { Component } from 'react';
1818
import queryString from 'query-string';
19-
import { bindActionCreators } from 'redux';
2019
import { connect } from 'react-redux';
21-
import { Field, reduxForm, formValueSelector } from 'redux-form';
2220
import { Link } from 'react-router-dom';
21+
import { bindActionCreators } from 'redux';
22+
import { Field, reduxForm, formValueSelector } from 'redux-form';
23+
import store from 'store';
2324

2425
import JaegerLogo from '../../img/jaeger-logo.svg';
2526

@@ -61,35 +62,45 @@ const traceResultsFiltersFormSelector = formValueSelector('traceResultsFilters')
6162

6263
export default class SearchTracePage extends Component {
6364
componentDidMount() {
64-
const { searchTraces, urlQueryParams, fetchServices } = this.props;
65+
const { searchTraces, urlQueryParams, fetchServices, fetchServiceOperations } = this.props;
6566
if (urlQueryParams.service || urlQueryParams.traceID) {
6667
searchTraces(urlQueryParams);
6768
}
6869
fetchServices();
70+
const { service } = store.get('lastSearch') || {};
71+
if (service && service !== '-') {
72+
fetchServiceOperations(service);
73+
}
6974
}
75+
7076
render() {
7177
const {
72-
traceResults,
73-
services,
74-
numberOfTraceResults,
75-
maxTraceDuration,
76-
loading,
7778
errorMessage,
7879
isHomepage,
80+
loadingServices,
81+
loadingTraces,
82+
maxTraceDuration,
83+
numberOfTraceResults,
84+
services,
85+
traceResults,
7986
} = this.props;
8087
const hasTraceResults = traceResults && traceResults.length > 0;
8188
return (
8289
<div className="trace-search ui grid padded">
8390
<div className="four wide column">
8491
<div className="ui tertiary segment" style={{ background: 'whitesmoke' }}>
8592
<h3>Find Traces</h3>
86-
<TraceSearchForm services={services} />
93+
{!loadingServices && services
94+
? <TraceSearchForm services={services} />
95+
: <div className="m1">
96+
<div className="ui active centered inline loader" />
97+
</div>}
8798
</div>
8899
</div>
89100
<div className="twelve wide column padded">
90-
{loading && <div className="ui active centered inline loader" />}
101+
{loadingTraces && <div className="ui active centered inline loader" />}
91102
{errorMessage &&
92-
!loading &&
103+
!loadingTraces &&
93104
<div className="ui message red trace-search--error">
94105
There was an error querying for traces:<br />
95106
{errorMessage}
@@ -103,11 +114,11 @@ export default class SearchTracePage extends Component {
103114
</div>}
104115
{!isHomepage &&
105116
!hasTraceResults &&
106-
!loading &&
117+
!loadingTraces &&
107118
!errorMessage &&
108119
<div className="ui message trace-search--no-results">No trace results. Try another query.</div>}
109120
{hasTraceResults &&
110-
!loading &&
121+
!loadingTraces &&
111122
<div>
112123
<div>
113124
<div style={{ border: '1px solid #e6e6e6' }}>
@@ -165,7 +176,8 @@ SearchTracePage.propTypes = {
165176
traceResults: PropTypes.array,
166177
numberOfTraceResults: PropTypes.number,
167178
maxTraceDuration: PropTypes.number,
168-
loading: PropTypes.bool,
179+
loadingServices: PropTypes.bool,
180+
loadingTraces: PropTypes.bool,
169181
urlQueryParams: PropTypes.shape({
170182
service: PropTypes.string,
171183
limit: PropTypes.string,
@@ -180,30 +192,38 @@ SearchTracePage.propTypes = {
180192
history: PropTypes.shape({
181193
push: PropTypes.func,
182194
}),
195+
fetchServiceOperations: PropTypes.func,
183196
fetchServices: PropTypes.func,
184197
errorMessage: PropTypes.string,
185198
};
186199

187200
const stateTraceXformer = getLastXformCacher(stateTrace => {
188-
const { traces: traceMap, loading, error: traceError } = stateTrace;
201+
const { traces: traceMap, loading: loadingTraces, error: traceError } = stateTrace;
189202
const { traces, maxDuration } = getTraceSummaries(_values(traceMap));
190-
return { traces, maxDuration, loading, traceError };
203+
return { traces, maxDuration, traceError, loadingTraces };
191204
});
192205

193206
const stateServicesXformer = getLastXformCacher(stateServices => {
194-
const { services: serviceList, operationsForService: opsBySvc, error: serviceError } = stateServices;
195-
const services = serviceList.map(name => ({
196-
name,
197-
operations: opsBySvc[name] || [],
198-
}));
199-
return { services, serviceError };
207+
const {
208+
loading: loadingServices,
209+
services: serviceList,
210+
operationsForService: opsBySvc,
211+
error: serviceError,
212+
} = stateServices;
213+
const services =
214+
serviceList &&
215+
serviceList.map(name => ({
216+
name,
217+
operations: opsBySvc[name] || [],
218+
}));
219+
return { loadingServices, services, serviceError };
200220
});
201221

202222
function mapStateToProps(state) {
203223
const query = queryString.parse(state.router.location.search);
204224
const isHomepage = !Object.keys(query).length;
205-
const { traces, maxDuration, loading, traceError } = stateTraceXformer(state.trace);
206-
const { services, serviceError } = stateServicesXformer(state.services);
225+
const { traces, maxDuration, traceError, loadingTraces } = stateTraceXformer(state.trace);
226+
const { loadingServices, services, serviceError } = stateServicesXformer(state.services);
207227
const errorMessage = serviceError || traceError ? `${serviceError || ''} ${traceError || ''}` : '';
208228
const sortBy = traceResultsFiltersFormSelector(state, 'sortBy');
209229
sortTraces(traces, sortBy);
@@ -216,16 +236,21 @@ function mapStateToProps(state) {
216236
maxTraceDuration: maxDuration,
217237
urlQueryParams: query,
218238
services,
219-
loading,
239+
loadingTraces,
240+
loadingServices,
220241
errorMessage,
221242
};
222243
}
223244

224245
function mapDispatchToProps(dispatch) {
225-
const { searchTraces, fetchServices } = bindActionCreators(jaegerApiActions, dispatch);
246+
const { searchTraces, fetchServices, fetchServiceOperations } = bindActionCreators(
247+
jaegerApiActions,
248+
dispatch
249+
);
226250
return {
227-
searchTraces,
251+
fetchServiceOperations,
228252
fetchServices,
253+
searchTraces,
229254
};
230255
}
231256
export const ConnectedSearchTracePage = connect(mapStateToProps, mapDispatchToProps)(SearchTracePage);

src/reducers/services.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { fetchServices, fetchServiceOperations as fetchOps } from '../actions/ja
1818
import { baseStringComparator } from '../utils/sort';
1919

2020
const initialState = {
21-
services: [],
21+
// `services` initial value of `null` indicates they haven't yet been loaded
22+
services: null,
2223
operationsForService: {},
2324
loading: false,
2425
error: null,
@@ -48,7 +49,7 @@ function fetchOpsDone(state, { meta, payload }) {
4849
if (Array.isArray(operations)) {
4950
operations.sort(baseStringComparator);
5051
}
51-
const operationsForService = { ...state.operationsForService, [meta.serviceName]: operations };
52+
const operationsForService = { ...state.operationsForService, [meta.serviceName]: operations || [] };
5253
return { ...state, operationsForService };
5354
}
5455

src/reducers/services.test.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const initialState = serviceReducer(undefined, {});
1919

2020
function verifyInitialState() {
2121
expect(initialState).toEqual({
22-
services: [],
22+
services: null,
2323
loading: false,
2424
error: null,
2525
operationsForService: {},
@@ -47,12 +47,8 @@ it('should handle a fetch services with loading state', () => {
4747
const state = serviceReducer(initialState, {
4848
type: `${fetchServices}_PENDING`,
4949
});
50-
expect(state).toEqual({
51-
services: [],
52-
operationsForService: {},
53-
loading: true,
54-
error: null,
55-
});
50+
const expected = { ...initialState, loading: true };
51+
expect(state).toEqual(expected);
5652
});
5753

5854
it('should handle successful services fetch', () => {
@@ -90,12 +86,11 @@ it('should handle a successful fetching operations for a service ', () => {
9086
meta: { serviceName: 'serviceA' },
9187
payload: { data: ops.slice() },
9288
});
93-
expect(state).toEqual({
94-
services: [],
89+
const expected = {
90+
...initialState,
9591
operationsForService: {
9692
serviceA: ops,
9793
},
98-
loading: false,
99-
error: null,
100-
});
94+
};
95+
expect(state).toEqual(expected);
10196
});

0 commit comments

Comments
 (0)