-
Notifications
You must be signed in to change notification settings - Fork 487
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
Improve search dropdowns #84
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import { handleActions } from 'redux-actions'; | ||
|
||
import { fetchServices, fetchServiceOperations as fetchOps } from '../actions/jaeger-api'; | ||
import { baseStringComparator } from '../utils/sort'; | ||
|
||
const initialState = { | ||
services: [], | ||
|
@@ -35,6 +36,9 @@ function fetchStarted(state) { | |
|
||
function fetchServicesDone(state, { payload }) { | ||
const services = payload.data; | ||
if (Array.isArray(services)) { | ||
services.sort(baseStringComparator); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, I think we should use lodash as much as we can on util stuff. It's well tested, easier to read and immutable. const sortedServices = _.sortBy(services, s => s)
// or if it was an obj { "name": "svc1" }
const sortedServices = _.sortBy(services, 'name') There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saminzadeh I would generally go with The sort util function is using I don't think lodash gets us anywhere, here, because it takes a transform function instead of a comparator. Can you elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than keeping things immutable (redux approach), I think its just about keeping it consistent. Both work, just my 2 cents. |
||
} | ||
return { ...state, services, error: null, loading: false }; | ||
} | ||
|
||
|
@@ -49,6 +53,9 @@ function fetchOpsStarted(state, { meta: { serviceName } }) { | |
|
||
function fetchOpsDone(state, { meta, payload }) { | ||
const { data: operations } = payload; | ||
if (Array.isArray(operations)) { | ||
operations.sort(baseStringComparator); | ||
} | ||
const operationsForService = { ...state.operationsForService, [meta.serviceName]: operations }; | ||
return { ...state, operationsForService }; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
export default function regexpEscape(s) { | ||
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a small comment with the use cases this escapes |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import regexpEscape from './regexp-escape'; | ||
|
||
describe('regexp-escape', () => { | ||
const chars = '-/\\^$*+?.()|[]{}'.split(''); | ||
chars.forEach(c => { | ||
it(`escapes "${c}" correctly`, () => { | ||
const result = regexpEscape(c); | ||
expect(result.length).toBe(2); | ||
expect(result[0]).toBe('\\'); | ||
expect(result[1]).toBe(c); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: Although this is pretty local in scope, name this to
rgx
or something else.rx is common used with RxJS